summaryrefslogtreecommitdiff
path: root/lang/sql/sqlite/test
diff options
context:
space:
mode:
Diffstat (limited to 'lang/sql/sqlite/test')
-rw-r--r--lang/sql/sqlite/test/8_3_names.test197
-rw-r--r--lang/sql/sqlite/test/aggnested.test231
-rw-r--r--lang/sql/sqlite/test/all.test4
-rw-r--r--lang/sql/sqlite/test/alter.test30
-rw-r--r--lang/sql/sqlite/test/alter2.test5
-rw-r--r--lang/sql/sqlite/test/alter3.test6
-rw-r--r--lang/sql/sqlite/test/alter4.test11
-rw-r--r--lang/sql/sqlite/test/amatch1.test117
-rw-r--r--lang/sql/sqlite/test/analyze.test60
-rw-r--r--lang/sql/sqlite/test/analyze2.test554
-rw-r--r--lang/sql/sqlite/test/analyze3.test76
-rw-r--r--lang/sql/sqlite/test/analyze4.test2
-rw-r--r--lang/sql/sqlite/test/analyze5.test208
-rw-r--r--lang/sql/sqlite/test/analyze6.test36
-rw-r--r--lang/sql/sqlite/test/analyze7.test51
-rw-r--r--lang/sql/sqlite/test/analyze8.test115
-rw-r--r--lang/sql/sqlite/test/analyze9.test953
-rw-r--r--lang/sql/sqlite/test/analyzeA.test167
-rw-r--r--lang/sql/sqlite/test/analyzeB.test683
-rw-r--r--lang/sql/sqlite/test/async.test2
-rw-r--r--lang/sql/sqlite/test/async2.test2
-rw-r--r--lang/sql/sqlite/test/async3.test4
-rw-r--r--lang/sql/sqlite/test/async5.test3
-rw-r--r--lang/sql/sqlite/test/atof1.test60
-rw-r--r--lang/sql/sqlite/test/attach.test41
-rw-r--r--lang/sql/sqlite/test/attach2.test11
-rw-r--r--lang/sql/sqlite/test/attach3.test5
-rw-r--r--lang/sql/sqlite/test/attach4.test6
-rw-r--r--lang/sql/sqlite/test/attachmalloc.test8
-rw-r--r--lang/sql/sqlite/test/auth.test79
-rw-r--r--lang/sql/sqlite/test/auth2.test14
-rw-r--r--lang/sql/sqlite/test/autoinc.test8
-rw-r--r--lang/sql/sqlite/test/autoindex1.test187
-rw-r--r--lang/sql/sqlite/test/autovacuum.test12
-rw-r--r--lang/sql/sqlite/test/autovacuum_ioerr2.test8
-rw-r--r--lang/sql/sqlite/test/backcompat.test380
-rw-r--r--lang/sql/sqlite/test/backup.test54
-rw-r--r--lang/sql/sqlite/test/backup2.test39
-rw-r--r--lang/sql/sqlite/test/backup4.test103
-rw-r--r--lang/sql/sqlite/test/backup_ioerr.test10
-rw-r--r--lang/sql/sqlite/test/bc_common.tcl72
-rw-r--r--lang/sql/sqlite/test/between.test24
-rw-r--r--lang/sql/sqlite/test/bigfile.test9
-rw-r--r--lang/sql/sqlite/test/bigfile2.test62
-rw-r--r--lang/sql/sqlite/test/boundary3.tcl17
-rw-r--r--lang/sql/sqlite/test/btreefault.test57
-rw-r--r--lang/sql/sqlite/test/cache.test4
-rw-r--r--lang/sql/sqlite/test/capi2.test16
-rw-r--r--lang/sql/sqlite/test/capi3.test78
-rw-r--r--lang/sql/sqlite/test/capi3c.test65
-rw-r--r--lang/sql/sqlite/test/capi3d.test33
-rw-r--r--lang/sql/sqlite/test/capi3e.test2
-rw-r--r--lang/sql/sqlite/test/cast.test10
-rw-r--r--lang/sql/sqlite/test/check.test120
-rw-r--r--lang/sql/sqlite/test/close.test78
-rw-r--r--lang/sql/sqlite/test/closure01.test276
-rw-r--r--lang/sql/sqlite/test/collate1.test29
-rw-r--r--lang/sql/sqlite/test/collate2.test34
-rw-r--r--lang/sql/sqlite/test/collate3.test98
-rw-r--r--lang/sql/sqlite/test/collate4.test45
-rw-r--r--lang/sql/sqlite/test/collate5.test10
-rw-r--r--lang/sql/sqlite/test/collate7.test2
-rw-r--r--lang/sql/sqlite/test/conflict.test44
-rw-r--r--lang/sql/sqlite/test/conflict2.test855
-rw-r--r--lang/sql/sqlite/test/conflict3.test356
-rw-r--r--lang/sql/sqlite/test/contrib01.test90
-rw-r--r--lang/sql/sqlite/test/corrupt.test36
-rw-r--r--lang/sql/sqlite/test/corrupt2.test46
-rw-r--r--lang/sql/sqlite/test/corrupt3.test6
-rw-r--r--lang/sql/sqlite/test/corrupt4.test4
-rw-r--r--lang/sql/sqlite/test/corrupt5.test4
-rw-r--r--lang/sql/sqlite/test/corrupt6.test4
-rw-r--r--lang/sql/sqlite/test/corrupt7.test4
-rw-r--r--lang/sql/sqlite/test/corrupt8.test4
-rw-r--r--lang/sql/sqlite/test/corrupt9.test10
-rw-r--r--lang/sql/sqlite/test/corruptA.test14
-rw-r--r--lang/sql/sqlite/test/corruptB.test20
-rw-r--r--lang/sql/sqlite/test/corruptC.test52
-rw-r--r--lang/sql/sqlite/test/corruptD.test12
-rw-r--r--lang/sql/sqlite/test/corruptE.test26
-rw-r--r--lang/sql/sqlite/test/corruptF.test153
-rw-r--r--lang/sql/sqlite/test/corruptG.test81
-rw-r--r--lang/sql/sqlite/test/corruptH.test176
-rw-r--r--lang/sql/sqlite/test/count.test10
-rw-r--r--lang/sql/sqlite/test/coveridxscan.test93
-rw-r--r--lang/sql/sqlite/test/crash.test8
-rw-r--r--lang/sql/sqlite/test/crash3.test6
-rw-r--r--lang/sql/sqlite/test/crash4.test2
-rw-r--r--lang/sql/sqlite/test/crash5.test8
-rw-r--r--lang/sql/sqlite/test/crash6.test6
-rw-r--r--lang/sql/sqlite/test/crash7.test36
-rw-r--r--lang/sql/sqlite/test/crash8.test120
-rw-r--r--lang/sql/sqlite/test/createtab.test2
-rw-r--r--lang/sql/sqlite/test/date.test25
-rw-r--r--lang/sql/sqlite/test/dbstatus.test41
-rw-r--r--lang/sql/sqlite/test/dbstatus2.test102
-rw-r--r--lang/sql/sqlite/test/default.test35
-rw-r--r--lang/sql/sqlite/test/delete.test6
-rw-r--r--lang/sql/sqlite/test/descidx1.test10
-rw-r--r--lang/sql/sqlite/test/descidx3.test6
-rw-r--r--lang/sql/sqlite/test/diskfull.test4
-rw-r--r--lang/sql/sqlite/test/distinct.test200
-rw-r--r--lang/sql/sqlite/test/e_createtable.test213
-rw-r--r--lang/sql/sqlite/test/e_delete.test14
-rw-r--r--lang/sql/sqlite/test/e_droptrigger.test2
-rw-r--r--lang/sql/sqlite/test/e_dropview.test2
-rw-r--r--lang/sql/sqlite/test/e_expr.test100
-rw-r--r--lang/sql/sqlite/test/e_fkey.test252
-rw-r--r--lang/sql/sqlite/test/e_fts3.test4
-rw-r--r--lang/sql/sqlite/test/e_insert.test60
-rw-r--r--lang/sql/sqlite/test/e_reindex.test16
-rw-r--r--lang/sql/sqlite/test/e_select.test175
-rw-r--r--lang/sql/sqlite/test/e_select2.test34
-rw-r--r--lang/sql/sqlite/test/e_update.test31
-rw-r--r--lang/sql/sqlite/test/e_uri.test457
-rw-r--r--lang/sql/sqlite/test/e_vacuum.test4
-rw-r--r--lang/sql/sqlite/test/enc2.test28
-rw-r--r--lang/sql/sqlite/test/enc3.test4
-rw-r--r--lang/sql/sqlite/test/enc4.test276
-rw-r--r--lang/sql/sqlite/test/eqp.test372
-rw-r--r--lang/sql/sqlite/test/errmsg.test118
-rw-r--r--lang/sql/sqlite/test/exclusive.test17
-rw-r--r--lang/sql/sqlite/test/exclusive2.test13
-rw-r--r--lang/sql/sqlite/test/exists.test2
-rw-r--r--lang/sql/sqlite/test/expr.test111
-rw-r--r--lang/sql/sqlite/test/fallocate.test3
-rw-r--r--lang/sql/sqlite/test/filectrl.test10
-rw-r--r--lang/sql/sqlite/test/filefmt.test44
-rw-r--r--lang/sql/sqlite/test/fkey1.test3
-rw-r--r--lang/sql/sqlite/test/fkey2.test186
-rw-r--r--lang/sql/sqlite/test/fkey3.test110
-rw-r--r--lang/sql/sqlite/test/fkey4.test2
-rw-r--r--lang/sql/sqlite/test/fkey5.test363
-rw-r--r--lang/sql/sqlite/test/fkey6.test175
-rw-r--r--lang/sql/sqlite/test/fkey7.test54
-rw-r--r--lang/sql/sqlite/test/fkey_malloc.test8
-rw-r--r--lang/sql/sqlite/test/fts-9fd058691.test59
-rw-r--r--lang/sql/sqlite/test/fts1j.test6
-rw-r--r--lang/sql/sqlite/test/fts1o.test2
-rw-r--r--lang/sql/sqlite/test/fts2j.test6
-rw-r--r--lang/sql/sqlite/test/fts2o.test4
-rw-r--r--lang/sql/sqlite/test/fts3_common.tcl134
-rw-r--r--lang/sql/sqlite/test/fts3aa.test2
-rw-r--r--lang/sql/sqlite/test/fts3ab.test1
-rw-r--r--lang/sql/sqlite/test/fts3ag.test1
-rw-r--r--lang/sql/sqlite/test/fts3ai.test5
-rw-r--r--lang/sql/sqlite/test/fts3aj.test6
-rw-r--r--lang/sql/sqlite/test/fts3ao.test8
-rw-r--r--lang/sql/sqlite/test/fts3atoken.test21
-rw-r--r--lang/sql/sqlite/test/fts3auto.test709
-rw-r--r--lang/sql/sqlite/test/fts3aux1.test105
-rw-r--r--lang/sql/sqlite/test/fts3aux2.test144
-rw-r--r--lang/sql/sqlite/test/fts3conf.test181
-rw-r--r--lang/sql/sqlite/test/fts3corrupt.test8
-rw-r--r--lang/sql/sqlite/test/fts3d.test54
-rw-r--r--lang/sql/sqlite/test/fts3defer.test105
-rw-r--r--lang/sql/sqlite/test/fts3defer2.test22
-rw-r--r--lang/sql/sqlite/test/fts3defer3.test84
-rw-r--r--lang/sql/sqlite/test/fts3drop.test61
-rw-r--r--lang/sql/sqlite/test/fts3expr.test13
-rw-r--r--lang/sql/sqlite/test/fts3expr3.test206
-rw-r--r--lang/sql/sqlite/test/fts3fault.test10
-rw-r--r--lang/sql/sqlite/test/fts3fault2.test73
-rw-r--r--lang/sql/sqlite/test/fts3first.test163
-rw-r--r--lang/sql/sqlite/test/fts3join.test66
-rw-r--r--lang/sql/sqlite/test/fts3malloc.test6
-rw-r--r--lang/sql/sqlite/test/fts3matchinfo.test70
-rw-r--r--lang/sql/sqlite/test/fts3near.test15
-rw-r--r--lang/sql/sqlite/test/fts3prefix.test213
-rw-r--r--lang/sql/sqlite/test/fts3prefix2.test61
-rw-r--r--lang/sql/sqlite/test/fts3query.test17
-rw-r--r--lang/sql/sqlite/test/fts3rnd.test68
-rw-r--r--lang/sql/sqlite/test/fts3shared.test106
-rw-r--r--lang/sql/sqlite/test/fts3snippet.test73
-rw-r--r--lang/sql/sqlite/test/fts3sort.test184
-rw-r--r--lang/sql/sqlite/test/fts3tok1.test114
-rw-r--r--lang/sql/sqlite/test/fts3tok_err.test47
-rw-r--r--lang/sql/sqlite/test/fts3varint.test118
-rw-r--r--lang/sql/sqlite/test/fts4aa.test1672
-rw-r--r--lang/sql/sqlite/test/fts4check.test155
-rw-r--r--lang/sql/sqlite/test/fts4content.test625
-rw-r--r--lang/sql/sqlite/test/fts4docid.test116
-rw-r--r--lang/sql/sqlite/test/fts4incr.test75
-rw-r--r--lang/sql/sqlite/test/fts4langid.test485
-rw-r--r--lang/sql/sqlite/test/fts4merge.test341
-rw-r--r--lang/sql/sqlite/test/fts4merge2.test38
-rw-r--r--lang/sql/sqlite/test/fts4merge3.test105
-rw-r--r--lang/sql/sqlite/test/fts4merge4.test58
-rw-r--r--lang/sql/sqlite/test/fts4noti.test171
-rw-r--r--lang/sql/sqlite/test/fts4unicode.test558
-rw-r--r--lang/sql/sqlite/test/full.test20
-rw-r--r--lang/sql/sqlite/test/func.test116
-rw-r--r--lang/sql/sqlite/test/func3.test121
-rw-r--r--lang/sql/sqlite/test/func4.test758
-rw-r--r--lang/sql/sqlite/test/func5.test63
-rw-r--r--lang/sql/sqlite/test/fuzz-oss1.test2001
-rw-r--r--lang/sql/sqlite/test/fuzz3.test3
-rw-r--r--lang/sql/sqlite/test/fuzz_malloc.test2
-rw-r--r--lang/sql/sqlite/test/fuzzer1.test652
-rw-r--r--lang/sql/sqlite/test/fuzzerfault.test92
-rw-r--r--lang/sql/sqlite/test/genesis.tcl1560
-rw-r--r--lang/sql/sqlite/test/hook.test85
-rw-r--r--lang/sql/sqlite/test/in.test18
-rw-r--r--lang/sql/sqlite/test/in5.test138
-rw-r--r--lang/sql/sqlite/test/incrblob.test26
-rw-r--r--lang/sql/sqlite/test/incrblob2.test6
-rw-r--r--lang/sql/sqlite/test/incrblob3.test1
-rw-r--r--lang/sql/sqlite/test/incrblob4.test89
-rw-r--r--lang/sql/sqlite/test/incrblob_err.test6
-rw-r--r--lang/sql/sqlite/test/incrblobfault.test1
-rw-r--r--lang/sql/sqlite/test/incrvacuum.test12
-rw-r--r--lang/sql/sqlite/test/incrvacuum2.test6
-rw-r--r--lang/sql/sqlite/test/incrvacuum3.test153
-rw-r--r--lang/sql/sqlite/test/incrvacuum_ioerr.test9
-rw-r--r--lang/sql/sqlite/test/index.test21
-rw-r--r--lang/sql/sqlite/test/index3.test2
-rw-r--r--lang/sql/sqlite/test/index4.test126
-rw-r--r--lang/sql/sqlite/test/index5.test75
-rw-r--r--lang/sql/sqlite/test/index6.test251
-rw-r--r--lang/sql/sqlite/test/index7.test251
-rw-r--r--lang/sql/sqlite/test/indexedby.test121
-rw-r--r--lang/sql/sqlite/test/indexfault.test342
-rw-r--r--lang/sql/sqlite/test/insert.test17
-rw-r--r--lang/sql/sqlite/test/insert4.test247
-rw-r--r--lang/sql/sqlite/test/insert5.test2
-rw-r--r--lang/sql/sqlite/test/instr.test251
-rw-r--r--lang/sql/sqlite/test/interrupt.test4
-rw-r--r--lang/sql/sqlite/test/intpkey.test11
-rw-r--r--lang/sql/sqlite/test/io.test94
-rw-r--r--lang/sql/sqlite/test/ioerr.test10
-rw-r--r--lang/sql/sqlite/test/ioerr2.test2
-rw-r--r--lang/sql/sqlite/test/ioerr4.test10
-rw-r--r--lang/sql/sqlite/test/ioerr6.test91
-rw-r--r--lang/sql/sqlite/test/join6.test42
-rw-r--r--lang/sql/sqlite/test/journal1.test10
-rw-r--r--lang/sql/sqlite/test/journal2.test5
-rw-r--r--lang/sql/sqlite/test/journal3.test9
-rw-r--r--lang/sql/sqlite/test/jrnlmode.test12
-rw-r--r--lang/sql/sqlite/test/jrnlmode2.test2
-rw-r--r--lang/sql/sqlite/test/jrnlmode3.test4
-rw-r--r--lang/sql/sqlite/test/keyword1.test3
-rw-r--r--lang/sql/sqlite/test/lastinsert.test11
-rw-r--r--lang/sql/sqlite/test/like.test131
-rw-r--r--lang/sql/sqlite/test/limit.test147
-rw-r--r--lang/sql/sqlite/test/loadext.test20
-rw-r--r--lang/sql/sqlite/test/loadext2.test28
-rw-r--r--lang/sql/sqlite/test/lock.test23
-rw-r--r--lang/sql/sqlite/test/lock4.test2
-rw-r--r--lang/sql/sqlite/test/lock5.test4
-rw-r--r--lang/sql/sqlite/test/lock7.test1
-rw-r--r--lang/sql/sqlite/test/lock_common.tcl4
-rw-r--r--lang/sql/sqlite/test/main.test14
-rw-r--r--lang/sql/sqlite/test/malloc.test46
-rw-r--r--lang/sql/sqlite/test/malloc3.test86
-rw-r--r--lang/sql/sqlite/test/malloc5.test12
-rw-r--r--lang/sql/sqlite/test/mallocA.test56
-rw-r--r--lang/sql/sqlite/test/mallocG.test5
-rw-r--r--lang/sql/sqlite/test/malloc_common.tcl34
-rw-r--r--lang/sql/sqlite/test/manydb.test6
-rw-r--r--lang/sql/sqlite/test/memdb.test4
-rw-r--r--lang/sql/sqlite/test/memsubsys1.test14
-rw-r--r--lang/sql/sqlite/test/memsubsys2.test2
-rw-r--r--lang/sql/sqlite/test/minmax.test92
-rw-r--r--lang/sql/sqlite/test/minmax2.test2
-rw-r--r--lang/sql/sqlite/test/minmax4.test150
-rw-r--r--lang/sql/sqlite/test/misc1.test23
-rw-r--r--lang/sql/sqlite/test/misc2.test6
-rw-r--r--lang/sql/sqlite/test/misc3.test10
-rw-r--r--lang/sql/sqlite/test/misc5.test6
-rw-r--r--lang/sql/sqlite/test/misc7.test84
-rw-r--r--lang/sql/sqlite/test/misuse.test65
-rw-r--r--lang/sql/sqlite/test/mmap1.test331
-rw-r--r--lang/sql/sqlite/test/mmap2.test87
-rw-r--r--lang/sql/sqlite/test/mmap3.test98
-rw-r--r--lang/sql/sqlite/test/mmapfault.test76
-rw-r--r--lang/sql/sqlite/test/multiplex.test136
-rw-r--r--lang/sql/sqlite/test/multiplex2.test70
-rw-r--r--lang/sql/sqlite/test/multiplex3.test166
-rw-r--r--lang/sql/sqlite/test/nan.test62
-rw-r--r--lang/sql/sqlite/test/notify1.test4
-rw-r--r--lang/sql/sqlite/test/notify2.test6
-rw-r--r--lang/sql/sqlite/test/notify3.test3
-rw-r--r--lang/sql/sqlite/test/notnull.test79
-rw-r--r--lang/sql/sqlite/test/numcast.test46
-rw-r--r--lang/sql/sqlite/test/openv2.test2
-rw-r--r--lang/sql/sqlite/test/orderby1.test457
-rw-r--r--lang/sql/sqlite/test/orderby2.test117
-rw-r--r--lang/sql/sqlite/test/orderby3.test123
-rw-r--r--lang/sql/sqlite/test/orderby4.test56
-rw-r--r--lang/sql/sqlite/test/orderby5.test112
-rw-r--r--lang/sql/sqlite/test/oserror.test37
-rw-r--r--lang/sql/sqlite/test/pager1.test645
-rw-r--r--lang/sql/sqlite/test/pager2.test19
-rw-r--r--lang/sql/sqlite/test/pager4.test99
-rw-r--r--lang/sql/sqlite/test/pagerfault.test312
-rw-r--r--lang/sql/sqlite/test/pagerfault2.test1
-rw-r--r--lang/sql/sqlite/test/pagerfault3.test1
-rw-r--r--lang/sql/sqlite/test/pageropt.test9
-rw-r--r--lang/sql/sqlite/test/pagesize.test8
-rw-r--r--lang/sql/sqlite/test/pcache.test1
-rw-r--r--lang/sql/sqlite/test/pcache2.test5
-rw-r--r--lang/sql/sqlite/test/percentile.test209
-rw-r--r--lang/sql/sqlite/test/permutations.test188
-rw-r--r--lang/sql/sqlite/test/pragma.test267
-rw-r--r--lang/sql/sqlite/test/pragma2.test97
-rw-r--r--lang/sql/sqlite/test/printf.test2
-rw-r--r--lang/sql/sqlite/test/printf2.test99
-rw-r--r--lang/sql/sqlite/test/progress.test4
-rw-r--r--lang/sql/sqlite/test/queryonly.test72
-rw-r--r--lang/sql/sqlite/test/quota-glob.test87
-rw-r--r--lang/sql/sqlite/test/quota.test149
-rw-r--r--lang/sql/sqlite/test/quota2.test302
-rw-r--r--lang/sql/sqlite/test/randexpr1.test5
-rw-r--r--lang/sql/sqlite/test/regexp1.test211
-rw-r--r--lang/sql/sqlite/test/releasetest.tcl52
-rw-r--r--lang/sql/sqlite/test/resolver01.test208
-rw-r--r--lang/sql/sqlite/test/rollback.test6
-rw-r--r--lang/sql/sqlite/test/rowid.test6
-rw-r--r--lang/sql/sqlite/test/run-wordcount.sh78
-rw-r--r--lang/sql/sqlite/test/savepoint.test38
-rw-r--r--lang/sql/sqlite/test/savepoint6.test2
-rw-r--r--lang/sql/sqlite/test/savepoint7.test96
-rw-r--r--lang/sql/sqlite/test/schema5.test69
-rw-r--r--lang/sql/sqlite/test/securedel.test3
-rw-r--r--lang/sql/sqlite/test/securedel2.test94
-rw-r--r--lang/sql/sqlite/test/select1.test8
-rw-r--r--lang/sql/sqlite/test/select4.test19
-rw-r--r--lang/sql/sqlite/test/select6.test44
-rw-r--r--lang/sql/sqlite/test/select7.test30
-rw-r--r--lang/sql/sqlite/test/select9.test53
-rw-r--r--lang/sql/sqlite/test/selectA.test20
-rw-r--r--lang/sql/sqlite/test/selectB.test73
-rw-r--r--lang/sql/sqlite/test/selectC.test2
-rw-r--r--lang/sql/sqlite/test/selectD.test174
-rw-r--r--lang/sql/sqlite/test/selectE.test95
-rw-r--r--lang/sql/sqlite/test/server1.test2
-rw-r--r--lang/sql/sqlite/test/shared.test160
-rw-r--r--lang/sql/sqlite/test/shared2.test44
-rw-r--r--lang/sql/sqlite/test/shared3.test37
-rw-r--r--lang/sql/sqlite/test/shared4.test8
-rw-r--r--lang/sql/sqlite/test/shared6.test2
-rw-r--r--lang/sql/sqlite/test/shared7.test5
-rw-r--r--lang/sql/sqlite/test/shared8.test112
-rw-r--r--lang/sql/sqlite/test/shared9.test230
-rw-r--r--lang/sql/sqlite/test/sharedA.test188
-rw-r--r--lang/sql/sqlite/test/shared_err.test5
-rw-r--r--lang/sql/sqlite/test/sharedlock.test31
-rw-r--r--lang/sql/sqlite/test/shell1.test812
-rw-r--r--lang/sql/sqlite/test/shell2.test199
-rw-r--r--lang/sql/sqlite/test/shell3.test97
-rw-r--r--lang/sql/sqlite/test/shell4.test116
-rw-r--r--lang/sql/sqlite/test/shell5.test290
-rw-r--r--lang/sql/sqlite/test/shrink.test43
-rw-r--r--lang/sql/sqlite/test/skipscan1.test212
-rw-r--r--lang/sql/sqlite/test/skipscan2.test190
-rw-r--r--lang/sql/sqlite/test/softheap1.test23
-rw-r--r--lang/sql/sqlite/test/speed1p.test3
-rw-r--r--lang/sql/sqlite/test/speed3.test2
-rw-r--r--lang/sql/sqlite/test/speedtest1.c1011
-rw-r--r--lang/sql/sqlite/test/spellfix.test273
-rw-r--r--lang/sql/sqlite/test/sqllimits1.test22
-rw-r--r--lang/sql/sqlite/test/stat.test90
-rw-r--r--lang/sql/sqlite/test/subquery.test94
-rw-r--r--lang/sql/sqlite/test/subquery2.test107
-rw-r--r--lang/sql/sqlite/test/superlock.test10
-rw-r--r--lang/sql/sqlite/test/sync.test34
-rw-r--r--lang/sql/sqlite/test/syscall.test3
-rw-r--r--lang/sql/sqlite/test/sysfault.test32
-rw-r--r--lang/sql/sqlite/test/table.test19
-rw-r--r--lang/sql/sqlite/test/tableopts.test76
-rw-r--r--lang/sql/sqlite/test/tclsqlite.test28
-rw-r--r--lang/sql/sqlite/test/temptable.test9
-rw-r--r--lang/sql/sqlite/test/temptrigger.test79
-rw-r--r--lang/sql/sqlite/test/tester.tcl690
-rw-r--r--lang/sql/sqlite/test/thread001.test12
-rw-r--r--lang/sql/sqlite/test/thread002.test4
-rw-r--r--lang/sql/sqlite/test/thread003.test20
-rw-r--r--lang/sql/sqlite/test/thread005.test2
-rw-r--r--lang/sql/sqlite/test/tkt-02a8e81d44.test5
-rw-r--r--lang/sql/sqlite/test/tkt-2a5629202f.test76
-rw-r--r--lang/sql/sqlite/test/tkt-2d1a5c67d.test127
-rw-r--r--lang/sql/sqlite/test/tkt-31338dca7e.test101
-rw-r--r--lang/sql/sqlite/test/tkt-385a5b56b9.test53
-rw-r--r--lang/sql/sqlite/test/tkt-38cb5df375.test5
-rw-r--r--lang/sql/sqlite/test/tkt-3a77c9714e.test72
-rw-r--r--lang/sql/sqlite/test/tkt-3fe897352e.test6
-rw-r--r--lang/sql/sqlite/test/tkt-4a03edc4c8.test2
-rw-r--r--lang/sql/sqlite/test/tkt-4c86b126f2.test49
-rw-r--r--lang/sql/sqlite/test/tkt-4dd95f6943.test151
-rw-r--r--lang/sql/sqlite/test/tkt-54844eea3f.test67
-rw-r--r--lang/sql/sqlite/test/tkt-5d863f876e.test2
-rw-r--r--lang/sql/sqlite/test/tkt-5ee23731f.test2
-rw-r--r--lang/sql/sqlite/test/tkt-6bfb98dfc0.test61
-rw-r--r--lang/sql/sqlite/test/tkt-78e04e52ea.test20
-rw-r--r--lang/sql/sqlite/test/tkt-7a31705a7e6.test25
-rw-r--r--lang/sql/sqlite/test/tkt-7bbfb7d442.test154
-rw-r--r--lang/sql/sqlite/test/tkt-80ba201079.test26
-rw-r--r--lang/sql/sqlite/test/tkt-868145d012.test64
-rw-r--r--lang/sql/sqlite/test/tkt-91e2e8ba6f.test52
-rw-r--r--lang/sql/sqlite/test/tkt-94c04eaadb.test3
-rw-r--r--lang/sql/sqlite/test/tkt-9f2eb3abac.test79
-rw-r--r--lang/sql/sqlite/test/tkt-a7b7803e.test84
-rw-r--r--lang/sql/sqlite/test/tkt-b1d3a2e531.test109
-rw-r--r--lang/sql/sqlite/test/tkt-b72787b1.test5
-rw-r--r--lang/sql/sqlite/test/tkt-bd484a090c.test38
-rw-r--r--lang/sql/sqlite/test/tkt-bdc6bbbb38.test90
-rw-r--r--lang/sql/sqlite/test/tkt-c48d99d690.test25
-rw-r--r--lang/sql/sqlite/test/tkt-cbd054fa6b.test41
-rw-r--r--lang/sql/sqlite/test/tkt-d11f09d36e.test1
-rw-r--r--lang/sql/sqlite/test/tkt-d635236375.test38
-rw-r--r--lang/sql/sqlite/test/tkt-d82e3f3721.test5
-rw-r--r--lang/sql/sqlite/test/tkt-f3e5abed55.test7
-rw-r--r--lang/sql/sqlite/test/tkt-f777251dc7a.test7
-rw-r--r--lang/sql/sqlite/test/tkt-f973c7ac31.test1
-rw-r--r--lang/sql/sqlite/test/tkt-fa7bf5ec.test39
-rw-r--r--lang/sql/sqlite/test/tkt-fc7bd6358f.test78
-rw-r--r--lang/sql/sqlite/test/tkt1567.test33
-rw-r--r--lang/sql/sqlite/test/tkt1667.test2
-rw-r--r--lang/sql/sqlite/test/tkt1873.test2
-rw-r--r--lang/sql/sqlite/test/tkt2409.test4
-rw-r--r--lang/sql/sqlite/test/tkt2686.test2
-rw-r--r--lang/sql/sqlite/test/tkt2817.test2
-rw-r--r--lang/sql/sqlite/test/tkt2820.test4
-rw-r--r--lang/sql/sqlite/test/tkt2822.test12
-rw-r--r--lang/sql/sqlite/test/tkt2854.test2
-rw-r--r--lang/sql/sqlite/test/tkt3442.test6
-rw-r--r--lang/sql/sqlite/test/tkt3457.test26
-rw-r--r--lang/sql/sqlite/test/tkt3527.test13
-rw-r--r--lang/sql/sqlite/test/tkt35xx.test4
-rw-r--r--lang/sql/sqlite/test/tkt3762.test4
-rw-r--r--lang/sql/sqlite/test/tkt3773.test5
-rw-r--r--lang/sql/sqlite/test/tkt3793.test18
-rw-r--r--lang/sql/sqlite/test/tkt3838.test19
-rw-r--r--lang/sql/sqlite/test/tkt3918.test1
-rw-r--r--lang/sql/sqlite/test/tkt3922.test8
-rw-r--r--lang/sql/sqlite/test/tkt3929.test1
-rw-r--r--lang/sql/sqlite/test/tpch01.test187
-rw-r--r--lang/sql/sqlite/test/trace2.test16
-rw-r--r--lang/sql/sqlite/test/trans2.test4
-rw-r--r--lang/sql/sqlite/test/trans3.test7
-rw-r--r--lang/sql/sqlite/test/transitive1.test284
-rw-r--r--lang/sql/sqlite/test/trigger1.test73
-rw-r--r--lang/sql/sqlite/test/trigger2.test12
-rw-r--r--lang/sql/sqlite/test/trigger3.test6
-rw-r--r--lang/sql/sqlite/test/trigger4.test6
-rw-r--r--lang/sql/sqlite/test/triggerA.test17
-rw-r--r--lang/sql/sqlite/test/triggerC.test132
-rw-r--r--lang/sql/sqlite/test/triggerD.test45
-rw-r--r--lang/sql/sqlite/test/triggerE.test112
-rw-r--r--lang/sql/sqlite/test/types3.test2
-rw-r--r--lang/sql/sqlite/test/unique.test22
-rw-r--r--lang/sql/sqlite/test/unixexcl.test45
-rw-r--r--lang/sql/sqlite/test/unordered.test33
-rw-r--r--lang/sql/sqlite/test/update.test6
-rw-r--r--lang/sql/sqlite/test/uri.test325
-rw-r--r--lang/sql/sqlite/test/vacuum.test30
-rw-r--r--lang/sql/sqlite/test/vacuum2.test2
-rw-r--r--lang/sql/sqlite/test/vacuum3.test2
-rw-r--r--lang/sql/sqlite/test/veryquick.test1
-rw-r--r--lang/sql/sqlite/test/view.test37
-rw-r--r--lang/sql/sqlite/test/vtab1.test260
-rw-r--r--lang/sql/sqlite/test/vtab6.test4
-rw-r--r--lang/sql/sqlite/test/vtab7.test4
-rw-r--r--lang/sql/sqlite/test/vtabC.test2
-rw-r--r--lang/sql/sqlite/test/vtabD.test10
-rw-r--r--lang/sql/sqlite/test/vtabF.test45
-rw-r--r--lang/sql/sqlite/test/vtab_shared.test37
-rw-r--r--lang/sql/sqlite/test/wal.test130
-rw-r--r--lang/sql/sqlite/test/wal2.test124
-rw-r--r--lang/sql/sqlite/test/wal3.test30
-rw-r--r--lang/sql/sqlite/test/wal4.test2
-rw-r--r--lang/sql/sqlite/test/wal5.test50
-rw-r--r--lang/sql/sqlite/test/wal6.test177
-rw-r--r--lang/sql/sqlite/test/wal7.test118
-rw-r--r--lang/sql/sqlite/test/wal8.test90
-rw-r--r--lang/sql/sqlite/test/wal9.test94
-rw-r--r--lang/sql/sqlite/test/walbak.test84
-rw-r--r--lang/sql/sqlite/test/walbig.test7
-rw-r--r--lang/sql/sqlite/test/walcksum.test31
-rw-r--r--lang/sql/sqlite/test/walcrash.test37
-rw-r--r--lang/sql/sqlite/test/walcrash2.test1
-rw-r--r--lang/sql/sqlite/test/walcrash3.test128
-rw-r--r--lang/sql/sqlite/test/walfault.test47
-rw-r--r--lang/sql/sqlite/test/walmode.test2
-rw-r--r--lang/sql/sqlite/test/walnoshm.test8
-rw-r--r--lang/sql/sqlite/test/walpersist.test126
-rw-r--r--lang/sql/sqlite/test/walro.test293
-rw-r--r--lang/sql/sqlite/test/walshared.test1
-rw-r--r--lang/sql/sqlite/test/walslow.test8
-rw-r--r--lang/sql/sqlite/test/walthread.test14
-rw-r--r--lang/sql/sqlite/test/where.test156
-rw-r--r--lang/sql/sqlite/test/where2.test151
-rw-r--r--lang/sql/sqlite/test/where3.test214
-rw-r--r--lang/sql/sqlite/test/where7.test12
-rw-r--r--lang/sql/sqlite/test/where8.test53
-rw-r--r--lang/sql/sqlite/test/where9.test239
-rw-r--r--lang/sql/sqlite/test/whereA.test6
-rw-r--r--lang/sql/sqlite/test/whereC.test69
-rw-r--r--lang/sql/sqlite/test/whereD.test222
-rw-r--r--lang/sql/sqlite/test/whereE.test62
-rw-r--r--lang/sql/sqlite/test/whereF.test122
-rw-r--r--lang/sql/sqlite/test/whereG.test170
-rw-r--r--lang/sql/sqlite/test/wild001.test311
-rw-r--r--lang/sql/sqlite/test/win32heap.test74
-rw-r--r--lang/sql/sqlite/test/win32lock.test134
-rw-r--r--lang/sql/sqlite/test/win32longpath.test110
-rw-r--r--lang/sql/sqlite/test/with1.test820
-rw-r--r--lang/sql/sqlite/test/with2.test391
-rw-r--r--lang/sql/sqlite/test/withM.test77
-rw-r--r--lang/sql/sqlite/test/without_rowid1.test203
-rw-r--r--lang/sql/sqlite/test/without_rowid2.test125
-rw-r--r--lang/sql/sqlite/test/without_rowid3.test2084
-rw-r--r--lang/sql/sqlite/test/without_rowid4.test764
-rw-r--r--lang/sql/sqlite/test/without_rowid5.test201
-rw-r--r--lang/sql/sqlite/test/wordcount.c545
-rw-r--r--lang/sql/sqlite/test/zerodamage.test121
516 files changed, 46899 insertions, 5755 deletions
diff --git a/lang/sql/sqlite/test/8_3_names.test b/lang/sql/sqlite/test/8_3_names.test
new file mode 100644
index 00000000..1d63f5dc
--- /dev/null
+++ b/lang/sql/sqlite/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/lang/sql/sqlite/test/aggnested.test b/lang/sql/sqlite/test/aggnested.test
new file mode 100644
index 00000000..6e2fd655
--- /dev/null
+++ b/lang/sql/sqlite/test/aggnested.test
@@ -0,0 +1,231 @@
+# 2012 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 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
+
+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 group_concat(a1,'x') FROM t2) FROM t1;
+ }
+} {1x2x3}
+do_test aggnested-1.2 {
+ db eval {
+ SELECT
+ (SELECT group_concat(a1,'x') || '-' || group_concat(b1,'y') FROM t2)
+ FROM t1;
+ }
+} {1x2x3-4y5}
+do_test aggnested-1.3 {
+ db eval {
+ SELECT (SELECT group_concat(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 3 33 333 3333}
+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.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);
+ }
+} {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}
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/all.test b/lang/sql/sqlite/test/all.test
index 96712466..f6e722f2 100644
--- a/lang/sql/sqlite/test/all.test
+++ b/lang/sql/sqlite/test/all.test
@@ -38,6 +38,8 @@ 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 {
@@ -46,5 +48,3 @@ if {$::tcl_platform(platform)=="unix"} {
}
finish_test
-
-
diff --git a/lang/sql/sqlite/test/alter.test b/lang/sql/sqlite/test/alter.test
index d4b72a6a..557162f8 100644
--- a/lang/sql/sqlite/test/alter.test
+++ b/lang/sql/sqlite/test/alter.test
@@ -221,8 +221,8 @@ do_test alter-1.7 {
#
ifcapable attach {
do_test alter-1.8.1 {
- file delete -force test2.db
- file delete -force test2.db-journal
+ forcedelete test2.db
+ forcedelete test2.db-journal
execsql {
ATTACH 'test2.db' AS aux;
}
@@ -349,7 +349,8 @@ db func trigfunc trigfunc
do_test alter-3.1.0 {
execsql {
CREATE TABLE t6(a, b, c);
- CREATE TRIGGER trig1 AFTER INSERT ON t6 BEGIN
+ -- 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;
}
@@ -412,8 +413,8 @@ do_test alter-3.1.8 {
# Make sure "ON" cannot be used as a database, table or column name without
# quoting. Otherwise the sqlite_alter_trigger() function might not work.
-file delete -force test3.db
-file delete -force test3.db-journal
+forcedelete test3.db
+forcedelete test3.db-journal
ifcapable attach {
do_test alter-3.2.1 {
catchsql {
@@ -650,7 +651,7 @@ do_test alter-6.7 {
# Ticket #1665: Make sure ALTER TABLE ADD COLUMN works on a table
# that includes a COLLATE clause.
#
-do_test alter-7.1 {
+do_realnum_test alter-7.1 {
execsql {
CREATE TABLE t1(a TEXT COLLATE BINARY);
ALTER TABLE t1 ADD COLUMN b INTEGER COLLATE NOCASE;
@@ -846,7 +847,8 @@ do_test alter-14.2 {
set system_table_list {1 sqlite_master}
catchsql ANALYZE
ifcapable analyze { lappend system_table_list 2 sqlite_stat1 }
-ifcapable stat2 { lappend system_table_list 3 sqlite_stat2 }
+ifcapable stat3 { lappend system_table_list 3 sqlite_stat3 }
+ifcapable stat4 { lappend system_table_list 4 sqlite_stat4 }
foreach {tn tbl} $system_table_list {
do_test alter-15.$tn.1 {
@@ -858,5 +860,19 @@ foreach {tn tbl} $system_table_list {
} [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}
finish_test
diff --git a/lang/sql/sqlite/test/alter2.test b/lang/sql/sqlite/test/alter2.test
index 712960c0..14be637f 100644
--- a/lang/sql/sqlite/test/alter2.test
+++ b/lang/sql/sqlite/test/alter2.test
@@ -137,6 +137,7 @@ do_test alter2-1.8 {
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;
@@ -314,8 +315,8 @@ do_test alter2-6.1 {
} {2}
ifcapable attach {
do_test alter2-6.2 {
- file delete -force test2.db-journal
- file delete -force test2.db
+ forcedelete test2.db-journal
+ forcedelete test2.db
execsql {
ATTACH 'test2.db' AS aux;
CREATE TABLE aux.t1(a, b);
diff --git a/lang/sql/sqlite/test/alter3.test b/lang/sql/sqlite/test/alter3.test
index 74ba33c5..28d293e2 100644
--- a/lang/sql/sqlite/test/alter3.test
+++ b/lang/sql/sqlite/test/alter3.test
@@ -196,7 +196,7 @@ ifcapable schema_version {
do_test alter3-4.1 {
db close
- file delete -force test.db
+ forcedelete test.db
set ::DB [sqlite3 db test.db]
execsql {
PRAGMA legacy_file_format=ON;
@@ -237,8 +237,8 @@ do_test alter3-4.99 {
ifcapable attach {
do_test alter3-5.1 {
- file delete -force test2.db
- file delete -force test2.db-journal
+ forcedelete test2.db
+ forcedelete test2.db-journal
execsql {
CREATE TABLE t1(a, b);
INSERT INTO t1 VALUES(1, 'one');
diff --git a/lang/sql/sqlite/test/alter4.test b/lang/sql/sqlite/test/alter4.test
index 738db3fd..59704fed 100644
--- a/lang/sql/sqlite/test/alter4.test
+++ b/lang/sql/sqlite/test/alter4.test
@@ -143,6 +143,11 @@ do_test alter4-2.6 {
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 (-+1);
+ }
+} {1 {Cannot add a column with non-constant default}}
do_test alter4-2.99 {
execsql {
DROP TABLE t1;
@@ -178,7 +183,7 @@ ifcapable schema_version {
do_test alter4-4.1 {
db close
- file delete -force test.db
+ forcedelete test.db
set ::DB [sqlite3 db test.db]
execsql {
CREATE TEMP TABLE t1(a, b);
@@ -213,8 +218,8 @@ do_test alter4-4.99 {
ifcapable attach {
do_test alter4-5.1 {
- file delete -force test2.db
- file delete -force test2.db-journal
+ forcedelete test2.db
+ forcedelete test2.db-journal
execsql {
CREATE TEMP TABLE t1(a, b);
INSERT INTO t1 VALUES(1, 'one');
diff --git a/lang/sql/sqlite/test/amatch1.test b/lang/sql/sqlite/test/amatch1.test
new file mode 100644
index 00000000..cc0f77af
--- /dev/null
+++ b/lang/sql/sqlite/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/lang/sql/sqlite/test/analyze.test b/lang/sql/sqlite/test/analyze.test
index 766cd50d..c4450842 100644
--- a/lang/sql/sqlite/test/analyze.test
+++ b/lang/sql/sqlite/test/analyze.test
@@ -287,6 +287,65 @@ do_test analyze-4.3 {
}
} {}
+# Verify that DROP TABLE and DROP INDEX remove entries from the
+# sqlite_stat1, sqlite_stat3 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||stat3 {
+ ifcapable stat4 {set stat sqlite_stat4} else {set stat sqlite_stat3}
+ do_test analyze-5.1 {
+ execsql "
+ SELECT DISTINCT idx FROM $stat ORDER BY 1;
+ SELECT DISTINCT tbl FROM $stat 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||stat3 {
+ do_test analyze-5.3 {
+ execsql "
+ SELECT DISTINCT idx FROM $stat ORDER BY 1;
+ SELECT DISTINCT tbl FROM $stat 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||stat3 {
+ do_test analyze-5.5 {
+ execsql "
+ SELECT DISTINCT idx FROM $stat ORDER BY 1;
+ SELECT DISTINCT tbl FROM $stat ORDER BY 1;
+ "
+ } {t4i1 t4i2 t4}
+}
+
# This test corrupts the database file so it must be the last test
# in the series.
#
@@ -302,5 +361,4 @@ do_test analyze-99.1 {
}
} {1 {malformed database schema (sqlite_stat1) - near "nonsense": syntax error}}
-
finish_test
diff --git a/lang/sql/sqlite/test/analyze2.test b/lang/sql/sqlite/test/analyze2.test
deleted file mode 100644
index de2567bb..00000000
--- a/lang/sql/sqlite/test/analyze2.test
+++ /dev/null
@@ -1,554 +0,0 @@
-# 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 the extra functionality provided by the ANALYZE
-# command when the library is compiled with SQLITE_ENABLE_STAT2 defined.
-#
-
-set testdir [file dirname $argv0]
-source $testdir/tester.tcl
-
-ifcapable !stat2 {
- finish_test
- return
-}
-
-set testprefix analyze2
-
-# 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
-
-#--------------------------------------------------------------------
-# Test organization:
-#
-# analyze2-1.*: Tests to verify that ANALYZE creates and populates the
-# sqlite_stat2 table as expected.
-#
-# analyze2-2.*: Test that when a table has two indexes on it and either
-# index may be used for the scan, the index suggested by
-# the contents of sqlite_stat2 table is prefered.
-#
-# analyze2-3.*: Similar to the previous block of tests, but using tables
-# that contain a mixture of NULL, numeric, text and blob
-# values.
-#
-# analyze2-4.*: Check that when an indexed column uses a collation other
-# than BINARY, the collation is taken into account when
-# using the contents of sqlite_stat2 to estimate the cost
-# of a range scan.
-#
-# analyze2-5.*: Check that collation sequences are used as described above
-# even when the only available version of the collation
-# function require UTF-16 encoded arguments.
-#
-# analyze2-6.*: Check that the library behaves correctly when one of the
-# sqlite_stat2 or sqlite_stat1 tables are missing.
-#
-# analyze2-7.*: Check that in a shared-schema situation, nothing goes
-# wrong if sqlite_stat2 data is read by one connection,
-# and freed by another.
-#
-
-proc eqp {sql {db db}} {
- uplevel execsql [list "EXPLAIN QUERY PLAN $sql"] $db
-}
-
-do_test analyze2-1.1 {
- execsql { CREATE TABLE t1(x PRIMARY KEY) }
- for {set i 0} {$i < 1000} {incr i} {
- execsql { INSERT INTO t1 VALUES($i) }
- }
- execsql {
- ANALYZE;
- SELECT * FROM sqlite_stat2;
- }
-} [list t1 sqlite_autoindex_t1_1 0 50 \
- t1 sqlite_autoindex_t1_1 1 149 \
- t1 sqlite_autoindex_t1_1 2 249 \
- t1 sqlite_autoindex_t1_1 3 349 \
- t1 sqlite_autoindex_t1_1 4 449 \
- t1 sqlite_autoindex_t1_1 5 549 \
- t1 sqlite_autoindex_t1_1 6 649 \
- t1 sqlite_autoindex_t1_1 7 749 \
- t1 sqlite_autoindex_t1_1 8 849 \
- t1 sqlite_autoindex_t1_1 9 949 \
-]
-
-do_test analyze2-1.2 {
- execsql {
- DELETE FROM t1 WHERe x>9;
- ANALYZE;
- SELECT tbl, idx, group_concat(sample, ' ') FROM sqlite_stat2;
- }
-} {t1 sqlite_autoindex_t1_1 {0 1 2 3 4 5 6 7 8 9}}
-do_test analyze2-1.3 {
- execsql {
- DELETE FROM t1 WHERE x>8;
- ANALYZE;
- SELECT * FROM sqlite_stat2;
- }
-} {}
-do_test analyze2-1.4 {
- execsql {
- DELETE FROM t1;
- ANALYZE;
- SELECT * FROM sqlite_stat2;
- }
-} {}
-
-do_test analyze2-2.1 {
- execsql {
- BEGIN;
- DROP TABLE t1;
- CREATE TABLE t1(x, y);
- CREATE INDEX t1_x ON t1(x);
- CREATE INDEX t1_y ON t1(y);
- }
- for {set i 0} {$i < 1000} {incr i} {
- execsql { INSERT INTO t1 VALUES($i, $i) }
- }
- execsql COMMIT
- execsql ANALYZE
-} {}
-do_eqp_test 2.2 {
- SELECT * FROM t1 WHERE x>500 AND y>700
-} {
- 0 0 0 {SEARCH TABLE t1 USING INDEX t1_y (y>?) (~100 rows)}
-}
-do_eqp_test 2.3 {
- SELECT * FROM t1 WHERE x>700 AND y>500
-} {
- 0 0 0 {SEARCH TABLE t1 USING INDEX t1_x (x>?) (~100 rows)}
-}
-do_eqp_test 2.3 {
- SELECT * FROM t1 WHERE y>700 AND x>500
-} {
- 0 0 0 {SEARCH TABLE t1 USING INDEX t1_y (y>?) (~100 rows)}
-}
-do_eqp_test 2.4 {
- SELECT * FROM t1 WHERE y>500 AND x>700
-} {
- 0 0 0 {SEARCH TABLE t1 USING INDEX t1_x (x>?) (~100 rows)}
-}
-do_eqp_test 2.5 {
- SELECT * FROM t1 WHERE x BETWEEN 100 AND 200 AND y BETWEEN 400 AND 700
-} {
- 0 0 0 {SEARCH TABLE t1 USING INDEX t1_x (x>? AND x<?) (~25 rows)}
-}
-do_eqp_test 2.6 {
- SELECT * FROM t1 WHERE x BETWEEN 100 AND 500 AND y BETWEEN 400 AND 700
-} {
- 0 0 0 {SEARCH TABLE t1 USING INDEX t1_y (y>? AND y<?) (~75 rows)}
-}
-do_eqp_test 2.7 {
- SELECT * FROM t1 WHERE x BETWEEN -400 AND -300 AND y BETWEEN 100 AND 300
-} {
- 0 0 0 {SEARCH TABLE t1 USING INDEX t1_x (x>? AND x<?) (~12 rows)}
-}
-do_eqp_test 2.8 {
- SELECT * FROM t1 WHERE x BETWEEN 100 AND 300 AND y BETWEEN -400 AND -300
-} {
- 0 0 0 {SEARCH TABLE t1 USING INDEX t1_y (y>? AND y<?) (~12 rows)}
-}
-do_eqp_test 2.9 {
- SELECT * FROM t1 WHERE x BETWEEN 500 AND 100 AND y BETWEEN 100 AND 300
-} {
- 0 0 0 {SEARCH TABLE t1 USING INDEX t1_x (x>? AND x<?) (~12 rows)}
-}
-do_eqp_test 2.10 {
- SELECT * FROM t1 WHERE x BETWEEN 100 AND 300 AND y BETWEEN 500 AND 100
-} {
- 0 0 0 {SEARCH TABLE t1 USING INDEX t1_y (y>? AND y<?) (~12 rows)}
-}
-
-do_test analyze2-3.1 {
- set alphabet [list a b c d e f g h i j]
- execsql BEGIN
- for {set i 0} {$i < 1000} {incr i} {
- set str [lindex $alphabet [expr ($i/100)%10]]
- append str [lindex $alphabet [expr ($i/ 10)%10]]
- append str [lindex $alphabet [expr ($i/ 1)%10]]
- execsql { INSERT INTO t1 VALUES($str, $str) }
- }
- execsql COMMIT
- execsql ANALYZE
- execsql {
- SELECT tbl,idx,group_concat(sample,' ')
- FROM sqlite_stat2
- WHERE idx = 't1_x'
- GROUP BY tbl,idx
- }
-} {t1 t1_x {100 299 499 699 899 ajj cjj ejj gjj ijj}}
-do_test analyze2-3.2 {
- execsql {
- SELECT tbl,idx,group_concat(sample,' ')
- FROM sqlite_stat2
- WHERE idx = 't1_y'
- GROUP BY tbl,idx
- }
-} {t1 t1_y {100 299 499 699 899 ajj cjj ejj gjj ijj}}
-
-do_eqp_test 3.3 {
- SELECT * FROM t1 WHERE x BETWEEN 100 AND 500 AND y BETWEEN 'a' AND 'b'
-} {
- 0 0 0 {SEARCH TABLE t1 USING INDEX t1_y (y>? AND y<?) (~50 rows)}
-}
-do_eqp_test 3.4 {
- SELECT * FROM t1 WHERE x BETWEEN 100 AND 400 AND y BETWEEN 'a' AND 'h'
-} {
- 0 0 0 {SEARCH TABLE t1 USING INDEX t1_x (x>? AND x<?) (~100 rows)}
-}
-do_eqp_test 3.5 {
- SELECT * FROM t1 WHERE x<'a' AND y>'h'
-} {
- 0 0 0 {SEARCH TABLE t1 USING INDEX t1_y (y>?) (~66 rows)}
-}
-do_eqp_test 3.6 {
- SELECT * FROM t1 WHERE x<444 AND y>'h'
-} {
- 0 0 0 {SEARCH TABLE t1 USING INDEX t1_y (y>?) (~66 rows)}
-}
-do_eqp_test 3.7 {
- SELECT * FROM t1 WHERE x<221 AND y>'g'
-} {
- 0 0 0 {SEARCH TABLE t1 USING INDEX t1_x (x<?) (~66 rows)}
-}
-
-do_test analyze2-4.1 {
- execsql { CREATE TABLE t3(a COLLATE nocase, b) }
- execsql { CREATE INDEX t3a ON t3(a) }
- execsql { CREATE INDEX t3b ON t3(b) }
- set alphabet [list A b C d E f G h I j]
- execsql BEGIN
- for {set i 0} {$i < 1000} {incr i} {
- set str [lindex $alphabet [expr ($i/100)%10]]
- append str [lindex $alphabet [expr ($i/ 10)%10]]
- append str [lindex $alphabet [expr ($i/ 1)%10]]
- execsql { INSERT INTO t3 VALUES($str, $str) }
- }
- execsql COMMIT
- execsql ANALYZE
-} {}
-do_test analyze2-4.2 {
- execsql {
- PRAGMA automatic_index=OFF;
- SELECT tbl,idx,group_concat(sample,' ')
- FROM sqlite_stat2
- WHERE idx = 't3a'
- GROUP BY tbl,idx;
- PRAGMA automatic_index=ON;
- }
-} {t3 t3a {AfA bEj CEj dEj EEj fEj GEj hEj IEj jEj}}
-do_test analyze2-4.3 {
- execsql {
- SELECT tbl,idx,group_concat(sample,' ')
- FROM sqlite_stat2
- WHERE idx = 't3b'
- GROUP BY tbl,idx
- }
-} {t3 t3b {AbA CIj EIj GIj IIj bIj dIj fIj hIj jIj}}
-
-do_eqp_test 4.4 {
- SELECT * FROM t3 WHERE a > 'A' AND a < 'C' AND b > 'A' AND b < 'C'
-} {
- 0 0 0 {SEARCH TABLE t3 USING INDEX t3b (b>? AND b<?) (~11 rows)}
-}
-do_eqp_test 4.5 {
- SELECT * FROM t3 WHERE a > 'A' AND a < 'c' AND b > 'A' AND b < 'c'
-} {
- 0 0 0 {SEARCH TABLE t3 USING INDEX t3a (a>? AND a<?) (~22 rows)}
-}
-
-ifcapable utf16 {
- proc test_collate {enc lhs rhs} {
- # puts $enc
- return [string compare $lhs $rhs]
- }
- do_test analyze2-5.1 {
- add_test_collate db 0 0 1
- execsql { CREATE TABLE t4(x COLLATE test_collate) }
- execsql { CREATE INDEX t4x ON t4(x) }
- set alphabet [list a b c d e f g h i j]
- execsql BEGIN
- for {set i 0} {$i < 1000} {incr i} {
- set str [lindex $alphabet [expr ($i/100)%10]]
- append str [lindex $alphabet [expr ($i/ 10)%10]]
- append str [lindex $alphabet [expr ($i/ 1)%10]]
- execsql { INSERT INTO t4 VALUES($str) }
- }
- execsql COMMIT
- execsql ANALYZE
- } {}
- do_test analyze2-5.2 {
- execsql {
- SELECT tbl,idx,group_concat(sample,' ')
- FROM sqlite_stat2
- WHERE tbl = 't4'
- GROUP BY tbl,idx
- }
- } {t4 t4x {afa bej cej dej eej fej gej hej iej jej}}
- do_eqp_test 5.3 {
- SELECT * FROM t4 WHERE x>'ccc'
- } {0 0 0 {SEARCH TABLE t4 USING COVERING INDEX t4x (x>?) (~800 rows)}}
- do_eqp_test 5.4 {
- SELECT * FROM t4 AS t41, t4 AS t42 WHERE t41.x>'ccc' AND t42.x>'ggg'
- } {
- 0 0 1 {SEARCH TABLE t4 AS t42 USING COVERING INDEX t4x (x>?) (~300 rows)}
- 0 1 0 {SEARCH TABLE t4 AS t41 USING COVERING INDEX t4x (x>?) (~800 rows)}
- }
- do_eqp_test 5.5 {
- SELECT * FROM t4 AS t41, t4 AS t42 WHERE t41.x>'ddd' AND t42.x>'ccc'
- } {
- 0 0 0 {SEARCH TABLE t4 AS t41 USING COVERING INDEX t4x (x>?) (~700 rows)}
- 0 1 1 {SEARCH TABLE t4 AS t42 USING COVERING INDEX t4x (x>?) (~800 rows)}
- }
-}
-
-#--------------------------------------------------------------------
-# These tests, analyze2-6.*, verify that the library behaves correctly
-# when one of the sqlite_stat1 and sqlite_stat2 tables is missing.
-#
-# If the sqlite_stat1 table is not present, then the sqlite_stat2
-# table is not read. However, if it is the sqlite_stat2 table that
-# is missing, the data in the sqlite_stat1 table is still used.
-#
-# Tests analyze2-6.1.* test the libary when the sqlite_stat2 table
-# is missing. Tests analyze2-6.2.* test the library when sqlite_stat1
-# is not present.
-#
-do_test analyze2-6.0 {
- execsql {
- DROP TABLE IF EXISTS t4;
- CREATE TABLE t5(a, b); CREATE INDEX t5i ON t5(a, b);
- CREATE TABLE t6(a, b); CREATE INDEX t6i ON t6(a, b);
- }
- for {set ii 0} {$ii < 20} {incr ii} {
- execsql {
- INSERT INTO t5 VALUES($ii, $ii);
- INSERT INTO t6 VALUES($ii/10, $ii/10);
- }
- }
- execsql {
- CREATE TABLE master AS
- SELECT * FROM sqlite_master WHERE name LIKE 'sqlite_stat%'
- }
-} {}
-
-do_test analyze2-6.1.1 {
- eqp {SELECT * FROM t5,t6 WHERE t5.rowid=t6.rowid AND
- t5.a = 1 AND
- t6.a = 1 AND t6.b = 1
- }
-} {0 0 1 {SEARCH TABLE t6 USING COVERING INDEX t6i (a=? AND b=?) (~9 rows)} 0 1 0 {SEARCH TABLE t5 USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)}}
-do_test analyze2-6.1.2 {
- db cache flush
- execsql ANALYZE
- eqp {SELECT * FROM t5,t6 WHERE t5.rowid=t6.rowid AND
- t5.a = 1 AND
- t6.a = 1 AND t6.b = 1
- }
-} {0 0 0 {SEARCH TABLE t5 USING COVERING INDEX t5i (a=?) (~1 rows)} 0 1 1 {SEARCH TABLE t6 USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)}}
-do_test analyze2-6.1.3 {
- sqlite3 db test.db
- eqp { SELECT * FROM t5,t6 WHERE t5.rowid=t6.rowid AND
- t5.a = 1 AND
- t6.a = 1 AND t6.b = 1
- }
-} {0 0 0 {SEARCH TABLE t5 USING COVERING INDEX t5i (a=?) (~1 rows)} 0 1 1 {SEARCH TABLE t6 USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)}}
-do_test analyze2-6.1.4 {
- execsql {
- PRAGMA writable_schema = 1;
- DELETE FROM sqlite_master WHERE tbl_name = 'sqlite_stat2';
- }
- sqlite3 db test.db
- eqp { SELECT * FROM t5,t6 WHERE t5.rowid=t6.rowid AND
- t5.a = 1 AND
- t6.a = 1 AND t6.b = 1
- }
-} {0 0 0 {SEARCH TABLE t5 USING COVERING INDEX t5i (a=?) (~1 rows)} 0 1 1 {SEARCH TABLE t6 USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)}}
-do_test analyze2-6.1.5 {
- execsql {
- PRAGMA writable_schema = 1;
- DELETE FROM sqlite_master WHERE tbl_name = 'sqlite_stat1';
- }
- sqlite3 db test.db
- eqp { SELECT * FROM t5,t6 WHERE t5.rowid=t6.rowid AND
- t5.a = 1 AND
- t6.a = 1 AND t6.b = 1
- }
-} {0 0 1 {SEARCH TABLE t6 USING COVERING INDEX t6i (a=? AND b=?) (~9 rows)} 0 1 0 {SEARCH TABLE t5 USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)}}
-do_test analyze2-6.1.6 {
- execsql {
- PRAGMA writable_schema = 1;
- INSERT INTO sqlite_master SELECT * FROM master;
- }
- sqlite3 db test.db
- eqp { SELECT * FROM t5,t6 WHERE t5.rowid=t6.rowid AND
- t5.a = 1 AND
- t6.a = 1 AND t6.b = 1
- }
-} {0 0 0 {SEARCH TABLE t5 USING COVERING INDEX t5i (a=?) (~1 rows)} 0 1 1 {SEARCH TABLE t6 USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)}}
-
-do_test analyze2-6.2.1 {
- execsql {
- DELETE FROM sqlite_stat1;
- DELETE FROM sqlite_stat2;
- }
- sqlite3 db test.db
- eqp { SELECT * FROM t5,t6 WHERE t5.rowid=t6.rowid AND
- t5.a>1 AND t5.a<15 AND
- t6.a>1
- }
-} {0 0 0 {SEARCH TABLE t5 USING COVERING INDEX t5i (a>? AND a<?) (~60000 rows)} 0 1 1 {SEARCH TABLE t6 USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)}}
-do_test analyze2-6.2.2 {
- db cache flush
- execsql ANALYZE
- eqp { SELECT * FROM t5,t6 WHERE t5.rowid=t6.rowid AND
- t5.a>1 AND t5.a<15 AND
- t6.a>1
- }
-} {0 0 1 {SEARCH TABLE t6 USING COVERING INDEX t6i (a>?) (~1 rows)} 0 1 0 {SEARCH TABLE t5 USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)}}
-do_test analyze2-6.2.3 {
- sqlite3 db test.db
- eqp { SELECT * FROM t5,t6 WHERE t5.rowid=t6.rowid AND
- t5.a>1 AND t5.a<15 AND
- t6.a>1
- }
-} {0 0 1 {SEARCH TABLE t6 USING COVERING INDEX t6i (a>?) (~1 rows)} 0 1 0 {SEARCH TABLE t5 USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)}}
-do_test analyze2-6.2.4 {
- execsql {
- PRAGMA writable_schema = 1;
- DELETE FROM sqlite_master WHERE tbl_name = 'sqlite_stat1';
- }
- sqlite3 db test.db
- eqp { SELECT * FROM t5,t6 WHERE t5.rowid=t6.rowid AND
- t5.a>1 AND t5.a<15 AND
- t6.a>1
- }
-} {0 0 0 {SEARCH TABLE t5 USING COVERING INDEX t5i (a>? AND a<?) (~60000 rows)} 0 1 1 {SEARCH TABLE t6 USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)}}
-do_test analyze2-6.2.5 {
- execsql {
- PRAGMA writable_schema = 1;
- DELETE FROM sqlite_master WHERE tbl_name = 'sqlite_stat2';
- }
- sqlite3 db test.db
- eqp { SELECT * FROM t5,t6 WHERE t5.rowid=t6.rowid AND
- t5.a>1 AND t5.a<15 AND
- t6.a>1
- }
-} {0 0 0 {SEARCH TABLE t5 USING COVERING INDEX t5i (a>? AND a<?) (~60000 rows)} 0 1 1 {SEARCH TABLE t6 USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)}}
-do_test analyze2-6.2.6 {
- execsql {
- PRAGMA writable_schema = 1;
- INSERT INTO sqlite_master SELECT * FROM master;
- }
- sqlite3 db test.db
- execsql ANALYZE
- eqp { SELECT * FROM t5,t6 WHERE t5.rowid=t6.rowid AND
- t5.a>1 AND t5.a<15 AND
- t6.a>1
- }
-} {0 0 1 {SEARCH TABLE t6 USING COVERING INDEX t6i (a>?) (~1 rows)} 0 1 0 {SEARCH TABLE t5 USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)}}
-
-#--------------------------------------------------------------------
-# These tests, analyze2-7.*, test that the sqlite_stat2 functionality
-# works in shared-cache mode. Note that these tests reuse the database
-# created for the analyze2-6.* tests.
-#
-ifcapable shared_cache {
- db close
- set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
-
- proc incr_schema_cookie {zDb} {
- foreach iOffset {24 40} {
- set cookie [hexio_get_int [hexio_read $zDb $iOffset 4]]
- incr cookie
- hexio_write $zDb $iOffset [hexio_render_int32 $cookie]
- }
- }
-
- do_test analyze2-7.1 {
- sqlite3 db1 test.db
- sqlite3 db2 test.db
- db1 cache size 0
- db2 cache size 0
- execsql { SELECT count(*) FROM t5 } db1
- } {20}
- do_test analyze2-7.2 {
- incr_schema_cookie test.db
- execsql { SELECT count(*) FROM t5 } db2
- } {20}
- do_test analyze2-7.3 {
- incr_schema_cookie test.db
- execsql { SELECT count(*) FROM t5 } db1
- } {20}
- do_test analyze2-7.4 {
- incr_schema_cookie test.db
- execsql { SELECT count(*) FROM t5 } db2
- } {20}
-
- do_test analyze2-7.5 {
- eqp { SELECT * FROM t5,t6 WHERE t5.rowid=t6.rowid AND
- t5.a>1 AND t5.a<15 AND
- t6.a>1
- } db1
- } {0 0 1 {SEARCH TABLE t6 USING COVERING INDEX t6i (a>?) (~1 rows)} 0 1 0 {SEARCH TABLE t5 USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)}}
- do_test analyze2-7.6 {
- incr_schema_cookie test.db
- execsql { SELECT * FROM sqlite_master } db2
- eqp { SELECT * FROM t5,t6 WHERE t5.rowid=t6.rowid AND
- t5.a>1 AND t5.a<15 AND
- t6.a>1
- } db2
- } {0 0 1 {SEARCH TABLE t6 USING COVERING INDEX t6i (a>?) (~1 rows)} 0 1 0 {SEARCH TABLE t5 USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)}}
- do_test analyze2-7.7 {
- incr_schema_cookie test.db
- execsql { SELECT * FROM sqlite_master } db1
- eqp { SELECT * FROM t5,t6 WHERE t5.rowid=t6.rowid AND
- t5.a>1 AND t5.a<15 AND
- t6.a>1
- } db1
- } {0 0 1 {SEARCH TABLE t6 USING COVERING INDEX t6i (a>?) (~1 rows)} 0 1 0 {SEARCH TABLE t5 USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)}}
-
- do_test analyze2-7.8 {
- execsql { DELETE FROM sqlite_stat2 } db2
- execsql { SELECT * FROM sqlite_master } db1
- eqp { SELECT * FROM t5,t6 WHERE t5.rowid=t6.rowid AND
- t5.a>1 AND t5.a<15 AND
- t6.a>1
- } db1
- } {0 0 1 {SEARCH TABLE t6 USING COVERING INDEX t6i (a>?) (~1 rows)} 0 1 0 {SEARCH TABLE t5 USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)}}
- do_test analyze2-7.9 {
- execsql { SELECT * FROM sqlite_master } db2
- eqp { SELECT * FROM t5,t6 WHERE t5.rowid=t6.rowid AND
- t5.a>1 AND t5.a<15 AND
- t6.a>1
- } db2
- } {0 0 1 {SEARCH TABLE t6 USING COVERING INDEX t6i (a>?) (~1 rows)} 0 1 0 {SEARCH TABLE t5 USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)}}
-
- do_test analyze2-7.10 {
- incr_schema_cookie test.db
- execsql { SELECT * FROM sqlite_master } db1
- eqp { SELECT * FROM t5,t6 WHERE t5.rowid=t6.rowid AND
- t5.a>1 AND t5.a<15 AND
- t6.a>1
- } db1
- } {0 0 0 {SEARCH TABLE t5 USING COVERING INDEX t5i (a>? AND a<?) (~1 rows)} 0 1 1 {SEARCH TABLE t6 USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)}}
-
- db1 close
- db2 close
- sqlite3_enable_shared_cache $::enable_shared_cache
-}
-
-finish_test
diff --git a/lang/sql/sqlite/test/analyze3.test b/lang/sql/sqlite/test/analyze3.test
index 2378ffaa..fb26303e 100644
--- a/lang/sql/sqlite/test/analyze3.test
+++ b/lang/sql/sqlite/test/analyze3.test
@@ -17,7 +17,7 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
-ifcapable !stat2 {
+ifcapable !stat4&&!stat3 {
finish_test
return
}
@@ -43,6 +43,8 @@ ifcapable !stat2 {
# 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.
#
proc getvar {varname} { uplevel #0 set $varname }
@@ -70,7 +72,7 @@ proc sf_execsql {sql {db db}} {
# 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_stat2.
+# 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
@@ -93,14 +95,20 @@ do_test analyze3-1.1.1 {
COMMIT;
ANALYZE;
}
-} {}
+
+ ifcapable stat4 {
+ execsql { SELECT count(*)>0 FROM sqlite_stat4; }
+ } else {
+ execsql { SELECT count(*)>0 FROM sqlite_stat3; }
+ }
+} {1}
do_eqp_test analyze3-1.1.2 {
SELECT sum(y) FROM t1 WHERE x>200 AND x<300
-} {0 0 0 {SEARCH TABLE t1 USING INDEX i1 (x>? AND x<?) (~100 rows)}}
+} {0 0 0 {SEARCH TABLE t1 USING INDEX i1 (x>? AND x<?)}}
do_eqp_test analyze3-1.1.3 {
SELECT sum(y) FROM t1 WHERE x>0 AND x<1100
-} {0 0 0 {SCAN TABLE t1 (~111 rows)}}
+} {0 0 0 {SEARCH TABLE t1 USING INDEX i1 (x>? AND x<?)}}
do_test analyze3-1.1.4 {
sf_execsql { SELECT sum(y) FROM t1 WHERE x>200 AND x<300 }
@@ -117,17 +125,17 @@ do_test analyze3-1.1.6 {
} {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}
+} {2000 0 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}
+} {2000 0 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}
+} {2000 0 499500}
# The following tests are similar to the block above. The difference is
@@ -146,10 +154,10 @@ do_test analyze3-1.2.1 {
} {}
do_eqp_test analyze3-1.2.2 {
SELECT sum(y) FROM t2 WHERE x>1 AND x<2
-} {0 0 0 {SEARCH TABLE t2 USING INDEX i2 (x>? AND x<?) (~200 rows)}}
+} {0 0 0 {SEARCH TABLE t2 USING INDEX i2 (x>? AND x<?)}}
do_eqp_test analyze3-1.2.3 {
SELECT sum(y) FROM t2 WHERE x>0 AND x<99
-} {0 0 0 {SCAN TABLE t2 (~111 rows)}}
+} {0 0 0 {SEARCH TABLE t2 USING INDEX i2 (x>? AND x<?)}}
do_test analyze3-1.2.4 {
sf_execsql { SELECT sum(y) FROM t2 WHERE x>12 AND x<20 }
} {161 0 4760}
@@ -165,17 +173,17 @@ do_test analyze3-1.2.6 {
} {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}
+} {1981 0 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}
+} {1981 0 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}
+} {1981 0 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
@@ -193,10 +201,10 @@ do_test analyze3-1.3.1 {
} {}
do_eqp_test analyze3-1.3.2 {
SELECT sum(y) FROM t3 WHERE x>200 AND x<300
-} {0 0 0 {SEARCH TABLE t3 USING INDEX i3 (x>? AND x<?) (~100 rows)}}
+} {0 0 0 {SEARCH TABLE t3 USING INDEX i3 (x>? AND x<?)}}
do_eqp_test analyze3-1.3.3 {
SELECT sum(y) FROM t3 WHERE x>0 AND x<1100
-} {0 0 0 {SCAN TABLE t3 (~111 rows)}}
+} {0 0 0 {SEARCH TABLE t3 USING INDEX i3 (x>? AND x<?)}}
do_test analyze3-1.3.4 {
sf_execsql { SELECT sum(y) FROM t3 WHERE x>200 AND x<300 }
@@ -213,17 +221,17 @@ do_test analyze3-1.3.6 {
} {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}
+} {2000 0 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}
+} {2000 0 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}
+} {2000 0 499500}
#-------------------------------------------------------------------------
# Test that the values of bound SQL variables may be used for the LIKE
@@ -248,10 +256,10 @@ do_test analyze3-2.1 {
} {}
do_eqp_test analyze3-2.2 {
SELECT count(a) FROM t1 WHERE b LIKE 'a%'
-} {0 0 0 {SEARCH TABLE t1 USING INDEX i1 (b>? AND b<?) (~30000 rows)}}
+} {0 0 0 {SEARCH TABLE t1 USING INDEX i1 (b>? AND b<?)}}
do_eqp_test analyze3-2.3 {
SELECT count(a) FROM t1 WHERE b LIKE '%a'
-} {0 0 0 {SCAN TABLE t1 (~500000 rows)}}
+} {0 0 0 {SCAN TABLE t1}}
do_test analyze3-2.4 {
sf_execsql { SELECT count(*) FROM t1 WHERE b LIKE 'a%' }
@@ -310,7 +318,6 @@ do_test analyze3-3.1 {
execsql COMMIT
execsql ANALYZE
} {}
-
do_test analyze3-3.2.1 {
set S [sqlite3_prepare_v2 db "SELECT * FROM t1 WHERE b>?" -1 dummy]
sqlite3_expired $S
@@ -330,7 +337,7 @@ do_test analyze3-3.2.5 {
do_test analyze3-3.2.6 {
sqlite3_bind_text $S 1 "abc" 3
sqlite3_expired $S
-} {0}
+} {1}
do_test analyze3-3.2.7 {
sqlite3_finalize $S
} {SQLITE_OK}
@@ -612,4 +619,29 @@ do_test analyze3-5.1.3 {
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;
+} {0 0 0 {SEARCH TABLE t1 USING INDEX i2 (c=?)}}
+
+do_eqp_test analyze3-6-2 {
+ SELECT * FROM t1 WHERE a = 5 AND b > 'w' AND c = 13;
+} {0 0 0 {SEARCH TABLE t1 USING INDEX i2 (c=?)}}
+
finish_test
diff --git a/lang/sql/sqlite/test/analyze4.test b/lang/sql/sqlite/test/analyze4.test
index 1fed564b..974ed89a 100644
--- a/lang/sql/sqlite/test/analyze4.test
+++ b/lang/sql/sqlite/test/analyze4.test
@@ -38,7 +38,7 @@ do_test analyze4-1.0 {
# 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}
-} {0 0 0 {SEARCH TABLE t1 USING INDEX t1a (a=?) (~1 rows)}}
+} {0 0 0 {SEARCH TABLE t1 USING INDEX t1a (a=?)}}
# Verify that the t1b index shows that it does not narrow down the
# search any at all.
diff --git a/lang/sql/sqlite/test/analyze5.test b/lang/sql/sqlite/test/analyze5.test
index a0469da1..ac175c07 100644
--- a/lang/sql/sqlite/test/analyze5.test
+++ b/lang/sql/sqlite/test/analyze5.test
@@ -10,14 +10,14 @@
#***********************************************************************
#
# This file implements tests for SQLite library. The focus of the tests
-# in this file is the use of the sqlite_stat2 histogram data on tables
+# 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 !stat2 {
+ifcapable !stat4&&!stat3 {
finish_test
return
}
@@ -28,6 +28,17 @@ 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)}
@@ -55,126 +66,138 @@ do_test analyze5-1.0 {
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;
- SELECT sample FROM sqlite_stat2 WHERE idx='t1u' ORDER BY sampleno;
}
-} {alpha alpha alpha alpha bravo bravo bravo charlie charlie delta}
-do_test analyze5-1.1 {
- string tolower \
- [db eval {SELECT sample from sqlite_stat2 WHERE idx='t1v' ORDER BY sampleno}]
-} {alpha alpha alpha alpha bravo bravo bravo charlie charlie delta}
-do_test analyze5-1.2 {
- db eval {SELECT sample from sqlite_stat2 WHERE idx='t1w' ORDER BY sampleno}
-} {{} 0 0 0 0 1 1 1 2 2}
-do_test analyze5-1.3 {
- db eval {SELECT sample from sqlite_stat2 WHERE idx='t1x' ORDER BY sampleno}
-} {{} {} {} {} 1 1 1 2 2 3}
-do_test analyze5-1.4 {
- db eval {SELECT sample from sqlite_stat2 WHERE idx='t1y' ORDER BY sampleno}
-} {0 0 0 0 0 0 0 0 0 0}
-do_test analyze5-1.5 {
- db eval {SELECT sample from sqlite_stat2 WHERE idx='t1z' ORDER BY sampleno}
-} {0 0 0 0 1 1 1 2 2 3}
-do_test analyze5-1.6 {
- db eval {SELECT sample from sqlite_stat2 WHERE idx='t1t' ORDER BY sampleno}
-} {0.5 0.5 0.5 0.5 1.5 1.5 1.5 2.5 2.5 3.5}
+ ifcapable stat4 {
+ db eval {
+ SELECT DISTINCT lindex(test_decode(sample),0)
+ FROM sqlite_stat4 WHERE idx='t1u' ORDER BY nlt;
+ }
+ } else {
+ db eval {
+ SELECT sample FROM sqlite_stat3 WHERE idx='t1u' ORDER BY nlt;
+ }
+ }
+} {alpha bravo charlie delta}
+do_test analyze5-1.1 {
+ ifcapable stat4 {
+ db eval {
+ SELECT DISTINCT lower(lindex(test_decode(sample), 0))
+ FROM sqlite_stat4 WHERE idx='t1v' ORDER BY 1
+ }
+ } else {
+ db eval {
+ SELECT lower(sample) FROM sqlite_stat3 WHERE idx='t1v' ORDER BY 1
+ }
+ }
+} {alpha bravo charlie delta}
+ifcapable stat4 {
+ 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}
+} else {
+ do_test analyze5-1.2 {
+ db eval {SELECT idx, count(*) FROM sqlite_stat3 GROUP BY 1 ORDER BY 1}
+ } {t1t 4 t1u 4 t1v 4 t1w 4 t1x 4 t1y 2 t1z 4}
+}
# 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 200
- 4 {z>=3 AND z<=3} t1z 100
- 5 {z>=4 AND z<=4} t1z 50
- 6 {z>=-1 AND z<=-1} t1z 50
- 7 {z>1 AND z<3} t1z 200
+ 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 100
- 13 {z>=3 AND z<100} t1z 100
- 14 {z>3 AND z<100} t1z 50
- 15 {z>=4 AND z<100} t1z 50
- 16 {z>=-100 AND z<=-1} t1z 50
+ 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 50
+ 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 900
- 22 {z>=-100 AND z<3} t1z 900
+ 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 200
- 34 {z>=3.0 AND z<=3.0} t1z 100
- 35 {z>=4.0 AND z<=4.0} t1z 50
- 36 {z>=-1.0 AND z<=-1.0} t1z 50
- 37 {z>1.5 AND z<3.0} t1z 200
- 38 {z>0.5 AND z<100} t1z 600
+ 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 300
+ 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 100
- 43 {z>=3.0 AND z<100} t1z 100
- 44 {z>3.2 AND z<100} t1z 50
- 45 {z>=4.0 AND z<100} t1z 50
- 46 {z>=-100 AND z<=-1.0} t1z 50
+ 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 50
+ 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 900
- 52 {z>=-100 AND z<3.0} t1z 900
+ 51 {z>=-100 AND z<=2.0} t1z 875
+ 52 {z>=-100 AND z<3.0} t1z 875
- 101 {z=-1} t1z 50
+ 101 {z=-1} t1z 1
102 {z=0} t1z 400
103 {z=1} t1z 300
- 104 {z=2} t1z 200
- 105 {z=3} t1z 100
- 106 {z=4} t1z 50
- 107 {z=-10.0} t1z 50
+ 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 200
- 111 {z=3.0} t1z 100
- 112 {z=4.0} t1z 50
- 113 {z=1.5} t1z 50
- 114 {z=2.5} t1z 50
+ 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 50
+ 201 {z IN (-1)} t1z 1
202 {z IN (0)} t1z 400
203 {z IN (1)} t1z 300
- 204 {z IN (2)} t1z 200
- 205 {z IN (3)} t1z 100
- 206 {z IN (4)} t1z 50
- 207 {z IN (0.5)} t1z 50
+ 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 900
+ 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 500
+ 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 150
- 216 {z=-1 OR z=3} t1z 150
+ 215 {z IN (-1,3)} t1z 126
+ 216 {z=-1 OR z=3} t1z 126
- 300 {y=0} {} 100
- 301 {y=1} t1y 50
- 302 {y=0.1} t1y 50
+ 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
- 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]
+ # 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
@@ -204,23 +227,24 @@ db eval {
# Verify that range queries generate the correct row count estimates
#
foreach {testid where index rows} {
- 500 {x IS NULL AND u='charlie'} t1u 20
- 501 {x=1 AND u='charlie'} t1x 5
- 502 {x IS NULL} {} 100
- 503 {x=1} t1x 50
- 504 {x IS NOT NULL} t1x 25
+ 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
- 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]
+ # 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
diff --git a/lang/sql/sqlite/test/analyze6.test b/lang/sql/sqlite/test/analyze6.test
index b090b5b0..f77f0532 100644
--- a/lang/sql/sqlite/test/analyze6.test
+++ b/lang/sql/sqlite/test/analyze6.test
@@ -17,7 +17,7 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
-ifcapable !stat2 {
+ifcapable !stat4&&!stat3 {
finish_test
return
}
@@ -30,14 +30,14 @@ proc eqp {sql {db db}} {
do_test analyze6-1.0 {
db eval {
- CREATE TABLE cat(x INT);
+ CREATE TABLE cat(x INT, yz TEXT);
CREATE UNIQUE INDEX catx ON cat(x);
/* Give cat 16 unique integers */
- INSERT INTO cat VALUES(1);
- INSERT INTO cat VALUES(2);
- INSERT INTO cat SELECT x+2 FROM cat;
- INSERT INTO cat SELECT x+4 FROM cat;
- INSERT INTO cat SELECT x+8 FROM cat;
+ 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);
@@ -61,14 +61,14 @@ do_test analyze6-1.0 {
#
do_test analyze6-1.1 {
eqp {SELECT count(*) FROM ev, cat WHERE x=y}
-} {0 0 1 {SCAN TABLE cat (~16 rows)} 0 1 0 {SEARCH TABLE ev USING COVERING INDEX evy (y=?) (~32 rows)}}
+} {0 0 1 {SCAN TABLE cat USING COVERING INDEX catx} 0 1 0 {SEARCH TABLE ev USING COVERING INDEX evy (y=?)}}
# The same plan is chosen regardless of the order of the tables in the
# FROM clause.
#
do_test analyze6-1.2 {
eqp {SELECT count(*) FROM cat, ev WHERE x=y}
-} {0 0 0 {SCAN TABLE cat (~16 rows)} 0 1 1 {SEARCH TABLE ev USING COVERING INDEX evy (y=?) (~32 rows)}}
+} {0 0 0 {SCAN TABLE cat USING COVERING INDEX catx} 0 1 1 {SEARCH TABLE ev USING COVERING INDEX evy (y=?)}}
# Ticket [83ea97620bd3101645138b7b0e71c12c5498fe3d] 2011-03-30
@@ -82,26 +82,26 @@ do_test analyze6-2.1 {
ANALYZE;
}
eqp {SELECT * FROM t201 WHERE z=5}
-} {0 0 0 {SEARCH TABLE t201 USING INDEX t201z (z=?) (~10 rows)}}
+} {0 0 0 {SEARCH TABLE t201 USING INDEX t201z (z=?)}}
do_test analyze6-2.2 {
eqp {SELECT * FROM t201 WHERE y=5}
-} {0 0 0 {SEARCH TABLE t201 USING INDEX sqlite_autoindex_t201_1 (y=?) (~1 rows)}}
+} {0 0 0 {SEARCH TABLE t201 USING INDEX sqlite_autoindex_t201_1 (y=?)}}
do_test analyze6-2.3 {
eqp {SELECT * FROM t201 WHERE x=5}
-} {0 0 0 {SEARCH TABLE t201 USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)}}
+} {0 0 0 {SEARCH TABLE t201 USING INTEGER PRIMARY KEY (rowid=?)}}
do_test analyze6-2.4 {
execsql {
INSERT INTO t201 VALUES(1,2,3);
ANALYZE t201;
}
eqp {SELECT * FROM t201 WHERE z=5}
-} {0 0 0 {SEARCH TABLE t201 USING INDEX t201z (z=?) (~10 rows)}}
+} {0 0 0 {SEARCH TABLE t201 USING INDEX t201z (z=?)}}
do_test analyze6-2.5 {
eqp {SELECT * FROM t201 WHERE y=5}
-} {0 0 0 {SEARCH TABLE t201 USING INDEX sqlite_autoindex_t201_1 (y=?) (~1 rows)}}
+} {0 0 0 {SEARCH TABLE t201 USING INDEX sqlite_autoindex_t201_1 (y=?)}}
do_test analyze6-2.6 {
eqp {SELECT * FROM t201 WHERE x=5}
-} {0 0 0 {SEARCH TABLE t201 USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)}}
+} {0 0 0 {SEARCH TABLE t201 USING INTEGER PRIMARY KEY (rowid=?)}}
do_test analyze6-2.7 {
execsql {
INSERT INTO t201 VALUES(4,5,7);
@@ -111,12 +111,12 @@ do_test analyze6-2.7 {
ANALYZE t201;
}
eqp {SELECT * FROM t201 WHERE z=5}
-} {0 0 0 {SEARCH TABLE t201 USING INDEX t201z (z=?) (~10 rows)}}
+} {0 0 0 {SEARCH TABLE t201 USING INDEX t201z (z=?)}}
do_test analyze6-2.8 {
eqp {SELECT * FROM t201 WHERE y=5}
-} {0 0 0 {SEARCH TABLE t201 USING INDEX sqlite_autoindex_t201_1 (y=?) (~1 rows)}}
+} {0 0 0 {SEARCH TABLE t201 USING INDEX sqlite_autoindex_t201_1 (y=?)}}
do_test analyze6-2.9 {
eqp {SELECT * FROM t201 WHERE x=5}
-} {0 0 0 {SEARCH TABLE t201 USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)}}
+} {0 0 0 {SEARCH TABLE t201 USING INTEGER PRIMARY KEY (rowid=?)}}
finish_test
diff --git a/lang/sql/sqlite/test/analyze7.test b/lang/sql/sqlite/test/analyze7.test
index 4892a223..76664546 100644
--- a/lang/sql/sqlite/test/analyze7.test
+++ b/lang/sql/sqlite/test/analyze7.test
@@ -26,7 +26,7 @@ ifcapable {!analyze||!vtab} {
# Generate some test data
#
do_test analyze7-1.0 {
- register_wholenumber_module db
+ load_static_extension db wholenumber
execsql {
CREATE TABLE t1(a,b,c,d);
CREATE INDEX t1a ON t1(a);
@@ -37,13 +37,13 @@ do_test analyze7-1.0 {
WHERE value BETWEEN 1 AND 256;
EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE a=123;
}
-} {0 0 0 {SEARCH TABLE t1 USING INDEX t1a (a=?) (~10 rows)}}
+} {0 0 0 {SEARCH TABLE t1 USING INDEX t1a (a=?)}}
do_test analyze7-1.1 {
execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE b=123;}
-} {0 0 0 {SEARCH TABLE t1 USING INDEX t1b (b=?) (~10 rows)}}
+} {0 0 0 {SEARCH TABLE t1 USING INDEX t1b (b=?)}}
do_test analyze7-1.2 {
execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE c=2;}
-} {0 0 0 {SEARCH TABLE t1 USING INDEX t1cd (c=?) (~10 rows)}}
+} {0 0 0 {SEARCH TABLE 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
@@ -53,20 +53,20 @@ do_test analyze7-2.0 {
execsql {ANALYZE t1a;}
db cache flush
execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE a=123;}
-} {0 0 0 {SEARCH TABLE t1 USING INDEX t1a (a=?) (~1 rows)}}
+} {0 0 0 {SEARCH TABLE t1 USING INDEX t1a (a=?)}}
do_test analyze7-2.1 {
execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE b=123;}
-} {0 0 0 {SEARCH TABLE t1 USING INDEX t1b (b=?) (~10 rows)}}
+} {0 0 0 {SEARCH TABLE t1 USING INDEX t1b (b=?)}}
do_test analyze7-2.2 {
execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE c=2;}
-} {0 0 0 {SEARCH TABLE t1 USING INDEX t1cd (c=?) (~10 rows)}}
+} {0 0 0 {SEARCH TABLE 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}
-} {0 0 0 {SEARCH TABLE t1 USING INDEX t1a (a=?) (~1 rows)}}
+} {0 0 0 {SEARCH TABLE 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.
@@ -75,37 +75,40 @@ do_test analyze7-3.0 {
execsql {ANALYZE t1cd;}
db cache flush;
execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE a=123;}
-} {0 0 0 {SEARCH TABLE t1 USING INDEX t1a (a=?) (~1 rows)}}
+} {0 0 0 {SEARCH TABLE t1 USING INDEX t1a (a=?)}}
do_test analyze7-3.1 {
execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE b=123;}
-} {0 0 0 {SEARCH TABLE t1 USING INDEX t1b (b=?) (~10 rows)}}
+} {0 0 0 {SEARCH TABLE t1 USING INDEX t1b (b=?)}}
do_test analyze7-3.2.1 {
execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE c=?;}
-} {0 0 0 {SEARCH TABLE t1 USING INDEX t1cd (c=?) (~86 rows)}}
-ifcapable stat2 {
- # If ENABLE_STAT2 is defined, SQLite comes up with a different estimated
+} {0 0 0 {SEARCH TABLE t1 USING INDEX t1cd (c=?)}}
+ifcapable stat4||stat3 {
+ # 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;}
- } {0 0 0 {SEARCH TABLE t1 USING INDEX t1cd (c=?) (~51 rows)}}
+ } {0 0 0 {SEARCH TABLE t1 USING INDEX t1cd (c=?)}}
} else {
- # If ENABLE_STAT2 is not defined, the expected row count for (c=2) is the
+ # 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;}
- } {0 0 0 {SEARCH TABLE t1 USING INDEX t1cd (c=?) (~86 rows)}}
+ } {0 0 0 {SEARCH TABLE t1 USING INDEX t1cd (c=?)}}
}
do_test analyze7-3.3 {
execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE a=123 AND b=123}
-} {0 0 0 {SEARCH TABLE t1 USING INDEX t1a (a=?) (~1 rows)}}
-do_test analyze7-3.4 {
- execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE c=123 AND b=123}
-} {0 0 0 {SEARCH TABLE t1 USING INDEX t1b (b=?) (~2 rows)}}
-do_test analyze7-3.5 {
- execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE a=123 AND c=123}
-} {0 0 0 {SEARCH TABLE t1 USING INDEX t1a (a=?) (~1 rows)}}
+} {0 0 0 {SEARCH TABLE t1 USING INDEX t1a (a=?)}}
+
+ifcapable {!stat4 && !stat3} {
+ do_test analyze7-3.4 {
+ execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE c=123 AND b=123}
+ } {0 0 0 {SEARCH TABLE t1 USING INDEX t1b (b=?)}}
+ do_test analyze7-3.5 {
+ execsql {EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE a=123 AND c=123}
+ } {0 0 0 {SEARCH TABLE 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}
-} {0 0 0 {SEARCH TABLE t1 USING INDEX t1cd (c=? AND d=?) (~1 rows)}}
+} {0 0 0 {SEARCH TABLE t1 USING INDEX t1cd (c=? AND d=?)}}
finish_test
diff --git a/lang/sql/sqlite/test/analyze8.test b/lang/sql/sqlite/test/analyze8.test
new file mode 100644
index 00000000..4384c396
--- /dev/null
+++ b/lang/sql/sqlite/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_stat3.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+ifcapable !stat4&&!stat3 {
+ 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}
+} {0 0 0 {SEARCH TABLE t1 USING INDEX t1b (b=?)}}
+do_test 1.2 {
+ eqp {SELECT * FROM t1 WHERE a=99 AND b=55}
+} {0 0 0 {SEARCH TABLE t1 USING INDEX t1a (a=?)}}
+do_test 1.3 {
+ eqp {SELECT * FROM t1 WHERE a=101 AND b=55}
+} {0 0 0 {SEARCH TABLE t1 USING INDEX t1a (a=?)}}
+do_test 1.4 {
+ eqp {SELECT * FROM t1 WHERE a=100 AND b=56}
+} {0 0 0 {SEARCH TABLE t1 USING INDEX t1b (b=?)}}
+do_test 1.5 {
+ eqp {SELECT * FROM t1 WHERE a=99 AND b=56}
+} {0 0 0 {SEARCH TABLE t1 USING INDEX t1a (a=?)}}
+do_test 1.6 {
+ eqp {SELECT * FROM t1 WHERE a=101 AND b=56}
+} {0 0 0 {SEARCH TABLE t1 USING INDEX t1a (a=?)}}
+do_test 2.1 {
+ eqp {SELECT * FROM t1 WHERE a=100 AND b BETWEEN 50 AND 54}
+} {0 0 0 {SEARCH TABLE t1 USING INDEX t1b (b>? AND b<?)}}
+
+# There are many more values of c between 0 and 100000 than there are
+# between 800000 and 900000. So t1c is more selective for the latter
+# range.
+#
+# Test 3.2 is a little unstable. It depends on the planner estimating
+# that (b BETWEEN 50 AND 54) will match more rows than (c BETWEEN
+# 800000 AND 900000). Which is a pretty close call (50 vs. 32), so
+# the planner could get it wrong with an unlucky set of samples. This
+# case happens to work, but others ("b BETWEEN 40 AND 44" for example)
+# will fail.
+#
+do_execsql_test 3.0 {
+ SELECT count(*) FROM t1 WHERE b BETWEEN 50 AND 54;
+ SELECT count(*) FROM t1 WHERE c BETWEEN 0 AND 100000;
+ SELECT count(*) FROM t1 WHERE c BETWEEN 800000 AND 900000;
+} {50 376 32}
+do_test 3.1 {
+ eqp {SELECT * FROM t1 WHERE b BETWEEN 50 AND 54 AND c BETWEEN 0 AND 100000}
+} {0 0 0 {SEARCH TABLE t1 USING INDEX t1b (b>? AND b<?)}}
+do_test 3.2 {
+ eqp {SELECT * FROM t1
+ WHERE b BETWEEN 50 AND 54 AND c BETWEEN 800000 AND 900000}
+} {0 0 0 {SEARCH TABLE t1 USING INDEX t1c (c>? AND c<?)}}
+do_test 3.3 {
+ eqp {SELECT * FROM t1 WHERE a=100 AND c BETWEEN 0 AND 100000}
+} {0 0 0 {SEARCH TABLE t1 USING INDEX t1a (a=?)}}
+do_test 3.4 {
+ eqp {SELECT * FROM t1
+ WHERE a=100 AND c BETWEEN 800000 AND 900000}
+} {0 0 0 {SEARCH TABLE t1 USING INDEX t1c (c>? AND c<?)}}
+
+finish_test
diff --git a/lang/sql/sqlite/test/analyze9.test b/lang/sql/sqlite/test/analyze9.test
new file mode 100644
index 00000000..0fce55ac
--- /dev/null
+++ b/lang/sql/sqlite/test/analyze9.test
@@ -0,0 +1,953 @@
+# 2013 August 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 contains automated tests used to verify that the sqlite_stat4
+# functionality is working.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix analyze9
+
+ifcapable !stat4 {
+ finish_test
+ return
+}
+
+proc s {blob} {
+ set ret ""
+ binary scan $blob c* bytes
+ foreach b $bytes {
+ set t [binary format c $b]
+ if {[string is print $t]} {
+ append ret $t
+ } else {
+ append ret .
+ }
+ }
+ return $ret
+}
+db function s s
+
+do_execsql_test 1.0 {
+ CREATE TABLE t1(a TEXT, b TEXT);
+ INSERT INTO t1 VALUES('(0)', '(0)');
+ INSERT INTO t1 VALUES('(1)', '(1)');
+ INSERT INTO t1 VALUES('(2)', '(2)');
+ INSERT INTO t1 VALUES('(3)', '(3)');
+ INSERT INTO t1 VALUES('(4)', '(4)');
+ CREATE INDEX i1 ON t1(a, b);
+} {}
+
+
+do_execsql_test 1.1 {
+ ANALYZE;
+} {}
+
+do_execsql_test 1.2 {
+ SELECT tbl,idx,nEq,nLt,nDLt,test_decode(sample) FROM sqlite_stat4;
+} {
+ t1 i1 {1 1 1} {0 0 0} {0 0 0} {(0) (0) 1}
+ t1 i1 {1 1 1} {1 1 1} {1 1 1} {(1) (1) 2}
+ t1 i1 {1 1 1} {2 2 2} {2 2 2} {(2) (2) 3}
+ t1 i1 {1 1 1} {3 3 3} {3 3 3} {(3) (3) 4}
+ t1 i1 {1 1 1} {4 4 4} {4 4 4} {(4) (4) 5}
+}
+
+if {[permutation] != "utf16"} {
+ do_execsql_test 1.3 {
+ SELECT tbl,idx,nEq,nLt,nDLt,s(sample) FROM sqlite_stat4;
+ } {
+ t1 i1 {1 1 1} {0 0 0} {0 0 0} ....(0)(0)
+ t1 i1 {1 1 1} {1 1 1} {1 1 1} ....(1)(1).
+ t1 i1 {1 1 1} {2 2 2} {2 2 2} ....(2)(2).
+ t1 i1 {1 1 1} {3 3 3} {3 3 3} ....(3)(3).
+ t1 i1 {1 1 1} {4 4 4} {4 4 4} ....(4)(4).
+ }
+}
+
+
+#-------------------------------------------------------------------------
+# This is really just to test SQL user function "test_decode".
+#
+reset_db
+do_execsql_test 2.1 {
+ CREATE TABLE t1(a, b, c);
+ INSERT INTO t1 VALUES('some text', 14, NULL);
+ INSERT INTO t1 VALUES(22.0, NULL, x'656667');
+ CREATE INDEX i1 ON t1(a, b, c);
+ ANALYZE;
+ SELECT test_decode(sample) FROM sqlite_stat4;
+} {
+ {22.0 NULL x'656667' 2}
+ {{some text} 14 NULL 1}
+}
+
+#-------------------------------------------------------------------------
+#
+reset_db
+do_execsql_test 3.1 {
+ CREATE TABLE t2(a, b);
+ CREATE INDEX i2 ON t2(a, b);
+ BEGIN;
+}
+
+do_test 3.2 {
+ for {set i 0} {$i < 1000} {incr i} {
+ set a [expr $i / 10]
+ set b [expr int(rand() * 15.0)]
+ execsql { INSERT INTO t2 VALUES($a, $b) }
+ }
+ execsql COMMIT
+} {}
+
+db func lindex lindex
+
+# Each value of "a" occurs exactly 10 times in the table.
+#
+do_execsql_test 3.3.1 {
+ SELECT count(*) FROM t2 GROUP BY a;
+} [lrange [string repeat "10 " 100] 0 99]
+
+# The first element in the "nEq" list of all samples should therefore be 10.
+#
+do_execsql_test 3.3.2 {
+ ANALYZE;
+ SELECT lindex(nEq, 0) FROM sqlite_stat4;
+} [lrange [string repeat "10 " 100] 0 23]
+
+#-------------------------------------------------------------------------
+#
+do_execsql_test 3.4 {
+ DROP TABLE IF EXISTS t1;
+ CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
+ INSERT INTO t1 VALUES(1, 1, 'one-a');
+ INSERT INTO t1 VALUES(11, 1, 'one-b');
+ INSERT INTO t1 VALUES(21, 1, 'one-c');
+ INSERT INTO t1 VALUES(31, 1, 'one-d');
+ INSERT INTO t1 VALUES(41, 1, 'one-e');
+ INSERT INTO t1 VALUES(51, 1, 'one-f');
+ INSERT INTO t1 VALUES(61, 1, 'one-g');
+ INSERT INTO t1 VALUES(71, 1, 'one-h');
+ INSERT INTO t1 VALUES(81, 1, 'one-i');
+ INSERT INTO t1 VALUES(91, 1, 'one-j');
+ INSERT INTO t1 SELECT a+1,2,'two' || substr(c,4) FROM t1;
+ INSERT INTO t1 SELECT a+2,3,'three'||substr(c,4) FROM t1 WHERE c GLOB 'one-*';
+ INSERT INTO t1 SELECT a+3,4,'four'||substr(c,4) FROM t1 WHERE c GLOB 'one-*';
+ INSERT INTO t1 SELECT a+4,5,'five'||substr(c,4) FROM t1 WHERE c GLOB 'one-*';
+ INSERT INTO t1 SELECT a+5,6,'six'||substr(c,4) FROM t1 WHERE c GLOB 'one-*';
+ CREATE INDEX t1b ON t1(b);
+ ANALYZE;
+ SELECT c FROM t1 WHERE b=3 AND a BETWEEN 30 AND 60;
+} {three-d three-e three-f}
+
+
+#-------------------------------------------------------------------------
+# These tests verify that the sample selection for stat4 appears to be
+# working as designed.
+#
+
+reset_db
+db func lindex lindex
+db func lrange lrange
+
+do_execsql_test 4.0 {
+ DROP TABLE IF EXISTS t1;
+ CREATE TABLE t1(a, b, c);
+ CREATE INDEX i1 ON t1(c, b, a);
+}
+
+
+proc insert_filler_rows_n {iStart args} {
+ set A(-ncopy) 1
+ set A(-nval) 1
+
+ foreach {k v} $args {
+ if {[info exists A($k)]==0} { error "no such option: $k" }
+ set A($k) $v
+ }
+ if {[llength $args] % 2} {
+ error "option requires an argument: [lindex $args end]"
+ }
+
+ for {set i 0} {$i < $A(-nval)} {incr i} {
+ set iVal [expr $iStart+$i]
+ for {set j 0} {$j < $A(-ncopy)} {incr j} {
+ execsql { INSERT INTO t1 VALUES($iVal, $iVal, $iVal) }
+ }
+ }
+}
+
+do_test 4.1 {
+ execsql { BEGIN }
+ insert_filler_rows_n 0 -ncopy 10 -nval 19
+ insert_filler_rows_n 20 -ncopy 1 -nval 100
+
+ execsql {
+ INSERT INTO t1(c, b, a) VALUES(200, 1, 'a');
+ INSERT INTO t1(c, b, a) VALUES(200, 1, 'b');
+ INSERT INTO t1(c, b, a) VALUES(200, 1, 'c');
+
+ INSERT INTO t1(c, b, a) VALUES(200, 2, 'e');
+ INSERT INTO t1(c, b, a) VALUES(200, 2, 'f');
+
+ INSERT INTO t1(c, b, a) VALUES(201, 3, 'g');
+ INSERT INTO t1(c, b, a) VALUES(201, 4, 'h');
+
+ ANALYZE;
+ SELECT count(*) FROM sqlite_stat4;
+ SELECT count(*) FROM t1;
+ }
+} {24 297}
+
+do_execsql_test 4.2 {
+ SELECT
+ neq,
+ lrange(nlt, 0, 2),
+ lrange(ndlt, 0, 2),
+ lrange(test_decode(sample), 0, 2)
+ FROM sqlite_stat4
+ ORDER BY rowid LIMIT 16;
+} {
+ {10 10 10 1} {0 0 0} {0 0 0} {0 0 0}
+ {10 10 10 1} {10 10 10} {1 1 1} {1 1 1}
+ {10 10 10 1} {20 20 20} {2 2 2} {2 2 2}
+ {10 10 10 1} {30 30 30} {3 3 3} {3 3 3}
+ {10 10 10 1} {40 40 40} {4 4 4} {4 4 4}
+ {10 10 10 1} {50 50 50} {5 5 5} {5 5 5}
+ {10 10 10 1} {60 60 60} {6 6 6} {6 6 6}
+ {10 10 10 1} {70 70 70} {7 7 7} {7 7 7}
+ {10 10 10 1} {80 80 80} {8 8 8} {8 8 8}
+ {10 10 10 1} {90 90 90} {9 9 9} {9 9 9}
+ {10 10 10 1} {100 100 100} {10 10 10} {10 10 10}
+ {10 10 10 1} {110 110 110} {11 11 11} {11 11 11}
+ {10 10 10 1} {120 120 120} {12 12 12} {12 12 12}
+ {10 10 10 1} {130 130 130} {13 13 13} {13 13 13}
+ {10 10 10 1} {140 140 140} {14 14 14} {14 14 14}
+ {10 10 10 1} {150 150 150} {15 15 15} {15 15 15}
+}
+
+do_execsql_test 4.3 {
+ SELECT
+ neq,
+ lrange(nlt, 0, 2),
+ lrange(ndlt, 0, 2),
+ lrange(test_decode(sample), 0, 1)
+ FROM sqlite_stat4
+ ORDER BY rowid DESC LIMIT 2;
+} {
+ {2 1 1 1} {295 296 296} {120 122 125} {201 4}
+ {5 3 1 1} {290 290 290} {119 119 119} {200 1}
+}
+
+do_execsql_test 4.4 { SELECT count(DISTINCT c) FROM t1 WHERE c<201 } 120
+do_execsql_test 4.5 { SELECT count(DISTINCT c) FROM t1 WHERE c<200 } 119
+
+# Check that the perioidic samples are present.
+do_execsql_test 4.6 {
+ SELECT count(*) FROM sqlite_stat4
+ WHERE lindex(test_decode(sample), 3) IN
+ ('34', '68', '102', '136', '170', '204', '238', '272')
+} {8}
+
+reset_db
+do_test 4.7 {
+ execsql {
+ BEGIN;
+ CREATE TABLE t1(o,t INTEGER PRIMARY KEY);
+ CREATE INDEX i1 ON t1(o);
+ }
+ for {set i 0} {$i<10000} {incr i [expr (($i<1000)?1:10)]} {
+ execsql { INSERT INTO t1 VALUES('x', $i) }
+ }
+ execsql {
+ COMMIT;
+ ANALYZE;
+ SELECT count(*) FROM sqlite_stat4;
+ }
+} {8}
+do_execsql_test 4.8 {
+ SELECT test_decode(sample) FROM sqlite_stat4;
+} {
+ {x 211} {x 423} {x 635} {x 847}
+ {x 1590} {x 3710} {x 5830} {x 7950}
+}
+
+
+#-------------------------------------------------------------------------
+# The following would cause a crash at one point.
+#
+reset_db
+do_execsql_test 5.1 {
+ PRAGMA encoding = 'utf-16';
+ CREATE TABLE t0(v);
+ ANALYZE;
+}
+
+#-------------------------------------------------------------------------
+# This was also crashing (corrupt sqlite_stat4 table).
+#
+reset_db
+do_execsql_test 6.1 {
+ CREATE TABLE t1(a, b);
+ CREATE INDEX i1 ON t1(a);
+ CREATE INDEX i2 ON t1(b);
+ INSERT INTO t1 VALUES(1, 1);
+ INSERT INTO t1 VALUES(2, 2);
+ INSERT INTO t1 VALUES(3, 3);
+ INSERT INTO t1 VALUES(4, 4);
+ INSERT INTO t1 VALUES(5, 5);
+ ANALYZE;
+ PRAGMA writable_schema = 1;
+ CREATE TEMP TABLE x1 AS
+ SELECT tbl,idx,neq,nlt,ndlt,sample FROM sqlite_stat4
+ ORDER BY (rowid%5), rowid;
+ DELETE FROM sqlite_stat4;
+ INSERT INTO sqlite_stat4 SELECT * FROM x1;
+ PRAGMA writable_schema = 0;
+ ANALYZE sqlite_master;
+}
+do_execsql_test 6.2 {
+ SELECT * FROM t1 WHERE a = 'abc';
+}
+
+#-------------------------------------------------------------------------
+# The following tests experiment with adding corrupted records to the
+# 'sample' column of the sqlite_stat4 table.
+#
+reset_db
+sqlite3_db_config_lookaside db 0 0 0
+
+do_execsql_test 7.1 {
+ CREATE TABLE t1(a, b);
+ CREATE INDEX i1 ON t1(a, b);
+ INSERT INTO t1 VALUES(1, 1);
+ INSERT INTO t1 VALUES(2, 2);
+ INSERT INTO t1 VALUES(3, 3);
+ INSERT INTO t1 VALUES(4, 4);
+ INSERT INTO t1 VALUES(5, 5);
+ ANALYZE;
+ UPDATE sqlite_stat4 SET sample = X'' WHERE rowid = 1;
+ ANALYZE sqlite_master;
+}
+
+do_execsql_test 7.2 {
+ UPDATE sqlite_stat4 SET sample = X'FFFF';
+ ANALYZE sqlite_master;
+ SELECT * FROM t1 WHERE a = 1;
+} {1 1}
+
+do_execsql_test 7.3 {
+ ANALYZE;
+ UPDATE sqlite_stat4 SET neq = '0 0 0';
+ ANALYZE sqlite_master;
+ SELECT * FROM t1 WHERE a = 1;
+} {1 1}
+
+do_execsql_test 7.4 {
+ ANALYZE;
+ UPDATE sqlite_stat4 SET ndlt = '0 0 0';
+ ANALYZE sqlite_master;
+ SELECT * FROM t1 WHERE a = 3;
+} {3 3}
+
+do_execsql_test 7.5 {
+ ANALYZE;
+ UPDATE sqlite_stat4 SET nlt = '0 0 0';
+ ANALYZE sqlite_master;
+ SELECT * FROM t1 WHERE a = 5;
+} {5 5}
+
+#-------------------------------------------------------------------------
+#
+reset_db
+do_execsql_test 8.1 {
+ CREATE TABLE t1(x TEXT);
+ CREATE INDEX i1 ON t1(x);
+ INSERT INTO t1 VALUES('1');
+ INSERT INTO t1 VALUES('2');
+ INSERT INTO t1 VALUES('3');
+ INSERT INTO t1 VALUES('4');
+ ANALYZE;
+}
+do_execsql_test 8.2 {
+ SELECT * FROM t1 WHERE x = 3;
+} {3}
+
+#-------------------------------------------------------------------------
+# Check that the bug fixed by [91733bc485] really is fixed.
+#
+reset_db
+do_execsql_test 9.1 {
+ CREATE TABLE t1(a, b, c, d, e);
+ CREATE INDEX i1 ON t1(a, b, c, d);
+ CREATE INDEX i2 ON t1(e);
+}
+do_test 9.2 {
+ execsql BEGIN;
+ for {set i 0} {$i < 100} {incr i} {
+ execsql "INSERT INTO t1 VALUES('x', 'y', 'z', $i, [expr $i/2])"
+ }
+ for {set i 0} {$i < 20} {incr i} {
+ execsql "INSERT INTO t1 VALUES('x', 'y', 'z', 101, $i)"
+ }
+ for {set i 102} {$i < 200} {incr i} {
+ execsql "INSERT INTO t1 VALUES('x', 'y', 'z', $i, [expr $i/2])"
+ }
+ execsql COMMIT
+ execsql ANALYZE
+} {}
+
+do_eqp_test 9.3.1 {
+ SELECT * FROM t1 WHERE a='x' AND b='y' AND c='z' AND d=101 AND e=5;
+} {/t1 USING INDEX i2/}
+do_eqp_test 9.3.2 {
+ SELECT * FROM t1 WHERE a='x' AND b='y' AND c='z' AND d=99 AND e=5;
+} {/t1 USING INDEX i1/}
+
+set value_d [expr 101]
+do_eqp_test 9.4.1 {
+ SELECT * FROM t1 WHERE a='x' AND b='y' AND c='z' AND d=$value_d AND e=5
+} {/t1 USING INDEX i2/}
+set value_d [expr 99]
+do_eqp_test 9.4.2 {
+ SELECT * FROM t1 WHERE a='x' AND b='y' AND c='z' AND d=$value_d AND e=5
+} {/t1 USING INDEX i1/}
+
+#-------------------------------------------------------------------------
+# Check that the planner takes stat4 data into account when considering
+# "IS NULL" and "IS NOT NULL" constraints.
+#
+do_execsql_test 10.1.1 {
+ DROP TABLE IF EXISTS t3;
+ CREATE TABLE t3(a, b);
+ CREATE INDEX t3a ON t3(a);
+ CREATE INDEX t3b ON t3(b);
+}
+do_test 10.1.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($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);
+ 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<20
+} {/SEARCH TABLE t1 USING INDEX i1/}
+do_eqp_test 13.2.2 {
+ SELECT * FROM t1 WHERE a='abc' AND rowid<'15' AND b<20
+} {/SEARCH TABLE t1 USING INDEX i1/}
+do_eqp_test 13.3.1 {
+ SELECT * FROM t1 WHERE a='abc' AND rowid<100 AND b<20
+} {/SEARCH TABLE t1 USING INDEX i2/}
+do_eqp_test 13.3.2 {
+ SELECT * FROM t1 WHERE a='abc' AND rowid<'100' AND b<20
+} {/SEARCH TABLE 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 TABLE t1 USING INDEX i1/}
+do_eqp_test 13.2.2 {
+ SELECT * FROM t1 WHERE a='ott' AND b<'10' AND c=1
+} {/SEARCH TABLE 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}
+}
+
+finish_test
diff --git a/lang/sql/sqlite/test/analyzeA.test b/lang/sql/sqlite/test/analyzeA.test
new file mode 100644
index 00000000..d9ca2c0f
--- /dev/null
+++ b/lang/sql/sqlite/test/analyzeA.test
@@ -0,0 +1,167 @@
+# 2013 August 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 contains automated tests used to verify that the current build
+# (which must be either ENABLE_STAT3 or ENABLE_STAT4) works with both stat3
+# and stat4 data.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix analyzeA
+
+ifcapable !stat4&&!stat3 {
+ finish_test
+ return
+}
+
+# Populate the stat3 table according to the current contents of the db
+#
+proc populate_stat3 {{bDropTable 1}} {
+ # Open a second connection on database "test.db" and run ANALYZE. If this
+ # is an ENABLE_STAT3 build, this is all that is required to create and
+ # populate the sqlite_stat3 table.
+ #
+ sqlite3 db2 test.db
+ execsql { ANALYZE }
+
+ # Now, if this is an ENABLE_STAT4 build, create and populate the
+ # sqlite_stat3 table based on the stat4 data gathered by the ANALYZE
+ # above. Then drop the sqlite_stat4 table.
+ #
+ ifcapable stat4 {
+ db2 func lindex lindex
+ execsql {
+ PRAGMA writable_schema = on;
+ CREATE TABLE sqlite_stat3(tbl,idx,neq,nlt,ndlt,sample);
+ INSERT INTO sqlite_stat3
+ SELECT DISTINCT tbl, idx,
+ lindex(neq,0), lindex(nlt,0), lindex(ndlt,0), test_extract(sample, 0)
+ FROM sqlite_stat4;
+ } db2
+ if {$bDropTable} { execsql {DROP TABLE sqlite_stat4} db2 }
+ execsql { PRAGMA writable_schema = off }
+ }
+
+ # Modify the database schema cookie to ensure that the other connection
+ # reloads the schema.
+ #
+ execsql {
+ CREATE TABLE obscure_tbl_nm(x);
+ DROP TABLE obscure_tbl_nm;
+ } db2
+ db2 close
+}
+
+# Populate the stat4 table according to the current contents of the db
+#
+proc populate_stat4 {{bDropTable 1}} {
+ sqlite3 db2 test.db
+ execsql { ANALYZE }
+
+ ifcapable stat3 {
+ execsql {
+ PRAGMA writable_schema = on;
+ CREATE TABLE sqlite_stat4(tbl,idx,neq,nlt,ndlt,sample);
+ INSERT INTO sqlite_stat4
+ SELECT tbl, idx, neq, nlt, ndlt, sqlite_record(sample)
+ FROM sqlite_stat3;
+ } db2
+ if {$bDropTable} { execsql {DROP TABLE sqlite_stat3} db2 }
+ execsql { PRAGMA writable_schema = off }
+ }
+
+ # Modify the database schema cookie to ensure that the other connection
+ # reloads the schema.
+ #
+ execsql {
+ CREATE TABLE obscure_tbl_nm(x);
+ DROP TABLE obscure_tbl_nm;
+ } db2
+ db2 close
+}
+
+# Populate the stat4 table according to the current contents of the db.
+# Leave deceptive data in the stat3 table. This data should be ignored
+# in favour of that from the stat4 table.
+#
+proc populate_both {} {
+ ifcapable stat4 { populate_stat3 0 }
+ ifcapable stat3 { populate_stat4 0 }
+
+ sqlite3 db2 test.db
+ execsql {
+ PRAGMA writable_schema = on;
+ UPDATE sqlite_stat3 SET idx =
+ CASE idx WHEN 't1b' THEN 't1c' ELSE 't1b'
+ END;
+ PRAGMA writable_schema = off;
+ CREATE TABLE obscure_tbl_nm(x);
+ DROP TABLE obscure_tbl_nm;
+ } db2
+ db2 close
+}
+
+foreach {tn analyze_cmd} {
+ 1 populate_stat4
+ 2 populate_stat3
+ 3 populate_both
+} {
+ reset_db
+ do_test 1.$tn.1 {
+ execsql { CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c) }
+ for {set i 0} {$i < 100} {incr i} {
+ set c [expr int(pow(1.1,$i)/100)]
+ set b [expr 125 - int(pow(1.1,99-$i))/100]
+ execsql {INSERT INTO t1 VALUES($i, $b, $c)}
+ }
+ } {}
+
+ execsql { CREATE INDEX t1b ON t1(b) }
+ execsql { CREATE INDEX t1c ON t1(c) }
+ $analyze_cmd
+
+ do_execsql_test 1.$tn.2.1 { SELECT count(*) FROM t1 WHERE b=31 } 1
+ do_execsql_test 1.$tn.2.2 { SELECT count(*) FROM t1 WHERE c=0 } 49
+ do_execsql_test 1.$tn.2.3 { SELECT count(*) FROM t1 WHERE b=125 } 49
+ do_execsql_test 1.$tn.2.4 { SELECT count(*) FROM t1 WHERE c=16 } 1
+
+ do_eqp_test 1.$tn.2.5 {
+ SELECT * FROM t1 WHERE b = 31 AND c = 0;
+ } {0 0 0 {SEARCH TABLE t1 USING INDEX t1b (b=?)}}
+ do_eqp_test 1.$tn.2.6 {
+ SELECT * FROM t1 WHERE b = 125 AND c = 16;
+ } {0 0 0 {SEARCH TABLE t1 USING INDEX t1c (c=?)}}
+
+ do_execsql_test 1.$tn.3.1 {
+ SELECT count(*) FROM t1 WHERE b BETWEEN 0 AND 50
+ } {6}
+ do_execsql_test 1.$tn.3.2 {
+ SELECT count(*) FROM t1 WHERE c BETWEEN 0 AND 50
+ } {90}
+ do_execsql_test 1.$tn.3.3 {
+ SELECT count(*) FROM t1 WHERE b BETWEEN 75 AND 125
+ } {90}
+ do_execsql_test 1.$tn.3.4 {
+ SELECT count(*) FROM t1 WHERE c BETWEEN 75 AND 125
+ } {6}
+
+ do_eqp_test 1.$tn.3.5 {
+ SELECT * FROM t1 WHERE b BETWEEN 0 AND 50 AND c BETWEEN 0 AND 50
+ } {0 0 0 {SEARCH TABLE t1 USING INDEX t1b (b>? AND b<?)}}
+
+ do_eqp_test 1.$tn.3.6 {
+ SELECT * FROM t1 WHERE b BETWEEN 75 AND 125 AND c BETWEEN 75 AND 125
+ } {0 0 0 {SEARCH TABLE t1 USING INDEX t1c (c>? AND c<?)}}
+}
+
+finish_test
+
diff --git a/lang/sql/sqlite/test/analyzeB.test b/lang/sql/sqlite/test/analyzeB.test
new file mode 100644
index 00000000..2a78c18b
--- /dev/null
+++ b/lang/sql/sqlite/test/analyzeB.test
@@ -0,0 +1,683 @@
+# 2013 August 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 contains automated tests used to verify that the sqlite_stat3
+# functionality is working. The tests in this file are based on a subset
+# of the sqlite_stat4 tests in analyze9.test.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix analyzeB
+
+ifcapable !stat3 {
+ finish_test
+ return
+}
+
+do_execsql_test 1.0 {
+ CREATE TABLE t1(a TEXT, b TEXT);
+ INSERT INTO t1 VALUES('(0)', '(0)');
+ INSERT INTO t1 VALUES('(1)', '(1)');
+ INSERT INTO t1 VALUES('(2)', '(2)');
+ INSERT INTO t1 VALUES('(3)', '(3)');
+ INSERT INTO t1 VALUES('(4)', '(4)');
+ CREATE INDEX i1 ON t1(a, b);
+} {}
+
+
+do_execsql_test 1.1 {
+ ANALYZE;
+} {}
+
+do_execsql_test 1.2 {
+ SELECT tbl,idx,nEq,nLt,nDLt,quote(sample) FROM sqlite_stat3;
+} {
+ t1 i1 1 0 0 '(0)'
+ t1 i1 1 1 1 '(1)'
+ t1 i1 1 2 2 '(2)'
+ t1 i1 1 3 3 '(3)'
+ t1 i1 1 4 4 '(4)'
+}
+
+if {[permutation] != "utf16"} {
+ do_execsql_test 1.3 {
+ SELECT tbl,idx,nEq,nLt,nDLt,quote(sample) FROM sqlite_stat3;
+ } {
+ t1 i1 1 0 0 '(0)'
+ t1 i1 1 1 1 '(1)'
+ t1 i1 1 2 2 '(2)'
+ t1 i1 1 3 3 '(3)'
+ t1 i1 1 4 4 '(4)'
+ }
+}
+
+
+#-------------------------------------------------------------------------
+# This is really just to test SQL user function "test_decode".
+#
+reset_db
+do_execsql_test 2.1 {
+ CREATE TABLE t1(a, b, c);
+ INSERT INTO t1(a) VALUES('some text');
+ INSERT INTO t1(a) VALUES(14);
+ INSERT INTO t1(a) VALUES(NULL);
+ INSERT INTO t1(a) VALUES(22.0);
+ INSERT INTO t1(a) VALUES(x'656667');
+ CREATE INDEX i1 ON t1(a, b, c);
+ ANALYZE;
+ SELECT quote(sample) FROM sqlite_stat3;
+} {
+ NULL 14 22.0 {'some text'} X'656667'
+}
+
+#-------------------------------------------------------------------------
+#
+reset_db
+do_execsql_test 3.1 {
+ CREATE TABLE t2(a, b);
+ CREATE INDEX i2 ON t2(a, b);
+ BEGIN;
+}
+
+do_test 3.2 {
+ for {set i 0} {$i < 1000} {incr i} {
+ set a [expr $i / 10]
+ set b [expr int(rand() * 15.0)]
+ execsql { INSERT INTO t2 VALUES($a, $b) }
+ }
+ execsql COMMIT
+} {}
+
+db func lindex lindex
+
+# Each value of "a" occurs exactly 10 times in the table.
+#
+do_execsql_test 3.3.1 {
+ SELECT count(*) FROM t2 GROUP BY a;
+} [lrange [string repeat "10 " 100] 0 99]
+
+# The first element in the "nEq" list of all samples should therefore be 10.
+#
+do_execsql_test 3.3.2 {
+ ANALYZE;
+ SELECT nEq FROM sqlite_stat3;
+} [lrange [string repeat "10 " 100] 0 23]
+
+#-------------------------------------------------------------------------
+#
+do_execsql_test 3.4 {
+ DROP TABLE IF EXISTS t1;
+ CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
+ INSERT INTO t1 VALUES(1, 1, 'one-a');
+ INSERT INTO t1 VALUES(11, 1, 'one-b');
+ INSERT INTO t1 VALUES(21, 1, 'one-c');
+ INSERT INTO t1 VALUES(31, 1, 'one-d');
+ INSERT INTO t1 VALUES(41, 1, 'one-e');
+ INSERT INTO t1 VALUES(51, 1, 'one-f');
+ INSERT INTO t1 VALUES(61, 1, 'one-g');
+ INSERT INTO t1 VALUES(71, 1, 'one-h');
+ INSERT INTO t1 VALUES(81, 1, 'one-i');
+ INSERT INTO t1 VALUES(91, 1, 'one-j');
+ INSERT INTO t1 SELECT a+1,2,'two' || substr(c,4) FROM t1;
+ INSERT INTO t1 SELECT a+2,3,'three'||substr(c,4) FROM t1 WHERE c GLOB 'one-*';
+ INSERT INTO t1 SELECT a+3,4,'four'||substr(c,4) FROM t1 WHERE c GLOB 'one-*';
+ INSERT INTO t1 SELECT a+4,5,'five'||substr(c,4) FROM t1 WHERE c GLOB 'one-*';
+ INSERT INTO t1 SELECT a+5,6,'six'||substr(c,4) FROM t1 WHERE c GLOB 'one-*';
+ CREATE INDEX t1b ON t1(b);
+ ANALYZE;
+ SELECT c FROM t1 WHERE b=3 AND a BETWEEN 30 AND 60;
+} {three-d three-e three-f}
+
+
+#-------------------------------------------------------------------------
+# These tests verify that the sample selection for stat3 appears to be
+# working as designed.
+#
+
+reset_db
+db func lindex lindex
+db func lrange lrange
+
+do_execsql_test 4.0 {
+ DROP TABLE IF EXISTS t1;
+ CREATE TABLE t1(a, b, c);
+ CREATE INDEX i1 ON t1(c, b, a);
+}
+
+
+proc insert_filler_rows_n {iStart args} {
+ set A(-ncopy) 1
+ set A(-nval) 1
+
+ foreach {k v} $args {
+ if {[info exists A($k)]==0} { error "no such option: $k" }
+ set A($k) $v
+ }
+ if {[llength $args] % 2} {
+ error "option requires an argument: [lindex $args end]"
+ }
+
+ for {set i 0} {$i < $A(-nval)} {incr i} {
+ set iVal [expr $iStart+$i]
+ for {set j 0} {$j < $A(-ncopy)} {incr j} {
+ execsql { INSERT INTO t1 VALUES($iVal, $iVal, $iVal) }
+ }
+ }
+}
+
+do_test 4.1 {
+ execsql { BEGIN }
+ insert_filler_rows_n 0 -ncopy 10 -nval 19
+ insert_filler_rows_n 20 -ncopy 1 -nval 100
+
+ execsql {
+ INSERT INTO t1(c, b, a) VALUES(200, 1, 'a');
+ INSERT INTO t1(c, b, a) VALUES(200, 1, 'b');
+ INSERT INTO t1(c, b, a) VALUES(200, 1, 'c');
+
+ INSERT INTO t1(c, b, a) VALUES(200, 2, 'e');
+ INSERT INTO t1(c, b, a) VALUES(200, 2, 'f');
+
+ INSERT INTO t1(c, b, a) VALUES(201, 3, 'g');
+ INSERT INTO t1(c, b, a) VALUES(201, 4, 'h');
+
+ ANALYZE;
+ SELECT count(*) FROM sqlite_stat3;
+ SELECT count(*) FROM t1;
+ }
+} {24 297}
+
+do_execsql_test 4.2 {
+ SELECT neq, nlt, ndlt, sample FROM sqlite_stat3 ORDER BY rowid LIMIT 16;
+} {
+ 10 0 0 0
+ 10 10 1 1
+ 10 20 2 2
+ 10 30 3 3
+ 10 40 4 4
+ 10 50 5 5
+ 10 60 6 6
+ 10 70 7 7
+ 10 80 8 8
+ 10 90 9 9
+ 10 100 10 10
+ 10 110 11 11
+ 10 120 12 12
+ 10 130 13 13
+ 10 140 14 14
+ 10 150 15 15
+}
+
+do_execsql_test 4.3 {
+ SELECT neq, nlt, ndlt, sample FROM sqlite_stat3
+ ORDER BY rowid DESC LIMIT 2;
+} {
+ 2 295 120 201
+ 5 290 119 200
+}
+
+do_execsql_test 4.4 { SELECT count(DISTINCT c) FROM t1 WHERE c<201 } 120
+do_execsql_test 4.5 { SELECT count(DISTINCT c) FROM t1 WHERE c<200 } 119
+
+reset_db
+do_test 4.7 {
+ execsql {
+ BEGIN;
+ CREATE TABLE t1(o,t INTEGER PRIMARY KEY);
+ CREATE INDEX i1 ON t1(o);
+ }
+ for {set i 0} {$i<10000} {incr i [expr (($i<1000)?1:10)]} {
+ execsql { INSERT INTO t1 VALUES('x', $i) }
+ }
+ execsql {
+ COMMIT;
+ ANALYZE;
+ SELECT count(*) FROM sqlite_stat3;
+ }
+} {1}
+do_execsql_test 4.8 {
+ SELECT sample FROM sqlite_stat3;
+} {x}
+
+
+#-------------------------------------------------------------------------
+# The following would cause a crash at one point.
+#
+reset_db
+do_execsql_test 5.1 {
+ PRAGMA encoding = 'utf-16';
+ CREATE TABLE t0(v);
+ ANALYZE;
+}
+
+#-------------------------------------------------------------------------
+# This was also crashing (corrupt sqlite_stat3 table).
+#
+reset_db
+do_execsql_test 6.1 {
+ CREATE TABLE t1(a, b);
+ CREATE INDEX i1 ON t1(a);
+ CREATE INDEX i2 ON t1(b);
+ INSERT INTO t1 VALUES(1, 1);
+ INSERT INTO t1 VALUES(2, 2);
+ INSERT INTO t1 VALUES(3, 3);
+ INSERT INTO t1 VALUES(4, 4);
+ INSERT INTO t1 VALUES(5, 5);
+ ANALYZE;
+ PRAGMA writable_schema = 1;
+ CREATE TEMP TABLE x1 AS
+ SELECT tbl,idx,neq,nlt,ndlt,sample FROM sqlite_stat3
+ ORDER BY (rowid%5), rowid;
+ DELETE FROM sqlite_stat3;
+ INSERT INTO sqlite_stat3 SELECT * FROM x1;
+ PRAGMA writable_schema = 0;
+ ANALYZE sqlite_master;
+}
+do_execsql_test 6.2 {
+ SELECT * FROM t1 WHERE a = 'abc';
+}
+
+#-------------------------------------------------------------------------
+# The following tests experiment with adding corrupted records to the
+# 'sample' column of the sqlite_stat3 table.
+#
+reset_db
+sqlite3_db_config_lookaside db 0 0 0
+
+do_execsql_test 7.1 {
+ CREATE TABLE t1(a, b);
+ CREATE INDEX i1 ON t1(a, b);
+ INSERT INTO t1 VALUES(1, 1);
+ INSERT INTO t1 VALUES(2, 2);
+ INSERT INTO t1 VALUES(3, 3);
+ INSERT INTO t1 VALUES(4, 4);
+ INSERT INTO t1 VALUES(5, 5);
+ ANALYZE;
+ UPDATE sqlite_stat3 SET sample = X'' WHERE rowid = 1;
+ ANALYZE sqlite_master;
+}
+
+do_execsql_test 7.2 {
+ UPDATE sqlite_stat3 SET sample = X'FFFF';
+ ANALYZE sqlite_master;
+ SELECT * FROM t1 WHERE a = 1;
+} {1 1}
+
+do_execsql_test 7.3 {
+ ANALYZE;
+ UPDATE sqlite_stat3 SET neq = '0 0 0';
+ ANALYZE sqlite_master;
+ SELECT * FROM t1 WHERE a = 1;
+} {1 1}
+
+do_execsql_test 7.4 {
+ ANALYZE;
+ UPDATE sqlite_stat3 SET ndlt = '0 0 0';
+ ANALYZE sqlite_master;
+ SELECT * FROM t1 WHERE a = 3;
+} {3 3}
+
+do_execsql_test 7.5 {
+ ANALYZE;
+ UPDATE sqlite_stat3 SET nlt = '0 0 0';
+ ANALYZE sqlite_master;
+ SELECT * FROM t1 WHERE a = 5;
+} {5 5}
+
+#-------------------------------------------------------------------------
+#
+reset_db
+do_execsql_test 8.1 {
+ CREATE TABLE t1(x TEXT);
+ CREATE INDEX i1 ON t1(x);
+ INSERT INTO t1 VALUES('1');
+ INSERT INTO t1 VALUES('2');
+ INSERT INTO t1 VALUES('3');
+ INSERT INTO t1 VALUES('4');
+ ANALYZE;
+}
+do_execsql_test 8.2 {
+ SELECT * FROM t1 WHERE x = 3;
+} {3}
+
+#-------------------------------------------------------------------------
+#
+reset_db
+do_execsql_test 9.1 {
+ CREATE TABLE t1(a, b, c, d, e);
+ CREATE INDEX i1 ON t1(a, b, c, d);
+ CREATE INDEX i2 ON t1(e);
+}
+do_test 9.2 {
+ execsql BEGIN;
+ for {set i 0} {$i < 100} {incr i} {
+ execsql "INSERT INTO t1 VALUES('x', 'y', 'z', $i, [expr $i/2])"
+ }
+ for {set i 0} {$i < 20} {incr i} {
+ execsql "INSERT INTO t1 VALUES('x', 'y', 'z', 101, $i)"
+ }
+ for {set i 102} {$i < 200} {incr i} {
+ execsql "INSERT INTO t1 VALUES('x', 'y', 'z', $i, [expr $i/2])"
+ }
+ execsql COMMIT
+ execsql ANALYZE
+} {}
+
+do_eqp_test 9.3.1 {
+ SELECT * FROM t1 WHERE a='x' AND b='y' AND c='z' AND d=101 AND e=5;
+} {/t1 USING INDEX i1/}
+do_eqp_test 9.3.2 {
+ SELECT * FROM t1 WHERE a='x' AND b='y' AND c='z' AND d=99 AND e=5;
+} {/t1 USING INDEX i1/}
+
+set value_d [expr 101]
+do_eqp_test 9.4.1 {
+ SELECT * FROM t1 WHERE a='x' AND b='y' AND c='z' AND d=$value_d AND e=5
+} {/t1 USING INDEX i1/}
+set value_d [expr 99]
+do_eqp_test 9.4.2 {
+ SELECT * FROM t1 WHERE a='x' AND b='y' AND c='z' AND d=$value_d AND e=5
+} {/t1 USING INDEX i1/}
+
+#-------------------------------------------------------------------------
+# Check that the planner takes stat3 data into account when considering
+# "IS NULL" and "IS NOT NULL" constraints.
+#
+do_execsql_test 10.1.1 {
+ DROP TABLE IF EXISTS t3;
+ CREATE TABLE t3(a, b);
+ CREATE INDEX t3a ON t3(a);
+ CREATE INDEX t3b ON t3(b);
+}
+do_test 10.1.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($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/}
+
+#-------------------------------------------------------------------------
+# Check that stat3 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/}
+ }
+}
+
+#-------------------------------------------------------------------------
+# Test that nothing untoward happens if the stat3 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_stat3 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_stat3 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_stat3 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_stat3 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]
+
+ expr {$nByte2 > $nByte+950 && $nByte2 < $nByte+1050}
+} {1}
+
+#-------------------------------------------------------------------------
+# Test that stat3 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} {
+ 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;
+} {/USING INDEX i1/}
+do_eqp_test 17.3 {
+ SELECT * FROM t1 WHERE d IS NOT NULL AND a=0;
+} {/USING INDEX i1/}
+
+do_execsql_test 17.4 {
+ CREATE INDEX i2 ON t1(c) WHERE d IS NOT NULL;
+ ANALYZE main.i2;
+}
+do_eqp_test 17.5 {
+ SELECT * FROM t1 WHERE d IS NOT NULL AND a=0;
+} {/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_stat3 }
+} {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
+ do_execsql_test 20.3.$i {
+ SELECT count(*) FROM sqlite_stat3 WHERE sample=$val
+ } {1}
+}
+
+finish_test
+
diff --git a/lang/sql/sqlite/test/async.test b/lang/sql/sqlite/test/async.test
index f1d641da..e1bc0864 100644
--- a/lang/sql/sqlite/test/async.test
+++ b/lang/sql/sqlite/test/async.test
@@ -68,7 +68,7 @@ foreach testfile [lsort -dictionary [glob $testdir/*.test]] {
# Make sure everything is flushed through. This is because [source]ing
# the next test file will delete the database file on disk (using
- # [file delete]). If the asynchronous backend still has the file
+ # [delete_file]). If the asynchronous backend still has the file
# open, it will become confused.
#
flush_async_queue
diff --git a/lang/sql/sqlite/test/async2.test b/lang/sql/sqlite/test/async2.test
index ec4ae308..7994a721 100644
--- a/lang/sql/sqlite/test/async2.test
+++ b/lang/sql/sqlite/test/async2.test
@@ -51,7 +51,7 @@ foreach err [list ioerr malloc-transient malloc-persistent] {
for {set n 1} {$::go} {incr n} {
set ::sqlite_io_error_pending 0
sqlite3_memdebug_fail -1
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db test.db
execsql $::setup_script
db close
diff --git a/lang/sql/sqlite/test/async3.test b/lang/sql/sqlite/test/async3.test
index 77c4d55d..9336b660 100644
--- a/lang/sql/sqlite/test/async3.test
+++ b/lang/sql/sqlite/test/async3.test
@@ -41,8 +41,8 @@ set paths {
do_test async3-1.0 {
file mkdir [file join chocolate banana vanilla]
- file delete -force chocolate/banana/vanilla/file.db
- file delete -force chocolate/banana/vanilla/file.db-journal
+ forcedelete chocolate/banana/vanilla/file.db
+ forcedelete chocolate/banana/vanilla/file.db-journal
} {}
do_test async3-1.1 {
diff --git a/lang/sql/sqlite/test/async5.test b/lang/sql/sqlite/test/async5.test
index 5ea4c70e..abac11f7 100644
--- a/lang/sql/sqlite/test/async5.test
+++ b/lang/sql/sqlite/test/async5.test
@@ -20,7 +20,7 @@ if {[info commands sqlite3async_initialize] eq ""} {
}
db close
-file delete -force test2.db
+forcedelete test2.db
sqlite3async_initialize "" 1
sqlite3async_control halt never
sqlite3 db test.db
@@ -66,4 +66,3 @@ sqlite3async_control halt never
sqlite3async_shutdown
set sqlite3async_trace 0
finish_test
-
diff --git a/lang/sql/sqlite/test/atof1.test b/lang/sql/sqlite/test/atof1.test
new file mode 100644
index 00000000..5c04d022
--- /dev/null
+++ b/lang/sql/sqlite/test/atof1.test
@@ -0,0 +1,60 @@
+# 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
+
+if {![info exists __GNUC__] || [regexp arm $tcl_platform(machine)]} {
+ finish_test
+ return
+}
+
+expr srand(1)
+for {set i 1} {$i<20000} {incr i} {
+ set pow [expr {int((rand()-0.5)*100)}]
+ 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 "\nIN: $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}
+}
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/attach.test b/lang/sql/sqlite/test/attach.test
index 1bb596cb..be5f9881 100644
--- a/lang/sql/sqlite/test/attach.test
+++ b/lang/sql/sqlite/test/attach.test
@@ -24,8 +24,8 @@ ifcapable !attach {
}
for {set i 2} {$i<=15} {incr i} {
- file delete -force test$i.db
- file delete -force test$i.db-journal
+ forcedelete test$i.db
+ forcedelete test$i.db-journal
}
do_test attach-1.1 {
@@ -51,6 +51,25 @@ do_test attach-1.3 {
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;
@@ -628,7 +647,7 @@ do_test attach-5.1 {
db close
sqlite3 db test.db
db2 close
- file delete -force test2.db
+ forcedelete test2.db
sqlite3 db2 test2.db
catchsql {
ATTACH DATABASE 'test.db' AS orig;
@@ -725,7 +744,7 @@ if {$tcl_platform(platform)=="unix"} {
file attributes cannot-read -permission 0000
if {[file writable cannot-read]} {
puts "\n**** Tests do not work when run as root ****"
- file delete -force cannot-read
+ forcedelete cannot-read
exit 1
}
catchsql {
@@ -735,7 +754,7 @@ if {$tcl_platform(platform)=="unix"} {
do_test attach-6.2.2 {
db errorcode
} {14}
- file delete -force cannot-read
+ forcedelete cannot-read
}
# Check the error message if we try to access a database that has
@@ -749,12 +768,12 @@ for {set i 2} {$i<=15} {incr i} {
catch {db$i close}
}
db close
-file delete -force test2.db
-file delete -force no-such-file
+forcedelete test2.db
+forcedelete no-such-file
ifcapable subquery {
do_test attach-7.1 {
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db test.db
catchsql {
DETACH RAISE ( IGNORE ) IN ( SELECT "AAAAAA" . * ORDER BY
@@ -777,7 +796,7 @@ do_test attach-8.1 {
do_test attach-8.2 {
db errorcode
} {26}
-file delete -force test2.db
+forcedelete test2.db
do_test attach-8.3 {
sqlite3 db2 test2.db
db2 eval {CREATE TABLE t1(x); BEGIN EXCLUSIVE}
@@ -789,13 +808,13 @@ do_test attach-8.4 {
db errorcode
} {5}
db2 close
-file delete -force test2.db
+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 {
- file delete -force test4.db
+ forcedelete test4.db
execsql {
ATTACH 'test4.db' AS aux1;
CREATE TABLE aux1.t1(a, b);
diff --git a/lang/sql/sqlite/test/attach2.test b/lang/sql/sqlite/test/attach2.test
index 3cc5af96..f8705685 100644
--- a/lang/sql/sqlite/test/attach2.test
+++ b/lang/sql/sqlite/test/attach2.test
@@ -33,8 +33,8 @@ do_test attach2-1.1 {
CREATE TABLE t1(a,b);
CREATE INDEX x1 ON t1(a);
}
- file delete -force test2.db
- file delete -force test2.db-journal
+ forcedelete test2.db
+ forcedelete test2.db-journal
sqlite3 db2 test2.db
db2 eval {
CREATE TABLE t1(a,b);
@@ -327,7 +327,7 @@ do_test attach2-4.15 {
db close
db2 close
-file delete -force test2.db
+forcedelete test2.db
sqlite3_soft_heap_limit $soft_limit
# These tests - attach2-5.* - check that the master journal file is deleted
@@ -335,7 +335,7 @@ sqlite3_soft_heap_limit $soft_limit
#
# Update: It's not actually created if a rollback occurs, so that test
# doesn't really prove too much.
-foreach f [glob test.db*] {file delete -force $f}
+foreach f [glob test.db*] {forcedelete $f}
do_test attach2-5.1 {
sqlite3 db test.db
execsql {
@@ -377,6 +377,9 @@ do_test attach2-6.2 {
}
} {1 {cannot ATTACH database within transaction}}
+# EVIDENCE-OF: R-59740-55581 This statement will fail if SQLite is in
+# the middle of a transaction.
+#
do_test attach2-6.3 {
catchsql {
DETACH aux;
diff --git a/lang/sql/sqlite/test/attach3.test b/lang/sql/sqlite/test/attach3.test
index 36d39991..1ac10d97 100644
--- a/lang/sql/sqlite/test/attach3.test
+++ b/lang/sql/sqlite/test/attach3.test
@@ -35,8 +35,8 @@ execsql {
}
# Create tables t1 and t2 in database file test2.db
-file delete -force test2.db
-file delete -force test2.db-journal
+forcedelete test2.db
+forcedelete test2.db-journal
sqlite3 db2 test2.db
execsql {
CREATE TABLE t1(a, b);
@@ -322,7 +322,6 @@ do_test attach3-12.9 {
db_list
} {main temp {}}
do_test attach3-12.10 {
-breakpoint
execsql {
DETACH ?
}
diff --git a/lang/sql/sqlite/test/attach4.test b/lang/sql/sqlite/test/attach4.test
index f597f5d0..77dd7e41 100644
--- a/lang/sql/sqlite/test/attach4.test
+++ b/lang/sql/sqlite/test/attach4.test
@@ -75,10 +75,12 @@ set L [list]
set S ""
foreach {name f} $files {
if {[permutation] == "journaltest"} {
- lappend L delete
+ set mode delete
} else {
- lappend L wal
+ set mode wal
}
+ ifcapable !wal { set mode delete }
+ lappend L $mode
append S "
PRAGMA $name.journal_mode = WAL;
UPDATE $name.tbl SET x = '$name';
diff --git a/lang/sql/sqlite/test/attachmalloc.test b/lang/sql/sqlite/test/attachmalloc.test
index c485c618..7fee1e1b 100644
--- a/lang/sql/sqlite/test/attachmalloc.test
+++ b/lang/sql/sqlite/test/attachmalloc.test
@@ -29,8 +29,8 @@ do_malloc_test attachmalloc-1 -tclprep {
catch { db close }
for {set i 2} {$i<=4} {incr i} {
catch { db$i close }
- file delete -force test$i.db
- file delete -force test$i.db-journal
+ forcedelete test$i.db
+ forcedelete test$i.db-journal
}
} -tclbody {
if {[catch {sqlite3 db test.db}]} {
@@ -48,8 +48,8 @@ do_malloc_test attachmalloc-1 -tclprep {
}
do_malloc_test attachmalloc-2 -tclprep {
- file delete -force test2.db
- file delete -force test2.db-journal
+ forcedelete test2.db
+ forcedelete test2.db-journal
sqlite3 db2 test2.db
db2 eval {
CREATE TABLE t1(a, b, c);
diff --git a/lang/sql/sqlite/test/auth.test b/lang/sql/sqlite/test/auth.test
index 8d2159ec..43e53ef2 100644
--- a/lang/sql/sqlite/test/auth.test
+++ b/lang/sql/sqlite/test/auth.test
@@ -2080,6 +2080,42 @@ ifcapable {altertable} {
execsql {DROP TABLE t5}
} ;# ifcapable altertable
+ifcapable {cte} {
+ do_test auth-1.310 {
+ proc auth {code arg1 arg2 arg3 arg4} {
+ 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
+
do_test auth-2.1 {
proc auth {code arg1 arg2 arg3 arg4} {
if {$code=="SQLITE_READ" && $arg1=="t3" && $arg2=="x"} {
@@ -2262,7 +2298,9 @@ do_test auth-4.3 {
SQLITE_SELECT {} {} {} v1 \
SQLITE_READ t2 a main v1 \
SQLITE_READ t2 b main v1 \
- SQLITE_SELECT {} {} {} {} \
+ 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 \
@@ -2288,7 +2326,9 @@ do_test auth-4.5 {
SQLITE_SELECT {} {} {} v1 \
SQLITE_READ t2 a main v1 \
SQLITE_READ t2 b main v1 \
- SQLITE_SELECT {} {} {} {} \
+ 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 \
@@ -2321,10 +2361,14 @@ ifcapable compound&&subquery {
}
}
}
- ifcapable stat2 {
- set stat2 "sqlite_stat2 "
+ ifcapable stat4 {
+ set stat4 "sqlite_stat4 "
} else {
- set stat2 ""
+ ifcapable stat3 {
+ set stat4 "sqlite_stat3 "
+ } else {
+ set stat4 ""
+ }
}
do_test auth-5.2 {
execsql {
@@ -2333,7 +2377,7 @@ ifcapable compound&&subquery {
WHERE type='table'
ORDER BY name
}
- } "sqlite_stat1 ${stat2}t1 t2 t3 t4"
+ } "sqlite_stat1 ${stat4}t1 t2 t3 t4"
}
# Ticket #3944
@@ -2364,6 +2408,29 @@ ifcapable trigger {
} {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 $args
+ 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}
rename proc {}
rename proc_real proc
diff --git a/lang/sql/sqlite/test/auth2.test b/lang/sql/sqlite/test/auth2.test
index f5dba148..65e05912 100644
--- a/lang/sql/sqlite/test/auth2.test
+++ b/lang/sql/sqlite/test/auth2.test
@@ -102,6 +102,7 @@ SQLITE_READ sqlite_master name main {}
SQLITE_READ sqlite_master rootpage main {}
SQLITE_READ sqlite_master sql main {}
SQLITE_READ sqlite_master tbl_name main {}
+SQLITE_READ sqlite_master type main {}
SQLITE_READ sqlite_master ROWID main {}
}
do_test auth2-2.2 {
@@ -122,6 +123,7 @@ SQLITE_READ sqlite_master name main {}
SQLITE_READ sqlite_master rootpage main {}
SQLITE_READ sqlite_master sql main {}
SQLITE_READ sqlite_master tbl_name main {}
+SQLITE_READ sqlite_master type main {}
SQLITE_READ sqlite_master ROWID main {}
}
do_test auth2-2.3 {
@@ -131,12 +133,12 @@ do_test auth2-2.3 {
}
set ::authargs
} {SQLITE_SELECT {} {} {} {}
-SQLITE_READ v2 a main {}
-SQLITE_READ v2 b main {}
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 {
@@ -149,20 +151,20 @@ do_test auth2-2.4 {
}
set ::authargs
} {SQLITE_SELECT {} {} {} {}
-SQLITE_READ v2 b main {}
-SQLITE_READ v2 a main {}
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_SELECT {} {} {} v2
-SQLITE_SELECT {} {} {} {}
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
diff --git a/lang/sql/sqlite/test/autoinc.test b/lang/sql/sqlite/test/autoinc.test
index 983b9b83..23960061 100644
--- a/lang/sql/sqlite/test/autoinc.test
+++ b/lang/sql/sqlite/test/autoinc.test
@@ -216,7 +216,7 @@ do_test autoinc-2.27 {
} {t1 1238}
do_test autoinc-2.28 {
execsql {
- UPDATE sqlite_sequence SET seq='12345678901234567890'
+ UPDATE sqlite_sequence SET seq='-12345678901234567890'
WHERE name='t1';
INSERT INTO t1 VALUES(NULL,6);
SELECT * FROM t1;
@@ -427,8 +427,8 @@ ifcapable tempdb {
#
ifcapable tempdb&&attach {
do_test autoinc-5.1 {
- file delete -force test2.db
- file delete -force test2.db-journal
+ forcedelete test2.db
+ forcedelete test2.db-journal
sqlite3 db2 test2.db
execsql {
CREATE TABLE t4(m INTEGER PRIMARY KEY AUTOINCREMENT, n);
@@ -520,7 +520,7 @@ do_test autoinc-7.2 {
do_test autoinc-8.1 {
catch {db2 close}
catch {db close}
- file delete -force test.db
+ forcedelete test.db
sqlite3 db test.db
set DB [sqlite3_connection_pointer db]
set STMT [sqlite3_prepare $DB {
diff --git a/lang/sql/sqlite/test/autoindex1.test b/lang/sql/sqlite/test/autoindex1.test
index bc628dc2..0e5032b9 100644
--- a/lang/sql/sqlite/test/autoindex1.test
+++ b/lang/sql/sqlite/test/autoindex1.test
@@ -23,6 +23,14 @@ ifcapable {!autoindex} {
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 {
@@ -60,6 +68,15 @@ do_test autoindex1-111 {
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.
@@ -78,6 +95,9 @@ do_test autoindex1-202 {
do_test autoindex1-210 {
db eval {
PRAGMA automatic_index=ON;
+ ANALYZE;
+ UPDATE sqlite_stat1 SET stat='10000' WHERE tbl='t1';
+ 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}
@@ -91,9 +111,15 @@ do_test autoindex1-212 {
# 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 JOIN t2 ON (c=a)} {
+ 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}
}
@@ -143,22 +169,25 @@ do_test autoindex1-401 {
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;
EXPLAIN QUERY PLAN
SELECT b FROM t501
WHERE t501.a IN (SELECT x FROM t502 WHERE y=?);
} {
- 0 0 0 {SEARCH TABLE t501 USING INTEGER PRIMARY KEY (rowid=?) (~25 rows)}
+ 0 0 0 {SEARCH TABLE t501 USING INTEGER PRIMARY KEY (rowid=?)}
0 0 0 {EXECUTE LIST SUBQUERY 1}
- 1 0 0 {SCAN TABLE t502 (~100000 rows)}
+ 1 0 0 {SCAN TABLE t502}
}
do_execsql_test autoindex1-501 {
EXPLAIN QUERY PLAN
SELECT b FROM t501
WHERE t501.a IN (SELECT x FROM t502 WHERE y=t501.b);
} {
- 0 0 0 {SCAN TABLE t501 (~500000 rows)}
+ 0 0 0 {SCAN TABLE t501}
0 0 0 {EXECUTE CORRELATED LIST SUBQUERY 1}
- 1 0 0 {SEARCH TABLE t502 USING AUTOMATIC COVERING INDEX (y=?) (~7 rows)}
+ 1 0 0 {SEARCH TABLE t502 USING AUTOMATIC COVERING INDEX (y=?)}
}
do_execsql_test autoindex1-502 {
EXPLAIN QUERY PLAN
@@ -166,9 +195,9 @@ do_execsql_test autoindex1-502 {
WHERE t501.a=123
AND t501.a IN (SELECT x FROM t502 WHERE y=t501.b);
} {
- 0 0 0 {SEARCH TABLE t501 USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)}
+ 0 0 0 {SEARCH TABLE t501 USING INTEGER PRIMARY KEY (rowid=?)}
0 0 0 {EXECUTE CORRELATED LIST SUBQUERY 1}
- 1 0 0 {SCAN TABLE t502 (~100000 rows)}
+ 1 0 0 {SCAN TABLE t502}
}
@@ -240,12 +269,146 @@ do_execsql_test autoindex1-600 {
WHERE y.sheep_no IS NULL
ORDER BY x.registering_flock;
} {
- 1 0 0 {SCAN TABLE sheep AS s (~1000000 rows)}
- 1 1 1 {SEARCH TABLE flock_owner AS prev USING INDEX sqlite_autoindex_flock_owner_1 (flock_no=? AND owner_change_date<?) (~2 rows)}
+ 1 0 0 {SCAN TABLE sheep AS s}
+ 1 1 1 {SEARCH TABLE flock_owner AS prev USING INDEX sqlite_autoindex_flock_owner_1 (flock_no=? AND owner_change_date<?)}
1 0 0 {EXECUTE CORRELATED SCALAR SUBQUERY 2}
- 2 0 0 {SEARCH TABLE flock_owner AS later USING COVERING INDEX sqlite_autoindex_flock_owner_1 (flock_no=? AND owner_change_date>? AND owner_change_date<?) (~1 rows)}
- 0 0 0 {SCAN TABLE sheep AS x USING INDEX sheep_reg_flock_index (~1000000 rows)}
- 0 1 1 {SEARCH SUBQUERY 1 AS y USING AUTOMATIC COVERING INDEX (sheep_no=?) (~8 rows)}
+ 2 0 0 {SEARCH TABLE flock_owner AS later USING COVERING INDEX sqlite_autoindex_flock_owner_1 (flock_no=? AND owner_change_date>? AND owner_change_date<?)}
+ 0 0 0 {SCAN TABLE sheep AS x USING INDEX sheep_reg_flock_index}
+ 0 1 1 {SEARCH SUBQUERY 1 AS y USING AUTOMATIC COVERING INDEX (sheep_no=?)}
+}
+
+
+do_execsql_test autoindex1-700 {
+ CREATE TABLE t5(a, b, c);
+ EXPLAIN QUERY PLAN SELECT a FROM t5 WHERE b=10 ORDER BY c;
+} {
+ 0 0 0 {SCAN TABLE t5}
+ 0 0 0 {USE TEMP B-TREE FOR ORDER BY}
}
+# The following checks a performance issue reported on the sqlite-dev
+# mailing list on 2013-01-10
+#
+do_execsql_test autoindex1-800 {
+ CREATE TABLE accounts(
+ _id INTEGER PRIMARY KEY AUTOINCREMENT,
+ account_name TEXT,
+ account_type TEXT,
+ data_set TEXT
+ );
+ CREATE TABLE data(
+ _id INTEGER PRIMARY KEY AUTOINCREMENT,
+ package_id INTEGER REFERENCES package(_id),
+ mimetype_id INTEGER REFERENCES mimetype(_id) NOT NULL,
+ raw_contact_id INTEGER REFERENCES raw_contacts(_id) NOT NULL,
+ is_read_only INTEGER NOT NULL DEFAULT 0,
+ is_primary INTEGER NOT NULL DEFAULT 0,
+ is_super_primary INTEGER NOT NULL DEFAULT 0,
+ data_version INTEGER NOT NULL DEFAULT 0,
+ data1 TEXT,
+ data2 TEXT,
+ data3 TEXT,
+ data4 TEXT,
+ data5 TEXT,
+ data6 TEXT,
+ data7 TEXT,
+ data8 TEXT,
+ data9 TEXT,
+ data10 TEXT,
+ data11 TEXT,
+ data12 TEXT,
+ data13 TEXT,
+ data14 TEXT,
+ data15 TEXT,
+ data_sync1 TEXT,
+ data_sync2 TEXT,
+ data_sync3 TEXT,
+ data_sync4 TEXT
+ );
+ CREATE TABLE mimetypes(
+ _id INTEGER PRIMARY KEY AUTOINCREMENT,
+ mimetype TEXT NOT NULL
+ );
+ CREATE TABLE raw_contacts(
+ _id INTEGER PRIMARY KEY AUTOINCREMENT,
+ account_id INTEGER REFERENCES accounts(_id),
+ sourceid TEXT,
+ raw_contact_is_read_only INTEGER NOT NULL DEFAULT 0,
+ version INTEGER NOT NULL DEFAULT 1,
+ dirty INTEGER NOT NULL DEFAULT 0,
+ deleted INTEGER NOT NULL DEFAULT 0,
+ contact_id INTEGER REFERENCES contacts(_id),
+ aggregation_mode INTEGER NOT NULL DEFAULT 0,
+ aggregation_needed INTEGER NOT NULL DEFAULT 1,
+ custom_ringtone TEXT,
+ send_to_voicemail INTEGER NOT NULL DEFAULT 0,
+ times_contacted INTEGER NOT NULL DEFAULT 0,
+ last_time_contacted INTEGER,
+ starred INTEGER NOT NULL DEFAULT 0,
+ display_name TEXT,
+ display_name_alt TEXT,
+ display_name_source INTEGER NOT NULL DEFAULT 0,
+ phonetic_name TEXT,
+ phonetic_name_style TEXT,
+ sort_key TEXT,
+ sort_key_alt TEXT,
+ name_verified INTEGER NOT NULL DEFAULT 0,
+ sync1 TEXT,
+ sync2 TEXT,
+ sync3 TEXT,
+ sync4 TEXT,
+ sync_uid TEXT,
+ sync_version INTEGER NOT NULL DEFAULT 1,
+ has_calendar_event INTEGER NOT NULL DEFAULT 0,
+ modified_time INTEGER,
+ is_restricted INTEGER DEFAULT 0,
+ yp_source TEXT,
+ method_selected INTEGER DEFAULT 0,
+ custom_vibration_type INTEGER DEFAULT 0,
+ custom_ringtone_path TEXT,
+ message_notification TEXT,
+ message_notification_path TEXT
+ );
+ CREATE INDEX data_mimetype_data1_index ON data (mimetype_id,data1);
+ CREATE INDEX data_raw_contact_id ON data (raw_contact_id);
+ CREATE UNIQUE INDEX mime_type ON mimetypes (mimetype);
+ CREATE INDEX raw_contact_sort_key1_index ON raw_contacts (sort_key);
+ CREATE INDEX raw_contact_sort_key2_index ON raw_contacts (sort_key_alt);
+ CREATE INDEX raw_contacts_contact_id_index ON raw_contacts (contact_id);
+ CREATE INDEX raw_contacts_source_id_account_id_index
+ ON raw_contacts (sourceid, account_id);
+ ANALYZE sqlite_master;
+ INSERT INTO sqlite_stat1
+ VALUES('raw_contacts','raw_contact_sort_key2_index','1600 4');
+ INSERT INTO sqlite_stat1
+ VALUES('raw_contacts','raw_contact_sort_key1_index','1600 4');
+ INSERT INTO sqlite_stat1
+ VALUES('raw_contacts','raw_contacts_source_id_account_id_index',
+ '1600 1600 1600');
+ INSERT INTO sqlite_stat1
+ VALUES('raw_contacts','raw_contacts_contact_id_index','1600 1');
+ INSERT INTO sqlite_stat1 VALUES('mimetypes','mime_type','12 1');
+ INSERT INTO sqlite_stat1
+ VALUES('data','data_mimetype_data1_index','9819 2455 3');
+ INSERT INTO sqlite_stat1 VALUES('data','data_raw_contact_id','9819 7');
+ INSERT INTO sqlite_stat1 VALUES('accounts',NULL,'1');
+ DROP TABLE IF EXISTS sqlite_stat3;
+ ANALYZE sqlite_master;
+
+ EXPLAIN QUERY PLAN
+ SELECT * FROM
+ data JOIN mimetypes ON (data.mimetype_id=mimetypes._id)
+ JOIN raw_contacts ON (data.raw_contact_id=raw_contacts._id)
+ JOIN accounts ON (raw_contacts.account_id=accounts._id)
+ WHERE mimetype_id=10 AND data14 IS NOT NULL;
+} {/SEARCH TABLE data .*SEARCH TABLE raw_contacts/}
+do_execsql_test autoindex1-801 {
+ EXPLAIN QUERY PLAN
+ SELECT * FROM
+ data JOIN mimetypes ON (data.mimetype_id=mimetypes._id)
+ JOIN raw_contacts ON (data.raw_contact_id=raw_contacts._id)
+ JOIN accounts ON (raw_contacts.account_id=accounts._id)
+ WHERE mimetypes._id=10 AND data14 IS NOT NULL;
+} {/SEARCH TABLE data .*SEARCH TABLE raw_contacts/}
+
finish_test
diff --git a/lang/sql/sqlite/test/autovacuum.test b/lang/sql/sqlite/test/autovacuum.test
index 57dfd52d..9ee2cd0f 100644
--- a/lang/sql/sqlite/test/autovacuum.test
+++ b/lang/sql/sqlite/test/autovacuum.test
@@ -114,7 +114,7 @@ foreach delete_order $delete_orders {
}
do_test autovacuum-1.$tn.($delete).3 {
execsql {
- select a from av1
+ select a from av1 order by rowid
}
} $::tbl_data
}
@@ -467,7 +467,7 @@ do_test autovacuum-3.3 {
do_test autovacuum-3.4 {
db close
- file delete -force test.db
+ forcedelete test.db
sqlite3 db test.db
execsql {
PRAGMA auto_vacuum;
@@ -502,7 +502,7 @@ do_test autovacuum-4.0 {
# Reset everything just in case.
#
db close
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db test.db
execsql {
PRAGMA auto_vacuum = 1;
@@ -526,7 +526,7 @@ do_test autovacuum-4.2 {
catchsql {
CREATE UNIQUE INDEX av1_i ON av1(a);
}
-} {1 {indexed columns are not unique}}
+} {1 {UNIQUE constraint failed: av1.a}}
do_test autovacuum-4.3 {
execsql {
SELECT sum(a) FROM av1;
@@ -599,8 +599,8 @@ do_test autovacuum-6.1 {
#
do_test autovacuum-7.1 {
db close
- file delete -force test.db
- file delete -force test.db-journal
+ forcedelete test.db
+ forcedelete test.db-journal
sqlite3 db test.db
execsql {
diff --git a/lang/sql/sqlite/test/autovacuum_ioerr2.test b/lang/sql/sqlite/test/autovacuum_ioerr2.test
index dadb29c0..891d00eb 100644
--- a/lang/sql/sqlite/test/autovacuum_ioerr2.test
+++ b/lang/sql/sqlite/test/autovacuum_ioerr2.test
@@ -75,7 +75,7 @@ do_ioerr_test autovacuum-ioerr2-3 -sqlprep {
DROP TABLE abc2;
}
-file delete -force backup.db
+forcedelete backup.db
ifcapable subquery {
do_ioerr_test autovacuum-ioerr2-4 -tclprep {
if {![file exists backup.db]} {
@@ -99,9 +99,9 @@ ifcapable subquery {
dbb close
}
db close
- file delete -force test.db
- file delete -force test.db-journal
- copy_file backup.db test.db
+ forcedelete test.db
+ forcedelete test.db-journal
+ forcecopy backup.db test.db
set ::DB [sqlite3 db test.db]
execsql {
PRAGMA cache_size = 10;
diff --git a/lang/sql/sqlite/test/backcompat.test b/lang/sql/sqlite/test/backcompat.test
index fa643f9b..fdc2410b 100644
--- a/lang/sql/sqlite/test/backcompat.test
+++ b/lang/sql/sqlite/test/backcompat.test
@@ -27,41 +27,17 @@ 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
-# 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 pattern "[file tail [info nameofexec]]?*"
-if {$tcl_platform(platform)=="windows"} {
- set pattern [string map {\.exe {}} $pattern]
-}
-foreach file [glob -nocomplain $pattern] {
- if {[file executable $file] && [file isfile $file]} {lappend binaries $file}
-}
-if {[llength $binaries]==0} {
- puts "WARNING: No historical binaries to test against."
- puts "WARNING: No backwards-compatibility tests have been run."
+if {"" == [bc_find_binaries backcompat.test]} {
finish_test
return
}
-proc get_version {binary} {
- set chan [launch_testfixture $binary]
- set v [testfixture $chan { sqlite3 -version }]
- close $chan
- set v
-}
-foreach bin $binaries {
- puts -nonewline "Testing against $bin - "
- flush stdout
- puts "version [get_version $bin]"
-}
proc do_backcompat_test {rv bin1 bin2 script} {
- file delete -force test.db
+ forcedelete test.db
if {$bin1 != ""} { set ::bc_chan1 [launch_testfixture $bin1] }
set ::bc_chan2 [launch_testfixture $bin2]
@@ -93,7 +69,7 @@ proc do_backcompat_test {rv bin1 bin2 script} {
array set ::incompatible [list]
proc do_allbackcompat_test {script} {
- foreach bin $::binaries {
+ foreach bin $::BC(binaries) {
set nErr [set_test_counter errors]
foreach dir {0 1} {
@@ -152,7 +128,7 @@ proc read_file_system {} {
proc write_file_system {data} {
foreach f {test.db test.db-journal test.db-wal} d $data {
if {[string length $d] == 0} {
- file delete -force $f
+ forcedelete $f
} else {
write_file $f $d
}
@@ -224,6 +200,42 @@ do_allbackcompat_test {
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"
@@ -237,7 +249,9 @@ unset ::incompatible
#
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 {
@@ -275,96 +289,98 @@ do_allbackcompat_test {
# Test that FTS3 tables may be read/written by different versions of
# SQLite.
#
-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)}]
+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"
} {
-
- 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*'"
+ 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.7 [list sql1 $q] [sql2 $q]
+
+ 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]
+ }
}
}
}
@@ -373,72 +389,74 @@ do_allbackcompat_test {
# Test that Rtree tables may be read/written by different versions of
# SQLite.
#
-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)}]
+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
} {
-
- 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]
+ 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]
+ }
+
}
-
}
}
diff --git a/lang/sql/sqlite/test/backup.test b/lang/sql/sqlite/test/backup.test
index 2aaac49d..32b3b156 100644
--- a/lang/sql/sqlite/test/backup.test
+++ b/lang/sql/sqlite/test/backup.test
@@ -73,7 +73,7 @@ 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 {
- file delete test2.db
+ forcedelete test2.db
sqlite3 db2 test2.db
sqlite3_backup B db2 main db main
} {B}
@@ -168,8 +168,8 @@ foreach pgsz_dest {1024} {
foreach nPagePerStep {1 200} {
# Open the databases.
- catch { file delete -force -- test.db }
- catch { file delete -force -- test2.db }
+ catch { forcedelete test.db }
+ catch { forcedelete test2.db }
eval $zOpenScript
# Set to true if copying to an in-memory destination. Copying to an
@@ -245,7 +245,6 @@ foreach nPagePerStep {1 200} {
# End of backup-2.* tests.
#---------------------------------------------------------------------
-
#---------------------------------------------------------------------
# The following tests, backup-4.*, test various error conditions:
#
@@ -280,8 +279,8 @@ do_test backup-4.1.4 {
} {unknown database aux}
do_test backup-4.2.1 {
- catch { file delete -force test3.db }
- catch { file delete -force test4.db }
+ catch { forcedelete test3.db }
+ catch { forcedelete test4.db }
execsql {
ATTACH 'test3.db' AS aux1;
CREATE TABLE aux1.t1(a, b);
@@ -311,7 +310,7 @@ do_test backup-4.3.2 {
} {SQLITE_BUSY}
do_test backup-4.3.3 {
sqlite3_errmsg db2
-} {unable to close due to unfinished backup operation}
+} {unable to close due to unfinalized statements or unfinished backups}
do_test backup-4.3.4 {
B step 50
} {SQLITE_DONE}
@@ -327,7 +326,7 @@ db close
db2 close
do_test backup-4.5.1 {
- catch { file delete -force -- test.db }
+ catch { forcedelete test.db }
sqlite3 db test.db
sqlite3 db2 :memory:
execsql {
@@ -351,7 +350,7 @@ do_test backup-4.5.3 {
db close
db2 close
#
-# End of backup-5.* tests.
+# End of backup-4.* tests.
#---------------------------------------------------------------------
#---------------------------------------------------------------------
@@ -379,12 +378,12 @@ db2 close
# 3) Backing up memory-to-file.
#
set iTest 0
-file delete -force bak.db-wal
+forcedelete bak.db-wal
foreach {writer file} {db test.db db :memory:} {
incr iTest
- catch { file delete -force bak.db }
+ catch { forcedelete bak.db }
sqlite3 db2 bak.db
- catch { file delete -force $file }
+ catch { forcedelete $file }
sqlite3 db $file
sqlite3 db3 $file
@@ -485,9 +484,9 @@ foreach {writer file} {db test.db db :memory:} {
catch {db close}
catch {db2 close}
catch {db3 close}
- catch { file delete -force -- bak.db }
+ catch { forcedelete bak.db }
sqlite3 db2 bak.db
- catch { file delete -force -- $file }
+ catch { forcedelete $file }
sqlite3 db $file
sqlite3 db3 $file
do_test backup-5.$iTest.5.1 {
@@ -531,8 +530,8 @@ foreach {writer file} {db test.db db :memory:} {
# Test the sqlite3_backup_remaining() and backup_pagecount() APIs.
#
do_test backup-6.1 {
- catch { file delete -force -- test.db }
- catch { file delete -force -- test2.db }
+ catch { forcedelete test.db }
+ catch { forcedelete test2.db }
sqlite3 db test.db
sqlite3 db2 test2.db
execsql {
@@ -588,8 +587,8 @@ catch {db2 close}
# backup-7.3.*: Destination database is externally locked (return SQLITE_BUSY).
#
do_test backup-7.0 {
- catch { file delete -force -- test.db }
- catch { file delete -force -- test2.db }
+ catch { forcedelete test.db }
+ catch { forcedelete test2.db }
sqlite3 db2 test2.db
sqlite3 db test.db
sqlite3 db3 test.db
@@ -630,13 +629,13 @@ integrity_check backup-7.3.6 db2
do_test backup-7.3.1 {
db2 close
db3 close
- file delete -force -- test2.db
+ 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); COMMIT; } db3
-
+
B step 5
} {SQLITE_BUSY}
do_test backup-7.3.2 {
@@ -658,8 +657,8 @@ catch { db2 close }
# These tests reuse the database "test.db" left over from backup-7.*.
#
do_test backup-8.1 {
- catch { file delete -force -- test2.db }
- catch { file delete -force -- test3.db }
+ catch { forcedelete test2.db }
+ catch { forcedelete test3.db }
sqlite3 db2 test2.db
sqlite3 db3 test3.db
@@ -740,8 +739,8 @@ catch {db2 close}
ifcapable memorymanage {
db close
- file delete -force -- test.db
- file delete -force -- bak.db
+ forcedelete test.db
+ forcedelete bak.db
sqlite3 db test.db
sqlite3 db2 test.db
@@ -790,6 +789,7 @@ ifcapable memorymanage {
# 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.
# 10.2.*: If the db is a file, the backup is restarted.
# 10.3.*: If the db is in-memory, and not updated, the backup is not
# restarted
@@ -797,9 +797,9 @@ ifcapable memorymanage {
# restarted
#
db close
-file delete -force -- test.db test.db-journal
+forcedelete test.db test.db-journal
foreach {tn file update rc} {
- 1 test.db 1 SQLITE_OK
+ 1 test.db 1 SQLITE_DONE
2 :memory: 1 SQLITE_OK
1 test.db 0 SQLITE_DONE
2 :memory: 0 SQLITE_DONE
@@ -825,7 +825,7 @@ foreach {tn file update rc} {
} {256}
do_test backup-10.$tn.3 {
- file delete -force -- bak.db bak.db-journal
+ forcedelete bak.db bak.db-journal
sqlite3 db2 bak.db
sqlite3_backup B db2 main db main
B step 50
diff --git a/lang/sql/sqlite/test/backup2.test b/lang/sql/sqlite/test/backup2.test
index 749c460e..98931992 100644
--- a/lang/sql/sqlite/test/backup2.test
+++ b/lang/sql/sqlite/test/backup2.test
@@ -61,7 +61,7 @@ set cksum [dbcksum db main]
# is identical to the original.
#
do_test backup2-2 {
- file delete -force bu1.db
+ forcedelete bu1.db
db backup bu1.db
sqlite3 db2 bu1.db
dbcksum db2 main
@@ -72,7 +72,7 @@ do_test backup2-2 {
#
do_test backup2-3.1 {
db close
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db test.db
db2 eval {BEGIN EXCLUSIVE}
set rc [catch {db restore bu1.db} res]
@@ -82,7 +82,7 @@ do_test backup2-3.1 {
} {1 {restore failed: source database busy}}
do_test backup2-3.2 {
db close
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db test.db
db restore bu1.db
dbcksum db main
@@ -96,7 +96,7 @@ do_test backup2-4 {
} $cksum
do_test backup2-5 {
db2 close
- file delete -force bu1.db bu2.db
+ forcedelete bu1.db bu2.db
db backup temp bu2.db
sqlite3 db2 bu2.db
dbcksum db2 main
@@ -127,7 +127,7 @@ do_test backup2-7 {
# Try to backup database that does not exist
#
do_test backup2-8 {
- file delete -force bu1.db
+ forcedelete bu1.db
set rc [catch {db backup aux1 bu1.db} res]
lappend rc $res
} {1 {backup failed: unknown database aux1}}
@@ -142,21 +142,18 @@ do_test backup2-9 {
# Try to restore from an unreadable file.
#
if {$tcl_platform(platform)=="windows"} {
- do_test backup2-10 {
- file delete -force bu3.db
- file mkdir bu3.db
- set rc [catch {db restore temp bu3.db} res]
- lappend rc $res
- } {1 {cannot open source database: unable to open database file}}
-}
-if {$tcl_platform(platform)!="windows"} {
- do_test backup2-10 {
- file delete -force bu3.db
- file mkdir bu3.db
- set rc [catch {db restore temp bu3.db} res]
- lappend rc $res
- } {1 {cannot open source database: disk I/O error}}
+ set msg {cannot open source database: unable to open database file}
+} elseif {$tcl_platform(os)=="OpenBSD"} {
+ set msg {restore failed: file is encrypted or is not a database}
+} 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]
+ lappend rc $res
+} [list 1 $msg]
# Try to restore from something that is not a database file.
#
@@ -172,7 +169,7 @@ do_test backup2-12 {
lappend rc $res
} {1 {restore failed: unknown database aux1}}
do_test backup2-13 {
- file delete -force bu4.db
+ forcedelete bu4.db
set rc [catch {db restore bu4.db} res]
lappend rc $res
} {1 {cannot open source database: unable to open database file}}
@@ -184,6 +181,6 @@ do_test backup2-14 {
lappend rc $res
} {1 {wrong # args: should be "db restore ?DATABASE? FILENAME"}}
-file delete -force bu1.db bu2.db bu3.db bu4.db
+forcedelete bu1.db bu2.db bu3.db bu4.db
finish_test
diff --git a/lang/sql/sqlite/test/backup4.test b/lang/sql/sqlite/test/backup4.test
new file mode 100644
index 00000000..417df80e
--- /dev/null
+++ b/lang/sql/sqlite/test/backup4.test
@@ -0,0 +1,103 @@
+# 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
+
+#-------------------------------------------------------------------------
+# 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/lang/sql/sqlite/test/backup_ioerr.test b/lang/sql/sqlite/test/backup_ioerr.test
index 3b5e95df..ca3fd324 100644
--- a/lang/sql/sqlite/test/backup_ioerr.test
+++ b/lang/sql/sqlite/test/backup_ioerr.test
@@ -60,7 +60,7 @@ do_test backup_ioerr-1.2 {
} {1}
do_test backup_ioerr-1.3 {
db close
- file delete -force test.db
+ forcedelete test.db
} {}
# Turn off IO error simulation.
@@ -115,7 +115,7 @@ proc clear_ioerr_simulation {} {
# reported, then the backup process is concluded with a call to
# backup_finish().
#
-# Test that if an IO error occurs, or if one occured while updating
+# 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.
#
@@ -155,8 +155,8 @@ for {set iError 1} {$bStop == 0} {incr iError} {
catch { ddb close }
catch { sdb close }
- catch { file delete -force test.db }
- catch { file delete -force bak.db }
+ catch { forcedelete test.db }
+ catch { forcedelete bak.db }
# Open the source and destination databases.
sqlite3 sdb test.db
@@ -214,7 +214,7 @@ for {set iError 1} {$bStop == 0} {incr iError} {
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 occured while updating the source database. In this
+ # 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" } {
diff --git a/lang/sql/sqlite/test/bc_common.tcl b/lang/sql/sqlite/test/bc_common.tcl
new file mode 100644
index 00000000..eb9b6db9
--- /dev/null
+++ b/lang/sql/sqlite/test/bc_common.tcl
@@ -0,0 +1,72 @@
+
+
+
+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 pattern "[file tail [info nameofexec]]?*"
+ if {$::tcl_platform(platform)=="windows"} {
+ set pattern [string map {\.exe {}} $pattern]
+ }
+ foreach file [glob -nocomplain $pattern] {
+ 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 [string map {testfixture {}} $bin]
+ 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/lang/sql/sqlite/test/between.test b/lang/sql/sqlite/test/between.test
index 45436756..df4c6799 100644
--- a/lang/sql/sqlite/test/between.test
+++ b/lang/sql/sqlite/test/between.test
@@ -48,14 +48,24 @@ do_test between-1.0 {
# 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 ::sqlite_query_plan variable.
+# 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
- return [concat $data $::sqlite_query_plan]
+ set eqp [execsql "EXPLAIN QUERY PLAN $sql"]
+ # puts eqp=$eqp
+ foreach {a b c x} $eqp {
+ if {[regexp { TABLE (\w+ AS )?(\w+) USING.* INDEX (\w+)\y} \
+ $x all as tab idx]} {
+ lappend data $tab $idx
+ } elseif {[regexp { TABLE (\w+ AS )?(\w+)\y} $x all as tab]} {
+ lappend data $tab *
+ }
+ }
+ return $data
}
do_test between-1.1.1 {
@@ -67,7 +77,7 @@ 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 {}}
+} {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
@@ -77,7 +87,7 @@ 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 {}}
+} {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
@@ -87,12 +97,12 @@ 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 {}}
+} {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 {}}
+} {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
@@ -107,7 +117,7 @@ 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 {}}
+} {4 2 25 27 sort t1 *}
finish_test
diff --git a/lang/sql/sqlite/test/bigfile.test b/lang/sql/sqlite/test/bigfile.test
index 52d74edb..31c63232 100644
--- a/lang/sql/sqlite/test/bigfile.test
+++ b/lang/sql/sqlite/test/bigfile.test
@@ -15,6 +15,9 @@
# $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
@@ -69,7 +72,7 @@ do_test bigfile-1.1 {
# large files. So skip all of the remaining tests in this file.
#
db close
-if {[catch {fake_big_file 4096 [pwd]/test.db} msg]} {
+if {[catch {fake_big_file 4096 [get_pwd]/test.db} msg]} {
puts "**** Unable to create a file larger than 4096 MB. *****"
finish_test
return
@@ -109,7 +112,7 @@ do_test bigfile-1.4 {
} $::MAGIC_SUM
db close
-if {[catch {fake_big_file 8192 [pwd]/test.db}]} {
+if {[catch {fake_big_file 8192 [get_pwd]/test.db}]} {
puts "**** Unable to create a file larger than 8192 MB. *****"
finish_test
return
@@ -148,7 +151,7 @@ do_test bigfile-1.9 {
} $::MAGIC_SUM
db close
-if {[catch {fake_big_file 16384 [pwd]/test.db}]} {
+if {[catch {fake_big_file 16384 [get_pwd]/test.db}]} {
puts "**** Unable to create a file larger than 16384 MB. *****"
finish_test
return
diff --git a/lang/sql/sqlite/test/bigfile2.test b/lang/sql/sqlite/test/bigfile2.test
new file mode 100644
index 00000000..de3b14b5
--- /dev/null
+++ b/lang/sql/sqlite/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/lang/sql/sqlite/test/boundary3.tcl b/lang/sql/sqlite/test/boundary3.tcl
index ac3bf0ad..5fc26d61 100644
--- a/lang/sql/sqlite/test/boundary3.tcl
+++ b/lang/sql/sqlite/test/boundary3.tcl
@@ -13,7 +13,6 @@ puts {# 2008 December 11
# This file is automatically generated from a separate TCL script.
# This file seeks to exercise integer boundary values.
#
-# $Id: boundary3.tcl,v 1.3 2009/01/02 15:45:48 shane Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -40,16 +39,16 @@ foreach x {
} {
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 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 {$x+1}]) 1
+ set boundarynum([expr {wide($x+1)}]) 1
set x [expr {wide($x*128 + 127)}]
}
@@ -116,7 +115,7 @@ foreach r $nums1 {
incr a
set t1ra($r) $a
set t1ar($a) $r
- set x [format %08x%08x [expr {wide($r)>>32}] $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');"
@@ -158,7 +157,7 @@ foreach r $nums3 {
set r5 $r.5
set r0 $r.0
- if {abs($r)<9.22337203685477580800e+18} {
+ if {abs($r)<0x7FFFFFFFFFFFFFFF || $r==-9223372036854775808} {
set x $t1rx($r)
set a $t1ra($r)
puts "do_test $tname-2.$i.1 \173"
diff --git a/lang/sql/sqlite/test/btreefault.test b/lang/sql/sqlite/test/btreefault.test
new file mode 100644
index 00000000..61104c5a
--- /dev/null
+++ b/lang/sql/sqlite/test/btreefault.test
@@ -0,0 +1,57 @@
+# 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
+}
+
+finish_test
diff --git a/lang/sql/sqlite/test/cache.test b/lang/sql/sqlite/test/cache.test
index 8d801f05..ffc25c46 100644
--- a/lang/sql/sqlite/test/cache.test
+++ b/lang/sql/sqlite/test/cache.test
@@ -14,7 +14,7 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
-ifcapable {!pager_pragmas} {
+ifcapable !pager_pragmas||!compound {
finish_test
return
}
@@ -46,7 +46,7 @@ do_test cache-1.2 {
# 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 initialised, it can be locked
+# 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]
diff --git a/lang/sql/sqlite/test/capi2.test b/lang/sql/sqlite/test/capi2.test
index 8b36ac69..39f50dd0 100644
--- a/lang/sql/sqlite/test/capi2.test
+++ b/lang/sql/sqlite/test/capi2.test
@@ -235,8 +235,9 @@ do_test capi2-3.13 {
do_test capi2-3.13b {db changes} {0}
do_test capi2-3.14 {
- list [sqlite3_finalize $VM] [sqlite3_errmsg $DB]
-} {SQLITE_CONSTRAINT {column a is not unique}}
+ 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
@@ -258,8 +259,9 @@ do_test capi2-3.18 {
[get_column_names $VM]
} {SQLITE_ERROR 0 {} {}}
do_test capi2-3.19 {
- list [sqlite3_finalize $VM] [sqlite3_errmsg $DB]
-} {SQLITE_CONSTRAINT {t2.a may not be NULL}}
+ 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 {
@@ -278,8 +280,8 @@ do_test capi2-3.23 {
sqlite3_finalize $VM
} {SQLITE_CONSTRAINT}
do_test capi2-3.24 {
- sqlite3_errcode $DB
-} {SQLITE_CONSTRAINT}
+ list [sqlite3_errcode $DB] [sqlite3_extended_errcode $DB]
+} {SQLITE_CONSTRAINT SQLITE_CONSTRAINT_UNIQUE}
# Two or more virtual machines exists at the same time.
#
@@ -553,7 +555,7 @@ do_test capi2-6.27 {
INSERT INTO t1 VALUES(2,4,5);
SELECT * FROM t1;
}
-} {1 {column a is not unique}}
+} {1 {UNIQUE constraint failed: t1.a}}
do_test capi2-6.28 {
list [sqlite3_step $VM1] \
[sqlite3_column_count $VM1] \
diff --git a/lang/sql/sqlite/test/capi3.test b/lang/sql/sqlite/test/capi3.test
index cc1461a7..f0234e88 100644
--- a/lang/sql/sqlite/test/capi3.test
+++ b/lang/sql/sqlite/test/capi3.test
@@ -179,16 +179,18 @@ do_test capi3-3.4 {
do_test capi3-3.5 {
sqlite3_close $db2
} {SQLITE_OK}
-do_test capi3-3.6.1-misuse {
- sqlite3_close $db2
-} {SQLITE_MISUSE}
-do_test capi3-3.6.2-misuse {
- sqlite3_errmsg $db2
-} {library routine called out of sequence}
-ifcapable {utf16} {
- do_test capi3-3.6.3-misuse {
- utf8 [sqlite3_errmsg16 $db2]
+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
} {library routine called out of sequence}
+ ifcapable {utf16} {
+ do_test capi3-3.6.3-misuse {
+ utf8 [sqlite3_errmsg16 $db2]
+ } {library routine called out of sequence}
+ }
}
do_test capi3-3.7 {
@@ -649,17 +651,24 @@ 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_ERROR}
+} {SQLITE_ROW}
#check_data $STMT capi3-6.3 {INTEGER} {1} {1.0} {1}
do_test capi3-6.3 {
sqlite3_finalize $STMT
-} {SQLITE_SCHEMA}
-do_test capi3-6.4-misuse {
- db cache flush
- sqlite3_close $DB
} {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'
@@ -697,7 +706,7 @@ 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 {
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db test.db
execsql {
CREATE TABLE t1(a);
@@ -722,7 +731,7 @@ if {![sqlite3 -has-codec]} {
# Build a 5-field row record. The first field is a string 'table', and
# subsequent fields are all NULL.
db close
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db test.db
execsql {
CREATE TABLE t1(a);
@@ -739,8 +748,8 @@ if {![sqlite3 -has-codec]} {
} {1 {malformed database schema (?)}}
db close
}
-file delete -force test.db
-file delete -force test.db-journal
+forcedelete test.db
+forcedelete test.db-journal
# Test the english language string equivalents for sqlite error codes
@@ -778,6 +787,7 @@ foreach {code english} $code2english {
}
# Test the error message when a "real" out of memory occurs.
+if { [permutation] != "nofaultsim" } {
ifcapable memdebug {
do_test capi3-10-1 {
sqlite3 db test.db
@@ -816,6 +826,7 @@ ifcapable memdebug {
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
@@ -894,18 +905,25 @@ do_test capi3-11.9.2 {
catchsql {
ROLLBACK;
}
-} {1 {cannot rollback transaction - SQL statements in progress}}
+} {0 {}}
do_test capi3-11.9.3 {
sqlite3_get_autocommit $DB
-} 0
+} 1
do_test capi3-11.10 {
sqlite3_step $STMT
-} {SQLITE_ROW}
+} {SQLITE_ERROR}
+ifcapable !autoreset {
+ # If SQLITE_OMIT_AUTORESET is defined, then the statement must be
+ # reset() before it can be passed to step() again.
+ do_test capi3-11.11a { sqlite3_step $STMT } {SQLITE_MISUSE}
+ do_test capi3-11.11b { sqlite3_reset $STMT } {SQLITE_ABORT}
+}
do_test capi3-11.11 {
sqlite3_step $STMT
} {SQLITE_ROW}
do_test capi3-11.12 {
sqlite3_step $STMT
+ sqlite3_step $STMT
} {SQLITE_DONE}
do_test capi3-11.13 {
sqlite3_finalize $STMT
@@ -914,15 +932,15 @@ do_test capi3-11.14 {
execsql {
SELECT a FROM t2;
}
-} {1 2 3}
+} {1 2}
do_test capi3-11.14.1 {
sqlite3_get_autocommit $DB
-} 0
+} 1
do_test capi3-11.15 {
catchsql {
ROLLBACK;
}
-} {0 {}}
+} {1 {cannot rollback - no transaction is active}}
do_test capi3-11.15.1 {
sqlite3_get_autocommit $DB
} 1
@@ -1046,11 +1064,13 @@ if {[llength [info commands sqlite3_sleep]]>0} {
}
# Ticket #1219: Make sure binding APIs can handle a NULL pointer.
-#
-do_test capi3-14.1-misuse {
- set rc [catch {sqlite3_bind_text 0 1 hello 5} msg]
- lappend rc $msg
-} {1 SQLITE_MISUSE}
+#
+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.
#
diff --git a/lang/sql/sqlite/test/capi3c.test b/lang/sql/sqlite/test/capi3c.test
index af979438..6388717e 100644
--- a/lang/sql/sqlite/test/capi3c.test
+++ b/lang/sql/sqlite/test/capi3c.test
@@ -169,16 +169,18 @@ do_test capi3c-3.4 {
do_test capi3c-3.5 {
sqlite3_close $db2
} {SQLITE_OK}
-do_test capi3c-3.6.1-misuse {
- sqlite3_close $db2
-} {SQLITE_MISUSE}
-do_test capi3c-3.6.2-misuse {
- sqlite3_errmsg $db2
-} {library routine called out of sequence}
-ifcapable {utf16} {
- do_test capi3c-3.6.3-misuse {
- utf8 [sqlite3_errmsg16 $db2]
+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
} {library routine called out of sequence}
+ ifcapable {utf16} {
+ do_test capi3c-3.6.3-misuse {
+ utf8 [sqlite3_errmsg16 $db2]
+ } {library routine called out of sequence}
+ }
}
# rename sqlite3_open ""
@@ -627,13 +629,17 @@ check_data $STMT capi3c-6.3 {INTEGER} {1} {1.0} {1}
do_test capi3c-6.3 {
sqlite3_finalize $STMT
} {SQLITE_OK}
-do_test capi3c-6.4 {
- db cache flush
- sqlite3_close $DB
-} {SQLITE_OK}
-do_test capi3c-6.99-misuse {
+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.
@@ -670,7 +676,7 @@ 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 {
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db test.db
execsql {
CREATE TABLE t1(a);
@@ -695,7 +701,7 @@ if {![sqlite3 -has-codec]} {
# Build a 5-field row record. The first field is a string 'table', and
# subsequent fields are all NULL.
db close
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db test.db
execsql {
CREATE TABLE t1(a);
@@ -712,8 +718,8 @@ if {![sqlite3 -has-codec]} {
} {1 {malformed database schema (?)}}
db close
}
-file delete -force test.db
-file delete -force test.db-journal
+forcedelete test.db
+forcedelete test.db-journal
# Test the english language string equivalents for sqlite error codes
@@ -751,6 +757,7 @@ foreach {code english} $code2english {
}
# Test the error message when a "real" out of memory occurs.
+if { [permutation] != "nofaultsim" } {
ifcapable memdebug {
do_test capi3c-10-1 {
sqlite3 db test.db
@@ -771,6 +778,7 @@ ifcapable memdebug {
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
@@ -849,18 +857,25 @@ do_test capi3c-11.9.2 {
catchsql {
ROLLBACK;
}
-} {1 {cannot rollback transaction - SQL statements in progress}}
+} {0 {}}
do_test capi3c-11.9.3 {
sqlite3_get_autocommit $DB
-} 0
+} 1
do_test capi3c-11.10 {
sqlite3_step $STMT
-} {SQLITE_ROW}
+} {SQLITE_ABORT}
+ifcapable !autoreset {
+ # If SQLITE_OMIT_AUTORESET is defined, then the statement must be
+ # reset() before it can be passed to step() again.
+ do_test capi3-11.11a { sqlite3_step $STMT } {SQLITE_MISUSE}
+ do_test capi3-11.11b { sqlite3_reset $STMT } {SQLITE_ABORT}
+}
do_test capi3c-11.11 {
sqlite3_step $STMT
} {SQLITE_ROW}
do_test capi3c-11.12 {
sqlite3_step $STMT
+ sqlite3_step $STMT
} {SQLITE_DONE}
do_test capi3c-11.13 {
sqlite3_finalize $STMT
@@ -869,15 +884,15 @@ do_test capi3c-11.14 {
execsql {
SELECT a FROM t2;
}
-} {1 2 3}
+} {1 2}
do_test capi3c-11.14.1 {
sqlite3_get_autocommit $DB
-} 0
+} 1
do_test capi3c-11.15 {
catchsql {
ROLLBACK;
}
-} {0 {}}
+} {1 {cannot rollback - no transaction is active}}
do_test capi3c-11.15.1 {
sqlite3_get_autocommit $DB
} 1
diff --git a/lang/sql/sqlite/test/capi3d.test b/lang/sql/sqlite/test/capi3d.test
index 49e64476..ed3765b0 100644
--- a/lang/sql/sqlite/test/capi3d.test
+++ b/lang/sql/sqlite/test/capi3d.test
@@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library.
#
# This file is devoted to testing the sqlite3_next_stmt and
-# sqlite3_stmt_readonly interfaces.
+# sqlite3_stmt_readonly and sqlite3_stmt_busy interfaces.
#
# $Id: capi3d.test,v 1.2 2008/07/14 15:11:20 drh Exp $
#
@@ -108,9 +108,40 @@ 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.99 {
sqlite3_stmt_readonly 0
} 1
+# 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}
finish_test
diff --git a/lang/sql/sqlite/test/capi3e.test b/lang/sql/sqlite/test/capi3e.test
index 21304cb8..d7ab8d0b 100644
--- a/lang/sql/sqlite/test/capi3e.test
+++ b/lang/sql/sqlite/test/capi3e.test
@@ -60,7 +60,7 @@ proc utf8 {str} {
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 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 {
diff --git a/lang/sql/sqlite/test/cast.test b/lang/sql/sqlite/test/cast.test
index 7a239439..f47f4bb2 100644
--- a/lang/sql/sqlite/test/cast.test
+++ b/lang/sql/sqlite/test/cast.test
@@ -234,7 +234,7 @@ do_test cast-3.1 {
do_test cast-3.2 {
execsql {SELECT CAST(9223372036854774800 AS numeric)}
} 9223372036854774800
-do_test cast-3.3 {
+do_realnum_test cast-3.3 {
execsql {SELECT CAST(9223372036854774800 AS real)}
} 9.22337203685477e+18
do_test cast-3.4 {
@@ -246,7 +246,7 @@ do_test cast-3.5 {
do_test cast-3.6 {
execsql {SELECT CAST(-9223372036854774800 AS numeric)}
} -9223372036854774800
-do_test cast-3.7 {
+do_realnum_test cast-3.7 {
execsql {SELECT CAST(-9223372036854774800 AS real)}
} -9.22337203685477e+18
do_test cast-3.8 {
@@ -258,7 +258,7 @@ do_test cast-3.11 {
do_test cast-3.12 {
execsql {SELECT CAST('9223372036854774800' AS numeric)}
} 9223372036854774800
-do_test cast-3.13 {
+do_realnum_test cast-3.13 {
execsql {SELECT CAST('9223372036854774800' AS real)}
} 9.22337203685477e+18
ifcapable long_double {
@@ -272,7 +272,7 @@ do_test cast-3.15 {
do_test cast-3.16 {
execsql {SELECT CAST('-9223372036854774800' AS numeric)}
} -9223372036854774800
-do_test cast-3.17 {
+do_realnum_test cast-3.17 {
execsql {SELECT CAST('-9223372036854774800' AS real)}
} -9.22337203685477e+18
ifcapable long_double {
@@ -287,7 +287,7 @@ if {[db eval {PRAGMA encoding}]=="UTF-8"} {
do_test cast-3.22 {
execsql {SELECT CAST(x'39323233333732303336383534373734383030' AS numeric)}
} 9223372036854774800
- do_test cast-3.23 {
+ do_realnum_test cast-3.23 {
execsql {SELECT CAST(x'39323233333732303336383534373734383030' AS real)}
} 9.22337203685477e+18
ifcapable long_double {
diff --git a/lang/sql/sqlite/test/check.test b/lang/sql/sqlite/test/check.test
index d2867a09..02b99f2a 100644
--- a/lang/sql/sqlite/test/check.test
+++ b/lang/sql/sqlite/test/check.test
@@ -15,6 +15,7 @@
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 {
@@ -40,7 +41,7 @@ do_test check-1.3 {
catchsql {
INSERT INTO t1 VALUES(6,7);
}
-} {1 {constraint failed}}
+} {1 {CHECK constraint failed: t1}}
do_test check-1.4 {
execsql {
SELECT * FROM t1;
@@ -50,7 +51,7 @@ do_test check-1.5 {
catchsql {
INSERT INTO t1 VALUES(4,3);
}
-} {1 {constraint failed}}
+} {1 {CHECK constraint failed: t1}}
do_test check-1.6 {
execsql {
SELECT * FROM t1;
@@ -87,7 +88,7 @@ do_test check-1.12 {
catchsql {
UPDATE t1 SET x=7 WHERE x==2
}
-} {1 {constraint failed}}
+} {1 {CHECK constraint failed: t1}}
do_test check-1.13 {
execsql {
SELECT * FROM t1;
@@ -97,7 +98,7 @@ do_test check-1.14 {
catchsql {
UPDATE t1 SET x=5 WHERE x==2
}
-} {1 {constraint failed}}
+} {1 {CHECK constraint failed: t1}}
do_test check-1.15 {
execsql {
SELECT * FROM t1;
@@ -117,9 +118,9 @@ do_test check-1.17 {
do_test check-2.1 {
execsql {
CREATE TABLE t2(
- x INTEGER CHECK( typeof(coalesce(x,0))=="integer" ),
- y REAL CHECK( typeof(coalesce(y,0.1))=='real' ),
- z TEXT CHECK( typeof(coalesce(z,''))=='text' )
+ 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' )
);
}
} {}
@@ -141,17 +142,59 @@ do_test check-2.4 {
catchsql {
INSERT INTO t2 VALUES(1.1, NULL, NULL);
}
-} {1 {constraint failed}}
+} {1 {CHECK constraint failed: one}}
do_test check-2.5 {
catchsql {
INSERT INTO t2 VALUES(NULL, 5, NULL);
}
-} {1 {constraint failed}}
+} {1 {CHECK constraint failed: two}}
do_test check-2.6 {
catchsql {
INSERT INTO t2 VALUES(NULL, NULL, 3.14159);
}
-} {1 {constraint failed}}
+} {1 {CHECK constraint failed: three}}
+
+# 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: t2b}}
+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;
+ }
+} {}
ifcapable subquery {
do_test check-3.1 {
@@ -213,7 +256,7 @@ do_test check-3.9 {
catchsql {
INSERT INTO t3 VALUES(111,222,333);
}
-} {1 {constraint failed}}
+} {1 {CHECK constraint failed: t3}}
do_test check-4.1 {
execsql {
@@ -255,7 +298,7 @@ do_test check-4.6 {
catchsql {
UPDATE t4 SET x=0, y=1;
}
-} {1 {constraint failed}}
+} {1 {CHECK constraint failed: t4}}
do_test check-4.7 {
execsql {
SELECT * FROM t4;
@@ -273,7 +316,7 @@ do_test check-4.9 {
PRAGMA ignore_check_constraints=OFF;
UPDATE t4 SET x=0, y=2;
}
-} {1 {constraint failed}}
+} {1 {CHECK constraint failed: t4}}
ifcapable vacuum {
do_test check_4.10 {
catchsql {
@@ -324,7 +367,7 @@ do_test check-6.5 {
catchsql {
UPDATE OR FAIL t1 SET x=7-x, y=y+1;
}
-} {1 {constraint failed}}
+} {1 {CHECK constraint failed: t1}}
do_test check-6.6 {
execsql {
SELECT * FROM t1;
@@ -336,7 +379,7 @@ do_test check-6.7 {
INSERT INTO t1 VALUES(1,30.0);
INSERT OR ROLLBACK INTO t1 VALUES(8,40.0);
}
-} {1 {constraint failed}}
+} {1 {CHECK constraint failed: t1}}
do_test check-6.8 {
catchsql {
COMMIT;
@@ -355,7 +398,7 @@ do_test check-6.12 {
catchsql {
REPLACE INTO t1 VALUES(6,7);
}
-} {1 {constraint failed}}
+} {1 {CHECK constraint failed: t1}}
do_test check-6.13 {
execsql {SELECT * FROM t1}
} {3 12.0 2 20.0}
@@ -371,4 +414,49 @@ do_test check-6.15 {
}
+#--------------------------------------------------------------------------
+# If a connection opens a database that contains a CHECK constraint that
+# uses an unknown UDF, the schema should not be considered malformed.
+# Attempting to modify the table should fail (since the CHECK constraint
+# cannot be tested).
+#
+reset_db
+proc myfunc {x} {expr $x < 10}
+db func myfunc myfunc
+
+do_execsql_test 7.1 { CREATE TABLE t6(a CHECK (myfunc(a))) }
+do_execsql_test 7.2 { INSERT INTO t6 VALUES(9) }
+do_catchsql_test 7.3 { INSERT INTO t6 VALUES(11) } \
+ {1 {CHECK constraint failed: t6}}
+
+do_test 7.4 {
+ sqlite3 db2 test.db
+ execsql { SELECT * FROM t6 } db2
+} {9}
+
+do_test 7.5 {
+ catchsql { INSERT INTO t6 VALUES(8) } db2
+} {1 {unknown function: myfunc()}}
+
+do_test 7.6 {
+ catchsql { CREATE TABLE t7(a CHECK (myfunc(a))) } db2
+} {1 {no such function: myfunc}}
+
+do_test 7.7 {
+ db2 func myfunc myfunc
+ execsql { INSERT INTO t6 VALUES(8) } db2
+} {}
+
+do_test 7.8 {
+ db2 func myfunc myfunc
+ catchsql { INSERT INTO t6 VALUES(12) } db2
+} {1 {CHECK constraint failed: t6}}
+
+# 2013-08-02: Silently ignore database name qualifiers in CHECK constraints.
+#
+do_execsql_test 8.1 {
+ CREATE TABLE t810(a, CHECK( main.t810.a>0 ));
+ CREATE TABLE t811(b, CHECK( xyzzy.t811.b BETWEEN 5 AND 10 ));
+} {}
+
finish_test
diff --git a/lang/sql/sqlite/test/close.test b/lang/sql/sqlite/test/close.test
new file mode 100644
index 00000000..d5d6391a
--- /dev/null
+++ b/lang/sql/sqlite/test/close.test
@@ -0,0 +1,78 @@
+# 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
+
+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) library routine called out of sequence}}
+
+do_test 1.4.4 {
+ sqlite3_finalize $STMT
+} {SQLITE_OK}
+
+finish_test
diff --git a/lang/sql/sqlite/test/closure01.test b/lang/sql/sqlite/test/closure01.test
new file mode 100644
index 00000000..213ef4e9
--- /dev/null
+++ b/lang/sql/sqlite/test/closure01.test
@@ -0,0 +1,276 @@
+# 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}
+
+finish_test
diff --git a/lang/sql/sqlite/test/collate1.test b/lang/sql/sqlite/test/collate1.test
index ac2c75be..20854157 100644
--- a/lang/sql/sqlite/test/collate1.test
+++ b/lang/sql/sqlite/test/collate1.test
@@ -304,4 +304,33 @@ do_test collate1-4.5 {
}
} {}
+# 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}
+
finish_test
diff --git a/lang/sql/sqlite/test/collate2.test b/lang/sql/sqlite/test/collate2.test
index bf619231..d5aadb4e 100644
--- a/lang/sql/sqlite/test/collate2.test
+++ b/lang/sql/sqlite/test/collate2.test
@@ -17,6 +17,8 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
+set ::testprefix collate2
+
#
# Tests are organised as follows:
#
@@ -636,13 +638,15 @@ do_test collate2-4.2 {
do_test collate2-4.3 {
execsql {
SELECT collate2t1.a FROM collate2t1, collate2t3
- WHERE collate2t1.b = collate2t3.b||'';
+ 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;
+ WHERE collate2t3.b||'' = collate2t1.b
+ ORDER BY +collate2t1.a DESC;
}
} {aa aA Aa AA}
@@ -691,4 +695,30 @@ do_test collate2-5.5 {
}
} {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/lang/sql/sqlite/test/collate3.test b/lang/sql/sqlite/test/collate3.test
index c4dbfbe4..2c051cb9 100644
--- a/lang/sql/sqlite/test/collate3.test
+++ b/lang/sql/sqlite/test/collate3.test
@@ -55,6 +55,104 @@ 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
diff --git a/lang/sql/sqlite/test/collate4.test b/lang/sql/sqlite/test/collate4.test
index 12bc16ef..2ddf53d5 100644
--- a/lang/sql/sqlite/test/collate4.test
+++ b/lang/sql/sqlite/test/collate4.test
@@ -60,7 +60,7 @@ proc cksort {sql} {
#
# Because these tests also exercise all the different ways indices
# can be created, they also serve to verify that indices are correctly
-# initialised with user-defined collation sequences when they are
+# initialized with user-defined collation sequences when they are
# created.
#
# Tests named collate4-1.1.* use indices with a single column. Tests
@@ -94,7 +94,7 @@ 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}
+ cksort {SELECT b FROM collate4t1 ORDER BY b COLLATE NOCASE, rowid}
} {{} a A b B sort}
do_test collate4-1.1.7 {
@@ -171,13 +171,13 @@ do_test collate4-1.1.21 {
}
} {}
do_test collate4-1.1.22 {
- cksort {SELECT a FROM collate4t4 ORDER BY a}
+ 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}
+ 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}
+ 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}
@@ -222,7 +222,7 @@ 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}
+ 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}
@@ -271,10 +271,10 @@ do_test collate4-1.2.14 {
}
} {}
do_test collate4-1.2.15 {
- cksort {SELECT a FROM collate4t3 ORDER BY a}
+ 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}
+ 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}
@@ -364,7 +364,8 @@ do_test collate4-2.1.4 {
CREATE INDEX collate4i1 ON collate4t1(a COLLATE TEXT);
}
count {
- SELECT * FROM collate4t2, collate4t1 WHERE a = b;
+ SELECT * FROM collate4t2, collate4t1 WHERE a = b
+ ORDER BY collate4t2.rowid, collate4t1.rowid
}
} {A a A A 19}
do_test collate4-2.1.5 {
@@ -375,7 +376,8 @@ do_test collate4-2.1.5 {
ifcapable subquery {
do_test collate4-2.1.6 {
count {
- SELECT a FROM collate4t1 WHERE a IN (SELECT * FROM collate4t2);
+ SELECT a FROM collate4t1 WHERE a IN (SELECT * FROM collate4t2)
+ ORDER BY rowid
}
} {a A 10}
do_test collate4-2.1.7 {
@@ -384,7 +386,8 @@ ifcapable subquery {
CREATE INDEX collate4i1 ON collate4t1(a);
}
count {
- SELECT a FROM collate4t1 WHERE a IN (SELECT * FROM collate4t2);
+ SELECT a FROM collate4t1 WHERE a IN (SELECT * FROM collate4t2)
+ ORDER BY rowid
}
} {a A 6}
do_test collate4-2.1.8 {
@@ -398,7 +401,7 @@ ifcapable subquery {
CREATE INDEX collate4i1 ON collate4t1(a COLLATE TEXT);
}
count {
- SELECT a FROM collate4t1 WHERE a IN ('z', 'a');
+ SELECT a FROM collate4t1 WHERE a IN ('z', 'a') ORDER BY rowid;
}
} {a A 9}
}
@@ -470,7 +473,7 @@ do_test collate4-3.1 {
INSERT INTO collate4t1 VALUES('abc');
INSERT INTO collate4t1 VALUES('ABC');
}
-} {1 {column a is not unique}}
+} {1 {UNIQUE constraint failed: collate4t1.a}}
do_test collate4-3.2 {
execsql {
SELECT * FROM collate4t1;
@@ -480,13 +483,13 @@ do_test collate4-3.3 {
catchsql {
INSERT INTO collate4t1 SELECT upper(a) FROM collate4t1;
}
-} {1 {column a is not unique}}
+} {1 {UNIQUE constraint failed: collate4t1.a}}
do_test collate4-3.4 {
catchsql {
INSERT INTO collate4t1 VALUES(1);
UPDATE collate4t1 SET a = 'abc';
}
-} {1 {column a is not unique}}
+} {1 {UNIQUE constraint failed: collate4t1.a}}
do_test collate4-3.5 {
execsql {
DROP TABLE collate4t1;
@@ -498,7 +501,7 @@ do_test collate4-3.6 {
INSERT INTO collate4t1 VALUES('abc');
INSERT INTO collate4t1 VALUES('ABC');
}
-} {1 {column a is not unique}}
+} {1 {UNIQUE constraint failed: collate4t1.a}}
do_test collate4-3.7 {
execsql {
SELECT * FROM collate4t1;
@@ -508,13 +511,13 @@ do_test collate4-3.8 {
catchsql {
INSERT INTO collate4t1 SELECT upper(a) FROM collate4t1;
}
-} {1 {column a is not unique}}
+} {1 {UNIQUE constraint failed: collate4t1.a}}
do_test collate4-3.9 {
catchsql {
INSERT INTO collate4t1 VALUES(1);
UPDATE collate4t1 SET a = 'abc';
}
-} {1 {column a is not unique}}
+} {1 {UNIQUE constraint failed: collate4t1.a}}
do_test collate4-3.10 {
execsql {
DROP TABLE collate4t1;
@@ -527,7 +530,7 @@ do_test collate4-3.11 {
INSERT INTO collate4t1 VALUES('abc');
INSERT INTO collate4t1 VALUES('ABC');
}
-} {1 {column a is not unique}}
+} {1 {UNIQUE constraint failed: collate4t1.a}}
do_test collate4-3.12 {
execsql {
SELECT * FROM collate4t1;
@@ -537,13 +540,13 @@ do_test collate4-3.13 {
catchsql {
INSERT INTO collate4t1 SELECT upper(a) FROM collate4t1;
}
-} {1 {column a is not unique}}
+} {1 {UNIQUE constraint failed: collate4t1.a}}
do_test collate4-3.14 {
catchsql {
INSERT INTO collate4t1 VALUES(1);
UPDATE collate4t1 SET a = 'abc';
}
-} {1 {column a is not unique}}
+} {1 {UNIQUE constraint failed: collate4t1.a}}
do_test collate4-3.15 {
execsql {
diff --git a/lang/sql/sqlite/test/collate5.test b/lang/sql/sqlite/test/collate5.test
index 2e4b89d5..5f8697ea 100644
--- a/lang/sql/sqlite/test/collate5.test
+++ b/lang/sql/sqlite/test/collate5.test
@@ -57,17 +57,17 @@ do_test collate5-1.1 {
execsql {
SELECT DISTINCT a FROM collate5t1;
}
-} {A B N}
+} {a b n}
do_test collate5-1.2 {
execsql {
SELECT DISTINCT b FROM collate5t1;
}
-} {{} Apple apple banana}
+} {apple Apple banana {}}
do_test collate5-1.3 {
execsql {
SELECT DISTINCT a, b FROM collate5t1;
}
-} {A Apple a apple B banana N {}}
+} {a apple A Apple b banana n {}}
# Ticket #3376
#
@@ -221,7 +221,7 @@ do_test collate5-3.0 {
execsql {
SELECT a FROM collate5t1 UNION ALL SELECT a FROM collate5t2 ORDER BY 1;
}
-} {a A a A b B b B n N}
+} {/[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;
@@ -282,7 +282,7 @@ do_test collate5-4.2 {
execsql {
SELECT a, b, count(*) FROM collate5t1 GROUP BY a, b ORDER BY a, b;
}
-} {A 1.0 2 b 2 1 B 3 1}
+} {/[aA] 1(.0)? 2 [bB] 2 1 [bB] 3 1/}
do_test collate5-4.3 {
execsql {
DROP TABLE collate5t1;
diff --git a/lang/sql/sqlite/test/collate7.test b/lang/sql/sqlite/test/collate7.test
index 22b67310..da97491e 100644
--- a/lang/sql/sqlite/test/collate7.test
+++ b/lang/sql/sqlite/test/collate7.test
@@ -44,7 +44,7 @@ do_test collate7-1.4 {
} {2}
do_test collate7-2.1 {
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db test.db
sqlite3_create_collation_v2 db CASELESS caseless_cmp {incr ::caseless_del}
execsql {
diff --git a/lang/sql/sqlite/test/conflict.test b/lang/sql/sqlite/test/conflict.test
index 17c7263f..af5668ed 100644
--- a/lang/sql/sqlite/test/conflict.test
+++ b/lang/sql/sqlite/test/conflict.test
@@ -242,7 +242,7 @@ foreach {i conf1 cmd t0 t1 t2} {
15 {} {INSERT OR ABORT} 1 {} 1
16 {} {INSERT OR ROLLBACK} 1 {} {}
} {
- if {$t0} {set t1 {t1.c may not be NULL}}
+ 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 {
@@ -306,7 +306,7 @@ foreach {i conf1 cmd t0 t1 t2 t3 t4} {
15 {} {UPDATE OR ABORT} 1 {1 2 3 4} 1 0 1
16 {} {UPDATE OR ROLLBACK} 1 {1 2 3 4} 0 0 0
} {
- if {$t0} {set t1 {column a is not unique}}
+ if {$t0} {set t1 {UNIQUE constraint failed: t1.a}}
if {[info exists TEMP_STORE] && $TEMP_STORE==3} {
set t3 0
} else {
@@ -493,13 +493,13 @@ do_test conflict-9.5 {
INSERT INTO t2 VALUES(3,1,3,3,3);
SELECT * FROM t2;
}
-} {1 {column b is not unique}}
+} {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 {column b is not unique}}
+} {1 {UNIQUE constraint failed: t2.b}}
do_test conflict-9.7 {
catchsql {
BEGIN;
@@ -507,7 +507,7 @@ do_test conflict-9.7 {
INSERT INTO t2 VALUES(3,1,3,3,3);
SELECT * FROM t2;
}
-} {1 {column b is not unique}}
+} {1 {UNIQUE constraint failed: t2.b}}
do_test conflict-9.8 {
execsql {COMMIT}
execsql {SELECT * FROM t3}
@@ -519,7 +519,7 @@ do_test conflict-9.9 {
UPDATE t2 SET b=b+1 WHERE b=1;
SELECT * FROM t2;
}
-} {1 {column b is not unique}}
+} {1 {UNIQUE constraint failed: t2.b}}
do_test conflict-9.10 {
execsql {COMMIT}
execsql {SELECT * FROM t3}
@@ -529,13 +529,13 @@ do_test conflict-9.11 {
INSERT INTO t2 VALUES(3,3,3,1,3);
SELECT * FROM t2;
}
-} {1 {column d is not unique}}
+} {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 {column d is not unique}}
+} {1 {UNIQUE constraint failed: t2.d}}
do_test conflict-9.13 {
catchsql {
BEGIN;
@@ -543,7 +543,7 @@ do_test conflict-9.13 {
INSERT INTO t2 VALUES(3,3,3,1,3);
SELECT * FROM t2;
}
-} {1 {column d is not unique}}
+} {1 {UNIQUE constraint failed: t2.d}}
do_test conflict-9.14 {
execsql {COMMIT}
execsql {SELECT * FROM t3}
@@ -555,7 +555,7 @@ do_test conflict-9.15 {
UPDATE t2 SET d=d+1 WHERE d=1;
SELECT * FROM t2;
}
-} {1 {column d is not unique}}
+} {1 {UNIQUE constraint failed: t2.d}}
do_test conflict-9.16 {
execsql {COMMIT}
execsql {SELECT * FROM t3}
@@ -565,13 +565,13 @@ do_test conflict-9.17 {
INSERT INTO t2 VALUES(3,3,3,3,1);
SELECT * FROM t2;
}
-} {1 {column e is not unique}}
+} {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 {column e is not unique}}
+} {1 {UNIQUE constraint failed: t2.e}}
do_test conflict-9.19 {
catchsql {
BEGIN;
@@ -579,7 +579,8 @@ do_test conflict-9.19 {
INSERT INTO t2 VALUES(3,3,3,3,1);
SELECT * FROM t2;
}
-} {1 {column e is not unique}}
+} {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}
@@ -591,7 +592,8 @@ do_test conflict-9.21 {
UPDATE t2 SET e=e+1 WHERE e=1;
SELECT * FROM t2;
}
-} {1 {column e is not unique}}
+} {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}
@@ -780,13 +782,22 @@ do_test conflict-12.3 {
catchsql {
UPDATE t5 SET a=a+1 WHERE a=1;
}
-} {1 {PRIMARY KEY must be unique}}
+} {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]
@@ -801,7 +812,8 @@ do_test conflict-13.1 {
catchsql {
REPLACE INTO t13 VALUES(2);
}
-} {1 {constraint failed}}
+} {1 {CHECK constraint failed: t13}}
+verify_ex_errcode conflict-13.1b SQLITE_CONSTRAINT_CHECK
do_test conflict-13.2 {
execsql {
REPLACE INTO t13 VALUES(3);
diff --git a/lang/sql/sqlite/test/conflict2.test b/lang/sql/sqlite/test/conflict2.test
new file mode 100644
index 00000000..8419f1a3
--- /dev/null
+++ b/lang/sql/sqlite/test/conflict2.test
@@ -0,0 +1,855 @@
+# 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.
+#
+foreach {i conf1 cmd t0 t1 t2 t3 t4} {
+ 1 {} UPDATE 1 {6 7 8 9} 1 0 1
+ 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 1
+ 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 1
+ 9 FAIL {UPDATE OR IGNORE} 0 {6 7 3 9} 1 0 0
+ 10 ABORT {UPDATE OR REPLACE} 0 {7 6 9} 1 0 1
+ 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 1
+ 14 {} {UPDATE OR FAIL} 1 {6 7 3 4} 1 0 0
+ 15 {} {UPDATE OR ABORT} 1 {1 2 3 4} 1 0 1
+ 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: t13}}
+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/lang/sql/sqlite/test/conflict3.test b/lang/sql/sqlite/test/conflict3.test
new file mode 100644
index 00000000..b51a55ee
--- /dev/null
+++ b/lang/sql/sqlite/test/conflict3.test
@@ -0,0 +1,356 @@
+# 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
+
+ifcapable !conflict {
+ finish_test
+ return
+}
+
+do_execsql_test conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-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 conflict-11.4 {
+ SELECT a,b,c FROM t1 ORDER BY a;
+} {1 2 3 2 3 4 4 5 6}
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/contrib01.test b/lang/sql/sqlite/test/contrib01.test
new file mode 100644
index 00000000..43ea47c3
--- /dev/null
+++ b/lang/sql/sqlite/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/lang/sql/sqlite/test/corrupt.test b/lang/sql/sqlite/test/corrupt.test
index 719c19cc..3e49a9ff 100644
--- a/lang/sql/sqlite/test/corrupt.test
+++ b/lang/sql/sqlite/test/corrupt.test
@@ -15,7 +15,7 @@
#
# $Id: corrupt.test,v 1.12 2009/07/13 09:41:45 danielk1977 Exp $
-catch {file delete -force test.db test.db-journal test.bu}
+catch {forcedelete test.db test.db-journal test.bu}
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -25,6 +25,10 @@ source $testdir/tester.tcl
#
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 {
@@ -51,22 +55,10 @@ do_test corrupt-1.1 {
} {}
integrity_check corrupt-1.2
-# Copy file $from into $to
-#
-proc copy_file {from to} {
- set f [open $from]
- fconfigure $f -translation binary
- set t [open $to w]
- fconfigure $t -translation binary
- puts -nonewline $t [read $f [file size $from]]
- close $t
- close $f
-}
-
# 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.
#
-copy_file test.db test.bu
+forcecopy test.db test.bu
set fsize [file size test.db]
set junk "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
while {[string length $junk]<256} {append junk $junk}
@@ -79,7 +71,7 @@ set junk [string range $junk 0 255]
for {set i [expr {1*256}]} {$i<$fsize-256} {incr i 256} {
set tn [expr {$i/256}]
db close
- copy_file test.bu test.db
+ forcecopy test.bu test.db
set fd [open test.db r+]
fconfigure $fd -translation binary
seek $fd $i
@@ -132,7 +124,7 @@ for {set i [expr {1*256}]} {$i<$fsize-256} {incr i 256} {
#
do_test corrupt-3.1 {
db close
- copy_file test.bu test.db
+ forcecopy test.bu test.db
sqlite3 db test.db
list
} {}
@@ -181,7 +173,7 @@ do_test corrupt-3.6 {
do_test corrupt-4.1 {
db close
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db test.db
execsql {
PRAGMA page_size = 1024;
@@ -213,7 +205,7 @@ do_test corrupt-4.2 {
do_test corrupt-5.1 {
db close
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db test.db
execsql { PRAGMA page_size = 1024 }
@@ -236,7 +228,7 @@ do_test corrupt-5.2 {
# running this testcase under valgrind revealed the problem.
do_test corrupt-6.1 {
db close
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db test.db
execsql {
PRAGMA page_size = 1024; CREATE TABLE t1(x);
@@ -264,7 +256,7 @@ do_test corrupt-6.1 {
ifcapable oversize_cell_check {
db close
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db test.db
execsql {
PRAGMA page_size = 1024; CREATE TABLE t1(x);
@@ -317,7 +309,7 @@ ifcapable oversize_cell_check {
}
db close
-file delete -force test.db test.db-journal
+forcedelete test.db test.db-journal
do_test corrupt-8.1 {
sqlite3 db test.db
execsql {
@@ -335,7 +327,7 @@ do_test corrupt-8.1 {
} {1 {database disk image is malformed}}
db close
-file delete -force test.db test.db-journal
+forcedelete test.db test.db-journal
do_test corrupt-8.2 {
sqlite3 db test.db
execsql {
diff --git a/lang/sql/sqlite/test/corrupt2.test b/lang/sql/sqlite/test/corrupt2.test
index bdbc0165..805a6148 100644
--- a/lang/sql/sqlite/test/corrupt2.test
+++ b/lang/sql/sqlite/test/corrupt2.test
@@ -23,6 +23,10 @@ source $testdir/tester.tcl
#
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)
@@ -41,9 +45,9 @@ do_test corrupt2-1.1 {
do_test corrupt2-1.2 {
# Corrupt the 16 byte magic string at the start of the file
- file delete -force corrupt.db
- file delete -force corrupt.db-journal
- copy_file test.db corrupt.db
+ 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
@@ -60,9 +64,9 @@ do_test corrupt2-1.3 {
db2 close
# Corrupt the page-size (bytes 16 and 17 of page 1).
- file delete -force corrupt.db
- file delete -force corrupt.db-journal
- copy_file test.db corrupt.db
+ 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
@@ -80,9 +84,9 @@ do_test corrupt2-1.4 {
db2 close
# Corrupt the free-block list on page 1.
- file delete -force corrupt.db
- file delete -force corrupt.db-journal
- copy_file test.db corrupt.db
+ 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
@@ -100,9 +104,9 @@ do_test corrupt2-1.5 {
db2 close
# Corrupt the free-block list on page 1.
- file delete -force corrupt.db
- file delete -force corrupt.db-journal
- copy_file test.db corrupt.db
+ 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
@@ -123,9 +127,9 @@ db2 close
# Corrupt a database by having 2 indices of the same name:
do_test corrupt2-2.1 {
- file delete -force corrupt.db
- file delete -force corrupt.db-journal
- copy_file test.db corrupt.db
+ forcedelete corrupt.db
+ forcedelete corrupt.db-journal
+ forcecopy test.db corrupt.db
sqlite3 db2 corrupt.db
execsql "
@@ -150,8 +154,8 @@ do_test corrupt2-2.1 {
db2 close
do_test corrupt2-3.1 {
- file delete -force corrupt.db
- file delete -force corrupt.db-journal
+ forcedelete corrupt.db
+ forcedelete corrupt.db-journal
sqlite3 db2 corrupt.db
execsql "
@@ -200,8 +204,8 @@ db2 close
unset -nocomplain result
do_test corrupt2-5.1 {
- file delete -force corrupt.db
- file delete -force corrupt.db-journal
+ forcedelete corrupt.db
+ forcedelete corrupt.db-journal
sqlite3 db2 corrupt.db
execsql "
@@ -257,8 +261,8 @@ proc corruption_test {args} {
array set A $args
catch {db close}
- file delete -force corrupt.db
- file delete -force corrupt.db-journal
+ forcedelete corrupt.db
+ forcedelete corrupt.db-journal
sqlite3 db corrupt.db
db eval $::presql
diff --git a/lang/sql/sqlite/test/corrupt3.test b/lang/sql/sqlite/test/corrupt3.test
index fba3ba79..436a4661 100644
--- a/lang/sql/sqlite/test/corrupt3.test
+++ b/lang/sql/sqlite/test/corrupt3.test
@@ -23,9 +23,13 @@ source $testdir/tester.tcl
#
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 {
+ifcapable !pager_pragmas||direct_read {
finish_test
return
}
diff --git a/lang/sql/sqlite/test/corrupt4.test b/lang/sql/sqlite/test/corrupt4.test
index 19061134..24db60fd 100644
--- a/lang/sql/sqlite/test/corrupt4.test
+++ b/lang/sql/sqlite/test/corrupt4.test
@@ -23,6 +23,10 @@ source $testdir/tester.tcl
#
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 {
diff --git a/lang/sql/sqlite/test/corrupt5.test b/lang/sql/sqlite/test/corrupt5.test
index dca06e5f..3f509963 100644
--- a/lang/sql/sqlite/test/corrupt5.test
+++ b/lang/sql/sqlite/test/corrupt5.test
@@ -19,6 +19,10 @@
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 {
diff --git a/lang/sql/sqlite/test/corrupt6.test b/lang/sql/sqlite/test/corrupt6.test
index c0dcedf3..7d90c4a3 100644
--- a/lang/sql/sqlite/test/corrupt6.test
+++ b/lang/sql/sqlite/test/corrupt6.test
@@ -24,6 +24,10 @@ source $testdir/tester.tcl
#
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 {
diff --git a/lang/sql/sqlite/test/corrupt7.test b/lang/sql/sqlite/test/corrupt7.test
index ad566560..db92cf1d 100644
--- a/lang/sql/sqlite/test/corrupt7.test
+++ b/lang/sql/sqlite/test/corrupt7.test
@@ -24,6 +24,10 @@ source $testdir/tester.tcl
#
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 {
diff --git a/lang/sql/sqlite/test/corrupt8.test b/lang/sql/sqlite/test/corrupt8.test
index 012beb56..d7bceba3 100644
--- a/lang/sql/sqlite/test/corrupt8.test
+++ b/lang/sql/sqlite/test/corrupt8.test
@@ -24,6 +24,10 @@ source $testdir/tester.tcl
#
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 {
diff --git a/lang/sql/sqlite/test/corrupt9.test b/lang/sql/sqlite/test/corrupt9.test
index f083cf24..bb37758b 100644
--- a/lang/sql/sqlite/test/corrupt9.test
+++ b/lang/sql/sqlite/test/corrupt9.test
@@ -24,6 +24,10 @@ source $testdir/tester.tcl
#
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 {
@@ -86,7 +90,7 @@ integrity_check corrupt9-1.2
# Make sure the corruption is detected.
#
db close
-file copy -force test.db test.db-template
+forcecopy test.db test.db-template
corrupt_freelist test.db 1
sqlite3 db test.db
@@ -103,7 +107,7 @@ do_test corrupt9-2.2 {
db close
-file copy -force test.db-template test.db
+forcecopy test.db-template test.db
corrupt_freelist test.db 2
sqlite3 db test.db
do_test corrupt9-3.1 {
@@ -118,7 +122,7 @@ do_test corrupt9-3.2 {
} {1 {database disk image is malformed}}
db close
-file copy -force test.db-template test.db
+forcecopy test.db-template test.db
corrupt_freelist test.db 3
sqlite3 db test.db
do_test corrupt9-4.1 {
diff --git a/lang/sql/sqlite/test/corruptA.test b/lang/sql/sqlite/test/corruptA.test
index 9c7d228f..bb9912bd 100644
--- a/lang/sql/sqlite/test/corruptA.test
+++ b/lang/sql/sqlite/test/corruptA.test
@@ -24,6 +24,10 @@ source $testdir/tester.tcl
#
do_not_use_codec
+# These tests deal with corrupt database files
+#
+database_may_be_corrupt
+
# Create a database to work with.
#
@@ -40,12 +44,12 @@ integrity_check corruptA-1.2
# is detected when opening the database file.
#
db close
-file copy -force test.db test.db-template
+forcecopy test.db test.db-template
set unreadable_version 02
ifcapable wal { set unreadable_version 03 }
do_test corruptA-2.1 {
- file copy -force test.db-template test.db
+ 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}
@@ -53,7 +57,7 @@ do_test corruptA-2.1 {
do_test corruptA-2.2 {
db close
- file copy -force test.db-template test.db
+ forcecopy test.db-template test.db
hexio_write test.db 21 41 ;# max embedded payload fraction
sqlite3 db test.db
catchsql {SELECT * FROM t1}
@@ -61,7 +65,7 @@ do_test corruptA-2.2 {
do_test corruptA-2.3 {
db close
- file copy -force test.db-template test.db
+ forcecopy test.db-template test.db
hexio_write test.db 22 1f ;# min embedded payload fraction
sqlite3 db test.db
catchsql {SELECT * FROM t1}
@@ -69,7 +73,7 @@ do_test corruptA-2.3 {
do_test corruptA-2.4 {
db close
- file copy -force test.db-template test.db
+ forcecopy test.db-template test.db
hexio_write test.db 23 21 ;# min leaf payload fraction
sqlite3 db test.db
catchsql {SELECT * FROM t1}
diff --git a/lang/sql/sqlite/test/corruptB.test b/lang/sql/sqlite/test/corruptB.test
index 4aa1d010..c51cb576 100644
--- a/lang/sql/sqlite/test/corruptB.test
+++ b/lang/sql/sqlite/test/corruptB.test
@@ -30,6 +30,10 @@ source $testdir/tester.tcl
#
do_not_use_codec
+# These tests deal with corrupt database files
+#
+database_may_be_corrupt
+
do_test corruptB-1.1 {
execsql {
@@ -46,7 +50,7 @@ do_test corruptB-1.1 {
} {1}
integrity_check corruptB-1.2
-file copy -force test.db bak.db
+forcecopy test.db bak.db
# Set the right-child of a B-Tree rootpage to refer to the root-page itself.
#
@@ -65,7 +69,7 @@ do_test corruptB-1.3.2 {
#
do_test corruptB-1.4.1 {
db close
- file copy -force bak.db test.db
+ 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}
@@ -78,7 +82,7 @@ do_test corruptB-1.4.2 {
#
do_test corruptB-1.5.1 {
db close
- file copy -force bak.db test.db
+ forcecopy bak.db test.db
sqlite3 db test.db
execsql {
INSERT INTO t1 SELECT randomblob(200) FROM t1;
@@ -91,7 +95,7 @@ do_test corruptB-1.5.1 {
}
} {}
-file copy -force test.db bak.db
+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.
@@ -112,7 +116,7 @@ do_test corruptB-1.6.2 {
#
do_test corruptB-1.7.1 {
db close
- file copy -force bak.db test.db
+ 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}
@@ -140,7 +144,7 @@ do_test corruptB-1.8.2 {
#
do_test corruptB-1.9.1 {
db close
- file copy -force bak.db test.db
+ 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}
@@ -153,7 +157,7 @@ do_test corruptB-1.9.2 {
do_test corruptB-2.1.1 {
db close
- file copy -force bak.db test.db
+ forcecopy bak.db test.db
hexio_write test.db [expr $offset+8] [hexio_render_int32 0x6FFFFFFF]
} {4}
do_test corruptB-2.1.2 {
@@ -167,7 +171,7 @@ do_test corruptB-2.1.2 {
#
do_test corruptB-3.1.1 {
db close
- file copy -force bak.db test.db
+ forcecopy bak.db test.db
sqlite3 db test.db
set v [string repeat abcdefghij 200]
execsql {
diff --git a/lang/sql/sqlite/test/corruptC.test b/lang/sql/sqlite/test/corruptC.test
index 05804263..adf6f44c 100644
--- a/lang/sql/sqlite/test/corruptC.test
+++ b/lang/sql/sqlite/test/corruptC.test
@@ -17,7 +17,7 @@
#
# $Id: corruptC.test,v 1.14 2009/07/11 06:55:34 danielk1977 Exp $
-catch {file delete -force test.db test.db-journal test.bu}
+catch {forcedelete test.db test.db-journal test.bu}
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -27,6 +27,10 @@ source $testdir/tester.tcl
#
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 {
@@ -58,16 +62,10 @@ proc random {range} {
return [expr {round(rand()*$range)}]
}
-# Copy file $from into $to
-#
-proc copy_file {from to} {
- file copy -force $from $to
-}
-
# Setup for the tests. Make a backup copy of the good database in test.bu.
#
db close
-copy_file test.db test.bu
+forcecopy test.db test.bu
sqlite3 db test.db
set fsize [file size test.db]
@@ -92,7 +90,7 @@ expr srand($qseed)
# test that a corrupt content offset size is handled (seed 5577)
do_test corruptC-2.1 {
db close
- copy_file test.bu test.db
+ forcecopy test.bu test.db
# insert corrupt byte(s)
hexio_write test.db 2053 [format %02x 0x04]
@@ -104,7 +102,7 @@ do_test corruptC-2.1 {
# test that a corrupt content offset size is handled (seed 5649)
do_test corruptC-2.2 {
db close
- copy_file test.bu test.db
+ forcecopy test.bu test.db
# insert corrupt byte(s)
hexio_write test.db 27 [format %02x 0x08]
@@ -125,7 +123,7 @@ do_test corruptC-2.2 {
# test that a corrupt free cell size is handled (seed 13329)
do_test corruptC-2.3 {
db close
- copy_file test.bu test.db
+ forcecopy test.bu test.db
# insert corrupt byte(s)
hexio_write test.db 1094 [format %02x 0x76]
@@ -137,7 +135,7 @@ do_test corruptC-2.3 {
# test that a corrupt free cell size is handled (seed 169571)
do_test corruptC-2.4 {
db close
- copy_file test.bu test.db
+ forcecopy test.bu test.db
# insert corrupt byte(s)
hexio_write test.db 3119 [format %02x 0xdf]
@@ -149,7 +147,7 @@ do_test corruptC-2.4 {
# test that a corrupt free cell size is handled (seed 169571)
do_test corruptC-2.5 {
db close
- copy_file test.bu test.db
+ forcecopy test.bu test.db
# insert corrupt byte(s)
hexio_write test.db 3119 [format %02x 0xdf]
@@ -169,7 +167,7 @@ Page 4: btreeInitPage() returns error code 11}}}
# test that a corrupt free cell size is handled (seed 169595)
do_test corruptC-2.6 {
db close
- copy_file test.bu test.db
+ forcecopy test.bu test.db
# insert corrupt byte(s)
hexio_write test.db 619 [format %02x 0xe2]
@@ -182,7 +180,7 @@ do_test corruptC-2.6 {
# corruption (seed 178692)
do_test corruptC-2.7 {
db close
- copy_file test.bu test.db
+ forcecopy test.bu test.db
# insert corrupt byte(s)
hexio_write test.db 3074 [format %02x 0xa0]
@@ -194,7 +192,7 @@ do_test corruptC-2.7 {
# corruption (seed 179069)
do_test corruptC-2.8 {
db close
- copy_file test.bu test.db
+ forcecopy test.bu test.db
# insert corrupt byte(s)
hexio_write test.db 1393 [format %02x 0x7d]
@@ -208,21 +206,25 @@ do_test corruptC-2.8 {
} {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
- copy_file test.bu test.db
+ 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;}
-} {1 {database disk image is malformed}}
+} {0 {}}
# corruption (seed 186504)
do_test corruptC-2.10 {
db close
- copy_file test.bu test.db
+ forcecopy test.bu test.db
# insert corrupt byte(s)
hexio_write test.db 3130 [format %02x 0x02]
@@ -234,7 +236,7 @@ do_test corruptC-2.10 {
# corruption (seed 1589)
do_test corruptC-2.11 {
db close
- copy_file test.bu test.db
+ forcecopy test.bu test.db
# insert corrupt byte(s)
hexio_write test.db 55 [format %02x 0xa7]
@@ -246,7 +248,7 @@ do_test corruptC-2.11 {
# corruption (seed 14166)
do_test corruptC-2.12 {
db close
- copy_file test.bu test.db
+ forcecopy test.bu test.db
# insert corrupt byte(s)
hexio_write test.db 974 [format %02x 0x2e]
@@ -258,7 +260,7 @@ do_test corruptC-2.12 {
# corruption (seed 218803)
do_test corruptC-2.13 {
db close
- copy_file test.bu test.db
+ forcecopy test.bu test.db
# insert corrupt byte(s)
hexio_write test.db 102 [format %02x 0x12]
@@ -269,7 +271,7 @@ do_test corruptC-2.13 {
do_test corruptC-2.14 {
db close
- copy_file test.bu test.db
+ forcecopy test.bu test.db
sqlite3 db test.db
set blob [string repeat abcdefghij 10000]
@@ -286,7 +288,7 @@ do_test corruptC-2.14 {
#
do_test corruptC-2.15 {
db close
- copy_file test.bu test.db
+ forcecopy test.bu test.db
hexio_write test.db 986 b9
sqlite3 db test.db
catchsql {SELECT count(*) FROM sqlite_master;}
@@ -300,7 +302,7 @@ for {set tn 0} {$tn<$fsize} {incr tn 1} {
# setup for test
db close
- copy_file test.bu test.db
+ forcecopy test.bu test.db
sqlite3 db test.db
# Seek to a random location in the file, and write a random single byte
diff --git a/lang/sql/sqlite/test/corruptD.test b/lang/sql/sqlite/test/corruptD.test
index 61dada65..63474584 100644
--- a/lang/sql/sqlite/test/corruptD.test
+++ b/lang/sql/sqlite/test/corruptD.test
@@ -19,6 +19,10 @@ source $testdir/tester.tcl
#
do_not_use_codec
+# These tests deal with corrupt database files
+#
+database_may_be_corrupt
+
#--------------------------------------------------------------------------
# OVERVIEW
#
@@ -85,7 +89,7 @@ do_test corruptD-1.0 {
DELETE FROM t1 WHERE a = 30;
DELETE FROM t1 WHERE a = 40;
}
- copy_file test.db test.bu
+ forcecopy test.db test.bu
} {}
proc incr_change_counter {} {
@@ -96,7 +100,7 @@ proc incr_change_counter {} {
proc restore_file {} {
db close
- copy_file test.bu test.db
+ forcecopy test.bu test.db
sqlite3 db test.db
}
@@ -107,12 +111,12 @@ proc restore_file {} {
do_test corruptD-1.1.1 {
incr_change_counter
hexio_write test.db [expr 1024+1] FFFF
- catchsql { SELECT * FROM t1 }
+ catchsql { SELECT * FROM t1 ORDER BY rowid }
} {1 {database disk image is malformed}}
do_test corruptD-1.1.2 {
incr_change_counter
hexio_write test.db [expr 1024+1] [hexio_render_int32 1021]
- catchsql { SELECT * FROM t1 }
+ catchsql { SELECT * FROM t1 ORDER BY rowid }
} {1 {database disk image is malformed}}
#-------------------------------------------------------------------------
diff --git a/lang/sql/sqlite/test/corruptE.test b/lang/sql/sqlite/test/corruptE.test
index a47adba1..4d5b5db3 100644
--- a/lang/sql/sqlite/test/corruptE.test
+++ b/lang/sql/sqlite/test/corruptE.test
@@ -16,8 +16,6 @@
#
# $Id: corruptE.test,v 1.14 2009/07/11 06:55:34 danielk1977 Exp $
-catch {file delete -force test.db test.db-journal test.bu}
-
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -26,6 +24,10 @@ source $testdir/tester.tcl
#
do_not_use_codec
+# 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 {
@@ -51,7 +53,7 @@ do_test corruptE-1.1 {
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;
+ CREATE TABLE t2 AS SELECT x,2 as y FROM t1 WHERE rowid%5!=0 ORDER BY rowid;
COMMIT;
}
} {}
@@ -60,23 +62,17 @@ ifcapable {integrityck} {
integrity_check corruptE-1.2
}
-# Copy file $from into $to
-#
-proc copy_file {from to} {
- file copy -force $from $to
-}
-
# Setup for the tests. Make a backup copy of the good database in test.bu.
#
db close
-copy_file test.db test.bu
+forcecopy test.db test.bu
sqlite3 db test.db
set fsize [file size test.db]
do_test corruptE-2.1 {
db close
- copy_file test.bu test.db
+ forcecopy test.bu test.db
# insert corrupt byte(s)
hexio_write test.db 2041 [format %02x 0x2e]
@@ -92,7 +88,7 @@ do_test corruptE-2.1 {
do_test corruptE-2.2 {
db close
- copy_file test.bu test.db
+ forcecopy test.bu test.db
# insert corrupt byte(s)
hexio_write test.db 2047 [format %02x 0x84]
@@ -108,7 +104,7 @@ do_test corruptE-2.2 {
do_test corruptE-2.3 {
db close
- copy_file test.bu test.db
+ forcecopy test.bu test.db
# insert corrupt byte(s)
hexio_write test.db 7420 [format %02x 0xa8]
@@ -124,7 +120,7 @@ do_test corruptE-2.3 {
do_test corruptE-2.4 {
db close
- copy_file test.bu test.db
+ forcecopy test.bu test.db
# insert corrupt byte(s)
hexio_write test.db 10233 [format %02x 0xd0]
@@ -165,7 +161,7 @@ set tc 1
foreach test $tests {
do_test corruptE-3.$tc {
db close
- copy_file test.bu test.db
+ forcecopy test.bu test.db
# insert corrupt byte(s)
hexio_write test.db [lindex $test 0] [format %02x [lindex $test 1]]
diff --git a/lang/sql/sqlite/test/corruptF.test b/lang/sql/sqlite/test/corruptF.test
new file mode 100644
index 00000000..8c4fd842
--- /dev/null
+++ b/lang/sql/sqlite/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/lang/sql/sqlite/test/corruptG.test b/lang/sql/sqlite/test/corruptG.test
new file mode 100644
index 00000000..11253fd1
--- /dev/null
+++ b/lang/sql/sqlite/test/corruptG.test
@@ -0,0 +1,81 @@
+# 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
+
+# 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 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';
+ }
+} {0 {}}
+do_test 1.3 {
+ catchsql {
+ PRAGMA integrity_check
+ }
+} {0 ok}
+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';
+ }
+ # The following test result is brittle. The point above is to try to
+ # force a buffer overread by a corrupt database file. If we get an
+ # incorrect answer from a corrupt database file, that is OK. If the
+ # result below changes, that just means that "undefined behavior" has
+ # changed.
+} {0 52}
+
+finish_test
diff --git a/lang/sql/sqlite/test/corruptH.test b/lang/sql/sqlite/test/corruptH.test
new file mode 100644
index 00000000..775c30d2
--- /dev/null
+++ b/lang/sql/sqlite/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
+
+# 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
+database_may_be_corrupt
+
+# 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 corruption migration caused by the test case below does not
+# cause corruption to be detected in mmap mode.
+#
+# 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.
+#
+# However, in mmap mode, the outer query and the inner queries use
+# different PgHdr objects (same data, but different PgHdr container
+# objects). And so the corruption is not detected. Instead, the second
+# seek fails to find anything and only a single row is returned.
+#
+set res23 {1 {database disk image is malformed}}
+if {[permutation]=="mmap"} {
+ set res23 {0 one}
+}
+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/lang/sql/sqlite/test/count.test b/lang/sql/sqlite/test/count.test
index fbdd13b6..3461e49c 100644
--- a/lang/sql/sqlite/test/count.test
+++ b/lang/sql/sqlite/test/count.test
@@ -1,4 +1,4 @@
-# 2009 February 24
+# 2009-02-24
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
@@ -11,7 +11,6 @@
# This file implements regression tests for SQLite library. The
# focus of this file is testing "SELECT count(*)" statements.
#
-# $Id: count.test,v 1.6 2009/06/05 17:09:12 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -24,8 +23,6 @@ source $testdir/tester.tcl
# tables and indexes. Test both when they contain 0 entries,
# when all entries are on the root page, and when the b-tree
# forms a structure 2 and 3 levels deep.
-#
-# count-2.*: Test that
#
#
@@ -188,5 +185,10 @@ do_test count-4.3 {
}
} {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}
finish_test
diff --git a/lang/sql/sqlite/test/coveridxscan.test b/lang/sql/sqlite/test/coveridxscan.test
new file mode 100644
index 00000000..7b3c0b0b
--- /dev/null
+++ b/lang/sql/sqlite/test/coveridxscan.test
@@ -0,0 +1,93 @@
+# 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}
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/crash.test b/lang/sql/sqlite/test/crash.test
index 42f41a36..c1901dae 100644
--- a/lang/sql/sqlite/test/crash.test
+++ b/lang/sql/sqlite/test/crash.test
@@ -119,7 +119,7 @@ do_test crash-1.11 {
} {0 {}}
#--------------------------------------------------------------------------
-# The following tests test recovery when both the database file and the the
+# 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.
@@ -215,8 +215,8 @@ for {set i 1} {$i < $repeats} {incr i} {
#
ifcapable attach {
do_test crash-4.0 {
- file delete -force test2.db
- file delete -force test2.db-journal
+ forcedelete test2.db
+ forcedelete test2.db-journal
execsql {
ATTACH 'test2.db' AS aux;
PRAGMA aux.default_cache_size = 10;
@@ -318,7 +318,7 @@ ifcapable attach {
# in test crash-5.3 for details.
#
db close
-file delete -force test.db
+forcedelete test.db
sqlite3 db test.db
do_test crash-5.1 {
execsql {
diff --git a/lang/sql/sqlite/test/crash3.test b/lang/sql/sqlite/test/crash3.test
index 9b7a6784..7958af99 100644
--- a/lang/sql/sqlite/test/crash3.test
+++ b/lang/sql/sqlite/test/crash3.test
@@ -73,7 +73,7 @@ foreach {sql res2} [list \
for {set ii 0} {$ii < 10} {incr ii} {
db close
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db test.db
do_test crash3-1.$tn.1 {
execsql {
@@ -106,7 +106,7 @@ foreach {sql res2} [list \
# This block tests both the IOCAP_SEQUENTIAL and IOCAP_SAFE_APPEND flags.
#
db close
-file delete -force test.db test.db-journal
+forcedelete test.db test.db-journal
sqlite3 db test.db
do_test crash3-2.0 {
execsql {
@@ -177,7 +177,7 @@ foreach {::crashfile ::delay ::char} {
#
for {set ii 0} {$ii < 10} {incr ii} {
db close
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
crashsql -file test.db -char {sequential atomic} {
CREATE TABLE abc(a, b, c);
}
diff --git a/lang/sql/sqlite/test/crash4.test b/lang/sql/sqlite/test/crash4.test
index 839299b5..f68caecd 100644
--- a/lang/sql/sqlite/test/crash4.test
+++ b/lang/sql/sqlite/test/crash4.test
@@ -63,7 +63,7 @@ foreach cmd $sql_cmd_list {
#
for {set cnt 1; set fin 0} {!$fin} {incr cnt} {
db close
- file delete -force test.db test.db-journal
+ 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}]
diff --git a/lang/sql/sqlite/test/crash5.test b/lang/sql/sqlite/test/crash5.test
index e8faa01b..83d1647a 100644
--- a/lang/sql/sqlite/test/crash5.test
+++ b/lang/sql/sqlite/test/crash5.test
@@ -34,7 +34,7 @@ for {set ii 0} {$ii < 10} {incr ii} {
# 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).
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db test.db
set c [string repeat 3 1500]
db eval {
@@ -47,7 +47,7 @@ for {set ii 0} {$ii < 10} {incr ii} {
do_test crash5-$ii.$jj.1 {
crashsql -delay 1 -file test.db-journal -seed $ii -tclbody [join [list \
[list set iFail $jj] {
- sqlite3_crashparams 0 [file join [pwd] test.db-journal]
+ 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
@@ -65,7 +65,7 @@ for {set ii 0} {$ii < 10} {incr ii} {
# puts "$n $msg ac=[sqlite3_get_autocommit db]"
# If the transaction is still active (it may not be if the malloc()
- # failure occured in the OS layer), write to the database. Make sure
+ # failure occurred in the OS layer), write to the database. Make sure
# page 4 is among those written.
#
if {![sqlite3_get_autocommit db]} {
@@ -89,7 +89,7 @@ for {set ii 0} {$ii < 10} {incr ii} {
# by writing page 4 out to the db file. If it crashes later on,
# before syncing the journal... Corruption!
#
- sqlite3_crashparams 1 [file join [pwd] test.db-journal]
+ sqlite3_crashparams 1 [file join [get_pwd] test.db-journal]
sqlite3_release_memory 8092
}]] {}
expr 1
diff --git a/lang/sql/sqlite/test/crash6.test b/lang/sql/sqlite/test/crash6.test
index d5ee439f..69c19464 100644
--- a/lang/sql/sqlite/test/crash6.test
+++ b/lang/sql/sqlite/test/crash6.test
@@ -23,7 +23,7 @@ ifcapable !crashtest {
for {set ii 0} {$ii < 10} {incr ii} {
catch {db close}
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
crashsql -delay 2 -file test.db {
PRAGMA auto_vacuum=OFF;
PRAGMA page_size=4096;
@@ -40,7 +40,7 @@ for {set ii 0} {$ii < 10} {incr ii} {
for {set ii 0} {$ii < 10} {incr ii} {
catch {db close}
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db test.db
execsql {
PRAGMA auto_vacuum=OFF;
@@ -66,7 +66,7 @@ proc signature {} {
#
for {set ii 0} {$ii < 30} {incr ii} {
db close
- file delete -force test.db
+ forcedelete test.db
sqlite3 db test.db
set pagesize [expr 1024 << ($ii % 4)]
diff --git a/lang/sql/sqlite/test/crash7.test b/lang/sql/sqlite/test/crash7.test
index fc0596a8..482999cb 100644
--- a/lang/sql/sqlite/test/crash7.test
+++ b/lang/sql/sqlite/test/crash7.test
@@ -13,6 +13,7 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
+set testprefix crash7
ifcapable !crashtest {
finish_test
@@ -26,7 +27,7 @@ proc signature {} {
foreach f [list test.db test.db-journal] {
for {set ii 1} {$ii < 64} {incr ii} {
db close
- file delete test.db
+ delete_file test.db
sqlite3 db test.db
set from_size [expr 1024 << ($ii&3)]
@@ -79,4 +80,37 @@ foreach f [list test.db test.db-journal] {
}
}
+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/lang/sql/sqlite/test/crash8.test b/lang/sql/sqlite/test/crash8.test
index 6424a1ab..930834a9 100644
--- a/lang/sql/sqlite/test/crash8.test
+++ b/lang/sql/sqlite/test/crash8.test
@@ -243,7 +243,7 @@ do_test crash8-3.11 {
#
ifcapable pragma {
reset_db
- file delete -force test2.db
+ forcedelete test2.db
do_test crash8-4.1 {
execsql {
@@ -336,67 +336,73 @@ ifcapable pragma {
} {def}
do_test crash8-4.10 {
- file delete $zMasterJournal
+ delete_file $zMasterJournal
execsql { SELECT b FROM main.ab WHERE a = 0 }
} {jkl}
}
-for {set i 1} {$i < 10} {incr i} {
- catch { db close }
- file delete -force 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}
+#
+# Since the following tests (crash8-5.*) rely upon being able
+# to copy a file while open, they will not work on Windows.
+#
+if {$::tcl_platform(platform)=="unix"} {
+ 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 }
- file delete -force 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);
- }
- file delete -force testX.db testX.db-journal testX.db-wal
- copy_file test.db testX.db
- copy_file 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 { 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}
}
-catch {db2 close}
finish_test
diff --git a/lang/sql/sqlite/test/createtab.test b/lang/sql/sqlite/test/createtab.test
index 3f036b76..01e0b612 100644
--- a/lang/sql/sqlite/test/createtab.test
+++ b/lang/sql/sqlite/test/createtab.test
@@ -27,7 +27,7 @@ ifcapable autovacuum {
#
for {set av 0} {$av<=$upperBound} {incr av} {
db close
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db test.db
# Create a table that spans multiple pages. It is important
diff --git a/lang/sql/sqlite/test/date.test b/lang/sql/sqlite/test/date.test
index c03492b9..21e4e288 100644
--- a/lang/sql/sqlite/test/date.test
+++ b/lang/sql/sqlite/test/date.test
@@ -151,7 +151,7 @@ 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.02426426
+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
@@ -534,4 +534,27 @@ if {0==[sqlite3 -has-codec]} {
}
}
}
+
+# 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}
+
finish_test
diff --git a/lang/sql/sqlite/test/dbstatus.test b/lang/sql/sqlite/test/dbstatus.test
index 202f34a0..368c6b28 100644
--- a/lang/sql/sqlite/test/dbstatus.test
+++ b/lang/sql/sqlite/test/dbstatus.test
@@ -15,6 +15,11 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
+ifcapable !compound {
+ finish_test
+ return
+}
+
# Memory statistics must be enabled for this test.
db close
sqlite3_shutdown
@@ -56,6 +61,17 @@ proc lookaside {db} {
}
}
+ifcapable stat4||stat3 {
+ set STAT3 1
+} else {
+ set STAT3 0
+}
+
+ifcapable malloc_usable_size {
+ finish_test
+ return
+}
+
#---------------------------------------------------------------------------
# Run the dbstatus-2 and dbstatus-3 tests with several of different
# lookaside buffer sizes.
@@ -118,7 +134,7 @@ foreach ::lookaside_buffer_size {0 64 120} {
CREATE TABLE t2(c, d);
CREATE VIEW v1 AS SELECT * FROM t1 UNION SELECT * FROM t2;
}
- 6 {
+ 6k {
CREATE TABLE t1(a, b);
CREATE INDEX i1 ON t1(a);
CREATE INDEX i2 ON t1(a,b);
@@ -155,7 +171,7 @@ foreach ::lookaside_buffer_size {0 64 120} {
# Step 1.
db close
- file delete -force test.db
+ forcedelete test.db
sqlite3 db test.db
sqlite3_db_config_lookaside db 0 $::lookaside_buffer_size 500
db cache size 0
@@ -188,6 +204,11 @@ foreach ::lookaside_buffer_size {0 64 120} {
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
@@ -198,7 +219,17 @@ foreach ::lookaside_buffer_size {0 64 120} {
# much greater than just that reported by DBSTATUS_SCHEMA_USED in this
# case.
#
- if {[string match *x $tn] || $AUTOVACUUM} {
+ # 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
@@ -221,7 +252,7 @@ foreach ::lookaside_buffer_size {0 64 120} {
# 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
+ # 3. Finalize all prepared statements. Measure the total memory
# and the prepared statement memory again.
#
# 4. Repeat step 2.
@@ -287,7 +318,7 @@ foreach ::lookaside_buffer_size {0 64 120} {
# Step 1.
db close
- file delete -force test.db
+ forcedelete test.db
sqlite3 db test.db
sqlite3_db_config_lookaside db 0 $::lookaside_buffer_size 500
db cache size 1000
diff --git a/lang/sql/sqlite/test/dbstatus2.test b/lang/sql/sqlite/test/dbstatus2.test
new file mode 100644
index 00000000..2541a1a8
--- /dev/null
+++ b/lang/sql/sqlite/test/dbstatus2.test
@@ -0,0 +1,102 @@
+# 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
+}
+
+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}
+
+ifcapable wal {
+ 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}
+
+finish_test
diff --git a/lang/sql/sqlite/test/default.test b/lang/sql/sqlite/test/default.test
index 95a4ee03..d6b6f97d 100644
--- a/lang/sql/sqlite/test/default.test
+++ b/lang/sql/sqlite/test/default.test
@@ -64,4 +64,39 @@ ifcapable pragma {
} {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}
+
finish_test
diff --git a/lang/sql/sqlite/test/delete.test b/lang/sql/sqlite/test/delete.test
index 61e979ef..47d35781 100644
--- a/lang/sql/sqlite/test/delete.test
+++ b/lang/sql/sqlite/test/delete.test
@@ -275,7 +275,7 @@ do_test delete-8.0 {
}
} {123}
db close
-catch {file delete -force test.db-journal}
+catch {forcedelete test.db-journal}
catch {file attributes test.db -permissions 0444}
catch {file attributes test.db -readonly 1}
sqlite3 db test.db
@@ -312,12 +312,12 @@ do_test delete-8.6 {
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 [file delete -force]
+# -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
-file delete -force test.db test.db-journal
+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
diff --git a/lang/sql/sqlite/test/descidx1.test b/lang/sql/sqlite/test/descidx1.test
index 1154dc56..a223664f 100644
--- a/lang/sql/sqlite/test/descidx1.test
+++ b/lang/sql/sqlite/test/descidx1.test
@@ -197,12 +197,12 @@ ifcapable bloblit {
} {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;
+ 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;
+ SELECT d FROM t2 WHERE a>2 ORDER BY a;
}
} {3.0 4.0 5.0 6.0}
do_test descidx1-4.5 {
@@ -297,14 +297,14 @@ do_test descidx1-5.9 {
ifcapable legacyformat {
do_test descidx1-6.1 {
db close
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db test.db
execsql {PRAGMA legacy_file_format}
} {1}
} else {
do_test descidx1-6.1 {
db close
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db test.db
execsql {PRAGMA legacy_file_format}
} {0}
@@ -328,7 +328,7 @@ ifcapable vacuum {
}
do_test descidx1-6.4 {
db close
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db test.db
execsql {PRAGMA legacy_file_format=NO}
execsql {PRAGMA legacy_file_format}
diff --git a/lang/sql/sqlite/test/descidx3.test b/lang/sql/sqlite/test/descidx3.test
index 3cc87afa..c375acc7 100644
--- a/lang/sql/sqlite/test/descidx3.test
+++ b/lang/sql/sqlite/test/descidx3.test
@@ -132,11 +132,11 @@ ifcapable subquery {
# the IN(...) operator is not available. Hence these tests cannot be
# run.
do_test descidx3-4.1 {
- execsql {
+ lsort [execsql {
UPDATE t1 SET a=2 WHERE i<6;
SELECT i FROM t1 WHERE a IN (1,2) AND b>0 AND b<'zzz';
- }
- } {8 6 2 4 3}
+ }]
+ } {2 3 4 6 8}
do_test descidx3-4.2 {
execsql {
UPDATE t1 SET a=1;
diff --git a/lang/sql/sqlite/test/diskfull.test b/lang/sql/sqlite/test/diskfull.test
index a71db91e..391dfb4f 100644
--- a/lang/sql/sqlite/test/diskfull.test
+++ b/lang/sql/sqlite/test/diskfull.test
@@ -82,8 +82,8 @@ proc do_diskfull_test {prefix sql} {
do_diskfull_test diskfull-2 VACUUM
# db close
-# file delete -force test.db
-# file delete -force test.db-journal
+# forcedelete test.db
+# forcedelete test.db-journal
# sqlite3 db test.db
#
# do_test diskfull-3.1 {
diff --git a/lang/sql/sqlite/test/distinct.test b/lang/sql/sqlite/test/distinct.test
new file mode 100644
index 00000000..2b006d3e
--- /dev/null
+++ b/lang/sql/sqlite/test/distinct.test
@@ -0,0 +1,200 @@
+# 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"} { lappend program1 $opcode }
+ }
+ db eval "EXPLAIN $sql2" {
+ if {$opcode != "Noop"} { 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 != "08" && $p5!="00"} { error "p5 = $p5" }
+ if {$p5 == "08"} {
+ 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)"
+ 23 1 "SELECT DISTINCT rowid 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}
+
+finish_test
diff --git a/lang/sql/sqlite/test/e_createtable.test b/lang/sql/sqlite/test/e_createtable.test
index c67195ed..2cd63280 100644
--- a/lang/sql/sqlite/test/e_createtable.test
+++ b/lang/sql/sqlite/test/e_createtable.test
@@ -58,8 +58,6 @@ proc table_list {} {
}
-# EVIDENCE-OF: R-25262-01881 -- syntax diagram type-name
-#
do_createtable_tests 0.1.1 -repair {
drop_all_tables
} {
@@ -79,12 +77,7 @@ do_createtable_tests 0.1.2 -error {
}
-# EVIDENCE-OF: R-18762-12428 -- syntax diagram column-constraint
-#
-# Note: Not shown in the syntax diagram is the "NULL" constraint. This
-# is the opposite of "NOT NULL" - it implies that the column may
-# take a NULL value. This is the default anyway, so this type of
-# constraint is rarely used.
+# syntax diagram column-constraint
#
do_createtable_tests 0.2.1 -repair {
drop_all_tables
@@ -131,7 +124,7 @@ do_createtable_tests 0.2.1 -repair {
} {}
}
-# EVIDENCE-OF: R-17905-31923 -- syntax diagram table-constraint
+# -- syntax diagram table-constraint
#
do_createtable_tests 0.3.1 -repair {
drop_all_tables
@@ -150,7 +143,7 @@ do_createtable_tests 0.3.1 -repair {
4.1 "CREATE TABLE t1(c1, c2, FOREIGN KEY(c1) REFERENCES t2)" {}
}
-# EVIDENCE-OF: R-18765-31171 -- syntax diagram column-def
+# -- syntax diagram column-def
#
do_createtable_tests 0.4.1 -repair {
drop_all_tables
@@ -165,7 +158,7 @@ do_createtable_tests 0.4.1 -repair {
} {}
}
-# EVIDENCE-OF: R-59573-11075 -- syntax diagram create-table-stmt
+# -- syntax diagram create-table-stmt
#
do_createtable_tests 0.5.1 -repair {
drop_all_tables
@@ -190,7 +183,6 @@ do_createtable_tests 0.5.1 -repair {
15 "CREATE TABLE t1 AS SELECT count(*), max(b), min(a) FROM t2" {}
}
-# EVIDENCE-OF: R-32138-02228 -- syntax diagram foreign-key-clause
#
# 1: Explicit parent-key columns.
# 2: Implicit child-key columns.
@@ -989,9 +981,9 @@ do_execsql_test e_createtable-3.7.4 {
SELECT quote(a), quote(b) FROM t6;
} {1 2 'X' 3 1 4 'X' 5}
-# EVIDENCE-OF: R-18683-56219 If the default value of a column is
-# CURRENT_TIME, CURRENT_DATE or CURRENT_DATETIME, then the value used in
-# the new row is a text representation of the current UTC date and/or
+# 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
@@ -1111,8 +1103,8 @@ do_catchsql_test e_createtable-3.11.5 {
# EVIDENCE-OF: R-52382-54248 Each table in SQLite may have at most one
# PRIMARY KEY.
#
-# EVIDENCE-OF: R-18080-47271 If there is more than one PRIMARY KEY
-# clause in a single CREATE TABLE statement, it is an error.
+# 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.
@@ -1135,6 +1127,17 @@ do_createtable_tests 4.1.2 -error {
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 {
@@ -1168,8 +1171,8 @@ do_createtable_tests 4.2 -repair {
2.3 "CREATE TABLE t5(a, b INTEGER PRIMARY KEY, c)" {b}
}
-# EVIDENCE-OF: R-33986-09410 Each row in a table with a primary key must
-# feature a unique combination of values in its primary key columns.
+# 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-39102-06737 If an INSERT or UPDATE statement attempts
# to modify the table content so that two or more rows feature identical
@@ -1190,13 +1193,14 @@ do_execsql_test 4.3.0 {
INSERT INTO t2 VALUES(X'ABCDEF', 'three');
} {}
-do_createtable_tests 4.3.1 -error { %s not unique } {
+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"}
@@ -1216,13 +1220,14 @@ do_createtable_tests 4.3.2 {
9 "INSERT INTO t2 VALUES('brambles', 'abc')" {}
10 "INSERT INTO t2 VALUES(X'ABCDEF', 'abc')" {}
}
-do_createtable_tests 4.3.3 -error { %s not unique } {
+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"}
@@ -1258,11 +1263,12 @@ do_createtable_tests 4.4 {
14 "INSERT INTO t2 VALUES(NULL, NULL)" {}
}
-# EVIDENCE-OF: R-61866-38053 Unless the column is an INTEGER PRIMARY KEY
-# SQLite allows NULL values in a PRIMARY KEY column.
+# EVIDENCE-OF: R-35113-43214 Unless the column is an INTEGER PRIMARY KEY
+# or the table is a WITHOUT ROWID 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 behaviour. Attempting
+# 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 {
@@ -1281,6 +1287,14 @@ 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}}
# 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
@@ -1294,14 +1308,12 @@ do_createtable_tests 4.6 {
4 "CREATE TABLE t4(a, b, c, UNIQUE(a, b, c))" {}
}
-# EVIDENCE-OF: R-55240-58877 For each UNIQUE constraint on the table,
-# each row must feature a unique combination of values in the columns
+# 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-47733-51480 If an INSERT or UPDATE statement attempts
-# to modify the table content so that two or more rows feature identical
-# values in a set of columns that are subject to a UNIQUE constraint, it
-# is a constraint violation.
+# 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);
@@ -1313,29 +1325,29 @@ do_execsql_test 4.7.0 {
INSERT INTO t4 VALUES('xyx', 2, 1);
INSERT INTO t4 VALUES('uvw', 1, 1);
}
-do_createtable_tests 4.7.1 -error { %s not unique } {
- 1 "INSERT INTO t1 VALUES(1, 'one')" {{column a is}}
- 2 "INSERT INTO t1 VALUES(4.3, 'two')" {{column a is}}
- 3 "INSERT INTO t1 VALUES('reveal', 'three')" {{column a is}}
- 4 "INSERT INTO t1 VALUES(X'123456', 'four')" {{column a is}}
+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" {{column a is}}
- 6 "UPDATE t1 SET a = 4.3 WHERE rowid=3" {{column a is}}
- 7 "UPDATE t1 SET a = 'reveal' WHERE rowid=4" {{column a is}}
- 8 "UPDATE t1 SET a = X'123456' WHERE rowid=1" {{column a is}}
+ 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)" {{columns a, b, c are}}
- 10 "INSERT INTO t4 VALUES('xyx', 2, 1)" {{columns a, b, c are}}
- 11 "INSERT INTO t4 VALUES('uvw', 1, 1)" {{columns a, b, c are}}
+ 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" {{columns a, b, c are}}
- 13 "UPDATE t4 SET b=1 WHERE rowid=2" {{columns a, b, c are}}
- 14 "UPDATE t4 SET a=0, b=0, c=0" {{columns a, b, c are}}
+ 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-21289-11559 As with PRIMARY KEY constraints, for the
-# purposes of UNIQUE constraints NULL values are considered distinct
-# from all other values (including other NULLs).
+# 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)" {}
@@ -1350,10 +1362,9 @@ do_createtable_tests 4.8 {
9 "UPDATE t4 SET c = NULL" {}
}
-# EVIDENCE-OF: R-26983-26377 INTEGER PRIMARY KEY columns aside, both
-# UNIQUE and PRIMARY KEY constraints are implemented by creating an
-# index in the database (in the same way as a "CREATE UNIQUE INDEX"
-# statement would).
+# 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'
} {
@@ -1364,7 +1375,7 @@ do_createtable_tests 4.9 -repair drop_all_tables -query {
5 "CREATE TABLE t1(a PRIMARY KEY, b, c, UNIQUE(c, b))" 2
}
-# EVIDENCE-OF: R-02252-33116 Such an index is used like any other index
+# 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 {
@@ -1373,13 +1384,13 @@ do_execsql_test 4.10.0 {
}
do_createtable_tests 4.10 {
1 "EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE b = 5"
- {0 0 0 {SEARCH TABLE t1 USING INDEX sqlite_autoindex_t1_1 (b=?) (~1 rows)}}
+ {0 0 0 {SEARCH TABLE t1 USING INDEX sqlite_autoindex_t1_1 (b=?)}}
2 "EXPLAIN QUERY PLAN SELECT * FROM t2 ORDER BY b, c"
- {0 0 0 {SCAN TABLE t2 USING INDEX sqlite_autoindex_t2_1 (~1000000 rows)}}
+ {0 0 0 {SCAN TABLE t2 USING INDEX sqlite_autoindex_t2_1}}
3 "EXPLAIN QUERY PLAN SELECT * FROM t2 WHERE b=10 AND c>10"
- {0 0 0 {SEARCH TABLE t2 USING INDEX sqlite_autoindex_t2_1 (b=? AND c>?) (~2 rows)}}
+ {0 0 0 {SEARCH TABLE t2 USING INDEX sqlite_autoindex_t2_1 (b=? AND c>?)}}
}
# EVIDENCE-OF: R-45493-35653 A CHECK constraint may be attached to a
@@ -1412,21 +1423,21 @@ do_execsql_test 4.11 {
INSERT INTO t2 SELECT * FROM x2;
}
-do_createtable_tests 4.11 -error {constraint failed} {
- 1a "INSERT INTO x1 VALUES('one', 0)" {}
- 1b "INSERT INTO t1 VALUES('one', -4.0)" {}
+do_createtable_tests 4.11 -error {CHECK constraint failed: %s} {
+ 1a "INSERT INTO x1 VALUES('one', 0)" {x1}
+ 1b "INSERT INTO t1 VALUES('one', -4.0)" {t1}
- 2a "INSERT INTO x2 VALUES('abc', 1)" {}
- 2b "INSERT INTO t2 VALUES('abc', 1)" {}
+ 2a "INSERT INTO x2 VALUES('abc', 1)" {x2}
+ 2b "INSERT INTO t2 VALUES('abc', 1)" {t2}
- 3a "INSERT INTO x2 VALUES(0, 'abc')" {}
- 3b "INSERT INTO t2 VALUES(0, 'abc')" {}
+ 3a "INSERT INTO x2 VALUES(0, 'abc')" {x2}
+ 3b "INSERT INTO t2 VALUES(0, 'abc')" {t2}
- 4a "UPDATE t1 SET b=-1 WHERE rowid=1" {}
- 4b "UPDATE x1 SET b=-1 WHERE rowid=1" {}
+ 4a "UPDATE t1 SET b=-1 WHERE rowid=1" {t1}
+ 4b "UPDATE x1 SET b=-1 WHERE rowid=1" {x1}
- 4a "UPDATE x2 SET a='' WHERE rowid=1" {}
- 4b "UPDATE t2 SET a='' WHERE rowid=1" {}
+ 4a "UPDATE x2 SET a='' WHERE rowid=1" {x2}
+ 4b "UPDATE t2 SET a='' WHERE rowid=1" {t2}
}
# EVIDENCE-OF: R-34109-39108 If the CHECK expression evaluates to NULL,
@@ -1477,9 +1488,7 @@ do_execsql_test 4.14.0 {
INSERT INTO t3 VALUES('x', 'y', 'z');
INSERT INTO t3 VALUES(1, 2, 3);
}
-do_createtable_tests 4.14 -error {
- %s may not be NULL
-} {
+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}
@@ -1545,12 +1554,12 @@ do_execsql_test 4.15.0 {
}
foreach {tn tbl res ac data} {
- 1 t1_ab {1 {column a is not unique}} 0 {1 one 2 two 3 three}
- 2 t1_ro {1 {column a is not unique}} 1 {1 one 2 two}
- 3 t1_fa {1 {column a is not unique}} 0 {1 one 2 two 3 three 4 string}
+ 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 {column a is not unique}} 0 {1 one 2 two 3 three}
+ 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')"
@@ -1563,12 +1572,12 @@ foreach {tn tbl res ac data} {
do_execsql_test 4.15.$tn.4 "SELECT * FROM $tbl" $data
}
foreach {tn tbl res ac data} {
- 1 t2_ab {1 {t2_ab.b may not be NULL}} 0 {1 one 2 two 3 three}
- 2 t2_ro {1 {t2_ro.b may not be NULL}} 1 {1 one 2 two}
- 3 t2_fa {1 {t2_fa.b may not be NULL}} 0 {1 one 2 two 3 three 4 xx}
+ 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 {t2_re.b may not be NULL}} 0 {1 one 2 two 3 three}
- 6 t2_xx {1 {t2_xx.b may not be NULL}} 0 {1 one 2 two 3 three}
+ 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')"
@@ -1581,12 +1590,16 @@ foreach {tn tbl res ac data} {
do_execsql_test 4.16.$tn.4 "SELECT * FROM $tbl" $data
}
foreach {tn tbl res ac data} {
- 1 t3_ab {1 {columns a, b are not unique}} 0 {1 one 2 two 3 three}
- 2 t3_ro {1 {columns a, b are not unique}} 1 {1 one 2 two}
- 3 t3_fa {1 {columns a, b are not unique}} 0 {1 one 2 two 3 three 4 three}
+ 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 {columns a, b are not unique}} 0 {1 one 2 two 3 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')"
@@ -1596,7 +1609,7 @@ foreach {tn tbl res ac data} {
" $res
do_test e_createtable-4.17.$tn.3 { sqlite3_get_autocommit db } $ac
- do_execsql_test 4.17.$tn.4 "SELECT * FROM $tbl" $data
+ do_execsql_test 4.17.$tn.4 "SELECT * FROM $tbl ORDER BY rowid" $data
}
catchsql COMMIT
@@ -1617,7 +1630,7 @@ do_execsql_test 4.18.1 {
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 {constraint failed}}
+} {1 {CHECK constraint failed: t4}}
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}
@@ -1630,7 +1643,7 @@ do_execsql_test 4.19.0 {
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 {t5.b may not be NULL}}
+ {1 {NOT NULL constraint failed: t5.b}}
do_execsql_test 4.19.4 { SELECT * FROM t5 } {}
#------------------------------------------------------------------------
@@ -1641,6 +1654,10 @@ do_execsql_test 4.19.4 { SELECT * FROM t5 } {}
# 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);
@@ -1665,6 +1682,10 @@ do_createtable_tests 5.1 {
# 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_);
@@ -1699,10 +1720,10 @@ proc is_integer_primary_key {tbl col} {
}]] 0
}
-# EVIDENCE-OF: R-53738-31673 With one exception, if a 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-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
@@ -1755,16 +1776,16 @@ do_execsql_test 5.4.3 {
do_catchsql_test 5.4.4.1 {
INSERT INTO t6 VALUES(2)
-} {1 {column pk is not unique}}
+} {1 {UNIQUE constraint failed: t6.pk}}
do_catchsql_test 5.4.4.2 {
INSERT INTO t7 VALUES(2)
-} {1 {column pk is not unique}}
+} {1 {UNIQUE constraint failed: t7.pk}}
do_catchsql_test 5.4.4.3 {
INSERT INTO t8 VALUES(2)
-} {1 {column pk is not unique}}
+} {1 {UNIQUE constraint failed: t8.pk}}
do_catchsql_test 5.4.4.4 {
INSERT INTO t9 VALUES(2)
-} {1 {column pk is not unique}}
+} {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
diff --git a/lang/sql/sqlite/test/e_delete.test b/lang/sql/sqlite/test/e_delete.test
index de391b11..b857cf14 100644
--- a/lang/sql/sqlite/test/e_delete.test
+++ b/lang/sql/sqlite/test/e_delete.test
@@ -15,6 +15,11 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
+ifcapable !compound {
+ finish_test
+ return
+}
+
proc do_delete_tests {args} {
uplevel do_select_tests $args
}
@@ -24,9 +29,8 @@ do_execsql_test e_delete-0.0 {
CREATE INDEX i1 ON t1(a);
} {}
-# EVIDENCE-OF: R-24177-52883 -- syntax diagram delete-stmt
-#
-# EVIDENCE-OF: R-12802-60464 -- syntax diagram qualified-table-name
+# -- syntax diagram delete-stmt
+# -- syntax diagram qualified-table-name
#
do_delete_tests e_delete-0.1 {
1 "DELETE FROM t1" {}
@@ -287,7 +291,7 @@ do_delete_tests e_delete-2.5 -error { near "%s": syntax error } {
# of the DELETE statement is extended by the addition of optional ORDER
# BY and LIMIT clauses:
#
-# EVIDENCE-OF: R-45897-01670 -- syntax diagram delete-stmt-limited
+# -- syntax diagram delete-stmt-limited
#
do_delete_tests e_delete-3.1 {
1 "DELETE FROM t1 LIMIT 5" {}
@@ -440,7 +444,7 @@ do_delete_tests e_delete-3.9 -repair rebuild_t1 -query {
}
-# EVIDENCE-OF: R-26627-30313 The ORDER BY clause on an DELETE statement
+# 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.
diff --git a/lang/sql/sqlite/test/e_droptrigger.test b/lang/sql/sqlite/test/e_droptrigger.test
index 0c148317..84dfe727 100644
--- a/lang/sql/sqlite/test/e_droptrigger.test
+++ b/lang/sql/sqlite/test/e_droptrigger.test
@@ -69,7 +69,7 @@ proc droptrigger_reopen_db {{event INSERT}} {
}
-# EVIDENCE-OF: R-52650-16855 -- syntax diagram drop-trigger-stmt
+# -- syntax diagram drop-trigger-stmt
#
do_droptrigger_tests 1.1 -repair {
droptrigger_reopen_db
diff --git a/lang/sql/sqlite/test/e_dropview.test b/lang/sql/sqlite/test/e_dropview.test
index 447e5c35..143dce29 100644
--- a/lang/sql/sqlite/test/e_dropview.test
+++ b/lang/sql/sqlite/test/e_dropview.test
@@ -70,7 +70,7 @@ proc do_dropview_tests {nm args} {
uplevel do_select_tests $nm $args
}
-# EVIDENCE-OF: R-21739-51207 -- syntax diagram drop-view-stmt
+# -- syntax diagram drop-view-stmt
#
# All paths in the syntax diagram for DROP VIEW are tested by tests 1.*.
#
diff --git a/lang/sql/sqlite/test/e_expr.test b/lang/sql/sqlite/test/e_expr.test
index 1e768535..a743c0c3 100644
--- a/lang/sql/sqlite/test/e_expr.test
+++ b/lang/sql/sqlite/test/e_expr.test
@@ -17,6 +17,10 @@ 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"] [
@@ -362,9 +366,9 @@ 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.
#
-# EVIDENCE-OF: R-23441-22541 The COLLATE operator has a higher
-# precedence (binds more tightly) than any prefix unary operator or any
-# binary operator.
+# 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
@@ -627,7 +631,7 @@ do_test e_expr-11.7.1 { sqlite3_finalize $stmt } SQLITE_OK
#-------------------------------------------------------------------------
# "Test" the syntax diagrams in lang_expr.html.
#
-# EVIDENCE-OF: R-62067-43884 -- syntax diagram signed-number
+# -- 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}
@@ -642,7 +646,7 @@ do_execsql_test e_expr-12.1.6 {
SELECT 0.0001, +0.0001, -0.0001
} {0.0001 0.0001 -0.0001}
-# EVIDENCE-OF: R-21258-25489 -- syntax diagram literal-value
+# -- syntax diagram literal-value
#
set sqlite_current_time 1
do_execsql_test e_expr-12.2.1 {SELECT 123} {123}
@@ -655,9 +659,9 @@ 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
-# EVIDENCE-OF: R-57598-59332 -- syntax diagram expr
+# -- syntax diagram expr
#
-file delete -force test.db2
+forcedelete test.db2
execsql {
ATTACH 'test.db2' AS dbname;
CREATE TABLE dbname.tblname(cname);
@@ -812,7 +816,7 @@ foreach {tn expr} {
}
}
-# EVIDENCE-OF: R-49462-56079 -- syntax diagram raise-function
+# -- syntax diagram raise-function
#
foreach {tn raiseexpr} {
1 "RAISE(IGNORE)"
@@ -1077,9 +1081,9 @@ ifcapable !icu {
# EVIDENCE-OF: R-33693-50180 The REGEXP operator is a special syntax for
# the regexp() user function.
#
-# EVIDENCE-OF: R-57289-13578 If a application-defined SQL function named
-# "regexp" is added at run-time, that function will be called in order
-# to implement the REGEXP operator.
+# 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
@@ -1290,7 +1294,7 @@ proc rev {str} {
set ret
}
proc reverse {lhs rhs} {
- string compare [rev $lhs] [ref $rhs]
+ string compare [rev $lhs] [rev $rhs]
}
db collate reverse reverse
do_execsql_test e_expr-23.1.1 {
@@ -1313,7 +1317,7 @@ do_execsql_test e_expr-23.1.4 {
} {B}
do_execsql_test e_expr-23.1.5 {
SELECT CASE b WHEN a THEN 'A' ELSE 'B' END FROM t1
-} {A}
+} {B}
do_execsql_test e_expr-23.1.6 {
SELECT CASE 55 WHEN '55' THEN 'A' ELSE 'B' END
} {B}
@@ -1403,10 +1407,12 @@ do_test e_expr-26.1.6 { set ::evalcount } {5}
#-------------------------------------------------------------------------
# Test statements related to CAST expressions.
#
-# EVIDENCE-OF: R-65079-31758 Application of a CAST expression is
-# different to application of a column affinity, as with a CAST
-# expression the storage class conversion is forced even if it is lossy
-# and irrreversible.
+# 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);
@@ -1590,26 +1596,29 @@ 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-00741-38776 A cast of a REAL value into an INTEGER will
-# truncate the fractional part of the REAL.
+# 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-06126-36021 If an REAL is too large to be represented
-# as an INTEGER then the result of the cast is the largest negative
-# integer: -9223372036854775808.
+# 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 -9223372036854775808
+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 -9223372036854775808
+} integer 9223372036854775807
# EVIDENCE-OF: R-09295-61337 Casting a TEXT or BLOB value into NUMERIC
@@ -1675,7 +1684,7 @@ db3 close
# Test statements related to the EXISTS and NOT EXISTS operators.
#
catch { db close }
-file delete -force test.db
+forcedelete test.db
sqlite3 db test.db
do_execsql_test e_expr-34.1 {
@@ -1756,7 +1765,7 @@ foreach {tn e1 e2} {
#
catch { db close }
-file delete -force test.db
+forcedelete test.db
sqlite3 db test.db
do_test e_expr-35.0 {
execsql {
@@ -1843,6 +1852,43 @@ foreach {tn expr} {
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;
+} {false}
+do_execsql_test e_expr-37.2 {
+ SELECT CASE WHEN 0.0 THEN 'true' ELSE 'false' END;
+} {false}
+do_execsql_test e_expr-37.3 {
+ SELECT CASE WHEN 0 THEN 'true' ELSE 'false' END;
+} {false}
+do_execsql_test e_expr-37.4 {
+ SELECT CASE WHEN 'engligh' THEN 'true' ELSE 'false' END;
+} {false}
+do_execsql_test e_expr-37.5 {
+ SELECT CASE WHEN '0' THEN 'true' ELSE 'false' END;
+} {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;
+} {true}
+do_execsql_test e_expr-37.7 {
+ SELECT CASE WHEN 1.0 THEN 'true' ELSE 'false' END;
+} {true}
+do_execsql_test e_expr-37.8 {
+ SELECT CASE WHEN 0.1 THEN 'true' ELSE 'false' END;
+} {true}
+do_execsql_test e_expr-37.9 {
+ SELECT CASE WHEN -0.1 THEN 'true' ELSE 'false' END;
+} {true}
+do_execsql_test e_expr-37.10 {
+ SELECT CASE WHEN '1english' THEN 'true' ELSE 'false' END;
+} {true}
+
finish_test
-
diff --git a/lang/sql/sqlite/test/e_fkey.test b/lang/sql/sqlite/test/e_fkey.test
index ae789d50..921e9671 100644
--- a/lang/sql/sqlite/test/e_fkey.test
+++ b/lang/sql/sqlite/test/e_fkey.test
@@ -211,7 +211,7 @@ do_test e_fkey-6.1 {
catchsql {
DELETE FROM t1
}
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test e_fkey-6.2 {
execsql { PRAGMA foreign_keys }
} {1}
@@ -265,11 +265,11 @@ do_test e_fkey-7.1 {
#
do_test e_fkey-8.1 {
catchsql { INSERT INTO track VALUES(1, 'track 1', 1) }
-} {1 {foreign key constraint failed}}
+} {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}}
+} {1 {FOREIGN KEY constraint failed}}
do_test e_fkey-8.2 {
execsql { INSERT INTO track VALUES(1, 'track 1', 2) }
} {}
@@ -283,7 +283,7 @@ do_test e_fkey-8.2 {
#
do_test e_fkey-9.1 {
catchsql { DELETE FROM artist WHERE artistid = 2 }
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test e_fkey-9.2 {
execsql {
DELETE FROM track WHERE trackartist = 2;
@@ -311,14 +311,14 @@ do_test e_fkey-10.2 {
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}}
+} {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}}
+} {1 {FOREIGN KEY constraint failed}}
do_test e_fkey-10.5 {
execsql {
UPDATE track SET trackartist = NULL WHERE trackid = 1;
@@ -344,8 +344,8 @@ proc test_r52486_21352 {tn sql} {
set res [catchsql $sql]
set results {
{0 {}}
- {1 {PRIMARY KEY must be unique}}
- {1 {foreign key constraint failed}}
+ {1 {UNIQUE constraint failed: artist.artistid}}
+ {1 {FOREIGN KEY constraint failed}}
}
if {[lsearch $results $res]<0} {
error $res
@@ -409,7 +409,7 @@ do_test e_fkey-12.1 {
} {}
do_test e_fkey-12.2 {
catchsql { INSERT INTO track VALUES(14, 'Mr. Bojangles', NULL) }
-} {1 {track.trackartist may not be NULL}}
+} {1 {NOT NULL constraint failed: track.trackartist}}
#-------------------------------------------------------------------------
# EVIDENCE-OF: R-16127-35442
@@ -438,7 +438,7 @@ do_test e_fkey-13.1 {
} {}
do_test e_fkey-13.2 {
catchsql { INSERT INTO track VALUES(14, 'Mr. Bojangles', 3) }
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test e_fkey-13.3 {
execsql { INSERT INTO track VALUES(14, 'Mr. Bojangles', NULL) }
} {}
@@ -446,7 +446,7 @@ do_test e_fkey-13.4 {
catchsql {
UPDATE track SET trackartist = 3 WHERE trackname = 'Mr. Bojangles';
}
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test e_fkey-13.5 {
execsql {
INSERT INTO artist VALUES(3, 'Sammy Davis Jr.');
@@ -464,7 +464,7 @@ do_test e_fkey-14.1 {
catchsql {
DELETE FROM artist WHERE artistname = 'Frank Sinatra';
}
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test e_fkey-14.2 {
execsql {
DELETE FROM track WHERE trackname = 'My Way';
@@ -475,7 +475,7 @@ do_test e_fkey-14.3 {
catchsql {
UPDATE artist SET artistid=4 WHERE artistname = 'Dean Martin';
}
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test e_fkey-14.4 {
execsql {
DELETE FROM track WHERE trackname IN('That''s Amore', 'Christmas Blues');
@@ -513,7 +513,7 @@ do_test e_fkey-15.1 {
proc test_efkey_45 {tn isError sql} {
do_test e_fkey-15.$tn.1 "
catchsql {$sql}
- " [lindex {{0 {}} {1 {foreign key constraint failed}}} $isError]
+ " [lindex {{0 {}} {1 {FOREIGN KEY constraint failed}}} $isError]
do_test e_fkey-15.$tn.2 {
execsql {
@@ -557,10 +557,10 @@ do_test e_fkey-16.2 {
} {}
do_test e_fkey-16.3 {
catchsql { UPDATE t2 SET b = 'two' WHERE rowid = 1 }
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test e_fkey-16.4 {
catchsql { DELETE FROM t1 WHERE rowid = 1 }
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
#-------------------------------------------------------------------------
# Specifically, test that when comparing child and parent key values the
@@ -592,7 +592,7 @@ do_test e_fkey-17.3 {
} {integer integer text}
do_test e_fkey-17.4 {
catchsql { DELETE FROM t1 WHERE rowid = 2 }
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
###########################################################################
### SECTION 3: Required and Suggested Database Indexes
@@ -627,7 +627,8 @@ proc test_efkey_57 {tn isError sql} {
execsql $sql
do_test e_fkey-18.$tn {
catchsql { INSERT INTO t2 VALUES(NULL) }
- } [lindex {{0 {}} {1 {foreign key mismatch}}} $isError]
+ } [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) }
@@ -698,16 +699,16 @@ do_test e_fkey-19.2 {
} {}
do_test e_fkey-19.2 {
catchsql { INSERT INTO child4 VALUES('xxx', 5) }
-} {1 {foreign key mismatch}}
+} {1 {foreign key mismatch - "child4" referencing "parent"}}
do_test e_fkey-19.3 {
catchsql { INSERT INTO child5 VALUES('xxx', 6) }
-} {1 {foreign key mismatch}}
+} {1 {foreign key mismatch - "child5" referencing "parent"}}
do_test e_fkey-19.4 {
catchsql { INSERT INTO child6 VALUES(2, 3) }
-} {1 {foreign key mismatch}}
+} {1 {foreign key mismatch - "child6" referencing "parent"}}
do_test e_fkey-19.5 {
catchsql { INSERT INTO child7 VALUES(3) }
-} {1 {foreign key mismatch}}
+} {1 {foreign key mismatch - "child7" referencing "parent"}}
#-------------------------------------------------------------------------
# Test errors in the database schema that are detected while preparing
@@ -765,12 +766,12 @@ do_test e_fkey-20.1 {
foreach {tn tbl ptbl err} {
2 c1 {} "no such table: main.nosuchtable"
- 3 c2 p2 "foreign key mismatch"
- 4 c3 p3 "foreign key mismatch"
- 5 c4 p4 "foreign key mismatch"
- 6 c5 p5 "foreign key mismatch"
- 7 c6 p6 "foreign key mismatch"
- 8 c7 p7 "foreign key mismatch"
+ 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')"
@@ -820,22 +821,22 @@ do_test e_fkey-21.2 {
} {}
do_test e_fkey-21.3 {
catchsql { INSERT INTO child9 VALUES('I') }
-} {1 {foreign key mismatch}}
+} {1 {foreign key mismatch - "child9" referencing "parent2"}}
do_test e_fkey-21.4 {
catchsql { INSERT INTO child9 VALUES('II') }
-} {1 {foreign key mismatch}}
+} {1 {foreign key mismatch - "child9" referencing "parent2"}}
do_test e_fkey-21.5 {
catchsql { INSERT INTO child9 VALUES(NULL) }
-} {1 {foreign key mismatch}}
+} {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}}
+} {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}}
+} {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}}
+} {1 {foreign key mismatch - "child10" referencing "parent2"}}
#-------------------------------------------------------------------------
# Test errors that are reported when creating the child table.
@@ -895,7 +896,7 @@ do_test e_fkey-23.1 {
proc test_efkey_60 {tn isError sql} {
do_test e_fkey-23.$tn "
catchsql {$sql}
- " [lindex {{0 {}} {1 {foreign key constraint failed}}} $isError]
+ " [lindex {{0 {}} {1 {FOREIGN KEY constraint failed}}} $isError]
}
test_efkey_60 2 1 "INSERT INTO c1 VALUES(239, 231)"
@@ -932,7 +933,7 @@ do_test e_fkey-24.1 {
proc test_efkey_61 {tn isError sql} {
do_test e_fkey-24.$tn "
catchsql {$sql}
- " [lindex {{0 {}} {1 {foreign key constraint failed}}} $isError]
+ " [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)"
@@ -973,15 +974,15 @@ do_execsql_test e_fkey-25.2 {
EXPLAIN QUERY PLAN DELETE FROM artist WHERE 1;
EXPLAIN QUERY PLAN SELECT rowid FROM track WHERE trackartist = ?;
} {
- 0 0 0 {SCAN TABLE artist (~1000000 rows)}
- 0 0 0 {SCAN TABLE track (~100000 rows)}
+ 0 0 0 {SCAN TABLE artist}
+ 0 0 0 {SCAN TABLE track}
}
do_execsql_test e_fkey-25.3 {
PRAGMA foreign_keys = ON;
EXPLAIN QUERY PLAN DELETE FROM artist WHERE 1;
} {
- 0 0 0 {SCAN TABLE artist (~1000000 rows)}
- 0 0 0 {SCAN TABLE track (~100000 rows)}
+ 0 0 0 {SCAN TABLE artist}
+ 0 0 0 {SCAN TABLE track}
}
do_test e_fkey-25.4 {
execsql {
@@ -997,7 +998,7 @@ 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}}
+} {1 1 {FOREIGN KEY constraint failed}}
do_test e_fkey-25.6 {
concat \
@@ -1009,7 +1010,7 @@ 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}}
+} {2 1 {FOREIGN KEY constraint failed}}
#-------------------------------------------------------------------------
# EVIDENCE-OF: R-47936-10044 Or, more generally:
@@ -1098,15 +1099,15 @@ do_test e_fkey-27.2 {
do_execsql_test e_fkey-27.3 {
EXPLAIN QUERY PLAN UPDATE artist SET artistid = ?, artistname = ?
} {
- 0 0 0 {SCAN TABLE artist (~1000000 rows)}
- 0 0 0 {SEARCH TABLE track USING COVERING INDEX trackindex (trackartist=?) (~10 rows)}
- 0 0 0 {SEARCH TABLE track USING COVERING INDEX trackindex (trackartist=?) (~10 rows)}
+ 0 0 0 {SCAN TABLE artist}
+ 0 0 0 {SEARCH TABLE track USING COVERING INDEX trackindex (trackartist=?)}
+ 0 0 0 {SEARCH TABLE track USING COVERING INDEX trackindex (trackartist=?)}
}
do_execsql_test e_fkey-27.4 {
EXPLAIN QUERY PLAN DELETE FROM artist
} {
- 0 0 0 {SCAN TABLE artist (~1000000 rows)}
- 0 0 0 {SEARCH TABLE track USING COVERING INDEX trackindex (trackartist=?) (~10 rows)}
+ 0 0 0 {SCAN TABLE artist}
+ 0 0 0 {SEARCH TABLE track USING COVERING INDEX trackindex (trackartist=?)}
}
@@ -1151,7 +1152,7 @@ do_test e_fkey-28.8 {
CREATE TABLE c(a, b, FOREIGN KEY(a,b) REFERENCES p);
}
catchsql {DELETE FROM p}
-} {1 {foreign key mismatch}}
+} {1 {foreign key mismatch - "c" referencing "p"}}
do_test e_fkey-28.9 {
drop_all_tables
execsql {
@@ -1159,7 +1160,7 @@ do_test e_fkey-28.9 {
CREATE TABLE c(a REFERENCES p);
}
catchsql {DELETE FROM p}
-} {1 {foreign key mismatch}}
+} {1 {foreign key mismatch - "c" referencing "p"}}
#-------------------------------------------------------------------------
@@ -1198,7 +1199,7 @@ do_test e_fkey-29.3 {
catchsql {
INSERT INTO song VALUES(2, 'Elvis Presley', 'Elvis Is Back!', 'Fever');
}
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
#-------------------------------------------------------------------------
@@ -1239,7 +1240,7 @@ do_test e_fkey-31.1 {
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}}
+} {1 {FOREIGN KEY constraint failed}}
do_test e_fkey-31.3 {
# This time, use a trigger to fix the constraint violation before the
@@ -1264,7 +1265,7 @@ do_test e_fkey-31.4 {
DROP TRIGGER kt;
}
catchsql { INSERT INTO prince VALUES(3, 4) }
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test e_fkey-31.5 {
execsql {
COMMIT;
@@ -1295,7 +1296,7 @@ do_test e_fkey-31.5 {
proc test_efkey_34 {tn isError sql} {
do_test e_fkey-32.$tn "
catchsql {$sql}
- " [lindex {{0 {}} {1 {foreign key constraint failed}}} $isError]
+ " [lindex {{0 {}} {1 {FOREIGN KEY constraint failed}}} $isError]
}
drop_all_tables
@@ -1326,7 +1327,7 @@ 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]
+ " [lindex {{0 {}} {1 {FOREIGN KEY constraint failed}}} $isError]
}
do_test e_fkey-33.1 {
execsql {
@@ -1416,7 +1417,7 @@ do_test e_fkey-34.1 {
proc test_efkey_29 {tn sql isError} {
do_test e_fkey-34.$tn "catchsql {$sql}" [
- lindex {{0 {}} {1 {foreign key constraint failed}}} $isError
+ lindex {{0 {}} {1 {FOREIGN KEY constraint failed}}} $isError
]
}
test_efkey_29 2 "BEGIN" 0
@@ -1490,7 +1491,7 @@ do_test e_fkey-35.2 {
INSERT INTO track VALUES(1, 'White Christmas', 5);
}
catchsql COMMIT
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test e_fkey-35.3 {
execsql {
INSERT INTO artist VALUES(5, 'Bing Crosby');
@@ -1527,7 +1528,7 @@ do_test e_fkey-36.2 {
} {}
do_test e_fkey-36.3 {
catchsql COMMIT
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test e_fkey-36.4 {
execsql {
UPDATE t1 SET a = 5 WHERE a = 4;
@@ -1557,7 +1558,7 @@ do_test e_fkey-37.1 {
} {}
do_test e_fkey-37.2 {
catchsql {RELEASE one}
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test e_fkey-37.3 {
execsql {
UPDATE t1 SET a = 7 WHERE a = 6;
@@ -1574,7 +1575,7 @@ do_test e_fkey-37.4 {
} {}
do_test e_fkey-37.5 {
catchsql {RELEASE one}
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test e_fkey-37.6 {
execsql {ROLLBACK TO one ; RELEASE one}
} {}
@@ -1605,7 +1606,7 @@ do_test e_fkey-38.2 {
} {1 1 2 2 3 3 4 4 5 6}
do_test e_fkey-38.3 {
catchsql COMMIT
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test e_fkey-38.4 {
execsql {
ROLLBACK TO one;
@@ -1626,11 +1627,11 @@ do_test e_fkey-38.5 {
} {}
do_test e_fkey-38.6 {
catchsql {RELEASE a}
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test e_fkey-38.7 {
execsql {ROLLBACK TO c}
catchsql {RELEASE a}
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test e_fkey-38.8 {
execsql {
ROLLBACK TO b;
@@ -1781,7 +1782,7 @@ do_test e_fkey-41.2 {
} {j k l m}
do_test e_fkey-41.3 {
catchsql COMMIT
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test e_fkey-41.4 {
execsql ROLLBACK
} {}
@@ -1819,10 +1820,10 @@ do_test e_fkey-41.2 {
} {}
do_test e_fkey-41.3 {
catchsql { DELETE FROM parent WHERE p1 = 'a' }
-} {1 {foreign key constraint failed}}
+} {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}}
+} {1 {FOREIGN KEY constraint failed}}
#-------------------------------------------------------------------------
# Test that RESTRICT is slightly different from NO ACTION for IMMEDIATE
@@ -1856,7 +1857,7 @@ do_test e_fkey-42.1 {
} {}
do_test e_fkey-42.2 {
catchsql { UPDATE parent SET x = 'key one' WHERE x = 'key1' }
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test e_fkey-42.3 {
execsql {
UPDATE parent SET x = 'key two' WHERE x = 'key2';
@@ -1884,7 +1885,7 @@ do_test e_fkey-42.4 {
} {}
do_test e_fkey-42.5 {
catchsql { DELETE FROM parent WHERE x = 'key1' }
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test e_fkey-42.6 {
execsql {
DELETE FROM parent WHERE x = 'key2';
@@ -1907,7 +1908,7 @@ do_test e_fkey-42.7 {
} {}
do_test e_fkey-42.8 {
catchsql { REPLACE INTO parent VALUES('key1') }
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test e_fkey-42.9 {
execsql {
REPLACE INTO parent VALUES('key2');
@@ -1943,13 +1944,13 @@ do_test e_fkey-43.1 {
} {}
do_test e_fkey-43.2 {
catchsql { UPDATE parent SET x = 'key one' WHERE x = 'key1' }
-} {1 {foreign key constraint failed}}
+} {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}}
+} {1 {FOREIGN KEY constraint failed}}
do_test e_fkey-43.5 {
execsql {
UPDATE child2 SET c = 'key two';
@@ -1977,13 +1978,13 @@ do_test e_fkey-43.6 {
} {}
do_test e_fkey-43.7 {
catchsql { DELETE FROM parent WHERE x = 'key1' }
-} {1 {foreign key constraint failed}}
+} {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}}
+} {1 {FOREIGN KEY constraint failed}}
do_test e_fkey-43.10 {
execsql {
UPDATE child2 SET c = NULL;
@@ -2060,7 +2061,7 @@ do_test e_fkey-45.1 {
do_test e_fkey-45.2 {
execsql {
DELETE FROM pA WHERE rowid = 3;
- SELECT quote(x) FROM pA;
+ SELECT quote(x) FROM pA ORDER BY rowid;
}
} {X'0000' X'9999' X'1234'}
do_test e_fkey-45.3 {
@@ -2069,7 +2070,7 @@ do_test e_fkey-45.3 {
do_test e_fkey-45.4 {
execsql {
UPDATE pA SET x = X'8765' WHERE rowid = 4;
- SELECT quote(x) FROM pA;
+ SELECT quote(x) FROM pA ORDER BY rowid;
}
} {X'0000' X'9999' X'8765'}
do_test e_fkey-45.5 {
@@ -2239,7 +2240,7 @@ do_test e_fkey-49.3 {
} {ONE two three}
do_test e_fkey-49.4 {
catchsql { UPDATE parent SET a = '' WHERE a = 'oNe' }
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
#-------------------------------------------------------------------------
@@ -2274,7 +2275,7 @@ do_test e_fkey-50.1 {
} {}
do_test e_fkey-50.2 {
catchsql { DELETE FROM artist WHERE artistname = 'Sammy Davis Jr.' }
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test e_fkey-50.3 {
execsql {
INSERT INTO artist VALUES(0, 'Unknown Artist');
@@ -2325,7 +2326,7 @@ do_test e_fkey-51.1 {
do_test e_fkey-51.2 {
execsql {
UPDATE parent SET x = 22;
- SELECT * FROM parent UNION ALL SELECT 'xxx' UNION ALL SELECT a FROM child;
+ SELECT * FROM parent ORDER BY rowid; SELECT 'xxx' ; SELECT a FROM child;
}
} {22 21 23 xxx 22}
do_test e_fkey-51.3 {
@@ -2335,7 +2336,7 @@ do_test e_fkey-51.3 {
INSERT INTO parent VALUES(-1);
INSERT INTO child VALUES(-1);
UPDATE parent SET x = 22;
- SELECT * FROM parent UNION ALL SELECT 'xxx' UNION ALL SELECT a FROM child;
+ SELECT * FROM parent ORDER BY rowid; SELECT 'xxx' ; SELECT a FROM child;
}
} {22 23 21 xxx 23}
@@ -2638,7 +2639,7 @@ do_test e_fkey-58.1 {
}
execsql { INSERT INTO c5 VALUES('a', 'b') }
catchsql { DROP TABLE p }
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test e_fkey-58.2 {
execsql { SELECT * FROM p }
} {a b}
@@ -2647,7 +2648,7 @@ do_test e_fkey-58.3 {
BEGIN;
DROP TABLE p;
}
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test e_fkey-58.4 {
execsql {
SELECT * FROM p;
@@ -2681,11 +2682,11 @@ do_test e_fkey-59.2 {
} {}
do_test e_fkey-59.3 {
catchsql COMMIT
-} {1 {foreign key constraint failed}}
+} {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}}
+} {1 {FOREIGN KEY constraint failed}}
do_test e_fkey-59.5 {
execsql { INSERT INTO p VALUES('a', 'b') }
execsql COMMIT
@@ -2729,19 +2730,19 @@ do_test e_fkey-60.3 {
do_test e_fkey-60.4 {
execsql { CREATE TABLE nosuchtable(x PRIMARY KEY) }
catchsql { DELETE FROM p }
-} {1 {foreign key mismatch}}
+} {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}}
+} {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 behaviours of ALTER and DROP TABLE are only
-# activated when foreign keys are enabled. Special behaviours are:
+# 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.
@@ -2836,7 +2837,7 @@ foreach zMatch [list SIMPLE PARTIAL FULL Simple parTIAL FuLL ] {
do_test e_fkey-62.$zMatch.2 {
execsql { INSERT INTO p VALUES(1, 2, 3) }
- # MATCH SIMPLE behaviour: Allow any child key that contains one or more
+ # 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.
@@ -2848,7 +2849,7 @@ foreach zMatch [list SIMPLE PARTIAL FULL Simple parTIAL FuLL ] {
# 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}}
+ } {1 {FOREIGN KEY constraint failed}}
}
#-------------------------------------------------------------------------
@@ -2878,13 +2879,13 @@ do_test e_fkey-62.3 {
} {}
do_test e_fkey-62.4 {
catchsql { INSERT INTO ci VALUES('x', 'y') }
-} {1 {foreign key constraint failed}}
+} {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}}
+} {1 {FOREIGN KEY constraint failed}}
do_test e_fkey-62.7 {
execsql {
DELETE FROM cd;
@@ -2945,38 +2946,45 @@ proc test_on_update_recursion {limit} {
"
}
-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}
+# 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
diff --git a/lang/sql/sqlite/test/e_fts3.test b/lang/sql/sqlite/test/e_fts3.test
index 808e6ef4..b7581785 100644
--- a/lang/sql/sqlite/test/e_fts3.test
+++ b/lang/sql/sqlite/test/e_fts3.test
@@ -60,7 +60,7 @@ foreach {DO_MALLOC_TEST enc} {
# [foreach] loop is testing with OOM errors, disable the lookaside buffer.
#
db close
-file delete -force test.db test.db-journal
+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'"
@@ -638,7 +638,7 @@ read_test 8.2.2 { PRAGMA table_info(t9c) } {0 c\"1 {} 0 {} 0 1 c'2 {} 0 {} 0}
#
foreach DO_MALLOC_TEST {0 1 2} {
db close
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db test.db
if {$DO_MALLOC_TEST} { sqlite3_db_config_lookaside db 0 0 0 }
diff --git a/lang/sql/sqlite/test/e_insert.test b/lang/sql/sqlite/test/e_insert.test
index 2192f2e9..adda996b 100644
--- a/lang/sql/sqlite/test/e_insert.test
+++ b/lang/sql/sqlite/test/e_insert.test
@@ -18,6 +18,11 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
+ifcapable !compound {
+ finish_test
+ return
+}
+
# Organization of tests:
#
# e_insert-0.*: Test the syntax diagram.
@@ -45,7 +50,7 @@ proc do_insert_tests {args} {
uplevel do_select_tests $args
}
-# EVIDENCE-OF: R-41448-54465 -- syntax diagram insert-stmt
+# -- syntax diagram insert-stmt
#
do_insert_tests e_insert-0 {
1 "INSERT INTO a1 DEFAULT VALUES" {}
@@ -118,12 +123,26 @@ do_insert_tests e_insert-0 {
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-20288-20462 The first form (with the "VALUES" keyword)
-# creates a single new row in an existing table.
+# 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}
@@ -133,11 +152,14 @@ do_insert_tests e_insert-1.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-36040-20870 If no column-list is specified then the
-# number of values must be the same as the number of columns in the
-# table.
+# EVIDENCE-OF: R-53616-44976 If no column-list is specified 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
@@ -152,9 +174,10 @@ do_insert_tests e_insert-1.2 -error {
4 "INSERT INTO a2 VALUES(1,2,3,4,5)" {a2 3 5}
}
-# EVIDENCE-OF: R-52422-65517 In this case the result of evaluting the
-# left-most expression in the VALUES list is inserted into the left-most
-# column of the new row, and so on.
+# EVIDENCE-OF: R-34231-22576 In this case the result of evaluating the
+# left-most expression in each term of the VALUES list is inserted into
+# the left-most column of the each new row, and forth for each
+# subsequent expression.
#
delete_all_data
do_insert_tests e_insert-1.3 {
@@ -168,8 +191,9 @@ do_insert_tests e_insert-1.3 {
3b "SELECT * FROM a2 WHERE oid=last_insert_rowid()" {2 x y}
}
-# EVIDENCE-OF: R-62524-00361 If a column-list is specified, then the
-# number of values must match the number of specified columns.
+# EVIDENCE-OF: R-09234-17933 If a column-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
@@ -347,22 +371,22 @@ do_execsql_test e_insert-4.1.0 {
INSERT INTO a4 VALUES(3, 'a');
} {}
foreach {tn sql error ac data } {
- 1.1 "INSERT INTO a4 VALUES(2,'b')" {column c is not unique} 1 {1 a 2 a 3 a}
+ 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')" {column c is not unique} 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')"
- {column c is not unique} 0 {1 a 3 a 2 b}
+ {UNIQUE constraint failed: a4.c} 0 {1 a 3 a 2 b}
1.7 "INSERT OR ROLLBACK INTO a4 VALUES(1, 'd')"
- {column c is not unique} 1 {1 a 3 a 2 b}
+ {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'"
- {column c is not unique} 1 {1 a 3 a 2 b}
+ {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'"
- {column c is not unique} 1 {1 a 3 a 2 b 4 e}
+ {UNIQUE constraint failed: a4.c} 1 {1 a 3 a 2 b 4 e}
2.1 "INSERT INTO a4 VALUES(2,'f')"
- {column c is not unique} 1 {1 a 3 a 2 b 4 e}
+ {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]
diff --git a/lang/sql/sqlite/test/e_reindex.test b/lang/sql/sqlite/test/e_reindex.test
index e9419dff..4b86787a 100644
--- a/lang/sql/sqlite/test/e_reindex.test
+++ b/lang/sql/sqlite/test/e_reindex.test
@@ -26,7 +26,7 @@ do_execsql_test e_reindex-0.0 {
CREATE INDEX i2 ON t1(b, a);
} {}
-# EVIDENCE-OF: R-57021-15304 -- syntax diagram reindex-stmt
+# -- syntax diagram reindex-stmt
#
do_reindex_tests e_reindex-0.1 {
1 "REINDEX" {}
@@ -34,8 +34,8 @@ do_reindex_tests e_reindex-0.1 {
3 "REINDEX binary" {}
4 "REINDEX t1" {}
5 "REINDEX main.t1" {}
- 4 "REINDEX i1" {}
- 5 "REINDEX main.i1" {}
+ 6 "REINDEX i1" {}
+ 7 "REINDEX main.i1" {}
}
# EVIDENCE-OF: R-52173-44778 The REINDEX command is used to delete and
@@ -67,10 +67,10 @@ sqlite3 db test.db
do_execsql_test e_reindex-1.3 {
PRAGMA integrity_check;
} [list \
- {rowid 4 missing from index i2} \
- {rowid 4 missing from index i1} \
- {rowid 5 missing from index i2} \
- {rowid 5 missing from index i1} \
+ {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}
]
@@ -98,7 +98,7 @@ proc sort_by_length {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)}]
+ set res [expr {$V($lhs) - $V($rhs)}]
if {$res!=0} {return $res}
return [string compare $lhs $rhs]
}
diff --git a/lang/sql/sqlite/test/e_select.test b/lang/sql/sqlite/test/e_select.test
index 79e334ce..89d61b53 100644
--- a/lang/sql/sqlite/test/e_select.test
+++ b/lang/sql/sqlite/test/e_select.test
@@ -16,6 +16,11 @@
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');
@@ -78,7 +83,7 @@ proc do_join_test {tn select res} {
# The following tests check that all paths on the syntax diagrams on
# the lang_select.html page may be taken.
#
-# EVIDENCE-OF: R-18428-22111 -- syntax diagram join-constraint
+# -- syntax diagram join-constraint
#
do_join_test e_select-0.1.1 {
SELECT count(*) FROM t1 %JOIN% t2 ON (t1.a=t2.a)
@@ -96,7 +101,7 @@ 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}}
-# EVIDENCE-OF: R-44854-11739 -- syntax diagram select-core
+# -- syntax diagram select-core
#
# 0: SELECT ...
# 1: SELECT DISTINCT ...
@@ -221,7 +226,7 @@ do_select_tests e_select-0.2 {
}
-# EVIDENCE-OF: R-23316-20169 -- syntax diagram result-column
+# -- syntax diagram result-column
#
do_select_tests e_select-0.3 {
1 "SELECT * FROM t1" {a one b two c three}
@@ -231,9 +236,9 @@ do_select_tests e_select-0.3 {
5 "SELECT 'x'||a||'x' AS alias FROM t1" {xax xbx xcx}
}
-# EVIDENCE-OF: R-41233-21397 -- syntax diagram join-source
+# -- syntax diagram join-source
#
-# EVIDENCE-OF: R-45040-11121 -- syntax diagram join-op
+# -- syntax diagram join-op
#
do_select_tests e_select-0.4 {
1 "SELECT t1.rowid FROM t1" {1 2 3}
@@ -258,7 +263,7 @@ do_select_tests e_select-0.4 {
16 "SELECT t1.rowid FROM t1 CROSS JOIN t3" {1 1 2 2 3 3}
}
-# EVIDENCE-OF: R-56911-63533 -- syntax diagram compound-operator
+# -- 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}
@@ -267,7 +272,7 @@ do_select_tests e_select-0.5 {
4 "SELECT rowid FROM t1 EXCEPT SELECT rowid+2 FROM t4" {1 2}
}
-# EVIDENCE-OF: R-60388-27458 -- syntax diagram ordering-term
+# -- syntax diagram ordering-term
#
do_select_tests e_select-0.6 {
1 "SELECT b||a FROM t1 ORDER BY b||a" {onea threec twob}
@@ -276,7 +281,7 @@ do_select_tests e_select-0.6 {
4 "SELECT b||a FROM t1 ORDER BY (b||a) DESC" {twob threec onea}
}
-# EVIDENCE-OF: R-36494-33519 -- syntax diagram select-stmt
+# -- syntax diagram select-stmt
#
do_select_tests e_select-0.7 {
1 "SELECT * FROM t1" {a one b two c three}
@@ -328,9 +333,9 @@ do_select_tests e_select-1.1 {
6 "SELECT count(*) WHERE 1" {1}
}
-# EVIDENCE-OF: R-48114-33255 If there is only a single table in the
-# join-source following the FROM clause, then the input data used by the
-# SELECT statement is the contents of the named table.
+# 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'.
@@ -352,10 +357,10 @@ do_select_tests e_select-1.2 {
3 "SELECT sum(x), sum(y) FROM xx" {-17.89 -16.87}
}
-# EVIDENCE-OF: R-23593-12456 If there is more than one table specified
-# as part of the join-source following the FROM keyword, then the
-# contents of each named table are joined into a single dataset for the
-# simple SELECT statement to operate on.
+# 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
@@ -378,10 +383,10 @@ do_select_tests e_select-1.3 {
# 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-46122-14930 If the join-op 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-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
@@ -390,8 +395,8 @@ do_select_tests e_select-1.3 {
# EVIDENCE-OF: R-46256-57243 There is no difference between the "INNER
# JOIN", "JOIN" and "," join operators.
#
-# EVIDENCE-OF: R-07544-24155 The "CROSS JOIN" join operator produces the
-# same data as the "INNER JOIN", "JOIN" and "," 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.
@@ -445,24 +450,24 @@ do_join_test e_select-1.4.1.4 {
# left-hand and right-hand datasets.
#
do_join_test e_select-1.4.2.1 {
- SELECT * FROM x2 %JOIN% x3
+ SELECT * FROM x2 %JOIN% x3 ORDER BY +c, +f
} [list -60.06 {} {} -39.24 {} encompass -1 \
- -60.06 {} {} presenting 51 reformation dignified \
- -60.06 {} {} conducting -87.24 37.56 {} \
- -60.06 {} {} coldest -96 dramatists 82.3 \
-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 presenting 51 reformation dignified \
- -58 {} 1.21 conducting -87.24 37.56 {} \
- -58 {} 1.21 coldest -96 dramatists 82.3 \
-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-20659-43267 In other words, if the left-hand dataset
-# consists of Nlhs rows of Mlhs columns, and the right-hand dataset of
-# Nrhs rows of Mrhs columns, then the cartesian product is a dataset of
-# Nlhs.Nrhs rows, each containing Mlhs+Mrhs columns.
+# 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&times;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 {
@@ -508,11 +513,10 @@ do_select_tests e_select-1.4.5 [list \
4 { SELECT * FROM t1 AS y INNER JOIN t1 AS x } $t1_cross_t1 \
]
-
-# EVIDENCE-OF: R-22775-56496 If there is an ON clause specified, then
-# the ON expression is evaluated for each row of the cartesian product
-# as a boolean expression. All rows for which the expression evaluates
-# to false are excluded from the dataset.
+# 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 \
@@ -535,9 +539,9 @@ foreach {tn select res} [list \
do_join_test e_select-1.3.$tn $select $res
}
-# EVIDENCE-OF: R-63358-54862 If there is a USING clause specified as
-# part of the join-constraint, then each of the column names specified
-# must exist in the datasets to both the left and right of the join-op.
+# 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
@@ -547,10 +551,10 @@ do_select_tests e_select-1.4 -error {
3 { SELECT * FROM t3, (SELECT a AS b, b AS c FROM t1) USING (a) } "a"
}
-# EVIDENCE-OF: R-55987-04584 For each pair of namesake columns, the
+# 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. All rows for which one or more of the
-# expressions evaluates to false are excluded from the result set.
+# 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}
@@ -561,8 +565,8 @@ do_select_tests e_select-1.5 {
# USING clause, the normal rules for handling affinities, collation
# sequences and NULL values in comparisons apply.
#
-# EVIDENCE-OF: R-35466-18578 The column from the dataset on the
-# left-hand side of the join operator is considered to be on the
+# 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.
#
@@ -617,10 +621,9 @@ foreach {tn select res} {
} {
do_join_test e_select-1.7.$tn $select $res
}
-
-# EVIDENCE-OF: R-41434-12448 If the join-op 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
+# EVIDENCE-OF: R-42531-52874 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 corresponds to no rows at all in
# the composite dataset (if any).
#
@@ -655,8 +658,8 @@ do_select_tests e_select-1.9 {
2b "SELECT * FROM t7 LEFT JOIN t8 USING (a)" {x ex 24 abc 24 y why 25 {} {}}
}
-# EVIDENCE-OF: R-01809-52134 If the NATURAL keyword is added to any of
-# the join-ops, then an implicit USING clause is added to the
+# 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.
@@ -729,10 +732,10 @@ do_execsql_test e_select-3.0 {
INSERT INTO x2 VALUES(7, 'mistrusted', 'standardized');
} {}
-# EVIDENCE-OF: R-06999-14330 If a WHERE clause is specified, the WHERE
+# 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. All rows for which the WHERE clause expression evaluates
-# to false are excluded from the dataset before continuing.
+# 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}
@@ -800,7 +803,7 @@ do_select_tests e_select-4.1 {
6 "SELECT count(*), * FROM z1" {6 63 born -26}
7 "SELECT max(a), * FROM z1" {63 63 born -26}
- 8 "SELECT *, min(a) FROM z1" {63 born -26 -5}
+ 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
@@ -810,8 +813,8 @@ do_select_tests e_select-4.1 {
}
}
-# EVIDENCE-OF: R-61869-22578 It is an error to use a "*" or "alias.*"
-# expression in any context other than than a result expression list.
+# 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
@@ -1004,12 +1007,12 @@ do_execsql_test e_select-4.9.0 {
INSERT INTO b3 VALUES('dEF', 'dEF');
} {}
-# EVIDENCE-OF: R-57754-57109 If the SELECT statement is an aggregate
+# EVIDENCE-OF: R-07284-35990 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. 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 are assigned to the same group.
+# the same get assigned to the same group.
#
# These tests also show that the following is not untrue:
#
@@ -1018,10 +1021,10 @@ do_execsql_test e_select-4.9.0 {
#
do_select_tests e_select-4.9 {
1 "SELECT group_concat(one), two FROM b1 GROUP BY two" {
- 4,5 f 1 o 7,6 s 3,2 t
+ /#,# f 1 o #,# s #,# t/
}
2 "SELECT group_concat(one), sum(one) FROM b1 GROUP BY (one>4)" {
- 1,4,3,2 10 5,7,6 18
+ 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
@@ -1035,7 +1038,7 @@ do_select_tests e_select-4.9 {
# values are considered equal.
#
do_select_tests e_select-4.10 {
- 1 "SELECT group_concat(y) FROM b2 GROUP BY x" {0,1 3 2,4}
+ 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}
}
@@ -1221,8 +1224,8 @@ do_select_tests e_select-5.1 {
# 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-47911-02086 If neither ALL or DISTINCT are present,
-# then the behaviour is as if ALL were specified.
+# 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
@@ -1238,8 +1241,8 @@ do_select_tests e_select-5 {
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" {four one three two}
- 4.2 "SELECT DISTINCT x FROM h1, h2 ON (x=b)" {four one}
+ 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
@@ -1253,11 +1256,11 @@ do_select_tests e_select-5.5 {
# sequence to compare text values with apply.
#
do_select_tests e_select-5.6 {
- 1 "SELECT DISTINCT b FROM h1" {I IV four i iv one}
- 2 "SELECT DISTINCT b COLLATE nocase FROM h1" {four i iv one}
- 3 "SELECT DISTINCT x FROM h2" {four one three two}
+ 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" {
- Four One Three Two four one three two
+ One Two Three Four one two three four
}
}
@@ -1368,8 +1371,9 @@ foreach {tn select op1 op2} {
do_catchsql_test e_select-7.2.$tn $select [list 1 $err]
}
-# EVIDENCE-OF: R-22874-32655 ORDER BY and LIMIT clauses may only occur
-# at the end of the entire compound SELECT.
+# 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"
@@ -1381,6 +1385,7 @@ foreach {tn select} {
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"
@@ -1402,6 +1407,14 @@ foreach {tn select} {
} {
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
@@ -1740,12 +1753,12 @@ do_select_tests e_select-8.4 {
1 2 7 1 2 8 1 4 93 1 5 -1
}
8 "SELECT z, x FROM d1 ORDER BY 2" {
- 3 1 8 1 7 1 -20 1
- 93 1 -1 1 -1 2 93 2
+ /# 1 # 1 # 1 # 1
+ # 1 # 1 # 2 # 2/
}
9 "SELECT z, x FROM d1 ORDER BY 1" {
- -20 1 -1 2 -1 1 3 1
- 7 1 8 1 93 2 93 1
+ /-20 1 -1 # -1 # 3 1
+ 7 1 8 1 93 # 93 #/
}
}
@@ -1761,16 +1774,16 @@ do_select_tests e_select-8.5 {
94 94 9 8 4 0 0 -19
}
3 "SELECT z AS x, x AS z FROM d1 ORDER BY z" {
- 3 1 8 1 7 1 -20 1 93 1 -1 1 -1 2 93 2
+ /# 1 # 1 # 1 # 1 # 1 # 1 # 2 # 2/
}
4 "SELECT z AS x, x AS z FROM d1 ORDER BY x" {
- -20 1 -1 2 -1 1 3 1 7 1 8 1 93 2 93 1
+ /-20 1 -1 # -1 # 3 1 7 1 8 1 93 # 93 #/
}
}
-# EVIDENCE-OF: R-27923-38747 Otherwise, if the ORDER BY expression is
-# any other expression, it is evaluated and the the returned value used
-# to order the output rows.
+# 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.
diff --git a/lang/sql/sqlite/test/e_select2.test b/lang/sql/sqlite/test/e_select2.test
index b338d4f3..83308944 100644
--- a/lang/sql/sqlite/test/e_select2.test
+++ b/lang/sql/sqlite/test/e_select2.test
@@ -344,16 +344,16 @@ foreach {tn indexes} {
catchsql { DROP INDEX i3 }
execsql $indexes
- # EVIDENCE-OF: R-46122-14930 If the join-op 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-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-07544-24155 The "CROSS JOIN" join operator produces the
- # same data as the "INNER JOIN", "JOIN" and "," 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}
@@ -368,10 +368,10 @@ foreach {tn indexes} {
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-22775-56496 If there is an ON clause specified, then
- # the ON expression is evaluated for each row of the cartesian product
- # as a boolean expression. All rows for which the expression evaluates
- # to false are excluded from the dataset.
+ # 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}}
@@ -504,14 +504,14 @@ do_execsql_test e_select-2.2.0 {
INSERT INTO t5 VALUES(2, 'two');
} {}
-# EVIDENCE-OF: R-55824-40976 A sub-select specified in the join-source
-# following the FROM clause in a simple SELECT statement is handled as
-# if it was a table containing the data returned by executing the
-# sub-select statement.
+# 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-42612-06757 Each column of the sub-select dataset
-# inherits the collation sequence and affinity of the corresponding
-# expression in the sub-select 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%"
diff --git a/lang/sql/sqlite/test/e_update.test b/lang/sql/sqlite/test/e_update.test
index d8032ce0..e9c6b268 100644
--- a/lang/sql/sqlite/test/e_update.test
+++ b/lang/sql/sqlite/test/e_update.test
@@ -49,7 +49,7 @@ proc do_update_tests {args} {
uplevel do_select_tests $args
}
-# EVIDENCE-OF: R-05685-44205 -- syntax diagram update-stmt
+# -- syntax diagram update-stmt
#
do_update_tests e_update-0 {
1 "UPDATE t1 SET a=10" {}
@@ -233,9 +233,9 @@ do_update_tests e_update-1.5 -query {
{3 1 4 1 5 9 2 6 5}
}
-# EVIDENCE-OF: R-09060-20018 If a single column-name appears more than
+# EVIDENCE-OF: R-34751-18293 If a single column-name appears more than
# once in the list of assignment expressions, all but the rightmost
-# occurence is ignored.
+# occurrence is ignored.
#
do_update_tests e_update-1.6 -query {
SELECT * FROM t2
@@ -278,30 +278,30 @@ do_execsql_test e_update-1.8.0 {
} {}
foreach {tn sql error ac data } {
1 "UPDATE t3 SET b='one' WHERE a=3"
- {column b is not unique} 1 {1 one 2 two 3 three 4 four}
+ {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'"
- {column b is not unique} 1 {2 three 3 one 4 four}
+ {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"
- {column b is not unique} 1 {2 three 3 one 4 four}
+ {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"
- {column b is not unique} 0 {2 three 3 one 4 four}
+ {UNIQUE constraint failed: t3.b} 0 {2 three 3 one 4 four}
8 "UPDATE OR ABORT t3 SET b='three' WHERE a=3"
- {column b is not unique} 0 {2 three 3 one 4 four}
+ {UNIQUE constraint failed: t3.b} 0 {2 three 3 one 4 four}
9 "UPDATE OR FAIL t3 SET b='two'"
- {column b is not unique} 0 {2 two 3 one 4 four}
+ {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}
@@ -310,7 +310,7 @@ foreach {tn sql error ac data } {
{} 0 {2 two 3 four}
12 "UPDATE OR ROLLBACK t3 SET b='four'"
- {column b is not unique} 1 {2 three 3 one 4 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]
@@ -381,11 +381,9 @@ do_execsql_test e_update-2.2.X {
# attached).
#
do_execsql_test e_update-2.3.0 {
- SELECT 'main', tbl_name FROM main.sqlite_master WHERE type = 'table'
- UNION ALL
- SELECT 'temp', tbl_name FROM sqlite_temp_master WHERE type = 'table'
- UNION ALL
- SELECT 'aux', tbl_name FROM aux.sqlite_master WHERE type = 'table'
+ 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
@@ -495,7 +493,7 @@ do_update_tests e_update-2.5 -error {
# of the UPDATE statement is extended with optional ORDER BY and LIMIT
# clauses
#
-# EVIDENCE-OF: R-08948-01887 -- syntax diagram update-stmt-limited
+# -- syntax diagram update-stmt-limited
#
do_update_tests e_update-3.0 {
1 "UPDATE t1 SET a=b LIMIT 5" {}
@@ -605,4 +603,3 @@ do_update_tests e_update-3.5 -query { SELECT x FROM t8 ; DELETE FROM t8 } {
} ;# ifcapable update_delete_limit
finish_test
-
diff --git a/lang/sql/sqlite/test/e_uri.test b/lang/sql/sqlite/test/e_uri.test
new file mode 100644
index 00000000..a8865cad
--- /dev/null
+++ b/lang/sql/sqlite/test/e_uri.test
@@ -0,0 +1,457 @@
+# 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
+
+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
+ } tvfs]
+ sqlite3_close $DB
+ 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-24124-56960 URI filename interpretation is enabled if
+# the SQLITE_OPEN_URI flag is set in the fourth 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-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
+}
+
+# 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
+
+# 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&parameter=is&ok=
+} {/test.db {an unknown parameter is ok {}}}
+do_filepath_test 12.2 {
+ parse_uri file://localhost/test.db?an&unknown&parameter&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/lang/sql/sqlite/test/e_vacuum.test b/lang/sql/sqlite/test/e_vacuum.test
index 414c854d..99b31aac 100644
--- a/lang/sql/sqlite/test/e_vacuum.test
+++ b/lang/sql/sqlite/test/e_vacuum.test
@@ -65,7 +65,7 @@ proc fragment_count {name} {
}
-# EVIDENCE-OF: R-63707-33375 -- syntax diagram vacuum-stmt
+# -- syntax diagram vacuum-stmt
#
do_execsql_test e_vacuum-0.1 { VACUUM } {}
@@ -122,7 +122,7 @@ foreach {tn avmode sz} {
# e_vacuum-1.2.4 - Verify that t1 and its indexes are now much
# less fragmented.
#
-ifcapable vtab {
+ifcapable vtab&&compound {
create_db
register_dbstat_vtab db
do_execsql_test e_vacuum-1.2.1 {
diff --git a/lang/sql/sqlite/test/enc2.test b/lang/sql/sqlite/test/enc2.test
index ce25bf39..3eb3aa27 100644
--- a/lang/sql/sqlite/test/enc2.test
+++ b/lang/sql/sqlite/test/enc2.test
@@ -32,7 +32,7 @@ ifcapable {!utf16} {
# 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 behaviour of the library when a collation sequence is
+# 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
@@ -142,7 +142,7 @@ set encodings [list UTF-8 UTF-16le UTF-16be]
set sqlite_os_trace 0
set i 1
foreach enc $encodings {
- file delete -force test.db
+ forcedelete test.db
sqlite3 db test.db
db eval "PRAGMA encoding = \"$enc\""
execsql $dbcontents
@@ -172,13 +172,13 @@ foreach enc $encodings {
# encoding to the main database.
ifcapable attach {
do_test enc2-4.1 {
- file delete -force test.db
+ 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 {
- file delete -force test2.db
+ forcedelete test2.db
sqlite3 db2 test2.db
db2 eval "PRAGMA encoding = 'UTF-16'"
db2 eval "CREATE TABLE abc(a, b, c);"
@@ -206,7 +206,7 @@ proc test_collate {enc lhs rhs} {
return $res
}
-file delete -force test.db
+forcedelete test.db
sqlite3 db test.db; set DB [sqlite3_connection_pointer db]
do_test enc2-5.0 {
execsql {
@@ -235,7 +235,7 @@ do_test enc2-5.3 {
} {one two three four five UTF-16BE}
db close
-file delete -force test.db
+forcedelete test.db
sqlite3 db test.db; set DB [sqlite3_connection_pointer db]
execsql {pragma encoding = 'UTF-16LE'}
do_test enc2-5.4 {
@@ -265,7 +265,7 @@ do_test enc2-5.7 {
} {one two three four five UTF-8}
db close
-file delete -force test.db
+forcedelete test.db
sqlite3 db test.db; set DB [sqlite3_connection_pointer db]
execsql {pragma encoding = 'UTF-16BE'}
do_test enc2-5.8 {
@@ -311,7 +311,7 @@ do_test enc2-5.14 {
} test_collate
db close
-file delete -force test.db
+forcedelete test.db
do_test enc2-5.15 {
sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db]
@@ -333,7 +333,7 @@ proc test_function {enc arg} {
}
db close
-file delete -force test.db
+forcedelete test.db
sqlite3 db test.db; set DB [sqlite3_connection_pointer db]
execsql {pragma encoding = 'UTF-8'}
do_test enc2-6.0 {
@@ -366,7 +366,7 @@ do_test enc2-6.3 {
} {{UTF-16BE sqlite}}
db close
-file delete -force test.db
+forcedelete test.db
sqlite3 db test.db; set DB [sqlite3_connection_pointer db]
execsql {pragma encoding = 'UTF-16LE'}
do_test enc2-6.3 {
@@ -399,7 +399,7 @@ do_test enc2-6.6 {
} {{UTF-16BE sqlite}}
db close
-file delete -force test.db
+forcedelete test.db
sqlite3 db test.db; set DB [sqlite3_connection_pointer db]
execsql {pragma encoding = 'UTF-16BE'}
do_test enc2-6.7 {
@@ -433,7 +433,7 @@ do_test enc2-6.10 {
db close
-file delete -force test.db
+forcedelete test.db
# The following tests - enc2-7.* - function as follows:
#
@@ -493,7 +493,7 @@ ifcapable {complete} {
# Test that the encoding of an empty database may still be set after the
# (empty) schema has been initialized.
-file delete -force test.db
+forcedelete test.db
do_test enc2-9.1 {
sqlite3 db test.db
execsql {
@@ -537,7 +537,7 @@ do_test enc2-9.5 {
#
do_test enc2-10.1 {
db close
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db test.db
db eval {
PRAGMA encoding=UTF16;
diff --git a/lang/sql/sqlite/test/enc3.test b/lang/sql/sqlite/test/enc3.test
index 44b21793..1d8a2581 100644
--- a/lang/sql/sqlite/test/enc3.test
+++ b/lang/sql/sqlite/test/enc3.test
@@ -81,7 +81,7 @@ ifcapable {bloblit && utf16} {
#
ifcapable {utf16 && shared_cache} {
db close
- file delete -force test8.db test8.db-journal
+ forcedelete test8.db test8.db-journal
set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
sqlite3 dbaux test8.db
sqlite3 db test.db
@@ -100,7 +100,7 @@ ifcapable {utf16 && shared_cache} {
} dbaux
} {1 {attached databases must use the same text encoding as main database}}
dbaux close
- file delete -force test8.db test8.db-journal
+ forcedelete test8.db test8.db-journal
sqlite3_enable_shared_cache $::enable_shared_cache
}
diff --git a/lang/sql/sqlite/test/enc4.test b/lang/sql/sqlite/test/enc4.test
index de2a1b88..94869b6f 100644
--- a/lang/sql/sqlite/test/enc4.test
+++ b/lang/sql/sqlite/test/enc4.test
@@ -1,139 +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 {
-
- file delete -force 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<18} {incr x} {
- set part [expr $init + [string range $val 0 [expr $x-1]]]
- regsub {e\+0} $part {e+} part
- regsub {^1e} $part {1.0e} part
-
- do_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_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
-}
-
-file delete -force 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
+# 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/lang/sql/sqlite/test/eqp.test b/lang/sql/sqlite/test/eqp.test
index 91a18d00..e5b3ddb0 100644
--- a/lang/sql/sqlite/test/eqp.test
+++ b/lang/sql/sqlite/test/eqp.test
@@ -13,6 +13,11 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
+ifcapable !compound {
+ finish_test
+ return
+}
+
set testprefix eqp
#-------------------------------------------------------------------------
@@ -28,47 +33,47 @@ set testprefix eqp
proc det {args} { uplevel do_eqp_test $args }
do_execsql_test 1.1 {
- CREATE TABLE t1(a, b);
+ 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, b);
- CREATE TABLE t3(a, 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;
} {
- 0 0 1 {SEARCH TABLE t1 USING INDEX i1 (a=?) (~10 rows)}
- 0 0 1 {SEARCH TABLE t1 USING INDEX i2 (b=?) (~10 rows)}
- 0 1 0 {SCAN TABLE t2 (~1000000 rows)}
+ 0 0 1 {SEARCH TABLE t1 USING INDEX i1 (a=?)}
+ 0 0 1 {SEARCH TABLE t1 USING INDEX i2 (b=?)}
+ 0 1 0 {SCAN TABLE t2}
}
do_eqp_test 1.3 {
SELECT * FROM t2 CROSS JOIN t1 WHERE t1.a=1 OR t1.b=2;
} {
- 0 0 0 {SCAN TABLE t2 (~1000000 rows)}
- 0 1 1 {SEARCH TABLE t1 USING INDEX i1 (a=?) (~10 rows)}
- 0 1 1 {SEARCH TABLE t1 USING INDEX i2 (b=?) (~10 rows)}
+ 0 0 0 {SCAN TABLE t2}
+ 0 1 1 {SEARCH TABLE t1 USING INDEX i1 (a=?)}
+ 0 1 1 {SEARCH TABLE t1 USING INDEX i2 (b=?)}
}
do_eqp_test 1.3 {
SELECT a FROM t1 ORDER BY a
} {
- 0 0 0 {SCAN TABLE t1 USING COVERING INDEX i1 (~1000000 rows)}
+ 0 0 0 {SCAN TABLE t1 USING COVERING INDEX i1}
}
do_eqp_test 1.4 {
SELECT a FROM t1 ORDER BY +a
} {
- 0 0 0 {SCAN TABLE t1 (~1000000 rows)}
+ 0 0 0 {SCAN TABLE t1 USING COVERING INDEX i1}
0 0 0 {USE TEMP B-TREE FOR ORDER BY}
}
do_eqp_test 1.5 {
SELECT a FROM t1 WHERE a=4
} {
- 0 0 0 {SEARCH TABLE t1 USING COVERING INDEX i1 (a=?) (~10 rows)}
+ 0 0 0 {SEARCH TABLE t1 USING COVERING INDEX i1 (a=?)}
}
do_eqp_test 1.6 {
SELECT DISTINCT count(*) FROM t3 GROUP BY a;
} {
- 0 0 0 {SCAN TABLE t3 (~1000000 rows)}
+ 0 0 0 {SCAN TABLE t3}
0 0 0 {USE TEMP B-TREE FOR GROUP BY}
0 0 0 {USE TEMP B-TREE FOR DISTINCT}
}
@@ -76,40 +81,40 @@ do_eqp_test 1.6 {
do_eqp_test 1.7 {
SELECT * FROM t3 JOIN (SELECT 1)
} {
- 0 0 1 {SCAN SUBQUERY 1 (~1 rows)}
- 0 1 0 {SCAN TABLE t3 (~1000000 rows)}
+ 0 0 1 {SCAN SUBQUERY 1}
+ 0 1 0 {SCAN TABLE t3}
}
do_eqp_test 1.8 {
SELECT * FROM t3 JOIN (SELECT 1 UNION SELECT 2)
} {
1 0 0 {COMPOUND SUBQUERIES 2 AND 3 USING TEMP B-TREE (UNION)}
- 0 0 1 {SCAN SUBQUERY 1 (~2 rows)}
- 0 1 0 {SCAN TABLE t3 (~1000000 rows)}
+ 0 0 1 {SCAN SUBQUERY 1}
+ 0 1 0 {SCAN TABLE t3}
}
do_eqp_test 1.9 {
SELECT * FROM t3 JOIN (SELECT 1 EXCEPT SELECT a FROM t3 LIMIT 17)
} {
- 3 0 0 {SCAN TABLE t3 (~1000000 rows)}
+ 3 0 0 {SCAN TABLE t3}
1 0 0 {COMPOUND SUBQUERIES 2 AND 3 USING TEMP B-TREE (EXCEPT)}
- 0 0 1 {SCAN SUBQUERY 1 (~17 rows)}
- 0 1 0 {SCAN TABLE t3 (~1000000 rows)}
+ 0 0 1 {SCAN SUBQUERY 1}
+ 0 1 0 {SCAN TABLE t3}
}
do_eqp_test 1.10 {
SELECT * FROM t3 JOIN (SELECT 1 INTERSECT SELECT a FROM t3 LIMIT 17)
} {
- 3 0 0 {SCAN TABLE t3 (~1000000 rows)}
+ 3 0 0 {SCAN TABLE t3}
1 0 0 {COMPOUND SUBQUERIES 2 AND 3 USING TEMP B-TREE (INTERSECT)}
- 0 0 1 {SCAN SUBQUERY 1 (~1 rows)}
- 0 1 0 {SCAN TABLE t3 (~1000000 rows)}
+ 0 0 1 {SCAN SUBQUERY 1}
+ 0 1 0 {SCAN TABLE t3}
}
do_eqp_test 1.11 {
SELECT * FROM t3 JOIN (SELECT 1 UNION ALL SELECT a FROM t3 LIMIT 17)
} {
- 3 0 0 {SCAN TABLE t3 (~1000000 rows)}
+ 3 0 0 {SCAN TABLE t3}
1 0 0 {COMPOUND SUBQUERIES 2 AND 3 (UNION ALL)}
- 0 0 1 {SCAN SUBQUERY 1 (~17 rows)}
- 0 1 0 {SCAN TABLE t3 (~1000000 rows)}
+ 0 0 1 {SCAN SUBQUERY 1}
+ 0 1 0 {SCAN TABLE t3}
}
#-------------------------------------------------------------------------
@@ -117,55 +122,55 @@ do_eqp_test 1.11 {
#
drop_all_tables
do_execsql_test 2.1 {
- CREATE TABLE t1(x, y);
+ CREATE TABLE t1(x INT, y INT, ex TEXT);
- CREATE TABLE t2(x, y);
+ 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" {
- 0 0 0 {SCAN TABLE t1 (~1000000 rows)}
+ 0 0 0 {SCAN TABLE t1}
0 0 0 {USE TEMP B-TREE FOR GROUP BY}
0 0 0 {USE TEMP B-TREE FOR DISTINCT}
0 0 0 {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" {
- 0 0 0 {SCAN TABLE t2 USING COVERING INDEX t2i1 (~1000000 rows)}
+ 0 0 0 {SCAN TABLE t2 USING COVERING INDEX t2i1}
0 0 0 {USE TEMP B-TREE FOR DISTINCT}
0 0 0 {USE TEMP B-TREE FOR ORDER BY}
}
det 2.2.3 "SELECT DISTINCT * FROM t1" {
- 0 0 0 {SCAN TABLE t1 (~1000000 rows)}
+ 0 0 0 {SCAN TABLE t1}
0 0 0 {USE TEMP B-TREE FOR DISTINCT}
}
det 2.2.4 "SELECT DISTINCT * FROM t1, t2" {
- 0 0 0 {SCAN TABLE t1 (~1000000 rows)}
- 0 1 1 {SCAN TABLE t2 (~1000000 rows)}
+ 0 0 0 {SCAN TABLE t1}
+ 0 1 1 {SCAN TABLE t2}
0 0 0 {USE TEMP B-TREE FOR DISTINCT}
}
det 2.2.5 "SELECT DISTINCT * FROM t1, t2 ORDER BY t1.x" {
- 0 0 0 {SCAN TABLE t1 (~1000000 rows)}
- 0 1 1 {SCAN TABLE t2 (~1000000 rows)}
+ 0 0 0 {SCAN TABLE t1}
+ 0 1 1 {SCAN TABLE t2}
0 0 0 {USE TEMP B-TREE FOR DISTINCT}
0 0 0 {USE TEMP B-TREE FOR ORDER BY}
}
det 2.2.6 "SELECT DISTINCT t2.x FROM t1, t2 ORDER BY t2.x" {
- 0 0 1 {SCAN TABLE t2 USING COVERING INDEX t2i1 (~1000000 rows)}
- 0 1 0 {SCAN TABLE t1 (~1000000 rows)}
+ 0 0 1 {SCAN TABLE t2 USING COVERING INDEX t2i1}
+ 0 1 0 {SCAN TABLE t1}
}
det 2.3.1 "SELECT max(x) FROM t2" {
- 0 0 0 {SEARCH TABLE t2 USING COVERING INDEX t2i1 (~1 rows)}
+ 0 0 0 {SEARCH TABLE t2 USING COVERING INDEX t2i1}
}
det 2.3.2 "SELECT min(x) FROM t2" {
- 0 0 0 {SEARCH TABLE t2 USING COVERING INDEX t2i1 (~1 rows)}
+ 0 0 0 {SEARCH TABLE t2 USING COVERING INDEX t2i1}
}
det 2.3.3 "SELECT min(x), max(x) FROM t2" {
- 0 0 0 {SCAN TABLE t2 (~1000000 rows)}
+ 0 0 0 {SCAN TABLE t2 USING COVERING INDEX t2i1}
}
det 2.4.1 "SELECT * FROM t1 WHERE rowid=?" {
- 0 0 0 {SEARCH TABLE t1 USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)}
+ 0 0 0 {SEARCH TABLE t1 USING INTEGER PRIMARY KEY (rowid=?)}
}
@@ -176,39 +181,39 @@ det 2.4.1 "SELECT * FROM t1 WHERE rowid=?" {
do_eqp_test 3.1.1 {
SELECT (SELECT x FROM t1 AS sub) FROM t1;
} {
- 0 0 0 {SCAN TABLE t1 (~1000000 rows)}
+ 0 0 0 {SCAN TABLE t1}
0 0 0 {EXECUTE SCALAR SUBQUERY 1}
- 1 0 0 {SCAN TABLE t1 AS sub (~1000000 rows)}
+ 1 0 0 {SCAN TABLE t1 AS sub}
}
do_eqp_test 3.1.2 {
SELECT * FROM t1 WHERE (SELECT x FROM t1 AS sub);
} {
- 0 0 0 {SCAN TABLE t1 (~1000000 rows)}
+ 0 0 0 {SCAN TABLE t1}
0 0 0 {EXECUTE SCALAR SUBQUERY 1}
- 1 0 0 {SCAN TABLE t1 AS sub (~1000000 rows)}
+ 1 0 0 {SCAN TABLE t1 AS sub}
}
do_eqp_test 3.1.3 {
SELECT * FROM t1 WHERE (SELECT x FROM t1 AS sub ORDER BY y);
} {
- 0 0 0 {SCAN TABLE t1 (~1000000 rows)}
+ 0 0 0 {SCAN TABLE t1}
0 0 0 {EXECUTE SCALAR SUBQUERY 1}
- 1 0 0 {SCAN TABLE t1 AS sub (~1000000 rows)}
+ 1 0 0 {SCAN TABLE t1 AS sub}
1 0 0 {USE TEMP B-TREE FOR ORDER BY}
}
do_eqp_test 3.1.4 {
SELECT * FROM t1 WHERE (SELECT x FROM t2 ORDER BY x);
} {
- 0 0 0 {SCAN TABLE t1 (~1000000 rows)}
+ 0 0 0 {SCAN TABLE t1}
0 0 0 {EXECUTE SCALAR SUBQUERY 1}
- 1 0 0 {SCAN TABLE t2 USING COVERING INDEX t2i1 (~1000000 rows)}
+ 1 0 0 {SCAN TABLE t2 USING COVERING INDEX t2i1}
}
det 3.2.1 {
SELECT * FROM (SELECT * FROM t1 ORDER BY x LIMIT 10) ORDER BY y LIMIT 5
} {
- 1 0 0 {SCAN TABLE t1 (~1000000 rows)}
+ 1 0 0 {SCAN TABLE t1}
1 0 0 {USE TEMP B-TREE FOR ORDER BY}
- 0 0 0 {SCAN SUBQUERY 1 (~10 rows)}
+ 0 0 0 {SCAN SUBQUERY 1}
0 0 0 {USE TEMP B-TREE FOR ORDER BY}
}
det 3.2.2 {
@@ -217,34 +222,34 @@ det 3.2.2 {
(SELECT * FROM t2 ORDER BY x LIMIT 10) AS x2
ORDER BY x2.y LIMIT 5
} {
- 1 0 0 {SCAN TABLE t1 (~1000000 rows)}
+ 1 0 0 {SCAN TABLE t1}
1 0 0 {USE TEMP B-TREE FOR ORDER BY}
- 2 0 0 {SCAN TABLE t2 USING INDEX t2i1 (~1000000 rows)}
- 0 0 0 {SCAN SUBQUERY 1 AS x1 (~10 rows)}
- 0 1 1 {SCAN SUBQUERY 2 AS x2 (~10 rows)}
+ 2 0 0 {SCAN TABLE t2 USING INDEX t2i1}
+ 0 0 0 {SCAN SUBQUERY 1 AS x1}
+ 0 1 1 {SCAN SUBQUERY 2 AS x2}
0 0 0 {USE TEMP B-TREE FOR ORDER BY}
}
det 3.3.1 {
SELECT * FROM t1 WHERE y IN (SELECT y FROM t2)
} {
- 0 0 0 {SCAN TABLE t1 (~100000 rows)}
+ 0 0 0 {SCAN TABLE t1}
0 0 0 {EXECUTE LIST SUBQUERY 1}
- 1 0 0 {SCAN TABLE t2 (~1000000 rows)}
+ 1 0 0 {SCAN TABLE t2}
}
det 3.3.2 {
SELECT * FROM t1 WHERE y IN (SELECT y FROM t2 WHERE t1.x!=t2.x)
} {
- 0 0 0 {SCAN TABLE t1 (~500000 rows)}
+ 0 0 0 {SCAN TABLE t1}
0 0 0 {EXECUTE CORRELATED LIST SUBQUERY 1}
- 1 0 0 {SCAN TABLE t2 (~500000 rows)}
+ 1 0 0 {SCAN TABLE t2}
}
det 3.3.3 {
SELECT * FROM t1 WHERE EXISTS (SELECT y FROM t2 WHERE t1.x!=t2.x)
} {
- 0 0 0 {SCAN TABLE t1 (~500000 rows)}
+ 0 0 0 {SCAN TABLE t1}
0 0 0 {EXECUTE CORRELATED SCALAR SUBQUERY 1}
- 1 0 0 {SCAN TABLE t2 (~500000 rows)}
+ 1 0 0 {SCAN TABLE t2}
}
#-------------------------------------------------------------------------
@@ -253,43 +258,43 @@ det 3.3.3 {
do_eqp_test 4.1.1 {
SELECT * FROM t1 UNION ALL SELECT * FROM t2
} {
- 1 0 0 {SCAN TABLE t1 (~1000000 rows)}
- 2 0 0 {SCAN TABLE t2 (~1000000 rows)}
+ 1 0 0 {SCAN TABLE t1}
+ 2 0 0 {SCAN TABLE t2}
0 0 0 {COMPOUND SUBQUERIES 1 AND 2 (UNION ALL)}
}
do_eqp_test 4.1.2 {
SELECT * FROM t1 UNION ALL SELECT * FROM t2 ORDER BY 2
} {
- 1 0 0 {SCAN TABLE t1 (~1000000 rows)}
+ 1 0 0 {SCAN TABLE t1}
1 0 0 {USE TEMP B-TREE FOR ORDER BY}
- 2 0 0 {SCAN TABLE t2 (~1000000 rows)}
+ 2 0 0 {SCAN TABLE t2}
2 0 0 {USE TEMP B-TREE FOR ORDER BY}
0 0 0 {COMPOUND SUBQUERIES 1 AND 2 (UNION ALL)}
}
do_eqp_test 4.1.3 {
SELECT * FROM t1 UNION SELECT * FROM t2 ORDER BY 2
} {
- 1 0 0 {SCAN TABLE t1 (~1000000 rows)}
+ 1 0 0 {SCAN TABLE t1}
1 0 0 {USE TEMP B-TREE FOR ORDER BY}
- 2 0 0 {SCAN TABLE t2 (~1000000 rows)}
+ 2 0 0 {SCAN TABLE t2}
2 0 0 {USE TEMP B-TREE FOR ORDER BY}
0 0 0 {COMPOUND SUBQUERIES 1 AND 2 (UNION)}
}
do_eqp_test 4.1.4 {
SELECT * FROM t1 INTERSECT SELECT * FROM t2 ORDER BY 2
} {
- 1 0 0 {SCAN TABLE t1 (~1000000 rows)}
+ 1 0 0 {SCAN TABLE t1}
1 0 0 {USE TEMP B-TREE FOR ORDER BY}
- 2 0 0 {SCAN TABLE t2 (~1000000 rows)}
+ 2 0 0 {SCAN TABLE t2}
2 0 0 {USE TEMP B-TREE FOR ORDER BY}
0 0 0 {COMPOUND SUBQUERIES 1 AND 2 (INTERSECT)}
}
do_eqp_test 4.1.5 {
SELECT * FROM t1 EXCEPT SELECT * FROM t2 ORDER BY 2
} {
- 1 0 0 {SCAN TABLE t1 (~1000000 rows)}
+ 1 0 0 {SCAN TABLE t1}
1 0 0 {USE TEMP B-TREE FOR ORDER BY}
- 2 0 0 {SCAN TABLE t2 (~1000000 rows)}
+ 2 0 0 {SCAN TABLE t2}
2 0 0 {USE TEMP B-TREE FOR ORDER BY}
0 0 0 {COMPOUND SUBQUERIES 1 AND 2 (EXCEPT)}
}
@@ -297,35 +302,35 @@ do_eqp_test 4.1.5 {
do_eqp_test 4.2.2 {
SELECT * FROM t1 UNION ALL SELECT * FROM t2 ORDER BY 1
} {
- 1 0 0 {SCAN TABLE t1 (~1000000 rows)}
+ 1 0 0 {SCAN TABLE t1}
1 0 0 {USE TEMP B-TREE FOR ORDER BY}
- 2 0 0 {SCAN TABLE t2 USING INDEX t2i1 (~1000000 rows)}
+ 2 0 0 {SCAN TABLE t2 USING INDEX t2i1}
0 0 0 {COMPOUND SUBQUERIES 1 AND 2 (UNION ALL)}
}
do_eqp_test 4.2.3 {
SELECT * FROM t1 UNION SELECT * FROM t2 ORDER BY 1
} {
- 1 0 0 {SCAN TABLE t1 (~1000000 rows)}
+ 1 0 0 {SCAN TABLE t1}
1 0 0 {USE TEMP B-TREE FOR ORDER BY}
- 2 0 0 {SCAN TABLE t2 (~1000000 rows)}
+ 2 0 0 {SCAN TABLE t2}
2 0 0 {USE TEMP B-TREE FOR ORDER BY}
0 0 0 {COMPOUND SUBQUERIES 1 AND 2 (UNION)}
}
do_eqp_test 4.2.4 {
SELECT * FROM t1 INTERSECT SELECT * FROM t2 ORDER BY 1
} {
- 1 0 0 {SCAN TABLE t1 (~1000000 rows)}
+ 1 0 0 {SCAN TABLE t1}
1 0 0 {USE TEMP B-TREE FOR ORDER BY}
- 2 0 0 {SCAN TABLE t2 (~1000000 rows)}
+ 2 0 0 {SCAN TABLE t2}
2 0 0 {USE TEMP B-TREE FOR ORDER BY}
0 0 0 {COMPOUND SUBQUERIES 1 AND 2 (INTERSECT)}
}
do_eqp_test 4.2.5 {
SELECT * FROM t1 EXCEPT SELECT * FROM t2 ORDER BY 1
} {
- 1 0 0 {SCAN TABLE t1 (~1000000 rows)}
+ 1 0 0 {SCAN TABLE t1}
1 0 0 {USE TEMP B-TREE FOR ORDER BY}
- 2 0 0 {SCAN TABLE t2 (~1000000 rows)}
+ 2 0 0 {SCAN TABLE t2}
2 0 0 {USE TEMP B-TREE FOR ORDER BY}
0 0 0 {COMPOUND SUBQUERIES 1 AND 2 (EXCEPT)}
}
@@ -333,28 +338,28 @@ do_eqp_test 4.2.5 {
do_eqp_test 4.3.1 {
SELECT x FROM t1 UNION SELECT x FROM t2
} {
- 1 0 0 {SCAN TABLE t1 (~1000000 rows)}
- 2 0 0 {SCAN TABLE t2 (~1000000 rows)}
+ 1 0 0 {SCAN TABLE t1}
+ 2 0 0 {SCAN TABLE t2 USING COVERING INDEX t2i1}
0 0 0 {COMPOUND SUBQUERIES 1 AND 2 USING TEMP B-TREE (UNION)}
}
do_eqp_test 4.3.2 {
SELECT x FROM t1 UNION SELECT x FROM t2 UNION SELECT x FROM t1
} {
- 2 0 0 {SCAN TABLE t1 (~1000000 rows)}
- 3 0 0 {SCAN TABLE t2 (~1000000 rows)}
+ 2 0 0 {SCAN TABLE t1}
+ 3 0 0 {SCAN TABLE t2 USING COVERING INDEX t2i1}
1 0 0 {COMPOUND SUBQUERIES 2 AND 3 USING TEMP B-TREE (UNION)}
- 4 0 0 {SCAN TABLE t1 (~1000000 rows)}
+ 4 0 0 {SCAN TABLE t1}
0 0 0 {COMPOUND SUBQUERIES 1 AND 4 USING TEMP B-TREE (UNION)}
}
do_eqp_test 4.3.3 {
SELECT x FROM t1 UNION SELECT x FROM t2 UNION SELECT x FROM t1 ORDER BY 1
} {
- 2 0 0 {SCAN TABLE t1 (~1000000 rows)}
+ 2 0 0 {SCAN TABLE t1}
2 0 0 {USE TEMP B-TREE FOR ORDER BY}
- 3 0 0 {SCAN TABLE t2 USING COVERING INDEX t2i1 (~1000000 rows)}
+ 3 0 0 {SCAN TABLE t2 USING COVERING INDEX t2i1}
1 0 0 {COMPOUND SUBQUERIES 2 AND 3 (UNION)}
- 4 0 0 {SCAN TABLE t1 (~1000000 rows)}
+ 4 0 0 {SCAN TABLE t1}
4 0 0 {USE TEMP B-TREE FOR ORDER BY}
0 0 0 {COMPOUND SUBQUERIES 1 AND 4 (UNION)}
}
@@ -365,128 +370,147 @@ do_eqp_test 4.3.3 {
#
drop_all_tables
-# EVIDENCE-OF: R-64208-08323 sqlite> EXPLAIN QUERY PLAN SELECT a, b
-# FROM t1 WHERE a=1; 0|0|0|SCAN TABLE t1 (~100000 rows)
-do_execsql_test 5.1.0 { CREATE TABLE t1(a, b) }
+# EVIDENCE-OF: R-47779-47605 sqlite> EXPLAIN QUERY PLAN SELECT a, b
+# FROM t1 WHERE a=1;
+# 0|0|0|SCAN TABLE 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 TABLE t1 (~100000 rows)}
+ 0 0 0 {SCAN TABLE t1}
}
-# EVIDENCE-OF: R-09022-44606 sqlite> CREATE INDEX i1 ON t1(a);
+# EVIDENCE-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 TABLE t1 USING INDEX i1 (a=?) (~10 rows)
+# 0|0|0|SEARCH TABLE 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 TABLE t1 USING INDEX i1 (a=?) (~10 rows)}
+ 0 0 0 {SEARCH TABLE t1 USING INDEX i1 (a=?)}
}
-# EVIDENCE-OF: R-62228-34103 sqlite> CREATE INDEX i2 ON t1(a, b);
+# EVIDENCE-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 TABLE t1 USING COVERING INDEX i2 (a=?) (~10 rows)
+# 0|0|0|SEARCH TABLE 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 TABLE t1 USING COVERING INDEX i2 (a=?) (~10 rows)}
+ 0 0 0 {SEARCH TABLE t1 USING COVERING INDEX i2 (a=?)}
}
-# EVIDENCE-OF: R-22253-05302 sqlite> EXPLAIN QUERY PLAN SELECT t1.*,
-# t2.* FROM t1, t2 WHERE t1.a=1 AND t1.b>2; 0|0|0|SEARCH TABLE t1
-# USING COVERING INDEX i2 (a=? AND b>?) (~3 rows) 0|1|1|SCAN TABLE t2
-# (~1000000 rows)
-do_execsql_test 5.4.0 {CREATE TABLE t2(c, d)}
-det 5.4.1 "SELECT t1.*, t2.* FROM t1, t2 WHERE t1.a=1 AND t1.b>2" {
- 0 0 0 {SEARCH TABLE t1 USING COVERING INDEX i2 (a=? AND b>?) (~2 rows)}
- 0 1 1 {SCAN TABLE t2 (~1000000 rows)}
+# EVIDENCE-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 TABLE t1 USING COVERING INDEX i2 (a=? AND b>?)
+# 0|1|1|SCAN TABLE 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 TABLE t1 USING COVERING INDEX i2 (a=? AND b>?)}
+ 0 1 1 {SCAN TABLE t2}
}
-# EVIDENCE-OF: R-21040-07025 sqlite> EXPLAIN QUERY PLAN SELECT t1.*,
-# t2.* FROM t2, t1 WHERE t1.a=1 AND t1.b>2; 0|0|1|SEARCH TABLE t1
-# USING COVERING INDEX i2 (a=? AND b>?) (~3 rows) 0|1|0|SCAN TABLE t2
-# (~1000000 rows)
-det 5.5 "SELECT t1.*, t2.* FROM t2, t1 WHERE t1.a=1 AND t1.b>2" {
- 0 0 1 {SEARCH TABLE t1 USING COVERING INDEX i2 (a=? AND b>?) (~2 rows)}
- 0 1 0 {SCAN TABLE t2 (~1000000 rows)}
+# EVIDENCE-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 TABLE t1 USING COVERING INDEX i2 (a=? AND b>?)
+# 0|1|0|SCAN TABLE t2
+#
+det 5.5 "SELECT t1.a, t2.c FROM t2, t1 WHERE t1.a=1 AND t1.b>2" {
+ 0 0 1 {SEARCH TABLE t1 USING COVERING INDEX i2 (a=? AND b>?)}
+ 0 1 0 {SCAN TABLE t2}
}
-# EVIDENCE-OF: R-39007-61103 sqlite> CREATE INDEX i3 ON t1(b);
+# EVIDENCE-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 TABLE t1 USING COVERING INDEX i2 (a=?) (~10 rows)
-# 0|0|0|SEARCH TABLE t1 USING INDEX i3 (b=?) (~10 rows)
+# 0|0|0|SEARCH TABLE t1 USING COVERING INDEX i2 (a=?)
+# 0|0|0|SEARCH TABLE t1 USING INDEX i3 (b=?)
+#
do_execsql_test 5.5.0 {CREATE INDEX i3 ON t1(b)}
-det 5.6.1 "SELECT * FROM t1 WHERE a=1 OR b=2" {
- 0 0 0 {SEARCH TABLE t1 USING COVERING INDEX i2 (a=?) (~10 rows)}
- 0 0 0 {SEARCH TABLE t1 USING INDEX i3 (b=?) (~10 rows)}
+det 5.6.1 "SELECT a, b FROM t1 WHERE a=1 OR b=2" {
+ 0 0 0 {SEARCH TABLE t1 USING COVERING INDEX i2 (a=?)}
+ 0 0 0 {SEARCH TABLE t1 USING INDEX i3 (b=?)}
}
-# EVIDENCE-OF: R-33025-54904 sqlite> EXPLAIN QUERY PLAN SELECT c, d
-# FROM t2 ORDER BY c; 0|0|0|SCAN TABLE t2 (~1000000 rows) 0|0|0|USE TEMP
-# B-TREE FOR ORDER BY
+# EVIDENCE-OF: R-24577-38891 sqlite> EXPLAIN QUERY PLAN
+# SELECT c, d FROM t2 ORDER BY c;
+# 0|0|0|SCAN TABLE 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 TABLE t2 (~1000000 rows)}
+ 0 0 0 {SCAN TABLE t2}
0 0 0 {USE TEMP B-TREE FOR ORDER BY}
}
-# EVIDENCE-OF: R-38854-22809 sqlite> CREATE INDEX i4 ON t2(c);
+# EVIDENCE-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 TABLE t2 USING INDEX i4 (~1000000 rows)
+# 0|0|0|SCAN TABLE 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 TABLE t2 USING INDEX i4 (~1000000 rows)}
+ 0 0 0 {SCAN TABLE t2 USING INDEX i4}
}
-# EVIDENCE-OF: R-29884-43993 sqlite> EXPLAIN QUERY PLAN SELECT
+# EVIDENCE-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 TABLE t2 (~1000000 rows) 0|0|0|EXECUTE SCALAR SUBQUERY 1
-# 1|0|0|SEARCH TABLE t1 USING COVERING INDEX i2 (a=?) (~10 rows)
-# 0|0|0|EXECUTE CORRELATED SCALAR SUBQUERY 2 2|0|0|SEARCH TABLE t1 USING
-# INDEX i3 (b=?) (~10 rows)
+# 0|0|0|SCAN TABLE t2
+# 0|0|0|EXECUTE SCALAR SUBQUERY 1
+# 1|0|0|SEARCH TABLE t1 USING COVERING INDEX i2 (a=?)
+# 0|0|0|EXECUTE CORRELATED SCALAR SUBQUERY 2
+# 2|0|0|SEARCH TABLE 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 TABLE t2 (~1000000 rows)}
+ 0 0 0 {SCAN TABLE t2 USING COVERING INDEX i4}
0 0 0 {EXECUTE SCALAR SUBQUERY 1}
- 1 0 0 {SEARCH TABLE t1 USING COVERING INDEX i2 (a=?) (~10 rows)}
+ 1 0 0 {SEARCH TABLE t1 USING COVERING INDEX i2 (a=?)}
0 0 0 {EXECUTE CORRELATED SCALAR SUBQUERY 2}
- 2 0 0 {SEARCH TABLE t1 USING INDEX i3 (b=?) (~10 rows)}
+ 2 0 0 {SEARCH TABLE t1 USING INDEX i3 (b=?)}
}
-# EVIDENCE-OF: R-17911-16445 sqlite> EXPLAIN QUERY PLAN SELECT
-# count(*) FROM (SELECT max(b) AS x FROM t1 GROUP BY a) GROUP BY x;
-# 1|0|0|SCAN TABLE t1 USING COVERING INDEX i2 (~1000000 rows) 0|0|0|SCAN
-# SUBQUERY 1 (~1000000 rows) 0|0|0|USE TEMP B-TREE FOR GROUP BY
+# EVIDENCE-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 TABLE 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 TABLE t1 USING COVERING INDEX i2 (~1000000 rows)}
- 0 0 0 {SCAN SUBQUERY 1 (~100 rows)}
+ 1 0 0 {SCAN TABLE t1 USING COVERING INDEX i2}
+ 0 0 0 {SCAN SUBQUERY 1}
0 0 0 {USE TEMP B-TREE FOR GROUP BY}
}
-# EVIDENCE-OF: R-18544-33103 sqlite> EXPLAIN QUERY PLAN SELECT * FROM
-# (SELECT * FROM t2 WHERE c=1), t1; 0|0|0|SEARCH TABLE t2 USING INDEX i4
-# (c=?) (~10 rows) 0|1|1|SCAN TABLE t1 (~1000000 rows)
-det 5.11 "SELECT * FROM (SELECT * FROM t2 WHERE c=1), t1" {
- 0 0 0 {SEARCH TABLE t2 USING INDEX i4 (c=?) (~10 rows)}
- 0 1 1 {SCAN TABLE t1 (~1000000 rows)}
+# EVIDENCE-OF: R-46219-33846 sqlite> EXPLAIN QUERY PLAN
+# SELECT * FROM (SELECT * FROM t2 WHERE c=1), t1;
+# 0|0|0|SEARCH TABLE t2 USING INDEX i4 (c=?)
+# 0|1|1|SCAN TABLE t1
+#
+det 5.11 "SELECT a, b FROM (SELECT * FROM t2 WHERE c=1), t1" {
+ 0 0 0 {SEARCH TABLE t2 USING INDEX i4 (c=?)}
+ 0 1 1 {SCAN TABLE t1 USING COVERING INDEX i2}
}
-# EVIDENCE-OF: R-40701-42164 sqlite> EXPLAIN QUERY PLAN SELECT a FROM
-# t1 UNION SELECT c FROM t2; 1|0|0|SCAN TABLE t1 (~1000000 rows)
-# 2|0|0|SCAN TABLE t2 (~1000000 rows) 0|0|0|COMPOUND SUBQUERIES 1 AND 2
-# USING TEMP B-TREE (UNION)
-det 5.12 "SELECT a FROM t1 UNION SELECT c FROM t2" {
- 1 0 0 {SCAN TABLE t1 (~1000000 rows)}
- 2 0 0 {SCAN TABLE t2 (~1000000 rows)}
+# EVIDENCE-OF: R-37879-39987 sqlite> EXPLAIN QUERY PLAN
+# SELECT a FROM t1 UNION SELECT c FROM t2;
+# 1|0|0|SCAN TABLE t1
+# 2|0|0|SCAN TABLE 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 TABLE t1 USING COVERING INDEX i2}
+ 2 0 0 {SCAN TABLE t2 USING COVERING INDEX i4}
0 0 0 {COMPOUND SUBQUERIES 1 AND 2 USING TEMP B-TREE (UNION)}
}
-# EVIDENCE-OF: R-61538-24748 sqlite> EXPLAIN QUERY PLAN SELECT a FROM
-# t1 EXCEPT SELECT d FROM t2 ORDER BY 1; 1|0|0|SCAN TABLE t1 USING
-# COVERING INDEX i2 (~1000000 rows) 2|0|0|SCAN TABLE t2 (~1000000 rows)
-# 2|0|0|USE TEMP B-TREE FOR ORDER BY 0|0|0|COMPOUND SUBQUERIES 1 AND 2
-# (EXCEPT)
+# EVIDENCE-OF: R-44864-63011 sqlite> EXPLAIN QUERY PLAN
+# SELECT a FROM t1 EXCEPT SELECT d FROM t2 ORDER BY 1;
+# 1|0|0|SCAN TABLE t1 USING COVERING INDEX i2
+# 2|0|0|SCAN TABLE 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 TABLE t1 USING COVERING INDEX i2 (~1000000 rows)}
- 2 0 0 {SCAN TABLE t2 (~1000000 rows)}
+ 1 0 0 {SCAN TABLE t1 USING COVERING INDEX i1}
+ 2 0 0 {SCAN TABLE t2}
2 0 0 {USE TEMP B-TREE FOR ORDER BY}
0 0 0 {COMPOUND SUBQUERIES 1 AND 2 (EXCEPT)}
}
@@ -497,6 +521,7 @@ det 5.13 "SELECT a FROM t1 EXCEPT SELECT d FROM t2 ORDER BY 1" {
# documentation page eqp.html works. The C code is duplicated in test1.c
# and wrapped in Tcl command [print_explain_query_plan]
#
+db close
set boilerplate {
proc explain_query_plan {db sql} {
set stmt [sqlite3_prepare_v2 db $sql -1 DUMMY]
@@ -524,14 +549,15 @@ proc do_peqp_test {tn sql res} {
}
do_peqp_test 6.1 {
- SELECT a FROM t1 EXCEPT SELECT d FROM t2 ORDER BY 1
+ SELECT a, b FROM t1 EXCEPT SELECT d, 99 FROM t2 ORDER BY 1
} [string trimleft {
-1 0 0 SCAN TABLE t1 USING COVERING INDEX i2 (~1000000 rows)
-2 0 0 SCAN TABLE t2 (~1000000 rows)
+1 0 0 SCAN TABLE t1 USING COVERING INDEX i2
+2 0 0 SCAN TABLE t2
2 0 0 USE TEMP B-TREE FOR ORDER BY
0 0 0 COMPOUND SUBQUERIES 1 AND 2 (EXCEPT)
}]
+sqlite3 db test.db
#-------------------------------------------------------------------------
# The following tests - eqp-7.* - test that queries that use the OP_Count
# optimization return something sensible with EQP.
@@ -539,26 +565,26 @@ do_peqp_test 6.1 {
drop_all_tables
do_execsql_test 7.0 {
- CREATE TABLE t1(a, b);
- CREATE TABLE t2(a, b);
+ 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" {
- 0 0 0 {SCAN TABLE t1 (~1000000 rows)}
+ 0 0 0 {SCAN TABLE t1}
}
det 7.2 "SELECT count(*) FROM t2" {
- 0 0 0 {SCAN TABLE t2 USING COVERING INDEX i1(~1000000 rows)}
+ 0 0 0 {SCAN TABLE t2 USING COVERING INDEX i1}
}
do_execsql_test 7.3 {
- INSERT INTO t1 VALUES(1, 2);
- INSERT INTO t1 VALUES(3, 4);
+ INSERT INTO t1(a,b) VALUES(1, 2);
+ INSERT INTO t1(a,b) VALUES(3, 4);
- INSERT INTO t2 VALUES(1, 2);
- INSERT INTO t2 VALUES(3, 4);
- INSERT INTO t2 VALUES(5, 6);
+ 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;
}
@@ -567,11 +593,11 @@ db close
sqlite3 db test.db
det 7.4 "SELECT count(*) FROM t1" {
- 0 0 0 {SCAN TABLE t1 (~2 rows)}
+ 0 0 0 {SCAN TABLE t1}
}
det 7.5 "SELECT count(*) FROM t2" {
- 0 0 0 {SCAN TABLE t2 USING COVERING INDEX i1(~3 rows)}
+ 0 0 0 {SCAN TABLE t2 USING COVERING INDEX i1}
}
diff --git a/lang/sql/sqlite/test/errmsg.test b/lang/sql/sqlite/test/errmsg.test
new file mode 100644
index 00000000..8df8a704
--- /dev/null
+++ b/lang/sql/sqlite/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 or missing database}
+ 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 or missing database}
+ 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 or missing database}
+ 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/lang/sql/sqlite/test/exclusive.test b/lang/sql/sqlite/test/exclusive.test
index db79d303..c000dfef 100644
--- a/lang/sql/sqlite/test/exclusive.test
+++ b/lang/sql/sqlite/test/exclusive.test
@@ -22,12 +22,12 @@ ifcapable {!pager_pragmas} {
return
}
-file delete -force test2.db-journal
-file delete -force test2.db
-file delete -force test3.db-journal
-file delete -force test3.db
-file delete -force test4.db-journal
-file delete -force test4.db
+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.
@@ -481,8 +481,8 @@ do_execsql_test exclusive-6.1 {
}
do_test exclusive-6.2 {
forcedelete test2.db test2.db-journal
- file copy test.db test2.db
- file copy test.db-journal test2.db-journal
+ copy_file test.db test2.db
+ copy_file test.db-journal test2.db-journal
sqlite3 db test2.db
} {}
@@ -506,4 +506,3 @@ do_execsql_test exclusive-6.5 {
} {exclusive}
finish_test
-
diff --git a/lang/sql/sqlite/test/exclusive2.test b/lang/sql/sqlite/test/exclusive2.test
index 18f304db..712363e7 100644
--- a/lang/sql/sqlite/test/exclusive2.test
+++ b/lang/sql/sqlite/test/exclusive2.test
@@ -25,6 +25,14 @@ ifcapable {!pager_pragmas} {
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.
#
@@ -259,8 +267,8 @@ do_test exclusive2-2.8 {
db close
catch {close $::fd}
-file delete -force test.db
-file delete -force test.db-journal
+forcedelete test.db
+forcedelete test.db-journal
do_test exclusive2-3.0 {
sqlite3 db test.db
@@ -293,7 +301,6 @@ do_test exclusive2-3.3 {
readPagerChangeCounter test.db
} {4}
do_test exclusive2-3.4 {
-breakpoint
execsql {
INSERT INTO t1 VALUES(randstr(200, 200));
}
diff --git a/lang/sql/sqlite/test/exists.test b/lang/sql/sqlite/test/exists.test
index c7c14a24..fb73797d 100644
--- a/lang/sql/sqlite/test/exists.test
+++ b/lang/sql/sqlite/test/exists.test
@@ -159,7 +159,7 @@ foreach jm {rollback wal} {
sql1 { DROP INDEX IF EXISTS i2 }
sql2 { CREATE INDEX aux.i2 ON t2(x) }
sql1 { DROP INDEX IF EXISTS i2 }
- sql2 { SELECT name FROM aux.sqlite_master WHERE type = 'index' }
+ sql2 { SELECT * FROM aux.sqlite_master WHERE type = 'index' }
} {}
# VIEW objects.
diff --git a/lang/sql/sqlite/test/expr.test b/lang/sql/sqlite/test/expr.test
index 5a3d1675..cc4c9c67 100644
--- a/lang/sql/sqlite/test/expr.test
+++ b/lang/sql/sqlite/test/expr.test
@@ -32,6 +32,11 @@ proc test_expr {name settings expr result} {
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
@@ -164,7 +169,7 @@ ifcapable floatingpoint {
}
if {[working_64bit_int]} {
- test_expr expr-1.106 {i1=0} {-9223372036854775808/-1} 9.22337203685478e+18
+ test_realnum_expr expr-1.106 {i1=0} {-9223372036854775808/-1} 9.22337203685478e+18
}
test_expr expr-1.107 {i1=0} {-9223372036854775808%-1} 0
@@ -203,100 +208,100 @@ test_expr expr-1.126 {i1=8, i2=8} \
ifcapable floatingpoint {if {[working_64bit_int]} {
test_expr expr-1.200\
{i1=9223372036854775806, i2=1} {i1+i2} 9223372036854775807
- test_expr expr-1.201\
+ test_realnum_expr expr-1.201\
{i1=9223372036854775806, i2=2} {i1+i2} 9.22337203685478e+18
- test_expr expr-1.202\
+ test_realnum_expr expr-1.202\
{i1=9223372036854775806, i2=100000} {i1+i2} 9.22337203685488e+18
- test_expr expr-1.203\
+ test_realnum_expr expr-1.203\
{i1=9223372036854775807, i2=0} {i1+i2} 9223372036854775807
- test_expr expr-1.204\
+ test_realnum_expr expr-1.204\
{i1=9223372036854775807, i2=1} {i1+i2} 9.22337203685478e+18
- test_expr expr-1.205\
+ test_realnum_expr expr-1.205\
{i2=9223372036854775806, i1=1} {i1+i2} 9223372036854775807
- test_expr expr-1.206\
+ test_realnum_expr expr-1.206\
{i2=9223372036854775806, i1=2} {i1+i2} 9.22337203685478e+18
- test_expr expr-1.207\
+ test_realnum_expr expr-1.207\
{i2=9223372036854775806, i1=100000} {i1+i2} 9.22337203685488e+18
- test_expr expr-1.208\
+ test_realnum_expr expr-1.208\
{i2=9223372036854775807, i1=0} {i1+i2} 9223372036854775807
- test_expr expr-1.209\
+ test_realnum_expr expr-1.209\
{i2=9223372036854775807, i1=1} {i1+i2} 9.22337203685478e+18
- test_expr expr-1.210\
+ test_realnum_expr expr-1.210\
{i1=-9223372036854775807, i2=-1} {i1+i2} -9223372036854775808
- test_expr expr-1.211\
+ test_realnum_expr expr-1.211\
{i1=-9223372036854775807, i2=-2} {i1+i2} -9.22337203685478e+18
- test_expr expr-1.212\
+ test_realnum_expr expr-1.212\
{i1=-9223372036854775807, i2=-100000} {i1+i2} -9.22337203685488e+18
- test_expr expr-1.213\
+ test_realnum_expr expr-1.213\
{i1=-9223372036854775808, i2=0} {i1+i2} -9223372036854775808
- test_expr expr-1.214\
+ test_realnum_expr expr-1.214\
{i1=-9223372036854775808, i2=-1} {i1+i2} -9.22337203685478e+18
- test_expr expr-1.215\
+ test_realnum_expr expr-1.215\
{i2=-9223372036854775807, i1=-1} {i1+i2} -9223372036854775808
- test_expr expr-1.216\
+ test_realnum_expr expr-1.216\
{i2=-9223372036854775807, i1=-2} {i1+i2} -9.22337203685478e+18
- test_expr expr-1.217\
+ test_realnum_expr expr-1.217\
{i2=-9223372036854775807, i1=-100000} {i1+i2} -9.22337203685488e+18
- test_expr expr-1.218\
+ test_realnum_expr expr-1.218\
{i2=-9223372036854775808, i1=0} {i1+i2} -9223372036854775808
- test_expr expr-1.219\
+ test_realnum_expr expr-1.219\
{i2=-9223372036854775808, i1=-1} {i1+i2} -9.22337203685478e+18
- test_expr expr-1.220\
+ test_realnum_expr expr-1.220\
{i1=9223372036854775806, i2=-1} {i1-i2} 9223372036854775807
- test_expr expr-1.221\
+ test_realnum_expr expr-1.221\
{i1=9223372036854775806, i2=-2} {i1-i2} 9.22337203685478e+18
- test_expr expr-1.222\
+ test_realnum_expr expr-1.222\
{i1=9223372036854775806, i2=-100000} {i1-i2} 9.22337203685488e+18
- test_expr expr-1.223\
+ test_realnum_expr expr-1.223\
{i1=9223372036854775807, i2=0} {i1-i2} 9223372036854775807
- test_expr expr-1.224\
+ test_realnum_expr expr-1.224\
{i1=9223372036854775807, i2=-1} {i1-i2} 9.22337203685478e+18
- test_expr expr-1.225\
+ test_realnum_expr expr-1.225\
{i2=-9223372036854775806, i1=1} {i1-i2} 9223372036854775807
- test_expr expr-1.226\
+ test_realnum_expr expr-1.226\
{i2=-9223372036854775806, i1=2} {i1-i2} 9.22337203685478e+18
- test_expr expr-1.227\
+ test_realnum_expr expr-1.227\
{i2=-9223372036854775806, i1=100000} {i1-i2} 9.22337203685488e+18
- test_expr expr-1.228\
+ test_realnum_expr expr-1.228\
{i2=-9223372036854775807, i1=0} {i1-i2} 9223372036854775807
- test_expr expr-1.229\
+ test_realnum_expr expr-1.229\
{i2=-9223372036854775807, i1=1} {i1-i2} 9.22337203685478e+18
- test_expr expr-1.230\
+ test_realnum_expr expr-1.230\
{i1=-9223372036854775807, i2=1} {i1-i2} -9223372036854775808
- test_expr expr-1.231\
+ test_realnum_expr expr-1.231\
{i1=-9223372036854775807, i2=2} {i1-i2} -9.22337203685478e+18
- test_expr expr-1.232\
+ test_realnum_expr expr-1.232\
{i1=-9223372036854775807, i2=100000} {i1-i2} -9.22337203685488e+18
- test_expr expr-1.233\
+ test_realnum_expr expr-1.233\
{i1=-9223372036854775808, i2=0} {i1-i2} -9223372036854775808
- test_expr expr-1.234\
+ test_realnum_expr expr-1.234\
{i1=-9223372036854775808, i2=1} {i1-i2} -9.22337203685478e+18
- test_expr expr-1.235\
+ test_realnum_expr expr-1.235\
{i2=9223372036854775807, i1=-1} {i1-i2} -9223372036854775808
- test_expr expr-1.236\
+ test_realnum_expr expr-1.236\
{i2=9223372036854775807, i1=-2} {i1-i2} -9.22337203685478e+18
- test_expr expr-1.237\
+ test_realnum_expr expr-1.237\
{i2=9223372036854775807, i1=-100000} {i1-i2} -9.22337203685488e+18
- test_expr expr-1.238\
+ test_realnum_expr expr-1.238\
{i2=9223372036854775807, i1=0} {i1-i2} -9223372036854775807
- test_expr expr-1.239\
+ test_realnum_expr expr-1.239\
{i2=9223372036854775807, i1=-1} {i1-i2} -9223372036854775808
- test_expr expr-1.250\
+ test_realnum_expr expr-1.250\
{i1=4294967296, i2=2147483648} {i1*i2} 9.22337203685478e+18
- test_expr expr-1.251\
+ test_realnum_expr expr-1.251\
{i1=4294967296, i2=2147483647} {i1*i2} 9223372032559808512
- test_expr expr-1.252\
+ test_realnum_expr expr-1.252\
{i1=-4294967296, i2=2147483648} {i1*i2} -9223372036854775808
- test_expr expr-1.253\
+ test_realnum_expr expr-1.253\
{i1=-4294967296, i2=2147483647} {i1*i2} -9223372032559808512
- test_expr expr-1.254\
+ test_realnum_expr expr-1.254\
{i1=4294967296, i2=-2147483648} {i1*i2} -9223372036854775808
- test_expr expr-1.255\
+ test_realnum_expr expr-1.255\
{i1=4294967296, i2=-2147483647} {i1*i2} -9223372032559808512
- test_expr expr-1.256\
+ test_realnum_expr expr-1.256\
{i1=-4294967296, i2=-2147483648} {i1*i2} 9.22337203685478e+18
- test_expr expr-1.257\
+ test_realnum_expr expr-1.257\
{i1=-4294967296, i2=-2147483647} {i1*i2} 9223372032559808512
}}
@@ -883,7 +888,7 @@ do_test expr-12.2 {
} {1 {near ")": syntax error}}
ifcapable floatingpoint {
- do_test expr-13.1 {
+ do_realnum_test expr-13.1 {
execsql {
SELECT 12345678901234567890;
}
@@ -908,12 +913,12 @@ if {[working_64bit_int]} {
# If the value is too large, use String->Float conversion.
#
ifcapable floatingpoint {
- do_test expr-13.4 {
+ do_realnum_test expr-13.4 {
execsql {
SELECT 0+'9223372036854775808'
}
} {9.22337203685478e+18}
- do_test expr-13.5 {
+ do_realnum_test expr-13.5 {
execsql {
SELECT '9223372036854775808'+0
}
@@ -923,12 +928,12 @@ ifcapable floatingpoint {
# Use String->float conversion if the value is explicitly a floating
# point value.
#
-do_test expr-13.6 {
+do_realnum_test expr-13.6 {
execsql {
SELECT 0+'9223372036854775807.0'
}
} {9.22337203685478e+18}
-do_test expr-13.7 {
+do_realnum_test expr-13.7 {
execsql {
SELECT '9223372036854775807.0'+0
}
diff --git a/lang/sql/sqlite/test/fallocate.test b/lang/sql/sqlite/test/fallocate.test
index 05aa2a81..f523c2cc 100644
--- a/lang/sql/sqlite/test/fallocate.test
+++ b/lang/sql/sqlite/test/fallocate.test
@@ -79,7 +79,7 @@ ifcapable !wal { set skipwaltests 1 }
if {!$skipwaltests} {
db close
- file delete -force test.db
+ forcedelete test.db
sqlite3 db test.db
file_control_chunksize_test db main [expr 32*1024]
@@ -143,4 +143,3 @@ if {!$skipwaltests} {
finish_test
-
diff --git a/lang/sql/sqlite/test/filectrl.test b/lang/sql/sqlite/test/filectrl.test
index 67e81830..1d878bf9 100644
--- a/lang/sql/sqlite/test/filectrl.test
+++ b/lang/sql/sqlite/test/filectrl.test
@@ -34,8 +34,14 @@ do_test filectrl-1.4 {
do_test filectrl-1.5 {
db close
sqlite3 db test_control_lockproxy.db
- file_control_lockproxy_test db [pwd]
+ file_control_lockproxy_test db [get_pwd]
} {}
+do_test filectrl-1.6 {
+ sqlite3 db test.db
+ set fn [file_control_tempfilename db]
+ puts -nonewline \[$fn\]
+ set fn
+} {/etilqs_/}
db close
-file delete -force .test_control_lockproxy.db-conch test.proxy
+forcedelete .test_control_lockproxy.db-conch test.proxy
finish_test
diff --git a/lang/sql/sqlite/test/filefmt.test b/lang/sql/sqlite/test/filefmt.test
index 72edbeeb..2df14244 100644
--- a/lang/sql/sqlite/test/filefmt.test
+++ b/lang/sql/sqlite/test/filefmt.test
@@ -23,7 +23,7 @@ source $testdir/tester.tcl
do_not_use_codec
db close
-file delete -force test.db test.db-journal
+forcedelete test.db test.db-journal
# Database begins with valid 16-byte header string.
#
@@ -63,7 +63,7 @@ ifcapable pager_pragmas {
&& $pagesize>$SQLITE_MAX_PAGE_SIZE} continue
do_test filefmt-1.5.$pagesize.1 {
db close
- file delete -force test.db
+ forcedelete test.db
sqlite3 db test.db
db eval "PRAGMA auto_vacuum=OFF"
db eval "PRAGMA page_size=$pagesize"
@@ -105,7 +105,7 @@ do_test filefmt-1.7 {
ifcapable pager_pragmas {
do_test filefmt-1.8 {
db close
- file delete -force test.db
+ forcedelete test.db
sqlite3 db test.db
db eval {PRAGMA page_size=512; CREATE TABLE t1(x)}
db close
@@ -125,7 +125,7 @@ ifcapable pager_pragmas {
# always derives this from the size of the file.
#
db close
-file delete -force test.db
+forcedelete test.db
set a_string_counter 1
proc a_string {n} {
@@ -157,7 +157,7 @@ integrity_check filefmt-2.1.5
do_test filefmt-2.1.6 { hexio_read test.db 28 4 } {00000010}
db close
-file delete -force test.db
+forcedelete test.db
sqlite3 db test.db
db func a_string a_string
@@ -213,4 +213,38 @@ do_execsql_test filefmt-3.3 {
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/lang/sql/sqlite/test/fkey1.test b/lang/sql/sqlite/test/fkey1.test
index e7c00d16..90a4c444 100644
--- a/lang/sql/sqlite/test/fkey1.test
+++ b/lang/sql/sqlite/test/fkey1.test
@@ -117,5 +117,8 @@ do_test fkey1-3.4 {
{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}
finish_test
diff --git a/lang/sql/sqlite/test/fkey2.test b/lang/sql/sqlite/test/fkey2.test
index f0cc4d24..4c8daa0b 100644
--- a/lang/sql/sqlite/test/fkey2.test
+++ b/lang/sql/sqlite/test/fkey2.test
@@ -104,49 +104,56 @@ set FkeySimpleSchema {
set FkeySimpleTests {
- 1.1 "INSERT INTO t2 VALUES(1, 3)" {1 {foreign key constraint failed}}
+ 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.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.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.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.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.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.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.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.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.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}}
+ 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 { catchsql $zSql } $res
+ 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
@@ -155,6 +162,12 @@ do_test fkey2-1.2.0 {
} {}
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
@@ -165,6 +178,12 @@ do_test fkey2-1.3.0 {
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
@@ -196,7 +215,7 @@ do_test fkey2-1.5.1 {
} {35.0 text}
do_test fkey2-1.5.2 {
catchsql { DELETE FROM i }
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
# Same test using a regular primary key with integer affinity.
drop_all_tables
@@ -212,7 +231,7 @@ do_test fkey2-1.6.1 {
} {35.0 text 35 integer}
do_test fkey2-1.6.2 {
catchsql { DELETE FROM i }
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
# Use a collation sequence on the parent key.
drop_all_tables
@@ -224,7 +243,7 @@ do_test fkey2-1.7.1 {
INSERT INTO j VALUES('sqlite');
}
catchsql { DELETE FROM i }
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
# Use the parent key collation even if it is default and the child key
# has an explicit value.
@@ -236,7 +255,7 @@ do_test fkey2-1.7.2 {
INSERT INTO i VALUES('SQLite');
}
catchsql { INSERT INTO j VALUES('sqlite') }
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test fkey2-1.7.3 {
execsql {
INSERT INTO i VALUES('sqlite');
@@ -244,7 +263,7 @@ do_test fkey2-1.7.3 {
DELETE FROM i WHERE i = 'SQLite';
}
catchsql { DELETE FROM i WHERE i = 'sqlite' }
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
#-------------------------------------------------------------------------
# This section (test cases fkey2-2.*) contains tests to check that the
@@ -252,7 +271,7 @@ do_test fkey2-1.7.3 {
#
proc fkey2-2-test {tn nocommit sql {res {}}} {
if {$res eq "FKV"} {
- set expected {1 {foreign key constraint failed}}
+ set expected {1 {FOREIGN KEY constraint failed}}
} else {
set expected [list 0 $res]
}
@@ -260,7 +279,7 @@ proc fkey2-2-test {tn nocommit sql {res {}}} {
if {$nocommit} {
do_test fkey2-2.${tn}c {
catchsql COMMIT
- } {1 {foreign key constraint failed}}
+ } {1 {FOREIGN KEY constraint failed}}
}
}
@@ -356,7 +375,7 @@ 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 {column nodeid is not unique}}
+} {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)"
@@ -398,14 +417,14 @@ do_test fkey2-3.1.2 {
} {}
do_test fkey2-3.1.3 {
catchsql { UPDATE ab SET a = 5 }
-} {1 {constraint failed}}
+} {1 {CHECK constraint failed: ef}}
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 {constraint failed}}
+} {1 {CHECK constraint failed: ef}}
do_test fkey2-3.1.5 {
execsql COMMIT;
execsql { SELECT * FROM ab; SELECT * FROM cd; SELECT * FROM ef }
@@ -414,7 +433,7 @@ do_test fkey2-3.1.5 {
do_test fkey2-3.2.1 {
execsql BEGIN;
catchsql { DELETE FROM ab }
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test fkey2-3.2.2 {
execsql COMMIT
execsql { SELECT * FROM ab; SELECT * FROM cd; SELECT * FROM ef }
@@ -536,7 +555,7 @@ do_test fkey2-7.1 {
} {}
do_test fkey2-7.2 {
catchsql { INSERT INTO t2 VALUES(1, 'A'); }
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test fkey2-7.3 {
execsql {
INSERT INTO t1 VALUES(1, 2);
@@ -549,19 +568,19 @@ do_test fkey2-7.4 {
} {}
do_test fkey2-7.5 {
catchsql { UPDATE t2 SET c = 3 }
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test fkey2-7.6 {
catchsql { DELETE FROM t1 WHERE a = 2 }
-} {1 {foreign key constraint failed}}
+} {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}}
+} {1 {FOREIGN KEY constraint failed}}
do_test fkey2-7.9 {
catchsql { UPDATE t2 SET rowid = 3 }
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
#-------------------------------------------------------------------------
# Test that it is not possible to enable/disable FK support while a
@@ -626,7 +645,7 @@ do_test fkey2-9.1.4 {
} {2 two}
do_test fkey2-9.1.5 {
catchsql { DELETE FROM t1 }
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test fkey2-9.2.1 {
execsql {
@@ -681,7 +700,7 @@ foreach zSql [list {
do_test fkey2-10.1.[incr tn] {
execsql $zSql
catchsql { INSERT INTO c DEFAULT VALUES }
- } {1 {foreign key mismatch}}
+ } {/1 {foreign key mismatch - "c" referencing "."}/}
}
# "rowid" cannot be used as part of a child or parent key definition
@@ -709,7 +728,7 @@ do_test fkey2-10.2.1 {
INSERT INTO t1(rowid, a, b) VALUES(1, 1, 1);
INSERT INTO t2 VALUES(1, 1);
}
-} {1 {foreign key mismatch}}
+} {1 {foreign key mismatch - "t2" referencing "t1"}}
do_test fkey2-10.2.2 {
drop_all_tables
catchsql {
@@ -761,13 +780,13 @@ do_test fkey2-12.1.3 {
} {}
do_test fkey2-12.1.4 {
catchsql "UPDATE t1 SET b = 'five' WHERE b = 'two'"
-} {1 {foreign key constraint failed}}
+} {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}}
+} {1 {FOREIGN KEY constraint failed}}
do_test fkey2-12.1.7 {
execsql {
INSERT INTO t1 VALUES(2, 'two');
@@ -809,7 +828,7 @@ do_test fkey2-12.2.3 {
INSERT INTO t2 VALUES('b');
}
catchsql { DELETE FROM t1 }
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test fkey2-12.2.4 {
execsql {
SELECT * FROM t1;
@@ -847,14 +866,14 @@ do_test fkey2-12.3.2 {
} {no possibly}
do_test fkey2-12.3.3 {
catchsql { INSERT INTO down(c39, c38) VALUES('yes', 'no') }
-} {1 {foreign key constraint failed}}
+} {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}}
+} {1 {FOREIGN KEY constraint failed}}
do_test fkey2-12.3.5 {
execsql {
DELETE FROM up WHERE c34 = 'possibly';
@@ -882,7 +901,7 @@ foreach {tn stmt} {
} {
do_test fkey2-13.1.$tn.1 {
catchsql $stmt
- } {1 {foreign key constraint failed}}
+ } {1 {FOREIGN KEY constraint failed}}
do_test fkey2-13.1.$tn.2 {
execsql {
SELECT * FROM pp;
@@ -892,7 +911,7 @@ foreach {tn stmt} {
do_test fkey2-13.1.$tn.3 {
execsql BEGIN;
catchsql $stmt
- } {1 {foreign key constraint failed}}
+ } {1 {FOREIGN KEY constraint failed}}
do_test fkey2-13.1.$tn.4 {
execsql {
COMMIT;
@@ -996,13 +1015,13 @@ ifcapable altertable {
]
do_test fkey2-14.2.2.3 {
catchsql { INSERT INTO t3 VALUES(1, 2, 3) }
- } {1 {foreign key constraint failed}}
+ } {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}}
+ } {1 {FOREIGN KEY constraint failed}}
do_test fkey2-14.2.2.6 {
catchsql { UPDATE t4 SET b = 1 }
} {0 {}}
@@ -1077,13 +1096,13 @@ ifcapable altertable {
]
do_test fkey2-14.2tmp.2.3 {
catchsql { INSERT INTO t3 VALUES(1, 2, 3) }
- } {1 {foreign key constraint failed}}
+ } {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}}
+ } {1 {FOREIGN KEY constraint failed}}
do_test fkey2-14.2tmp.2.6 {
catchsql { UPDATE t4 SET b = 1 }
} {0 {}}
@@ -1159,13 +1178,13 @@ ifcapable altertable {
]
do_test fkey2-14.2aux.2.3 {
catchsql { INSERT INTO t3 VALUES(1, 2, 3) }
- } {1 {foreign key constraint failed}}
+ } {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}}
+ } {1 {FOREIGN KEY constraint failed}}
do_test fkey2-14.2aux.2.6 {
catchsql { UPDATE t4 SET b = 1 }
} {0 {}}
@@ -1191,7 +1210,7 @@ do_test fkey-2.14.3.2 {
} {}
do_test fkey-2.14.3.3 {
catchsql { DROP TABLE t1 }
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test fkey-2.14.3.4 {
execsql {
DELETE FROM t2;
@@ -1210,7 +1229,7 @@ do_test fkey-2.14.3.5 {
} {}
do_test fkey-2.14.3.6 {
catchsql { DROP TABLE t1 }
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test fkey-2.14.3.7 {
execsql {
DROP TABLE t2;
@@ -1223,7 +1242,7 @@ do_test fkey-2.14.3.8 {
CREATE TABLE cc(a, b, FOREIGN KEY(a, b) REFERENCES pp(x, z));
}
catchsql { INSERT INTO cc VALUES(1, 2) }
-} {1 {foreign key mismatch}}
+} {1 {foreign key mismatch - "cc" referencing "pp"}}
do_test fkey-2.14.3.9 {
execsql { DROP TABLE cc }
} {}
@@ -1368,15 +1387,15 @@ foreach {tn zSchema} {
do_test fkey2-16.1.$tn.3 {
catchsql { UPDATE self SET b = 15 }
- } {1 {foreign key constraint failed}}
+ } {1 {FOREIGN KEY constraint failed}}
do_test fkey2-16.1.$tn.4 {
catchsql { UPDATE self SET a = 15 }
- } {1 {foreign key constraint failed}}
+ } {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}}
+ } {1 {FOREIGN KEY constraint failed}}
do_test fkey2-16.1.$tn.6 {
catchsql { UPDATE self SET a = 17, b = 17 }
@@ -1387,7 +1406,7 @@ foreach {tn zSchema} {
} {}
do_test fkey2-16.1.$tn.8 {
catchsql { INSERT INTO self VALUES(20, 21) }
- } {1 {foreign key constraint failed}}
+ } {1 {FOREIGN KEY constraint failed}}
}
#-------------------------------------------------------------------------
@@ -1414,10 +1433,12 @@ 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
@@ -1426,6 +1447,7 @@ ifcapable autoreset {
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);
@@ -1441,7 +1463,7 @@ do_test fkey2-17.1.6 {
INSERT INTO one VALUES(0, 0, 0);
UPDATE two SET e=e+1, f=f+1;
}
-} {1 {foreign key constraint failed}}
+} {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}
@@ -1469,9 +1491,11 @@ do_test fkey2-17.1.12 {
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 {
@@ -1595,7 +1619,7 @@ ifcapable auth {
}
do_test fkey2-18.8 {
catchsql { INSERT INTO short VALUES(1, 3, 2) }
- } {1 {foreign key constraint failed}}
+ } {1 {FOREIGN KEY constraint failed}}
do_test fkey2-18.9 {
execsql { INSERT INTO short VALUES(1, 3, NULL) }
} {}
@@ -1604,7 +1628,7 @@ ifcapable auth {
} {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}}
+ } {1 {FOREIGN KEY constraint failed}}
db auth {}
unset authargs
@@ -1625,9 +1649,11 @@ do_test fkey2-19.2 {
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
@@ -1654,7 +1680,7 @@ foreach {tn insert} {
} {
do_test fkey2-20.2.$tn.1 {
catchsql "$insert INTO cc VALUES(1, 2)"
- } {1 {foreign key constraint failed}}
+ } {1 {FOREIGN KEY constraint failed}}
do_test fkey2-20.2.$tn.2 {
execsql { SELECT * FROM cc }
} {}
@@ -1665,7 +1691,7 @@ foreach {tn insert} {
INSERT INTO cc VALUES(1, 2);
}
catchsql "$insert INTO cc VALUES(3, 4)"
- } {1 {foreign key constraint failed}}
+ } {1 {FOREIGN KEY constraint failed}}
do_test fkey2-20.2.$tn.4 {
execsql { COMMIT ; SELECT * FROM cc }
} {1 2}
@@ -1690,13 +1716,13 @@ foreach {tn update} {
} {}
do_test fkey2-20.3.$tn.2 {
catchsql "$update pp SET a = 1"
- } {1 {foreign key constraint failed}}
+ } {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}}
+ } {1 {FOREIGN KEY constraint failed}}
do_test fkey2-20.3.$tn.5 {
execsql { SELECT * FROM cc }
} {1 2}
@@ -1706,7 +1732,7 @@ foreach {tn update} {
INSERT INTO pp VALUES(3, 'three');
}
catchsql "$update pp SET a = 1 WHERE a = 2"
- } {1 {foreign key constraint failed}}
+ } {1 {FOREIGN KEY constraint failed}}
do_test fkey2-20.3.$tn.7 {
execsql { COMMIT ; SELECT * FROM pp }
} {2 two 3 three}
@@ -1716,7 +1742,7 @@ foreach {tn update} {
INSERT INTO cc VALUES(2, 2);
}
catchsql "$update cc SET d = 1 WHERE c = 1"
- } {1 {foreign key constraint failed}}
+ } {1 {FOREIGN KEY constraint failed}}
do_test fkey2-20.3.$tn.9 {
execsql { COMMIT ; SELECT * FROM cc }
} {1 2 2 2}
@@ -1742,7 +1768,7 @@ do_test fkey2-genfkey.1.1 {
} {}
do_test fkey2-genfkey.1.2 {
catchsql { INSERT INTO t2 VALUES(1, 2) }
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test fkey2-genfkey.1.3 {
execsql {
INSERT INTO t1 VALUES(1, 2, 3);
@@ -1754,7 +1780,7 @@ do_test fkey2-genfkey.1.4 {
} {}
do_test fkey2-genfkey.1.5 {
catchsql { UPDATE t2 SET e = 5 WHERE e IS NULL }
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test fkey2-genfkey.1.6 {
execsql { UPDATE t2 SET e = 1 WHERE e IS NULL }
} {}
@@ -1763,13 +1789,13 @@ do_test fkey2-genfkey.1.7 {
} {}
do_test fkey2-genfkey.1.8 {
catchsql { UPDATE t1 SET a = 10 }
-} {1 {foreign key constraint failed}}
+} {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}}
+} {1 {FOREIGN KEY constraint failed}}
do_test fkey2-genfkey.1.11 {
execsql { UPDATE t2 SET e = NULL }
} {}
@@ -1789,7 +1815,7 @@ do_test fkey2-genfkey.1.13 {
} {}
do_test fkey2-genfkey.1.14 {
catchsql { INSERT INTO t3 VALUES(3, 1, 4) }
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test fkey2-genfkey.1.15 {
execsql {
INSERT INTO t1 VALUES(1, 1, 4);
@@ -1798,16 +1824,16 @@ do_test fkey2-genfkey.1.15 {
} {}
do_test fkey2-genfkey.1.16 {
catchsql { DELETE FROM t1 }
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test fkey2-genfkey.1.17 {
catchsql { UPDATE t1 SET b = 10}
-} {1 {foreign key constraint failed}}
+} {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}}
+} {1 {FOREIGN KEY constraint failed}}
drop_all_tables
do_test fkey2-genfkey.2.1 {
@@ -1920,7 +1946,7 @@ do_test fkey2-dd08e5.1.2 {
catchsql {
DELETE FROM tdd08;
}
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test fkey2-dd08e5.1.3 {
execsql {
SELECT * FROM tdd08;
@@ -1930,17 +1956,17 @@ do_test fkey2-dd08e5.1.4 {
catchsql {
INSERT INTO tdd08_b VALUES(400,500,300);
}
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test fkey2-dd08e5.1.5 {
catchsql {
UPDATE tdd08_b SET x=x+1;
}
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test fkey2-dd08e5.1.6 {
catchsql {
UPDATE tdd08 SET a=a+1;
}
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
#-------------------------------------------------------------------------
# Verify that ticket ce7c133ea6cc9ccdc1a60d80441f80b6180f5eba
@@ -1961,12 +1987,12 @@ do_test fkey2-ce7c13.1.2 {
catchsql {
UPDATE tce71 set b = 201 where a = 100;
}
-} {1 {foreign key constraint failed}}
+} {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}}
+} {1 {FOREIGN KEY constraint failed}}
do_test fkey2-ce7c13.1.4 {
execsql {
CREATE TABLE tce73(a INTEGER PRIMARY KEY, b, UNIQUE(a,b));
@@ -1981,11 +2007,11 @@ do_test fkey2-ce7c13.1.5 {
catchsql {
UPDATE tce73 set b = 201 where a = 100;
}
-} {1 {foreign key constraint failed}}
+} {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}}
+} {1 {FOREIGN KEY constraint failed}}
finish_test
diff --git a/lang/sql/sqlite/test/fkey3.test b/lang/sql/sqlite/test/fkey3.test
index 88b5aad3..a8d03820 100644
--- a/lang/sql/sqlite/test/fkey3.test
+++ b/lang/sql/sqlite/test/fkey3.test
@@ -21,6 +21,8 @@ ifcapable {!foreignkey||!trigger} {
return
}
+set testprefix fkey3
+
# Create a table and some data to work with.
#
do_test fkey3-1.1 {
@@ -41,13 +43,13 @@ do_test fkey3-1.2 {
catchsql {
DELETE FROM t1 WHERE x=100;
}
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test fkey3-1.3 {
catchsql {
DROP TABLE t1;
}
-} {1 {foreign key constraint failed}}
+} {1 {FOREIGN KEY constraint failed}}
do_test fkey3-1.4 {
execsql {
@@ -77,4 +79,108 @@ do_test fkey3-2.1 {
}
} {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/lang/sql/sqlite/test/fkey4.test b/lang/sql/sqlite/test/fkey4.test
index d6dd2fc8..79cf6634 100644
--- a/lang/sql/sqlite/test/fkey4.test
+++ b/lang/sql/sqlite/test/fkey4.test
@@ -42,10 +42,12 @@ do_test fkey4-1.2 {
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}
diff --git a/lang/sql/sqlite/test/fkey5.test b/lang/sql/sqlite/test/fkey5.test
new file mode 100644
index 00000000..5aa8b1d4
--- /dev/null
+++ b/lang/sql/sqlite/test/fkey5.test
@@ -0,0 +1,363 @@
+# 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-05426-18119 PRAGMA foreign_key_check; PRAGMA
+# foreign_key_check(table-name);
+
+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.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);
+ }
+} {}
+
+# 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-25219-25618 The second column is the rowid of the row
+# that contains the invalid REFERENCES clause.
+#
+# 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 {
+ 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;
+ }
+} {c14 1 p4 0 c14 3 p4 0 c14 6 p4 0 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-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}
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/fkey6.test b/lang/sql/sqlite/test/fkey6.test
new file mode 100644
index 00000000..6fc3de21
--- /dev/null
+++ b/lang/sql/sqlite/test/fkey6.test
@@ -0,0 +1,175 @@
+# 2013-07-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 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
+
+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}
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/fkey7.test b/lang/sql/sqlite/test/fkey7.test
new file mode 100644
index 00000000..c2682edb
--- /dev/null
+++ b/lang/sql/sqlite/test/fkey7.test
@@ -0,0 +1,54 @@
+# 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}
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/fkey_malloc.test b/lang/sql/sqlite/test/fkey_malloc.test
index 05a2a4f4..382e6f67 100644
--- a/lang/sql/sqlite/test/fkey_malloc.test
+++ b/lang/sql/sqlite/test/fkey_malloc.test
@@ -29,6 +29,7 @@ do_malloc_test fkey_malloc-1 -sqlprep {
INSERT INTO t2 VALUES('aaa');
UPDATE t1 SET a = 'bbb';
DELETE FROM t1;
+ PRAGMA foreign_key_check;
}
do_malloc_test fkey_malloc-2 -sqlprep {
@@ -68,7 +69,10 @@ proc catch_fk_error {zSql} {
if {[string match {*foreign key*} $msg]} {
return ""
}
- if {$msg eq "out of memory"} {
+ if {$msg eq "out of memory"
+ || $msg eq "FOREIGN KEY constraint failed"
+ || $msg eq "constraint failed"
+ } {
error 1
}
error $msg
@@ -128,5 +132,3 @@ do_malloc_test fkey_malloc-7 -sqlprep {
}
finish_test
-
-
diff --git a/lang/sql/sqlite/test/fts-9fd058691.test b/lang/sql/sqlite/test/fts-9fd058691.test
new file mode 100644
index 00000000..b228482d
--- /dev/null
+++ b/lang/sql/sqlite/test/fts-9fd058691.test
@@ -0,0 +1,59 @@
+# 2011 October 13
+#
+# May you 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 FTS SQLite module.
+#
+# This file implements tests to verify that ticket [9fd058691] has been
+# fixed.
+#
+
+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 fts3-9fd058691
+
+do_execsql_test 1.0 {
+ CREATE VIRTUAL TABLE fts USING fts3( tags TEXT);
+ INSERT INTO fts (tags) VALUES ('tag1');
+ SELECT * FROM fts WHERE tags MATCH 'tag1';
+} {tag1}
+
+do_test 1.1 {
+ db close
+ sqlite3 db test.db
+ execsql {
+ UPDATE fts SET tags = 'tag1' WHERE rowid = 1;
+ SELECT * FROM fts WHERE tags MATCH 'tag1';
+ }
+} {tag1}
+
+db close
+forcedelete test.db
+sqlite3 db test.db
+
+do_execsql_test 2.0 {
+ CREATE VIRTUAL TABLE fts USING fts3(tags TEXT);
+ INSERT INTO fts (docid, tags) VALUES (1, 'tag1');
+ INSERT INTO fts (docid, tags) VALUES (2, NULL);
+ INSERT INTO fts (docid, tags) VALUES (3, 'three');
+} {}
+
+do_test 2.1 {
+ execsql {
+ UPDATE fts SET tags = 'two' WHERE rowid = 2;
+ SELECT * FROM fts WHERE tags MATCH 'two';
+ }
+} {two}
+
+finish_test
diff --git a/lang/sql/sqlite/test/fts1j.test b/lang/sql/sqlite/test/fts1j.test
index 5ff0d0ed..4dac22ab 100644
--- a/lang/sql/sqlite/test/fts1j.test
+++ b/lang/sql/sqlite/test/fts1j.test
@@ -19,8 +19,8 @@ ifcapable !fts1 {
}
# Clean up anything left over from a previous pass.
-file delete -force test2.db
-file delete -force test2.db-journal
+forcedelete test2.db
+forcedelete test2.db-journal
sqlite3 db2 test2.db
db eval {
@@ -84,6 +84,6 @@ do_test fts1j-1.3 {
catch {db eval {DETACH DATABASE two}}
catch {db2 close}
-file delete -force test2.db
+forcedelete test2.db
finish_test
diff --git a/lang/sql/sqlite/test/fts1o.test b/lang/sql/sqlite/test/fts1o.test
index 92666c6f..61fd74ca 100644
--- a/lang/sql/sqlite/test/fts1o.test
+++ b/lang/sql/sqlite/test/fts1o.test
@@ -95,7 +95,7 @@ do_test fts1o-3.6 {
# Test that it is possible to rename an fts1 table in an attached
# database.
#
-file delete -force test2.db test2.db-journal
+forcedelete test2.db test2.db-journal
do_test fts1o-4.1 {
execsql {
diff --git a/lang/sql/sqlite/test/fts2j.test b/lang/sql/sqlite/test/fts2j.test
index b8a89b20..a8a2c07c 100644
--- a/lang/sql/sqlite/test/fts2j.test
+++ b/lang/sql/sqlite/test/fts2j.test
@@ -19,8 +19,8 @@ ifcapable !fts2 {
}
# Clean up anything left over from a previous pass.
-file delete -force test2.db
-file delete -force test2.db-journal
+forcedelete test2.db
+forcedelete test2.db-journal
sqlite3 db2 test2.db
db eval {
@@ -84,6 +84,6 @@ do_test fts2j-1.3 {
catch {db eval {DETACH DATABASE two}}
catch {db2 close}
-file delete -force test2.db
+forcedelete test2.db
finish_test
diff --git a/lang/sql/sqlite/test/fts2o.test b/lang/sql/sqlite/test/fts2o.test
index 5a33c455..63e71b95 100644
--- a/lang/sql/sqlite/test/fts2o.test
+++ b/lang/sql/sqlite/test/fts2o.test
@@ -109,7 +109,7 @@ do_test fts2o-2.12 {
# be run on an initially empty db.
#
db close
-file delete -force test.db test.db-journal
+forcedelete test.db test.db-journal
sqlite3 db test.db
do_test fts2o-3.1 {
@@ -134,7 +134,7 @@ do_test fts2o-3.2 {
# Test that it is possible to rename an fts2 table in an attached
# database.
#
-file delete -force test2.db test2.db-journal
+forcedelete test2.db test2.db-journal
do_test fts2o-3.1 {
execsql {
diff --git a/lang/sql/sqlite/test/fts3_common.tcl b/lang/sql/sqlite/test/fts3_common.tcl
index 4d4ae38b..2ed1f70b 100644
--- a/lang/sql/sqlite/test/fts3_common.tcl
+++ b/lang/sql/sqlite/test/fts3_common.tcl
@@ -15,6 +15,129 @@
#
#-------------------------------------------------------------------------
+# INSTRUCTIONS
+#
+# The following commands are available:
+#
+# fts3_build_db_1 N
+# Using database handle [db] create an FTS4 table named t1 and populate
+# it with N rows of data. N must be less than 10,000. Refer to the
+# header comments above the proc implementation below for details.
+#
+# fts3_build_db_2 N
+# Using database handle [db] create an FTS4 table named t2 and populate
+# it with N rows of data. N must be less than 100,000. Refer to the
+# header comments above the proc implementation below for details.
+#
+# fts3_integrity_check TBL
+# TBL must be an FTS table in the database currently opened by handle
+# [db]. This proc loads and tokenizes all documents within the table,
+# then checks that the current contents of the FTS index matches the
+# results.
+#
+# fts3_terms TBL WHERE
+# Todo.
+#
+# fts3_doclist TBL TERM WHERE
+# Todo.
+#
+#
+#
+
+#-------------------------------------------------------------------------
+# USAGE: fts3_build_db_1 SWITCHES N
+#
+# Build a sample FTS table in the database opened by database connection
+# [db]. The name of the new table is "t1".
+#
+proc fts3_build_db_1 {args} {
+
+ set default(-module) fts4
+
+ 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 > 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
@@ -46,6 +169,7 @@ 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} {
@@ -97,7 +221,7 @@ proc fts3_integrity_check {tbl} {
set es "Error at docid=$iDoc col=$iCol pos=$pos. Index is missing"
lappend errors $es
} else {
- if {$C($iDoc,$iCol,$pos) != "$term"} {
+ 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
@@ -233,7 +357,8 @@ proc fts3_readleaf {blob} {
set zTerm [string range $zPrev 0 [expr $nPrefix-1]]
append zTerm [gobble_string blob $nSuffix]
- set doclist [gobble_string blob [gobble_varint blob]]
+ set nDoclist [gobble_varint blob]
+ set doclist [gobble_string blob $nDoclist]
lappend terms $zTerm $doclist
set zPrev $zTerm
@@ -249,7 +374,9 @@ proc fts3_read2 {tbl where varname} {
FROM ${tbl}_segdir WHERE $where
ORDER BY level ASC, idx DESC
" {
- if {$start_block == 0} {
+ 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
@@ -258,7 +385,6 @@ proc fts3_read2 {tbl where varname} {
ORDER BY blockid
" {
foreach {t d} [fts3_readleaf $block] { lappend a($t) $d }
-
}
}
}
diff --git a/lang/sql/sqlite/test/fts3aa.test b/lang/sql/sqlite/test/fts3aa.test
index 5d79e931..6ff384a0 100644
--- a/lang/sql/sqlite/test/fts3aa.test
+++ b/lang/sql/sqlite/test/fts3aa.test
@@ -146,7 +146,6 @@ do_test fts3aa-3.3 {
execsql {SELECT rowid FROM t1 WHERE content MATCH '-two one'}
} {1 5 9 13 17 21 25 29}
-breakpoint
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}
@@ -224,4 +223,3 @@ do_catchsql_test fts3aa-7.5 {
finish_test
-
diff --git a/lang/sql/sqlite/test/fts3ab.test b/lang/sql/sqlite/test/fts3ab.test
index e1f3bdc9..86124f78 100644
--- a/lang/sql/sqlite/test/fts3ab.test
+++ b/lang/sql/sqlite/test/fts3ab.test
@@ -115,7 +115,6 @@ for {set i 1} {$i<=15} {incr i} {
db eval "INSERT INTO t4(norm,plusone,invert) VALUES([join $vset ,]);"
}
-breakpoint
do_test fts3ab-4.1 {
execsql {SELECT rowid FROM t4 WHERE t4 MATCH 'norm:one'}
} {1 3 5 7 9 11 13 15}
diff --git a/lang/sql/sqlite/test/fts3ag.test b/lang/sql/sqlite/test/fts3ag.test
index 18ed5ae3..9b658d19 100644
--- a/lang/sql/sqlite/test/fts3ag.test
+++ b/lang/sql/sqlite/test/fts3ag.test
@@ -78,7 +78,6 @@ do_test fts3ag-1.10 {
# Test that docListOrMerge() correctly handles reaching the end of one
# doclist before it reaches the end of the other.
do_test fts3ag-1.11 {
-breakpoint
execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'this OR also'}
} {1 2}
do_test fts3ag-1.12 {
diff --git a/lang/sql/sqlite/test/fts3ai.test b/lang/sql/sqlite/test/fts3ai.test
index 144b4c3e..b17b5bdd 100644
--- a/lang/sql/sqlite/test/fts3ai.test
+++ b/lang/sql/sqlite/test/fts3ai.test
@@ -19,6 +19,11 @@ ifcapable !fts3 {
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.
diff --git a/lang/sql/sqlite/test/fts3aj.test b/lang/sql/sqlite/test/fts3aj.test
index 60d26c02..f3d46f2a 100644
--- a/lang/sql/sqlite/test/fts3aj.test
+++ b/lang/sql/sqlite/test/fts3aj.test
@@ -19,8 +19,8 @@ ifcapable !fts3 {
}
# Clean up anything left over from a previous pass.
-file delete -force test2.db
-file delete -force test2.db-journal
+forcedelete test2.db
+forcedelete test2.db-journal
sqlite3 db2 test2.db
db eval {
@@ -84,6 +84,6 @@ do_test fts3aj-1.3 {
catch {db eval {DETACH DATABASE two}}
catch {db2 close}
-file delete -force test2.db
+forcedelete test2.db
finish_test
diff --git a/lang/sql/sqlite/test/fts3ao.test b/lang/sql/sqlite/test/fts3ao.test
index cd9df01e..91693094 100644
--- a/lang/sql/sqlite/test/fts3ao.test
+++ b/lang/sql/sqlite/test/fts3ao.test
@@ -111,7 +111,7 @@ do_test fts3ao-2.12 {
# be run on an initially empty db.
#
db close
-file delete -force test.db test.db-journal
+forcedelete test.db test.db-journal
sqlite3 db test.db
do_test fts3ao-3.1 {
@@ -136,7 +136,7 @@ do_test fts3ao-3.2 {
# Test that it is possible to rename an fts3 table in an attached
# database.
#
-file delete -force test2.db test2.db-journal
+forcedelete test2.db test2.db-journal
do_test fts3ao-3.1 {
execsql {
@@ -200,6 +200,9 @@ do_test fts3ao-4.7 {
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.
@@ -217,4 +220,3 @@ do_execsql_test 5.2 {
} {0 6}
finish_test
-
diff --git a/lang/sql/sqlite/test/fts3atoken.test b/lang/sql/sqlite/test/fts3atoken.test
index cf9574e8..b7722c7d 100644
--- a/lang/sql/sqlite/test/fts3atoken.test
+++ b/lang/sql/sqlite/test/fts3atoken.test
@@ -24,6 +24,8 @@ ifcapable !fts3 {
return
}
+set ::testprefix fts3token
+
proc escape_string {str} {
set out ""
foreach char [split $str ""] {
@@ -165,10 +167,29 @@ ifcapable icu {
do_icu_test fts3token-4.6 MiddleOfTheOcean $input $output
do_icu_test fts3token-4.7 th_TH $input $output
do_icu_test fts3token-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 fts3token-internal {
execsql { SELECT fts3_tokenizer_internal_test() }
} {ok}
+
finish_test
diff --git a/lang/sql/sqlite/test/fts3auto.test b/lang/sql/sqlite/test/fts3auto.test
new file mode 100644
index 00000000..20640d29
--- /dev/null
+++ b/lang/sql/sqlite/test/fts3auto.test
@@ -0,0 +1,709 @@
+# 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 "<column-name>: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} {
+ 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*}
+}
+
+#--------------------------------------------------------------------------
+# 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/lang/sql/sqlite/test/fts3aux1.test b/lang/sql/sqlite/test/fts3aux1.test
index 5359521a..d17ac85d 100644
--- a/lang/sql/sqlite/test/fts3aux1.test
+++ b/lang/sql/sqlite/test/fts3aux1.test
@@ -38,10 +38,10 @@ do_execsql_test 1.2 {
six 1 1 three 4 6 two 1 1
}
-do_execsql_test 1.3 {
- DELETE FROM t1;
+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');
@@ -105,10 +105,10 @@ db func rec rec
#
do_execsql_test 2.1.1.1 {
EXPLAIN QUERY PLAN SELECT * FROM terms WHERE term='braid'
-} { 0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 1: (~0 rows)} }
+} { 0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 1:} }
do_execsql_test 2.1.1.2 {
EXPLAIN QUERY PLAN SELECT * FROM terms WHERE +term='braid'
-} {0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 0: (~0 rows)}}
+} {0 0 0 {SCAN TABLE 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.
@@ -154,24 +154,24 @@ 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'
-} { 0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 2: (~0 rows)} }
+} { 0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 2:} }
do_execsql_test 2.2.1.2 {
EXPLAIN QUERY PLAN SELECT * FROM terms WHERE +term>'brain'
-} { 0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 0: (~0 rows)} }
+} { 0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 0:} }
do_execsql_test 2.2.1.3 {
EXPLAIN QUERY PLAN SELECT * FROM terms WHERE term<'brain'
-} { 0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 4: (~0 rows)} }
+} { 0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 4:} }
do_execsql_test 2.2.1.4 {
EXPLAIN QUERY PLAN SELECT * FROM terms WHERE +term<'brain'
-} { 0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 0: (~0 rows)} }
+} { 0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 0:} }
do_execsql_test 2.2.1.5 {
EXPLAIN QUERY PLAN SELECT * FROM terms WHERE term BETWEEN 'brags' AND 'brain'
-} { 0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 6: (~0 rows)} }
+} { 0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 6:} }
do_execsql_test 2.2.1.6 {
EXPLAIN QUERY PLAN SELECT * FROM terms WHERE +term BETWEEN 'brags' AND 'brain'
-} { 0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 0: (~0 rows)} }
+} { 0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 0:} }
do_test 2.2.2.1 {
set cnt 0
@@ -335,7 +335,7 @@ foreach {tn sort orderby} {
9 1 "ORDER BY occurrences DESC"
} {
- set res [list 0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 0: (~0 rows)}]
+ set res [list 0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 0:}]
if {$sort} { lappend res 0 0 0 {USE TEMP B-TREE FOR ORDER BY} }
set sql "SELECT * FROM terms $orderby"
@@ -354,10 +354,10 @@ do_execsql_test 3.1.1 {
do_catchsql_test 3.1.2 {
CREATE VIRTUAL TABLE terms2 USING fts4aux;
-} {1 {wrong number of arguments to fts4aux constructor}}
+} {1 {invalid arguments to fts4aux constructor}}
do_catchsql_test 3.1.3 {
CREATE VIRTUAL TABLE terms2 USING fts4aux(t2, t2);
-} {1 {wrong number of arguments to fts4aux constructor}}
+} {1 {invalid arguments to fts4aux constructor}}
do_execsql_test 3.2.1 {
CREATE VIRTUAL TABLE terms3 USING fts4aux(does_not_exist)
@@ -410,32 +410,32 @@ proc do_plansql_test {tn sql r} {
do_plansql_test 4.2 {
SELECT y FROM x2, terms WHERE y = term AND col = '*'
} {
- 0 0 0 {SCAN TABLE x2 (~1000000 rows)}
- 0 1 1 {SCAN TABLE terms VIRTUAL TABLE INDEX 1: (~0 rows)}
+ 0 0 0 {SCAN TABLE x2}
+ 0 1 1 {SCAN TABLE 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 = '*'
} {
- 0 0 1 {SCAN TABLE x2 (~1000000 rows)}
- 0 1 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 1: (~0 rows)}
+ 0 0 1 {SCAN TABLE x2}
+ 0 1 0 {SCAN TABLE 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 = '*'
} {
- 0 0 1 {SCAN TABLE terms VIRTUAL TABLE INDEX 0: (~0 rows)}
- 0 1 0 {SEARCH TABLE x3 USING COVERING INDEX i1 (y=?) (~10 rows)}
+ 0 0 1 {SCAN TABLE terms VIRTUAL TABLE INDEX 0:}
+ 0 1 0 {SEARCH TABLE 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 = '*'
} {
- 0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 0: (~0 rows)}
- 0 1 1 {SEARCH TABLE x3 USING COVERING INDEX i1 (y=?) (~10 rows)}
+ 0 0 0 {SCAN TABLE terms VIRTUAL TABLE INDEX 0:}
+ 0 1 1 {SEARCH TABLE x3 USING COVERING INDEX i1 (y=?)}
a k l
}
@@ -444,7 +444,6 @@ do_plansql_test 4.5 {
# 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');
@@ -458,5 +457,65 @@ do_execsql_test 5.2 {
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 or missing database}}
finish_test
diff --git a/lang/sql/sqlite/test/fts3aux2.test b/lang/sql/sqlite/test/fts3aux2.test
new file mode 100644
index 00000000..e108fc4b
--- /dev/null
+++ b/lang/sql/sqlite/test/fts3aux2.test
@@ -0,0 +1,144 @@
+# 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
+}
+
+finish_test
diff --git a/lang/sql/sqlite/test/fts3conf.test b/lang/sql/sqlite/test/fts3conf.test
new file mode 100644
index 00000000..e91efbef
--- /dev/null
+++ b/lang/sql/sqlite/test/fts3conf.test
@@ -0,0 +1,181 @@
+# 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" 1 1 {{a b c d} {e f g h}}
+ 12 "UPDATE OR ABORT $T3" 1 1 {{a b c d} {e f g h} {i j k l}}
+ 13 "UPDATE OR FAIL $T3" 1 1 {{a b c d} {e f g h} {i j k l}}
+ 14 "UPDATE OR IGNORE $T3" 1 0 {{a b c d} {e f g h} {i j k l}}
+ 15 "UPDATE OR REPLACE $T3" 1 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
+
+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'}
+
+finish_test
diff --git a/lang/sql/sqlite/test/fts3corrupt.test b/lang/sql/sqlite/test/fts3corrupt.test
index b8b45c39..cb50e3e4 100644
--- a/lang/sql/sqlite/test/fts3corrupt.test
+++ b/lang/sql/sqlite/test/fts3corrupt.test
@@ -40,6 +40,7 @@ do_test fts3corrupt-1.2 {
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;
}
@@ -69,6 +70,7 @@ do_test fts3corrupt-2.1 {
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;
@@ -86,6 +88,7 @@ do_test fts3corrupt-3.1 {
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 {
@@ -111,6 +114,7 @@ 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] \
@@ -130,6 +134,7 @@ 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
@@ -152,11 +157,12 @@ 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
finish_test
-
diff --git a/lang/sql/sqlite/test/fts3d.test b/lang/sql/sqlite/test/fts3d.test
index 715980d8..818456bf 100644
--- a/lang/sql/sqlite/test/fts3d.test
+++ b/lang/sql/sqlite/test/fts3d.test
@@ -253,7 +253,6 @@ 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.
-breakpoint
do_test fts3d-4.5 {
execsql {
SELECT OPTIMIZE(t1) FROM t1 LIMIT 1;
@@ -304,4 +303,57 @@ do_test fts3d-5.1 {
}
} {{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}
+
+
finish_test
diff --git a/lang/sql/sqlite/test/fts3defer.test b/lang/sql/sqlite/test/fts3defer.test
index 1c9056fd..532d4dfa 100644
--- a/lang/sql/sqlite/test/fts3defer.test
+++ b/lang/sql/sqlite/test/fts3defer.test
@@ -13,13 +13,15 @@ set testdir [file dirname $argv0]
source $testdir/tester.tcl
source $testdir/malloc_common.tcl
-ifcapable !fts3 {
+ifcapable !fts3||!fts4_deferred {
finish_test
return
}
set sqlite_fts3_enable_parentheses 1
+set fts3_simple_deferred_tokens_only 1
+
set ::testprefix fts3defer
#--------------------------------------------------------------------------
@@ -257,7 +259,6 @@ foreach {tn setup} {
do_select_test 1.2 {
SELECT rowid FROM t1 WHERE t1 MATCH 'jk eh'
} {100}
-if {$tn==3} breakpoint
do_select_test 1.3 {
SELECT rowid FROM t1 WHERE t1 MATCH 'jk ubwrfqnbjf'
} {7 70 98}
@@ -282,13 +283,16 @@ if {$tn==3} breakpoint
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}
- 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}
+
+ 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"'
@@ -364,6 +368,7 @@ if {$tn==3} breakpoint
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}
@@ -416,9 +421,23 @@ if {$tn==3} breakpoint
do_select_test 6.2.2 {
SELECT rowid FROM t1 WHERE t1 MATCH '"zm azavwm"'
} {15 26 92 96}
- do_select_test 6.2.3 {
- SELECT rowid FROM t1 WHERE t1 MATCH '"jk xduvfhk" OR "zm azavwm"'
- } {8 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
@@ -442,5 +461,67 @@ 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/lang/sql/sqlite/test/fts3defer2.test b/lang/sql/sqlite/test/fts3defer2.test
index 84418033..608371f1 100644
--- a/lang/sql/sqlite/test/fts3defer2.test
+++ b/lang/sql/sqlite/test/fts3defer2.test
@@ -13,7 +13,10 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
source $testdir/malloc_common.tcl
-ifcapable !fts3 { finish_test ; return }
+ifcapable !fts3||!fts4_deferred {
+ finish_test
+ return
+}
set testprefix fts3defer2
@@ -48,6 +51,10 @@ do_execsql_test 1.1.4 {
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}}
@@ -58,7 +65,7 @@ do_execsql_test 1.2.2 {
} [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 8 8 1 8 8 8 5001 9]
+ [list 3 1 1 1 1 1 1 1 1 1 1 8 5001 9]
]
do_execsql_test 1.2.3 {
@@ -67,7 +74,7 @@ do_execsql_test 1.2.3 {
} [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 8 8 2 8 8 8 5001 9]
+ [list 3 1 1 1 1 1 1 1 2 2 1 8 5001 9]
]
do_execsql_test 1.3.1 { DROP TABLE t1 }
@@ -99,8 +106,14 @@ foreach {tn sql} {
[list 2 1 1 54 54 1 3 3 54 372 7] \
]
- set sqlite_fts3_enable_parentheses 1
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] \
@@ -140,4 +153,3 @@ foreach {tn sql} {
finish_test
-
diff --git a/lang/sql/sqlite/test/fts3defer3.test b/lang/sql/sqlite/test/fts3defer3.test
new file mode 100644
index 00000000..a795e92b
--- /dev/null
+++ b/lang/sql/sqlite/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/lang/sql/sqlite/test/fts3drop.test b/lang/sql/sqlite/test/fts3drop.test
new file mode 100644
index 00000000..8b76eafe
--- /dev/null
+++ b/lang/sql/sqlite/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/lang/sql/sqlite/test/fts3expr.test b/lang/sql/sqlite/test/fts3expr.test
index e7c4f655..192219f1 100644
--- a/lang/sql/sqlite/test/fts3expr.test
+++ b/lang/sql/sqlite/test/fts3expr.test
@@ -28,6 +28,7 @@ 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}
@@ -495,5 +496,17 @@ do_test fts3expr-7.1 {
} {}
+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
finish_test
diff --git a/lang/sql/sqlite/test/fts3expr3.test b/lang/sql/sqlite/test/fts3expr3.test
new file mode 100644
index 00000000..a8d73192
--- /dev/null
+++ b/lang/sql/sqlite/test/fts3expr3.test
@@ -0,0 +1,206 @@
+# 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
+}
+
+# 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]
+}
+
+set sqlite_fts3_enable_parentheses 0
+finish_test
diff --git a/lang/sql/sqlite/test/fts3fault.test b/lang/sql/sqlite/test/fts3fault.test
index 2dd7bbbc..ab82daa9 100644
--- a/lang/sql/sqlite/test/fts3fault.test
+++ b/lang/sql/sqlite/test/fts3fault.test
@@ -18,8 +18,6 @@ set ::testprefix fts3fault
# If SQLITE_ENABLE_FTS3 is not defined, omit this file.
ifcapable !fts3 { finish_test ; return }
-if 1 {
-
# Test error handling in the sqlite3Fts3Init() function. This is the
# function that registers the FTS3 module and various support functions
# with SQLite.
@@ -146,7 +144,8 @@ do_faultsim_test 7.2 -prep {
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 {vtable constructor failed: t1}} \
+ {1 {SQL logic error or missing database}}
}
do_faultsim_test 7.3 -prep {
faultsim_delete_and_reopen
@@ -154,9 +153,8 @@ do_faultsim_test 7.3 -prep {
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 {vtable constructor failed: t1}} \
+ {1 {SQL logic error or missing database}}
}
proc mit {blob} {
diff --git a/lang/sql/sqlite/test/fts3fault2.test b/lang/sql/sqlite/test/fts3fault2.test
index fb877737..f2d10bc3 100644
--- a/lang/sql/sqlite/test/fts3fault2.test
+++ b/lang/sql/sqlite/test/fts3fault2.test
@@ -82,4 +82,77 @@ do_faultsim_test 2.1 -prep {
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}}
+ }
+}
+
finish_test
diff --git a/lang/sql/sqlite/test/fts3first.test b/lang/sql/sqlite/test/fts3first.test
new file mode 100644
index 00000000..673f818d
--- /dev/null
+++ b/lang/sql/sqlite/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/lang/sql/sqlite/test/fts3join.test b/lang/sql/sqlite/test/fts3join.test
new file mode 100644
index 00000000..64363639
--- /dev/null
+++ b/lang/sql/sqlite/test/fts3join.test
@@ -0,0 +1,66 @@
+# 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}}
+
+finish_test
+
+
diff --git a/lang/sql/sqlite/test/fts3malloc.test b/lang/sql/sqlite/test/fts3malloc.test
index 932ea098..ed30fe24 100644
--- a/lang/sql/sqlite/test/fts3malloc.test
+++ b/lang/sql/sqlite/test/fts3malloc.test
@@ -62,6 +62,9 @@ do_error_test fts3_malloc-1.5 {
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 }
@@ -81,6 +84,7 @@ do_test fts3_malloc-2.0 {
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} {
@@ -294,10 +298,10 @@ do_write_test fts3_malloc-5.1 ft_content {
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/lang/sql/sqlite/test/fts3matchinfo.test b/lang/sql/sqlite/test/fts3matchinfo.test
index 8f194e72..fd475af2 100644
--- a/lang/sql/sqlite/test/fts3matchinfo.test
+++ b/lang/sql/sqlite/test/fts3matchinfo.test
@@ -19,6 +19,7 @@ source $testdir/tester.tcl
ifcapable !fts3 { finish_test ; return }
set testprefix fts3matchinfo
+set sqlite_fts3_enable_parentheses 0
proc mit {blob} {
set scan(littleEndian) i*
@@ -57,6 +58,9 @@ do_catchsql_test 2.0 {
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.
#
@@ -68,7 +72,11 @@ do_execsql_test 3.1 {
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';
}
@@ -220,6 +228,18 @@ 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;
@@ -240,9 +260,13 @@ 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]')";
-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}
+# 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} }
@@ -251,11 +275,14 @@ 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 {
- INSERT INTO t5(t5) VALUES('optimize');
- UPDATE t5_segments
- SET block = zeroblob(length(block))
- WHERE length(block)>10000;
+do_execsql_test 4.4.0.1 { INSERT INTO t5(t5) VALUES('optimize') }
+
+ifcapable fts4_deferred {
+ 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} }
@@ -380,5 +407,30 @@ do_catchsql_test 8.5.3.2 {
SELECT mit(matchinfo(t11, 'nxa')) FROM t11 WHERE t11 MATCH 'a*'
} {1 {database disk image is malformed}}
-finish_test
+#-------------------------------------------------------------------------
+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]}}
+
+finish_test
diff --git a/lang/sql/sqlite/test/fts3near.test b/lang/sql/sqlite/test/fts3near.test
index 9c4409e1..2d9981e5 100644
--- a/lang/sql/sqlite/test/fts3near.test
+++ b/lang/sql/sqlite/test/fts3near.test
@@ -165,7 +165,6 @@ do_test fts3near-3.6 {
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}}
-breakpoint
do_test fts3near-3.7 {
execsql {
SELECT offsets(t1) FROM t1 WHERE content MATCH '"two four" NEAR/0 three'}
@@ -580,5 +579,19 @@ do_test fts3near-6.5 {
}
} {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/lang/sql/sqlite/test/fts3prefix.test b/lang/sql/sqlite/test/fts3prefix.test
new file mode 100644
index 00000000..e7c197da
--- /dev/null
+++ b/lang/sql/sqlite/test/fts3prefix.test
@@ -0,0 +1,213 @@
+# 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 {}}
+
+finish_test
diff --git a/lang/sql/sqlite/test/fts3prefix2.test b/lang/sql/sqlite/test/fts3prefix2.test
new file mode 100644
index 00000000..e033fb6b
--- /dev/null
+++ b/lang/sql/sqlite/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/lang/sql/sqlite/test/fts3query.test b/lang/sql/sqlite/test/fts3query.test
index c8f8686b..2d12351a 100644
--- a/lang/sql/sqlite/test/fts3query.test
+++ b/lang/sql/sqlite/test/fts3query.test
@@ -118,26 +118,26 @@ do_test fts3query-4.1 {
do_eqp_test fts3query-4.2 {
SELECT t1.number FROM t1, ft WHERE t1.number=ft.rowid ORDER BY t1.date
} {
- 0 0 0 {SCAN TABLE t1 USING COVERING INDEX i1 (~1000000 rows)}
- 0 1 1 {SCAN TABLE ft VIRTUAL TABLE INDEX 1: (~0 rows)}
+ 0 0 0 {SCAN TABLE t1 USING COVERING INDEX i1}
+ 0 1 1 {SCAN TABLE 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
} {
- 0 0 1 {SCAN TABLE t1 USING COVERING INDEX i1 (~1000000 rows)}
- 0 1 0 {SCAN TABLE ft VIRTUAL TABLE INDEX 1: (~0 rows)}
+ 0 0 1 {SCAN TABLE t1 USING COVERING INDEX i1}
+ 0 1 0 {SCAN TABLE 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
} {
- 0 0 0 {SCAN TABLE t1 USING COVERING INDEX i1 (~1000000 rows)}
- 0 1 1 {SEARCH TABLE bt USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)}
+ 0 0 0 {SCAN TABLE t1 USING COVERING INDEX i1}
+ 0 1 1 {SEARCH TABLE 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
} {
- 0 0 1 {SCAN TABLE t1 USING COVERING INDEX i1 (~1000000 rows)}
- 0 1 0 {SEARCH TABLE bt USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)}
+ 0 0 1 {SCAN TABLE t1 USING COVERING INDEX i1}
+ 0 1 0 {SEARCH TABLE bt USING INTEGER PRIMARY KEY (rowid=?)}
}
@@ -210,4 +210,3 @@ do_select_tests 6.2 {
finish_test
-
diff --git a/lang/sql/sqlite/test/fts3rnd.test b/lang/sql/sqlite/test/fts3rnd.test
index 0909cee6..97af5492 100644
--- a/lang/sql/sqlite/test/fts3rnd.test
+++ b/lang/sql/sqlite/test/fts3rnd.test
@@ -162,7 +162,7 @@ proc simple_phrase {zPrefix} {
# This [proc] is used to test the FTS3 matchinfo() function.
#
-proc simple_token_matchinfo {zToken} {
+proc simple_token_matchinfo {zToken bDesc} {
set nDoc(0) 0
set nDoc(1) 0
@@ -171,6 +171,8 @@ proc simple_token_matchinfo {zToken} {
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)
@@ -184,7 +186,7 @@ proc simple_token_matchinfo {zToken} {
}
set ret [list]
- foreach docid [lsort -integer [array names a]] {
+ 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) {
@@ -262,22 +264,37 @@ proc mit {blob} {
return $r
}
db func mit mit
-
set sqlite_fts3_enable_parentheses 1
-foreach nodesize {50 500 1000 2000} {
+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 fts3(a, b, c)"
+ 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 <= 100} {incr iTest} {
+ for {set iTest 1} {$iTest <= $NUM_TRIALS} {incr iTest} {
catchsql COMMIT
set DO_MALLOC_TEST 0
@@ -286,6 +303,8 @@ foreach nodesize {50 500 1000 2000} {
set DO_MALLOC_TEST 1
set nRep 2
}
+
+ set ::testprefix fts3rnd-1.$testname.$iTest
# Delete one row, update one row and insert one row.
#
@@ -307,7 +326,7 @@ foreach nodesize {50 500 1000 2000} {
if {0==($iTest%2)} { execsql COMMIT }
if {0==($iTest%2)} {
- do_test fts3rnd-1.$nodesize.$iTest.0 { fts3_integrity_check t1 } ok
+ #do_test 0 { fts3_integrity_check t1 } ok
}
# Pick 10 terms from the vocabulary. Check that the results of querying
@@ -317,9 +336,14 @@ foreach nodesize {50 500 1000 2000} {
#
for {set i 0} {$i < 10} {incr i} {
set term [random_term]
- do_select_test fts3rnd-1.$nodesize.$iTest.1.$i {
+ do_select_test 1.$i.asc {
SELECT docid, mit(matchinfo(t1)) FROM t1 WHERE t1 MATCH $term
- } [simple_token_matchinfo $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
@@ -329,7 +353,7 @@ foreach nodesize {50 500 1000 2000} {
for {set i 0} {$i < $nRep} {incr i} {
set prefix [string range [random_term] 0 end-1]
set match "${prefix}*"
- do_select_test fts3rnd-1.$nodesize.$iTest.2.$i {
+ do_orderbydocid_test 2.$i {
SELECT docid FROM t1 WHERE t1 MATCH $match
} [simple_phrase $match]
}
@@ -339,7 +363,7 @@ foreach nodesize {50 500 1000 2000} {
for {set i 0} {$i < $nRep} {incr i} {
set term [list [random_term] [random_term]]
set match "\"$term\""
- do_select_test fts3rnd-1.$nodesize.$iTest.3.$i {
+ do_orderbydocid_test 3.$i {
SELECT docid FROM t1 WHERE t1 MATCH $match
} [simple_phrase $term]
}
@@ -349,7 +373,7 @@ foreach nodesize {50 500 1000 2000} {
for {set i 0} {$i < $nRep} {incr i} {
set term [list [random_term] [random_term] [random_term]]
set match "\"$term\""
- do_select_test fts3rnd-1.$nodesize.$iTest.4.$i {
+ do_orderbydocid_test 4.$i {
SELECT docid FROM t1 WHERE t1 MATCH $match
} [simple_phrase $term]
}
@@ -362,17 +386,19 @@ foreach nodesize {50 500 1000 2000} {
append query "[string range [random_term] 0 end-1]*"
set match "\"$query\""
- do_select_test fts3rnd-1.$nodesize.$iTest.5.$i {
+ do_orderbydocid_test 5.$i {
SELECT docid FROM t1 WHERE t1 MATCH $match
} [simple_phrase $query]
}
- # A NEAR query with terms as the arguments.
+ # 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_select_test fts3rnd-1.$nodesize.$iTest.6.$i {
+ do_orderbydocid_test 6.$i {
SELECT docid FROM t1 WHERE t1 MATCH $match
} [simple_near $terms 10]
}
@@ -383,7 +409,7 @@ foreach nodesize {50 500 1000 2000} {
set terms [list [random_term] [random_term] [random_term]]
set nNear 11
set match [join $terms " NEAR/$nNear "]
- do_select_test fts3rnd-1.$nodesize.$iTest.7.$i {
+ do_orderbydocid_test 7.$i {
SELECT docid FROM t1 WHERE t1 MATCH $match
} [simple_near $terms $nNear]
}
@@ -399,7 +425,7 @@ foreach nodesize {50 500 1000 2000} {
set term1 [random_term]
set term2 [random_term]
set match "$term1 $op $term2"
- do_select_test fts3rnd-1.$nodesize.$iTest.$tn.$i {
+ do_orderbydocid_test $tn.$i {
SELECT docid FROM t1 WHERE t1 MATCH $match
} [$proc [simple_phrase $term1] [simple_phrase $term2]]
}
@@ -408,9 +434,9 @@ foreach nodesize {50 500 1000 2000} {
# Set operations on NEAR queries.
#
foreach {tn op proc} {
- 8 OR setop_or
- 9 NOT setop_not
- 10 AND setop_and
+ 11 OR setop_or
+ 12 NOT setop_not
+ 13 AND setop_and
} {
for {set i 0} {$i < $nRep} {incr i} {
set term1 [random_term]
@@ -418,7 +444,7 @@ foreach nodesize {50 500 1000 2000} {
set term3 [random_term]
set term4 [random_term]
set match "$term1 NEAR $term2 $op $term3 NEAR $term4"
- do_select_test fts3rnd-1.$nodesize.$iTest.$tn.$i {
+ do_orderbydocid_test $tn.$i {
SELECT docid FROM t1 WHERE t1 MATCH $match
} [$proc \
[simple_near [list $term1 $term2] 10] \
diff --git a/lang/sql/sqlite/test/fts3shared.test b/lang/sql/sqlite/test/fts3shared.test
index 5f75bd5f..0943c051 100644
--- a/lang/sql/sqlite/test/fts3shared.test
+++ b/lang/sql/sqlite/test/fts3shared.test
@@ -1,3 +1,4 @@
+#
# 2010 September 17
#
# May you do good and not evil.
@@ -5,6 +6,9 @@
# 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]
@@ -14,6 +18,7 @@ ifcapable !fts3||!shared_cache {
finish_test
return
}
+set ::testprefix fts3shared
db close
set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
@@ -67,6 +72,105 @@ 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/lang/sql/sqlite/test/fts3snippet.test b/lang/sql/sqlite/test/fts3snippet.test
index 359a87c6..415251dc 100644
--- a/lang/sql/sqlite/test/fts3snippet.test
+++ b/lang/sql/sqlite/test/fts3snippet.test
@@ -16,6 +16,7 @@
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 }
@@ -131,14 +132,14 @@ foreach {DO_MALLOC_TEST enc} {
} {
db close
- file delete -force test.db
+ 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-$enc"
+ set T "fts3snippet-1.$enc"
##########################################################################
# Test the offset function.
@@ -432,10 +433,10 @@ foreach {DO_MALLOC_TEST enc} {
{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.
+ # 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
@@ -459,5 +460,65 @@ foreach {DO_MALLOC_TEST enc} {
} {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}
+}
+
set sqlite_fts3_enable_parentheses 0
finish_test
diff --git a/lang/sql/sqlite/test/fts3sort.test b/lang/sql/sqlite/test/fts3sort.test
new file mode 100644
index 00000000..218bf3e8
--- /dev/null
+++ b/lang/sql/sqlite/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/lang/sql/sqlite/test/fts3tok1.test b/lang/sql/sqlite/test/fts3tok1.test
new file mode 100644
index 00000000..e6fbbe10
--- /dev/null
+++ b/lang/sql/sqlite/test/fts3tok1.test
@@ -0,0 +1,114 @@
+# 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 or missing database}}
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/fts3tok_err.test b/lang/sql/sqlite/test/fts3tok_err.test
new file mode 100644
index 00000000..df0d4bee
--- /dev/null
+++ b/lang/sql/sqlite/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/lang/sql/sqlite/test/fts3varint.test b/lang/sql/sqlite/test/fts3varint.test
new file mode 100644
index 00000000..ca0189db
--- /dev/null
+++ b/lang/sql/sqlite/test/fts3varint.test
@@ -0,0 +1,118 @@
+# 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 }
+do_fts3_varint_test 2.63 {
+ 9223372036854775807 9223372036854775808 9223372036854775809 }
+
+do_fts3_varint_test 3.0 { 18446744073709551615 -18446744073709551615 }
+
+finish_test
diff --git a/lang/sql/sqlite/test/fts4aa.test b/lang/sql/sqlite/test/fts4aa.test
index c6fa3b9c..88550c99 100644
--- a/lang/sql/sqlite/test/fts4aa.test
+++ b/lang/sql/sqlite/test/fts4aa.test
@@ -21,1553 +21,45 @@ ifcapable !fts3 {
finish_test
return
}
-if {[db eval {SELECT sqlite_compileoption_used('ENABLE_FTS4')}]==0} {
- 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);
-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;
-}
+ 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
@@ -1587,50 +79,116 @@ proc mit {blob} {
}
db func mit mit
-do_test fts4aa-2.1 {
+do_test fts4aa-1.3 {
db eval {
- SELECT docid, mit(matchinfo(t1)) FROM t1 WHERE t1 MATCH 'melchizedek';
+ SELECT docid, mit(matchinfo(t1, 'pcxnal')) FROM t1 WHERE t1 MATCH 'melchizedek';
}
} {1014018 {1 1 1 1 1 1533 25 20}}
-do_test fts4aa-2.2 {
+do_test fts4aa-1.4 {
db eval {
- SELECT docid, mit(matchinfo(t1)) FROM t1
+ 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-2.3 {
+do_test fts4aa-1.5 {
db eval {
- SELECT docid, mit(matchinfo(t1)) FROM t1
+ 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-9.1 {
+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 0117}
+} {17 01176F}
-do_test fts4aa-9.2 {
+do_test fts4aa-1.7 {
db eval {
SELECT docid FROM t1 EXCEPT SELECT docid FROM t1_docsize
}
} {}
-do_test fts4aa-9.3 {
+do_test fts4aa-1.8 {
db eval {
SELECT docid FROM t1_docsize EXCEPT SELECT docid FROM t1
}
} {}
-do_test fts4aa-9.4 {
+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 {
- SELECT docid, mit(matchinfo(t1)) FROM t1
- WHERE t1 MATCH 'joseph died in egypt'
- ORDER BY docid;
+ 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} {
+ 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);
}
-} {1050026 {4 1 1 1 1 1 1 1 2 2 1 1 1 1 1 23 23}}
+ 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
+}
finish_test
diff --git a/lang/sql/sqlite/test/fts4check.test b/lang/sql/sqlite/test/fts4check.test
new file mode 100644
index 00000000..cc1d018a
--- /dev/null
+++ b/lang/sql/sqlite/test/fts4check.test
@@ -0,0 +1,155 @@
+# 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
+ );
+ }
+} {
+ 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 "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
+ );
+ }
+} {
+ 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_execsql_test 2.2.3.$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
+ )
+ }
+} {
+ 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"
+}
+
+finish_test
diff --git a/lang/sql/sqlite/test/fts4content.test b/lang/sql/sqlite/test/fts4content.test
new file mode 100644
index 00000000..6b2cd3cc
--- /dev/null
+++ b/lang/sql/sqlite/test/fts4content.test
@@ -0,0 +1,625 @@
+# 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.
+#
+
+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 {vtable constructor failed: ft7}}
+
+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 or missing database}}
+
+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 {vtable constructor failed: ft7}}
+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 or missing database}}
+do_catchsql_test 6.2.9 {
+ SELECT * FROM ft7 WHERE ft7 MATCH '"A A"';
+} {1 {SQL logic error or missing database}}
+
+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 or missing database}}
+
+#-------------------------------------------------------------------------
+# 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 * 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 * 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...}
+}
+
+finish_test
diff --git a/lang/sql/sqlite/test/fts4docid.test b/lang/sql/sqlite/test/fts4docid.test
new file mode 100644
index 00000000..2328b6ec
--- /dev/null
+++ b/lang/sql/sqlite/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/lang/sql/sqlite/test/fts4incr.test b/lang/sql/sqlite/test/fts4incr.test
new file mode 100644
index 00000000..17212efc
--- /dev/null
+++ b/lang/sql/sqlite/test/fts4incr.test
@@ -0,0 +1,75 @@
+# 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]
+ }
+ 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/lang/sql/sqlite/test/fts4langid.test b/lang/sql/sqlite/test/fts4langid.test
new file mode 100644
index 00000000..843e11f9
--- /dev/null
+++ b/lang/sql/sqlite/test/fts4langid.test
@@ -0,0 +1,485 @@
+# 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
+set ::testprefix fts4content
+
+# 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"]
+}
+
+#-------------------------------------------------------------------------
+# 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]
+ 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 or missing database}}
+
+#-------------------------------------------------------------------------
+# 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;
+ } {4 4}
+}
+finish_test
diff --git a/lang/sql/sqlite/test/fts4merge.test b/lang/sql/sqlite/test/fts4merge.test
new file mode 100644
index 00000000..fabb651e
--- /dev/null
+++ b/lang/sql/sqlite/test/fts4merge.test
@@ -0,0 +1,341 @@
+# 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, group_concat(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
+ } {
+ 0 {0 1 2 3}
+ 1 {0 1 2 3 4 5 6}
+ 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, group_concat(idx, ' ') FROM t1_segdir GROUP BY level
+ } {
+ 2 {0 1}
+ 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}
+ 8 {merge=6,0}
+ } {
+ do_catchsql_test 2.$tn {
+ INSERT INTO t2(t2) VALUES($arg);
+ } {1 {SQL logic error or missing database}}
+ }
+
+ #-------------------------------------------------------------------------
+ # 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, group_concat(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
+ } {
+ 0 0
+ 2 0
+ 3 0
+ 4 0
+ 6 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, group_concat(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'}
+
+ do_execsql_test 4.4.2 {
+ DELETE FROM t4_stat WHERE rowid=1;
+ INSERT INTO t4(t4) VALUES('merge=1,12');
+ SELECT level, group_concat(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, group_concat(idx, ' ') FROM t1_segdir GROUP BY level;
+ } {
+ 0 {0 1 2}
+ 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'0105'}
+ 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'0105'}
+
+ 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 8 9 10}
+ 1 {0 1 2 3 4 5 6 7 8 9 10 11 12}
+ 2 {0 1 2 3 4 5 6 7}
+ X'0105'
+ }
+
+ 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;
+ } {
+ 0 {0 1 2 3 4}
+ 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'0106'
+ }
+
+ 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 {0 1} 2 0 3 0 X'0106'
+ }
+
+ do_execsql_test 5.11 {
+ 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;
+ } {
+ 0 0 1 {0 1} 2 0 3 0 X''
+ }
+
+ #-------------------------------------------------------------------------
+ # 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}
+
+}
+
+finish_test
diff --git a/lang/sql/sqlite/test/fts4merge2.test b/lang/sql/sqlite/test/fts4merge2.test
new file mode 100644
index 00000000..308b6929
--- /dev/null
+++ b/lang/sql/sqlite/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/lang/sql/sqlite/test/fts4merge3.test b/lang/sql/sqlite/test/fts4merge3.test
new file mode 100644
index 00000000..329b4d2c
--- /dev/null
+++ b/lang/sql/sqlite/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
+ } } [list 0 1 2 18 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 13 1 13 2 5 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
+ } } {6 1}
+ }
+}
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/fts4merge4.test b/lang/sql/sqlite/test/fts4merge4.test
new file mode 100644
index 00000000..8e2119de
--- /dev/null
+++ b/lang/sql/sqlite/test/fts4merge4.test
@@ -0,0 +1,58 @@
+# 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 {
+ 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
+
+
+sqlite3_enable_shared_cache $::enable_shared_cache
+finish_test
diff --git a/lang/sql/sqlite/test/fts4noti.test b/lang/sql/sqlite/test/fts4noti.test
new file mode 100644
index 00000000..e9262283
--- /dev/null
+++ b/lang/sql/sqlite/test/fts4noti.test
@@ -0,0 +1,171 @@
+# 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 }
+
+finish_test
+
+
+
diff --git a/lang/sql/sqlite/test/fts4unicode.test b/lang/sql/sqlite/test/fts4unicode.test
new file mode 100644
index 00000000..f237119a
--- /dev/null
+++ b/lang/sql/sqlite/test/fts4unicode.test
@@ -0,0 +1,558 @@
+# 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.
+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
+ 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
+ do_isspace_test 6.$T.16 $T 8239
+ do_isspace_test 6.$T.17 $T 8287
+ do_isspace_test 6.$T.18 $T 12288
+
+ do_isspace_test 6.$T.19 $T {32 160 5760 6158}
+ 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
+}
+
+finish_test
diff --git a/lang/sql/sqlite/test/full.test b/lang/sql/sqlite/test/full.test
new file mode 100644
index 00000000..a8fe3714
--- /dev/null
+++ b/lang/sql/sqlite/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/lang/sql/sqlite/test/func.test b/lang/sql/sqlite/test/func.test
index eef05439..edec591e 100644
--- a/lang/sql/sqlite/test/func.test
+++ b/lang/sql/sqlite/test/func.test
@@ -14,6 +14,7 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
+set testprefix func
# Create a table to work with.
#
@@ -312,7 +313,7 @@ ifcapable floatingpoint {
execsql {SELECT round(9999999999999.55,1);}
} {9999999999999.6}
do_test func-4.38 {
- execsql {SELECT round(9999999999999.555,2);}
+ execsql {SELECT round(9999999999999.556,2);}
} {9999999999999.56}
}
@@ -682,6 +683,32 @@ do_test func-13.7 {
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 {
@@ -1247,4 +1274,91 @@ do_test func-28.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"} {
+ 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
+}
+
finish_test
diff --git a/lang/sql/sqlite/test/func3.test b/lang/sql/sqlite/test/func3.test
index e58d730f..2a2b7be4 100644
--- a/lang/sql/sqlite/test/func3.test
+++ b/lang/sql/sqlite/test/func3.test
@@ -17,24 +17,26 @@ set testdir [file dirname $argv0]
source $testdir/tester.tcl
-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
+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
@@ -68,4 +70,87 @@ do_test func3-4.1 {
} {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.40 {
+ db eval {EXPLAIN SELECT unlikely(min(1.0+'2.0',4*11))}
+} [db eval {EXPLAIN SELECT min(1.0+'2.0',4*11)}]
+
finish_test
diff --git a/lang/sql/sqlite/test/func4.test b/lang/sql/sqlite/test/func4.test
new file mode 100644
index 00000000..e94f8c34
--- /dev/null
+++ b/lang/sql/sqlite/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);
+} {-9223372036854775808}
+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);
+ } {-9.223372036854776e+18}
+ if {$highPrecision(2)} {
+ do_execsql_test func4-2.25 {
+ SELECT toreal(-9223372036854775808 + 1);
+ } {{}}
+ }
+ do_execsql_test func4-2.26 {
+ SELECT toreal(-9223372036854775807 - 1);
+ } {-9.223372036854776e+18}
+ 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: t1}}
+ do_test func4-3.3 {
+ catchsql {
+ INSERT INTO t1 (x) VALUES (NULL);
+ }
+ } {1 {CHECK constraint failed: t1}}
+ do_test func4-3.4 {
+ catchsql {
+ INSERT INTO t1 (x) VALUES ('');
+ }
+ } {1 {CHECK constraint failed: t1}}
+ do_test func4-3.5 {
+ catchsql {
+ INSERT INTO t1 (x) VALUES ('bad');
+ }
+ } {1 {CHECK constraint failed: t1}}
+ do_test func4-3.6 {
+ catchsql {
+ INSERT INTO t1 (x) VALUES ('1234bad');
+ }
+ } {1 {CHECK constraint failed: t1}}
+ do_test func4-3.7 {
+ catchsql {
+ INSERT INTO t1 (x) VALUES ('1234.56bad');
+ }
+ } {1 {CHECK constraint failed: t1}}
+ 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: t1}}
+ 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: t1}}
+ do_test func4-3.12 {
+ catchsql {
+ INSERT INTO t1 (x) VALUES (ZEROBLOB(4));
+ }
+ } {1 {CHECK constraint failed: t1}}
+ do_test func4-3.13 {
+ catchsql {
+ INSERT INTO t1 (x) VALUES (X'');
+ }
+ } {1 {CHECK constraint failed: t1}}
+ do_test func4-3.14 {
+ catchsql {
+ INSERT INTO t1 (x) VALUES (X'1234');
+ }
+ } {1 {CHECK constraint failed: t1}}
+ do_test func4-3.15 {
+ catchsql {
+ INSERT INTO t1 (x) VALUES (X'12345678');
+ }
+ } {1 {CHECK constraint failed: t1}}
+ do_test func4-3.16 {
+ catchsql {
+ INSERT INTO t1 (x) VALUES ('1234.00');
+ }
+ } {1 {CHECK constraint failed: t1}}
+ 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: t1}}
+ if {$highPrecision(1)} {
+ do_test func4-3.19 {
+ catchsql {
+ INSERT INTO t1 (x) VALUES (9223372036854775808);
+ }
+ } {1 {CHECK constraint failed: t1}}
+ }
+ do_execsql_test func4-3.20 {
+ SELECT x FROM t1 ORDER BY x;
+ } {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: t2}}
+ do_test func4-4.3 {
+ catchsql {
+ INSERT INTO t2 (x) VALUES (NULL);
+ }
+ } {1 {CHECK constraint failed: t2}}
+ do_test func4-4.4 {
+ catchsql {
+ INSERT INTO t2 (x) VALUES ('');
+ }
+ } {1 {CHECK constraint failed: t2}}
+ do_test func4-4.5 {
+ catchsql {
+ INSERT INTO t2 (x) VALUES ('bad');
+ }
+ } {1 {CHECK constraint failed: t2}}
+ do_test func4-4.6 {
+ catchsql {
+ INSERT INTO t2 (x) VALUES ('1234bad');
+ }
+ } {1 {CHECK constraint failed: t2}}
+ do_test func4-4.7 {
+ catchsql {
+ INSERT INTO t2 (x) VALUES ('1234.56bad');
+ }
+ } {1 {CHECK constraint failed: t2}}
+ 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: t2}}
+ do_test func4-4.13 {
+ catchsql {
+ INSERT INTO t2 (x) VALUES (X'');
+ }
+ } {1 {CHECK constraint failed: t2}}
+ do_test func4-4.14 {
+ catchsql {
+ INSERT INTO t2 (x) VALUES (X'1234');
+ }
+ } {1 {CHECK constraint failed: t2}}
+ do_test func4-4.15 {
+ catchsql {
+ INSERT INTO t2 (x) VALUES (X'12345678');
+ }
+ } {1 {CHECK constraint failed: t2}}
+ 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));
+ } {-9223372036854775808}
+ do_execsql_test func4-5.7 {
+ SELECT tointeger(toreal(-9223372036854775808));
+ } {-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/lang/sql/sqlite/test/func5.test b/lang/sql/sqlite/test/func5.test
new file mode 100644
index 00000000..bfd545b4
--- /dev/null
+++ b/lang/sql/sqlite/test/func5.test
@@ -0,0 +1,63 @@
+# 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;
+} {}
+do_execsql_test func5-2.3 {
+ SELECT x, y FROM t2
+ WHERE x+counter2('hello')=counter2('hello')+x
+ ORDER BY +x;
+} {1 2 3 4 5 6 7 8}
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/fuzz-oss1.test b/lang/sql/sqlite/test/fuzz-oss1.test
new file mode 100644
index 00000000..08bc6708
--- /dev/null
+++ b/lang/sql/sqlite/test/fuzz-oss1.test
@@ -0,0 +1,2001 @@
+# 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
+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 .*/}
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/fuzz3.test b/lang/sql/sqlite/test/fuzz3.test
index d0efc525..2b21404f 100644
--- a/lang/sql/sqlite/test/fuzz3.test
+++ b/lang/sql/sqlite/test/fuzz3.test
@@ -18,6 +18,9 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
+# These tests deal with corrupt database files
+#
+database_may_be_corrupt
expr srand(123)
diff --git a/lang/sql/sqlite/test/fuzz_malloc.test b/lang/sql/sqlite/test/fuzz_malloc.test
index f2209aab..1e31babd 100644
--- a/lang/sql/sqlite/test/fuzz_malloc.test
+++ b/lang/sql/sqlite/test/fuzz_malloc.test
@@ -47,7 +47,7 @@ proc do_fuzzy_malloc_test {testname args} {
sqlite3_memdebug_fail -1
db close
- file delete test.db test.db-journal
+ delete_file test.db test.db-journal
sqlite3 db test.db
set ::prep $::fuzzyopts(-sqlprep)
execsql $::prep
diff --git a/lang/sql/sqlite/test/fuzzer1.test b/lang/sql/sqlite/test/fuzzer1.test
index d0575d2d..4ee57308 100644
--- a/lang/sql/sqlite/test/fuzzer1.test
+++ b/lang/sql/sqlite/test/fuzzer1.test
@@ -22,100 +22,228 @@ ifcapable !vtab {
return
}
-register_fuzzer_module db
-do_test fuzzer1-1.0 {
- catchsql {CREATE VIRTUAL TABLE fault1 USING fuzzer;}
-} {1 {fuzzer virtual tables must be TEMP}}
-do_test fuzzer1-1.1 {
- db eval {CREATE VIRTUAL TABLE temp.f1 USING fuzzer;}
+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_test fuzzer1-1.2 {
- db eval {
- INSERT INTO f1(cfrom, cto, cost) VALUES('e','a',1);
- INSERT INTO f1(cfrom, cto, cost) VALUES('a','e',10);
- INSERT INTO f1(cfrom, cto, cost) VALUES('e','o',100);
- }
+
+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_test fuzzer1-1.3 {
+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'
+ 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 abcda 1 ebcde 10 ebcda 11 abcdo 100 ebcdo 110 obcde 110 obcda 111 obcdo 210}
+} {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 {
- CREATE VIRTUAL TABLE temp.f2 USING fuzzer;
-- costs based on English letter frequencies
- INSERT INTO f2(cFrom,cTo,cost) VALUES('a','e',24);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('a','o',47);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('a','u',50);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('e','a',23);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('e','i',33);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('e','o',37);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('i','e',33);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('i','y',33);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('o','a',41);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('o','e',46);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('o','u',57);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('u','o',58);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('y','i',33);
-
- INSERT INTO f2(cFrom,cTo,cost) VALUES('t','th',70);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('th','t',66);
+ 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(cFrom,cTo,cost) VALUES('a','',84);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('','b',106);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('b','',106);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('','c',94);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('c','',94);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('','d',89);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('d','',89);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('','e',83);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('e','',83);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('','f',97);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('f','',97);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('','g',99);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('g','',99);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('','h',86);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('h','',86);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('','i',85);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('i','',85);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('','j',120);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('j','',120);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('','k',120);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('k','',120);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('','l',89);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('l','',89);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('','m',96);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('m','',96);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('','n',85);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('n','',85);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('','o',85);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('o','',85);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('','p',100);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('p','',100);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('','q',120);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('q','',120);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('','r',86);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('r','',86);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('','s',86);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('s','',86);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('','t',84);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('t','',84);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('','u',94);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('u','',94);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('','v',120);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('v','',120);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('','w',96);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('w','',96);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('','x',120);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('x','',120);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('','y',100);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('y','',100);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('','z',120);
- INSERT INTO f2(cFrom,cTo,cost) VALUES('z','',120);
+ 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.
--
@@ -1376,7 +1504,363 @@ do_test fuzzer1-2.3 {
AND f2.distance<=200
AND streetname.n>=f2.word AND streetname.n<=(f2.word || x'F7BFBFBF')
}
-} {steelewood tallia tallu talwyn taymouth thelema trailer {tyler finley}}
+} {{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}}
+
+#-------------------------------------------------------------------------
+# 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 6.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 6.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 6.2 {
+ SELECT count(*) FROM x1_rules WHERE cTo!=cFrom;
+} [expr 26*26*26*26 - 26*26]
+
+do_execsql_test 6.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 6.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}
+
+#-------------------------------------------------------------------------
+# 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/lang/sql/sqlite/test/fuzzerfault.test b/lang/sql/sqlite/test/fuzzerfault.test
new file mode 100644
index 00000000..6449612a
--- /dev/null
+++ b/lang/sql/sqlite/test/fuzzerfault.test
@@ -0,0 +1,92 @@
+# 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}}
+}
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/genesis.tcl b/lang/sql/sqlite/test/genesis.tcl
new file mode 100644
index 00000000..4ba4c8ea
--- /dev/null
+++ b/lang/sql/sqlite/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/lang/sql/sqlite/test/hook.test b/lang/sql/sqlite/test/hook.test
index 6496d41e..de6fbdd2 100644
--- a/lang/sql/sqlite/test/hook.test
+++ b/lang/sql/sqlite/test/hook.test
@@ -74,6 +74,7 @@ do_test hook-3.6 {
INSERT INTO t2 VALUES(6,7);
}
} {1 {constraint failed}}
+verify_ex_errcode hook-3.6b SQLITE_CONSTRAINT_COMMITHOOK
do_test hook-3.7 {
set ::commit_cnt
} {1 2 2 3 3 4 4 5 5 6 6 7}
@@ -95,7 +96,7 @@ do_test hook-3.9 {
# Ticket #3564.
#
do_test hook-3.10 {
- file delete -force test2.db test2.db-journal
+ forcedelete test2.db test2.db-journal
sqlite3 db2 test2.db
proc commit_hook {} {
set y [db2 one {SELECT y FROM t3 WHERE y>10}]
@@ -126,21 +127,52 @@ db2 close
# depopulation of indices, to make sure the update-hook is not
# invoked incorrectly.
#
+# EVIDENCE-OF: R-21999-45122 The sqlite3_update_hook() interface
+# registers a callback function with the database connection identified
+# by the first argument to be invoked whenever a row is updated,
+# inserted or deleted in a rowid table.
# Simple tests
-do_test hook-4.1.1 {
+do_test hook-4.1.1a {
catchsql {
DROP TABLE t1;
}
+ unset -nocomplain ::update_hook
+ set ::update_hook {}
+ db update_hook [list lappend ::update_hook]
+ #
+ # EVIDENCE-OF: R-52223-27275 The update hook is not invoked when
+ # internal system tables are modified (i.e. sqlite_master and
+ # sqlite_sequence).
+ #
execsql {
CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
+ CREATE TABLE t1w(a INT PRIMARY KEY, b) WITHOUT ROWID;
+ }
+ set ::update_hook
+} {}
+do_test hook-4.1.1b {
+ execsql {
INSERT INTO t1 VALUES(1, 'one');
INSERT INTO t1 VALUES(2, 'two');
INSERT INTO t1 VALUES(3, 'three');
+ INSERT INTO t1w SELECT * FROM t1;
}
- db update_hook [list lappend ::update_hook]
} {}
+
+# EVIDENCE-OF: R-15506-57666 The second callback argument is one of
+# SQLITE_INSERT, SQLITE_DELETE, or SQLITE_UPDATE, depending on the
+# operation that caused the callback to be invoked.
+#
+# EVIDENCE-OF: R-29213-61195 The third and fourth arguments to the
+# callback contain pointers to the database and table name containing
+# the affected row.
+#
+# EVIDENCE-OF: R-30809-57812 The final callback parameter is the rowid
+# of the row.
+#
do_test hook-4.1.2 {
+ set ::update_hook {}
execsql {
INSERT INTO t1 VALUES(4, 'four');
DELETE FROM t1 WHERE b = 'two';
@@ -158,6 +190,23 @@ do_test hook-4.1.2 {
DELETE main t1 4 \
]
+# EVIDENCE-OF: R-61808-14344 The sqlite3_update_hook() interface does
+# not fire callbacks for changes to a WITHOUT ROWID table.
+#
+# EVIDENCE-OF: R-33257-44249 The update hook is not invoked when WITHOUT
+# ROWID tables are modified.
+#
+do_test hook-4.1.2w {
+ set ::update_hook {}
+ execsql {
+ INSERT INTO t1w VALUES(4, 'four');
+ DELETE FROM t1w WHERE b = 'two';
+ UPDATE t1w SET b = '' WHERE a = 1 OR a = 3;
+ DELETE FROM t1w WHERE 1; -- Avoid the truncate optimization (for now)
+ }
+ set ::update_hook
+} {}
+
ifcapable trigger {
# Update hook is not invoked for changes to sqlite_master
#
@@ -217,7 +266,7 @@ ifcapable trigger {
set ::update_hook {}
ifcapable attach {
do_test hook-4.2.3 {
- file delete -force test2.db
+ forcedelete test2.db
execsql {
ATTACH 'test2.db' AS aux;
CREATE TABLE aux.t3(a INTEGER PRIMARY KEY, b);
@@ -274,6 +323,34 @@ ifcapable compound&&attach {
set ::update_hook
} [list]
}
+
+do_test hook-4.4 {
+ execsql {
+ CREATE TABLE t4(a UNIQUE, b);
+ INSERT INTO t4 VALUES(1, 'a');
+ INSERT INTO t4 VALUES(2, 'b');
+ }
+ set ::update_hook [list]
+ execsql {
+ REPLACE INTO t4 VALUES(1, 'c');
+ }
+ set ::update_hook
+} [list INSERT main t4 3 ]
+do_execsql_test hook-4.4.1 {
+ SELECT * FROM t4 ORDER BY a;
+} {1 c 2 b}
+do_test hook-4.4.2 {
+ set ::update_hook [list]
+ execsql {
+ PRAGMA recursive_triggers = on;
+ REPLACE INTO t4 VALUES(1, 'd');
+ }
+ set ::update_hook
+} [list INSERT main t4 4 ]
+do_execsql_test hook-4.4.3 {
+ SELECT * FROM t4 ORDER BY a;
+} {1 d 2 b}
+
db update_hook {}
#
#----------------------------------------------------------------------------
diff --git a/lang/sql/sqlite/test/in.test b/lang/sql/sqlite/test/in.test
index 2c38a0f4..515e598c 100644
--- a/lang/sql/sqlite/test/in.test
+++ b/lang/sql/sqlite/test/in.test
@@ -258,17 +258,29 @@ do_test in-7.5 {
SELECT a FROM t1 WHERE a IN (5) AND b NOT IN ();
}
} {5}
-do_test in-7.6 {
+do_test in-7.6.1 {
execsql {
SELECT a FROM ta WHERE a IN ();
}
} {}
+do_test in-7.6.2 {
+ db status step
+} {0}
do_test in-7.7 {
execsql {
SELECT a FROM ta WHERE a NOT IN ();
}
} {1 2 3 4 6 8 10}
+do_test in-7.8.1 {
+ execsql {
+ SELECT * FROM ta LEFT JOIN tb ON (ta.b=tb.b) WHERE ta.a IN ();
+ }
+} {}
+do_test in-7.8.2 {
+ db status step
+} {0}
+
do_test in-8.1 {
execsql {
SELECT b FROM t1 WHERE a IN ('hello','there')
@@ -320,7 +332,7 @@ do_test in-10.2 {
catchsql {
INSERT INTO t5 VALUES(4);
}
-} {1 {constraint failed}}
+} {1 {CHECK constraint failed: t5}}
# Ticket #1821
#
@@ -431,6 +443,7 @@ do_test in-12.9 {
} {1 {SELECTs to the left and right of INTERSECT do not have the same number of result columns}}
}
+ifcapable compound {
do_test in-12.10 {
catchsql {
SELECT * FROM t2 WHERE a IN (
@@ -459,6 +472,7 @@ do_test in-12.13 {
);
}
} {1 {only a single result allowed for a SELECT that is part of an expression}}
+}; #ifcapable compound
#------------------------------------------------------------------------
diff --git a/lang/sql/sqlite/test/in5.test b/lang/sql/sqlite/test/in5.test
new file mode 100644
index 00000000..8a43b8d4
--- /dev/null
+++ b/lang/sql/sqlite/test/in5.test
@@ -0,0 +1,138 @@
+# 2012 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.
+#
+#***********************************************************************
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+do_test in5-1.1 {
+ execsql {
+ CREATE TABLE t1x(x INTEGER PRIMARY KEY);
+ INSERT INTO t1x VALUES(1),(3),(5),(7),(9);
+ CREATE TABLE t1y(y INTEGER UNIQUE);
+ INSERT INTO t1y VALUES(2),(4),(6),(8);
+ CREATE TABLE t1z(z TEXT UNIQUE);
+ INSERT INTO t1z VALUES('a'),('c'),('e'),('g');
+ CREATE TABLE t2(a INTEGER, b INTEGER, c TEXT, d TEXT);
+ INSERT INTO t2 VALUES(1,2,'a','12a'),(1,2,'b','12b'),
+ (2,3,'g','23g'),(3,5,'c','35c'),
+ (4,6,'h','46h'),(5,6,'e','56e');
+ CREATE TABLE t3x AS SELECT x FROM t1x;
+ CREATE TABLE t3y AS SELECT y FROM t1y;
+ CREATE TABLE t3z AS SELECT z FROM t1z;
+ SELECT d FROM t2 WHERE a IN t1x AND b IN t1y AND c IN t1z ORDER BY c;
+ }
+} {12a 56e}
+do_test in5-1.2 {
+ execsql {
+ SELECT d FROM t2 WHERE a IN t1y AND b IN t1x AND c IN t1z ORDER BY d;
+ }
+} {23g}
+do_test in5-1.3 {
+ execsql {
+ SELECT d FROM t2 WHERE a IN t3x AND b IN t3y AND c IN t3z ORDER BY d;
+ }
+} {12a 56e}
+
+
+do_test in5-2.1 {
+ execsql {
+ CREATE INDEX t2abc ON t2(a,b,c);
+ SELECT d FROM t2 WHERE a IN t1x AND b IN t1y AND c IN t1z ORDER BY d;
+ }
+} {12a 56e}
+do_test in5-2.2 {
+ execsql {
+ SELECT d FROM t2 WHERE a IN t1y AND b IN t1x AND c IN t1z ORDER BY d;
+ }
+} {23g}
+do_test in5-2.3 {
+ regexp {OpenEphemeral} [db eval {
+ EXPLAIN SELECT d FROM t2 WHERE a IN t1x AND b IN t1y AND c IN t1z
+ }]
+} {0}
+do_test in5-2.4 {
+ execsql {
+ SELECT d FROM t2 WHERE a IN t3x AND b IN t3y AND c IN t3z ORDER BY d;
+ }
+} {12a 56e}
+do_test in5-2.5.1 {
+ regexp {OpenEphemeral} [db eval {
+ EXPLAIN SELECT d FROM t2 WHERE a IN t3x AND b IN t1y AND c IN t1z
+ }]
+} {1}
+do_test in5-2.5.2 {
+ regexp {OpenEphemeral} [db eval {
+ EXPLAIN SELECT d FROM t2 WHERE a IN t1x AND b IN t3y AND c IN t1z
+ }]
+} {1}
+do_test in5-2.5.3 {
+ regexp {OpenEphemeral} [db eval {
+ EXPLAIN SELECT d FROM t2 WHERE a IN t1x AND b IN t1y AND c IN t3z
+ }]
+} {1}
+
+do_test in5-3.1 {
+ execsql {
+ DROP INDEX t2abc;
+ CREATE INDEX t2ab ON t2(a,b);
+ SELECT d FROM t2 WHERE a IN t1x AND b IN t1y AND c IN t1z ORDER BY d;
+ }
+} {12a 56e}
+do_test in5-3.2 {
+ execsql {
+ SELECT d FROM t2 WHERE a IN t1y AND b IN t1x AND c IN t1z ORDER BY d;
+ }
+} {23g}
+do_test in5-3.3 {
+ regexp {OpenEphemeral} [db eval {
+ EXPLAIN SELECT d FROM t2 WHERE a IN t1x AND b IN t1y AND c IN t1z
+ }]
+} {0}
+
+do_test in5-4.1 {
+ execsql {
+ DROP INDEX t2ab;
+ CREATE INDEX t2abcd ON t2(a,b,c,d);
+ SELECT d FROM t2 WHERE a IN t1x AND b IN t1y AND c IN t1z ORDER BY d;
+ }
+} {12a 56e}
+do_test in5-4.2 {
+ execsql {
+ SELECT d FROM t2 WHERE a IN t1y AND b IN t1x AND c IN t1z ORDER BY d;
+ }
+} {23g}
+do_test in5-4.3 {
+ regexp {OpenEphemeral} [db eval {
+ EXPLAIN SELECT d FROM t2 WHERE a IN t1x AND b IN t1y AND c IN t1z
+ }]
+} {0}
+
+
+do_test in5-5.1 {
+ execsql {
+ DROP INDEX t2abcd;
+ CREATE INDEX t2cbad ON t2(c,b,a,d);
+ SELECT d FROM t2 WHERE a IN t1x AND b IN t1y AND c IN t1z ORDER BY d;
+ }
+} {12a 56e}
+do_test in5-5.2 {
+ execsql {
+ SELECT d FROM t2 WHERE a IN t1y AND b IN t1x AND c IN t1z ORDER BY d;
+ }
+} {23g}
+do_test in5-5.3 {
+ regexp {OpenEphemeral} [db eval {
+ EXPLAIN SELECT d FROM t2 WHERE a IN t1x AND b IN t1y AND c IN t1z
+ }]
+} {0}
+
+finish_test
diff --git a/lang/sql/sqlite/test/incrblob.test b/lang/sql/sqlite/test/incrblob.test
index 98f23dd6..ae3369e9 100644
--- a/lang/sql/sqlite/test/incrblob.test
+++ b/lang/sql/sqlite/test/incrblob.test
@@ -120,9 +120,10 @@ foreach AutoVacuumMode [list 0 1] {
}
db close
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db test.db
+ execsql "PRAGMA mmap_size = 0"
execsql "PRAGMA auto_vacuum = $AutoVacuumMode"
do_test incrblob-2.$AutoVacuumMode.1 {
@@ -149,6 +150,7 @@ foreach AutoVacuumMode [list 0 1] {
# Open and close the db to make sure the page cache is empty.
db close
sqlite3 db test.db
+ execsql "PRAGMA mmap_size = 0"
# Read the last 20 bytes of the blob via a blob handle.
set ::blob [db incrblob blobs v 1]
@@ -171,6 +173,7 @@ foreach AutoVacuumMode [list 0 1] {
# Open and close the db to make sure the page cache is empty.
db close
sqlite3 db test.db
+ execsql "PRAGMA mmap_size = 0"
# Write the second-to-last 20 bytes of the blob via a blob handle.
#
@@ -200,6 +203,7 @@ foreach AutoVacuumMode [list 0 1] {
# Open and close the db to make sure the page cache is empty.
db close
sqlite3 db test.db
+ execsql { PRAGMA mmap_size = 0 }
execsql { SELECT i FROM blobs }
} {45}
@@ -379,7 +383,7 @@ ifcapable vtab {
#
ifcapable attach {
do_test incrblob-5.1 {
- file delete -force test2.db test2.db-journal
+ forcedelete test2.db test2.db-journal
set ::size [expr [file size [info script]]]
execsql {
ATTACH 'test2.db' AS aux;
@@ -437,7 +441,7 @@ if {[permutation] != "memsubsys1"} {
} {}
do_test incrblob-6.2 {
execsql {
- SELECT rowid FROM blobs
+ SELECT rowid FROM blobs ORDER BY rowid
}
} {1 2 3}
do_test incrblob-6.3 {
@@ -473,15 +477,9 @@ if {[permutation] != "memsubsys1"} {
flush $::blob
} {}
- # At this point rollback should be illegal (because
- # there is an open blob channel). But commit is also illegal because
- # the open blob is read-write.
+ # At this point commit should be illegal (because
+ # there is an open blob channel).
#
- do_test incrblob-6.10 {
- catchsql {
- ROLLBACK;
- } db2
- } {1 {cannot rollback transaction - SQL statements in progress}}
do_test incrblob-6.11 {
catchsql {
COMMIT;
@@ -511,7 +509,7 @@ if {[permutation] != "memsubsys1"} {
sqlite3_soft_heap_limit $cmdlinearg(soft-heap-limit)
#-----------------------------------------------------------------------
-# The following tests verify the behaviour of the incremental IO
+# The following tests verify the behavior of the incremental IO
# APIs in the following cases:
#
# 7.1 A row that containing an open blob is modified.
@@ -522,7 +520,7 @@ sqlite3_soft_heap_limit $cmdlinearg(soft-heap-limit)
# 7.3 An INCREMENTAL VACUUM moves an overflow page that is part
# of an open blob.
#
-# In the first case above, correct behaviour is for all subsequent
+# In the first case above, correct behavior is for all subsequent
# read/write operations on the blob-handle to return SQLITE_ABORT.
# More accurately, blob-handles are invalidated whenever the table
# they belong to is written to.
@@ -584,7 +582,7 @@ set ::data [read $fd 14000]
close $fd
db close
-file delete -force test.db test.db-journal
+forcedelete test.db test.db-journal
sqlite3 db test.db
do_test incrblob-7.2.1 {
diff --git a/lang/sql/sqlite/test/incrblob2.test b/lang/sql/sqlite/test/incrblob2.test
index 9046de27..a8f40f09 100644
--- a/lang/sql/sqlite/test/incrblob2.test
+++ b/lang/sql/sqlite/test/incrblob2.test
@@ -397,16 +397,16 @@ do_test incrblob2-8.4 {
} {cccccccccccccccccccc}
do_test incrblob2-8.5 {
catchsql {UPDATE t3 SET a = 6 WHERE a > 3}
-} {1 {column a is not unique}}
+} {1 {UNIQUE constraint failed: t3.a}}
do_test incrblob2-8.6 {
catchsql {UPDATE t3 SET a = 6 WHERE a > 3}
-} {1 {column a is not unique}}
+} {1 {UNIQUE constraint failed: t3.a}}
do_test incrblob2-8.7 {
sqlite3_blob_read $h 0 20
} {cccccccccccccccccccc}
do_test incrblob2-8.8 {
catchsql {UPDATE t3 SET a = 6 WHERE a = 3 OR a = 5}
-} {1 {column a is not unique}}
+} {1 {UNIQUE constraint failed: t3.a}}
do_test incrblob2-8.9 {
set rc [catch {sqlite3_blob_read $h 0 20} msg]
list $rc $msg
diff --git a/lang/sql/sqlite/test/incrblob3.test b/lang/sql/sqlite/test/incrblob3.test
index 4c49f156..5f2e860d 100644
--- a/lang/sql/sqlite/test/incrblob3.test
+++ b/lang/sql/sqlite/test/incrblob3.test
@@ -269,4 +269,3 @@ db close
tvfs delete
finish_test
-
diff --git a/lang/sql/sqlite/test/incrblob4.test b/lang/sql/sqlite/test/incrblob4.test
new file mode 100644
index 00000000..a92e3735
--- /dev/null
+++ b/lang/sql/sqlite/test/incrblob4.test
@@ -0,0 +1,89 @@
+# 2012 March 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
+ifcapable {!incrblob} { finish_test ; return }
+set testprefix incrblob4
+
+proc create_t1 {} {
+ execsql {
+ PRAGMA page_size = 1024;
+ CREATE TABLE t1(k INTEGER PRIMARY KEY, v);
+ }
+}
+
+proc populate_t1 {} {
+ set data [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]
+ foreach d $data {
+ set blob [string repeat $d 900]
+ execsql { INSERT INTO t1(v) VALUES($blob) }
+ }
+}
+
+
+do_test 1.1 {
+ create_t1
+ populate_t1
+} {}
+
+do_test 1.2 {
+ set blob [db incrblob t1 v 5]
+ read $blob 10
+} {eeeeeeeeee}
+
+do_test 1.3 {
+ execsql { DELETE FROM t1 }
+ populate_t1
+} {}
+
+
+
+do_test 2.1 {
+ reset_db
+ create_t1
+ populate_t1
+} {}
+
+do_test 2.2 {
+ set blob [db incrblob t1 v 10]
+ read $blob 10
+} {jjjjjjjjjj}
+
+do_test 2.3 {
+ set new [string repeat % 900]
+ execsql { DELETE FROM t1 WHERE k=10 }
+ execsql { DELETE FROM t1 WHERE k=9 }
+ execsql { INSERT INTO t1(v) VALUES($new) }
+} {}
+
+
+
+do_test 3.1 {
+ reset_db
+ create_t1
+ populate_t1
+} {}
+
+do_test 3.2 {
+ set blob [db incrblob t1 v 20]
+ read $blob 10
+} {tttttttttt}
+
+do_test 3.3 {
+ set new [string repeat % 900]
+ execsql { UPDATE t1 SET v = $new WHERE k = 20 }
+ execsql { DELETE FROM t1 WHERE k=19 }
+ execsql { INSERT INTO t1(v) VALUES($new) }
+} {}
+
+finish_test
diff --git a/lang/sql/sqlite/test/incrblob_err.test b/lang/sql/sqlite/test/incrblob_err.test
index b4c25877..35d37fee 100644
--- a/lang/sql/sqlite/test/incrblob_err.test
+++ b/lang/sql/sqlite/test/incrblob_err.test
@@ -35,6 +35,7 @@ do_malloc_test 1 -tclprep {
}
} -tclbody {
set ::blob [db incrblob blobs v 1]
+ fconfigure $::blob -translation binary
set rc [catch {puts -nonewline $::blob $::data}]
if {$rc} { error "out of memory" }
}
@@ -71,8 +72,7 @@ do_malloc_test 3 -tclprep {
if {$rc} {
error "out of memory"
}
-}
-
+}
do_ioerr_test incrblob_err-4 -cksum 1 -sqlprep {
CREATE TABLE blobs(k, v BLOB);
@@ -87,6 +87,7 @@ do_ioerr_test incrblob_err-5 -cksum 1 -sqlprep {
INSERT INTO blobs VALUES(1, zeroblob(length(CAST($::data AS BLOB))));
} -tclbody {
set ::blob [db incrblob blobs v 1]
+ fconfigure $::blob -translation binary
puts -nonewline $::blob $::data
close $::blob
}
@@ -96,6 +97,7 @@ do_ioerr_test incrblob_err-6 -cksum 1 -sqlprep {
INSERT INTO blobs VALUES(1, $::data || $::data || $::data);
} -tclbody {
set ::blob [db incrblob blobs v 1]
+ fconfigure $::blob -translation binary
seek $::blob -20 end
puts -nonewline $::blob "12345678900987654321"
close $::blob
diff --git a/lang/sql/sqlite/test/incrblobfault.test b/lang/sql/sqlite/test/incrblobfault.test
index d125471c..0c1d93d4 100644
--- a/lang/sql/sqlite/test/incrblobfault.test
+++ b/lang/sql/sqlite/test/incrblobfault.test
@@ -67,4 +67,3 @@ do_faultsim_test 3 -prep {
}
finish_test
-
diff --git a/lang/sql/sqlite/test/incrvacuum.test b/lang/sql/sqlite/test/incrvacuum.test
index ff21a31f..2f39857c 100644
--- a/lang/sql/sqlite/test/incrvacuum.test
+++ b/lang/sql/sqlite/test/incrvacuum.test
@@ -331,7 +331,7 @@ proc compare_dbs {A B tname} {
set ::str1 [string repeat abcdefghij 130]
set ::str2 [string repeat 1234567890 105]
-file delete -force test1.db test1.db-journal test2.db test2.db-journal
+forcedelete test1.db test1.db-journal test2.db test2.db-journal
sqlite3 db1 test1.db
sqlite3 db2 test2.db
execsql { PRAGMA auto_vacuum = 'none' } db1
@@ -477,7 +477,7 @@ do_test incrvacuum-8.1 {
#
do_test incrvacuum-9.1 {
db close
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db test.db
execsql {
@@ -595,7 +595,7 @@ do_test incrvacuum-10.8 {
# vacuum mode.
#
db close
-file delete -force test.db test.db-journal
+forcedelete test.db test.db-journal
sqlite3 db test.db
ifcapable default_autovacuum {
@@ -653,7 +653,7 @@ do_test incrvacuum-11.7 {
# auto_vacuum = XXX" statement is executed.
#
db close
-file delete -force test.db test.db-journal
+forcedelete test.db test.db-journal
sqlite3 db test.db
do_test incrvacuum-12.1 {
@@ -695,7 +695,7 @@ do_test incrvacuum-12.5 {
# DBSQL does not do "db2 close" here because incrvacuum-12.2 is excluded
# so db2 is not opended.
db close
-file delete -force test.db test.db-journal
+forcedelete test.db test.db-journal
sqlite3 db test.db ; set ::DB [sqlite3_connection_pointer db]
sqlite3 db2 test.db
@@ -746,7 +746,7 @@ if {[permutation] == ""} {
do_test incrvacuum-15.1 {
db close
db2 close
- file delete -force test.db
+ forcedelete test.db
sqlite3 db test.db
set str [string repeat "abcdefghij" 500]
diff --git a/lang/sql/sqlite/test/incrvacuum2.test b/lang/sql/sqlite/test/incrvacuum2.test
index 902517c9..6e8e1bed 100644
--- a/lang/sql/sqlite/test/incrvacuum2.test
+++ b/lang/sql/sqlite/test/incrvacuum2.test
@@ -70,7 +70,7 @@ do_test incrvacuum2-1.4 {
#
ifcapable attach {
do_test incrvacuum2-2.1 {
- file delete -force test2.db test2.db-journal
+ forcedelete test2.db test2.db-journal
execsql {
ATTACH DATABASE 'test2.db' AS aux;
PRAGMA aux.auto_vacuum=incremental;
@@ -191,7 +191,7 @@ ifcapable wal {
PRAGMA wal_checkpoint;
}
file size test.db-wal
- } {1640}
+ } [expr {32+2*(512+24)}]
do_test 4.3 {
db close
@@ -205,7 +205,7 @@ ifcapable wal {
if {$newsz>$maxsz} {set maxsz $newsz}
}
set maxsz
- } {2176}
+ } [expr {32+3*(512+24)}]
}
finish_test
diff --git a/lang/sql/sqlite/test/incrvacuum3.test b/lang/sql/sqlite/test/incrvacuum3.test
new file mode 100644
index 00000000..e901bfe1
--- /dev/null
+++ b/lang/sql/sqlite/test/incrvacuum3.test
@@ -0,0 +1,153 @@
+# 2013 Feb 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 the SQLite library, focusing
+# on the incremental vacuum feature.
+#
+# The tests in this file were added at the same time as optimizations
+# were made to:
+#
+# * Truncate the database after a rollback mode commit, and
+#
+# * Avoid moving pages to locations from which they may need to be moved
+# a second time if an incremental-vacuum proccess is allowed to vacuum
+# the entire database.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix incrvacuum3
+
+# If this build of the library does not support auto-vacuum, omit this
+# whole file.
+ifcapable {!autovacuum || !pragma} {
+ finish_test
+ return
+}
+
+proc check_on_disk {} {
+
+ # Copy the wal and journal files for database "test.db" to "test2.db".
+ forcedelete test2.db test2.db-journal test2.db-wal
+ if {[file exists test.db-journal]} {
+ forcecopy test.db-journal test2.db-journal
+ }
+ if {[file exists test.db-wal]} {
+ forcecopy test.db-wal test2.db-wal
+ }
+
+ # Now copy the database file itself. Do this using open/read/puts
+ # instead of the [file copy] command in order to avoid attempting
+ # to read the 512 bytes begining at offset $sqlite_pending_byte.
+ #
+ set sz [file size test.db]
+ set fd [open test.db]
+ set fd2 [open test2.db w]
+ fconfigure $fd -encoding binary -translation binary
+ fconfigure $fd2 -encoding binary -translation binary
+ if {$sz>$::sqlite_pending_byte} {
+ puts -nonewline $fd2 [read $fd $::sqlite_pending_byte]
+ seek $fd [expr $::sqlite_pending_byte+512]
+ seek $fd2 [expr $::sqlite_pending_byte+512]
+ }
+ puts -nonewline $fd2 [read $fd]
+ close $fd2
+ close $fd
+
+ # Open "test2.db" and check it is Ok.
+ sqlite3 dbcheck test2.db
+ set ret [dbcheck eval { PRAGMA integrity_check }]
+ dbcheck close
+ set ret
+}
+
+# Run these tests once in rollback journal mode, and once in wal mode.
+#
+foreach {T jrnl_mode} {
+ 1 delete
+ 2 wal
+} {
+ catch { db close }
+ forcedelete test.db test.db-journal test.db-wal
+ sqlite3 db test.db
+ db eval {
+ PRAGMA cache_size = 5;
+ PRAGMA page_size = 1024;
+ PRAGMA auto_vacuum = 2;
+ }
+ db eval "PRAGMA journal_mode = $jrnl_mode"
+
+ foreach {tn sql} {
+ 1 {
+ CREATE TABLE t1(x UNIQUE);
+ INSERT INTO t1 VALUES(randomblob(400));
+ INSERT INTO t1 VALUES(randomblob(400));
+ INSERT INTO t1 SELECT randomblob(400) FROM t1; -- 4
+ INSERT INTO t1 SELECT randomblob(400) FROM t1; -- 8
+ INSERT INTO t1 SELECT randomblob(400) FROM t1; -- 16
+ INSERT INTO t1 SELECT randomblob(400) FROM t1; -- 32
+ INSERT INTO t1 SELECT randomblob(400) FROM t1; -- 64
+ INSERT INTO t1 SELECT randomblob(400) FROM t1; -- 128
+ INSERT INTO t1 SELECT randomblob(400) FROM t1; -- 256
+ }
+
+ 2 {
+ DELETE FROM t1 WHERE rowid%8;
+ }
+
+ 3 {
+ BEGIN;
+ PRAGMA incremental_vacuum = 100;
+ INSERT INTO t1 SELECT randomblob(400) FROM t1; -- 64
+ INSERT INTO t1 SELECT randomblob(400) FROM t1; -- 128
+ INSERT INTO t1 SELECT randomblob(400) FROM t1; -- 256
+ ROLLBACK;
+ }
+
+ 4 {
+ BEGIN;
+ SAVEPOINT one;
+ PRAGMA incremental_vacuum = 100;
+ SAVEPOINT two;
+ INSERT INTO t1 SELECT randomblob(400) FROM t1; -- 64
+ INSERT INTO t1 SELECT randomblob(400) FROM t1; -- 128
+ INSERT INTO t1 SELECT randomblob(400) FROM t1; -- 256
+ }
+
+ 5 { ROLLBACK to two }
+
+ 6 { ROLLBACK to one }
+
+ 7 {
+ INSERT INTO t1 SELECT randomblob(400) FROM t1; -- 64
+ PRAGMA incremental_vacuum = 1000;
+ INSERT INTO t1 SELECT randomblob(400) FROM t1; -- 128
+ INSERT INTO t1 SELECT randomblob(400) FROM t1; -- 256
+ ROLLBACK;
+ }
+
+ 8 {
+ BEGIN;
+ INSERT INTO t1 SELECT randomblob(400) FROM t1; -- 64
+ PRAGMA incremental_vacuum = 1000;
+ INSERT INTO t1 SELECT randomblob(400) FROM t1; -- 128
+ COMMIT;
+ }
+ } {
+ do_execsql_test $T.1.$tn.1 $sql
+ do_execsql_test $T.1.$tn.2 {PRAGMA integrity_check} ok
+ do_test $T.1.$tn.3 { check_on_disk } ok
+ }
+
+ do_execsql_test $T.1.x.1 { PRAGMA freelist_count } 0
+ do_execsql_test $T.1.x.2 { SELECT count(*) FROM t1 } 128
+}
+
+finish_test
diff --git a/lang/sql/sqlite/test/incrvacuum_ioerr.test b/lang/sql/sqlite/test/incrvacuum_ioerr.test
index 47027b82..50f7fa20 100644
--- a/lang/sql/sqlite/test/incrvacuum_ioerr.test
+++ b/lang/sql/sqlite/test/incrvacuum_ioerr.test
@@ -108,7 +108,7 @@ do_ioerr_test incrvacuum-ioerr-3 -start 1 -cksum 1 -tclprep {
ifcapable shared_cache {
catch { db close }
- file delete -force test.db
+ forcedelete test.db
set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
# Create two connections to a single shared-cache:
@@ -139,8 +139,9 @@ ifcapable shared_cache {
# Figure out how big the database is and how many free pages it
# has before running incremental-vacuum.
#
- set nPage [expr {[file size test.db]/1024}]
set nFree [execsql {pragma freelist_count} db1]
+ set nPage [execsql {pragma page_count} db1]
+ puts "nFree=$nFree nPage=$nPage"
# Now run incremental-vacuum to vacuum 5 pages from the db file.
# The iTest'th I/O call is set to fail.
@@ -158,11 +159,11 @@ ifcapable shared_cache {
set ::sqlite_io_error_hardhit 0
set nFree2 [execsql {pragma freelist_count} db1]
- set nPage2 [expr {[file size test.db]/1024}]
+ set nPage2 [execsql {pragma page_count} db1]
do_test incrvacuum-ioerr-4.$iTest.2 {
set shrink [expr {$nPage-$nPage2}]
- expr {$shrink==0 || $shrink==5}
+ expr {$shrink==0 || $shrink==5 || ($nFree<5 && $shrink==$nFree)}
} {1}
do_test incrvacuum-ioerr-4.$iTest.3 {
diff --git a/lang/sql/sqlite/test/index.test b/lang/sql/sqlite/test/index.test
index 790bed90..59c0ea6f 100644
--- a/lang/sql/sqlite/test/index.test
+++ b/lang/sql/sqlite/test/index.test
@@ -666,7 +666,7 @@ ifcapable conflict {
BEGIN;
INSERT INTO t7 VALUES(1);
}
- } {1 {column a is not unique}}
+ } {1 {UNIQUE constraint failed: t7.a}}
do_test index-19.3 {
catchsql {
BEGIN;
@@ -676,7 +676,7 @@ ifcapable conflict {
catchsql {
INSERT INTO t8 VALUES(1);
}
- } {1 {column a is not unique}}
+ } {1 {UNIQUE constraint failed: t8.a}}
do_test index-19.5 {
catchsql {
BEGIN;
@@ -715,6 +715,23 @@ do_test index-20.2 {
DROP INDEX "t6i1";
}
} {}
+
+# Try to create a TEMP index on a non-TEMP table. */
+#
+do_test index-21.1 {
+ catchsql {
+ CREATE INDEX temp.i21 ON t6(c);
+ }
+} {1 {cannot create a TEMP index on non-TEMP table "t6"}}
+do_test index-21.2 {
+ catchsql {
+ CREATE TEMP TABLE t6(x);
+ INSERT INTO temp.t6 values(1),(5),(9);
+ CREATE INDEX temp.i21 ON t6(x);
+ SELECT x FROM t6 ORDER BY x DESC;
+ }
+} {0 {9 5 1}}
+
finish_test
diff --git a/lang/sql/sqlite/test/index3.test b/lang/sql/sqlite/test/index3.test
index 161ddecc..a9f9b7ae 100644
--- a/lang/sql/sqlite/test/index3.test
+++ b/lang/sql/sqlite/test/index3.test
@@ -34,7 +34,7 @@ do_test index3-1.2 {
BEGIN;
CREATE UNIQUE INDEX i1 ON t1(a);
}
-} {1 {indexed columns are not unique}}
+} {1 {UNIQUE constraint failed: t1.a}}
do_test index3-1.3 {
catchsql COMMIT;
} {0 {}}
diff --git a/lang/sql/sqlite/test/index4.test b/lang/sql/sqlite/test/index4.test
new file mode 100644
index 00000000..4fbfa529
--- /dev/null
+++ b/lang/sql/sqlite/test/index4.test
@@ -0,0 +1,126 @@
+# 2011 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. The
+# focus of this file is testing the CREATE INDEX statement.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+set testprefix index4
+
+do_execsql_test 1.1 {
+ BEGIN;
+ CREATE TABLE t1(x);
+ INSERT INTO t1 VALUES(randomblob(102));
+ INSERT INTO t1 SELECT randomblob(102) FROM t1; -- 2
+ INSERT INTO t1 SELECT randomblob(102) FROM t1; -- 4
+ INSERT INTO t1 SELECT randomblob(102) FROM t1; -- 8
+ INSERT INTO t1 SELECT randomblob(102) FROM t1; -- 16
+ INSERT INTO t1 SELECT randomblob(102) FROM t1; -- 32
+ INSERT INTO t1 SELECT randomblob(102) FROM t1; -- 64
+ INSERT INTO t1 SELECT randomblob(102) FROM t1; -- 128
+ INSERT INTO t1 SELECT randomblob(102) FROM t1; -- 256
+ INSERT INTO t1 SELECT randomblob(102) FROM t1; -- 512
+ INSERT INTO t1 SELECT randomblob(102) FROM t1; -- 1024
+ INSERT INTO t1 SELECT randomblob(102) FROM t1; -- 2048
+ INSERT INTO t1 SELECT randomblob(102) FROM t1; -- 4096
+ INSERT INTO t1 SELECT randomblob(102) FROM t1; -- 8192
+ INSERT INTO t1 SELECT randomblob(102) FROM t1; -- 16384
+ INSERT INTO t1 SELECT randomblob(102) FROM t1; -- 32768
+ INSERT INTO t1 SELECT randomblob(102) FROM t1; -- 65536
+ COMMIT;
+}
+
+do_execsql_test 1.2 {
+ CREATE INDEX i1 ON t1(x);
+}
+do_execsql_test 1.3 {
+ PRAGMA integrity_check
+} {ok}
+
+# The same test again - this time with limited memory.
+#
+ifcapable memorymanage {
+ set soft_limit [sqlite3_soft_heap_limit 50000]
+
+ db close
+ sqlite3 db test.db
+
+ do_execsql_test 1.4 {
+ PRAGMA cache_size = 10;
+ CREATE INDEX i2 ON t1(x);
+ }
+ do_execsql_test 1.5 {
+ PRAGMA integrity_check
+ } {ok}
+
+ sqlite3_soft_heap_limit $soft_limit
+}
+
+
+do_execsql_test 1.6 {
+ BEGIN;
+ DROP TABLE t1;
+ CREATE TABLE t1(x);
+ INSERT INTO t1 VALUES('a');
+ INSERT INTO t1 VALUES('b');
+ INSERT INTO t1 VALUES('c');
+ INSERT INTO t1 VALUES('d');
+ INSERT INTO t1 VALUES('e');
+ INSERT INTO t1 VALUES('f');
+ INSERT INTO t1 VALUES('g');
+ INSERT INTO t1 VALUES(NULL);
+ INSERT INTO t1 SELECT randomblob(1202) FROM t1; -- 16
+ INSERT INTO t1 SELECT randomblob(2202) FROM t1; -- 32
+ INSERT INTO t1 SELECT randomblob(3202) FROM t1; -- 64
+ INSERT INTO t1 SELECT randomblob(4202) FROM t1; -- 128
+ INSERT INTO t1 SELECT randomblob(5202) FROM t1; -- 256
+ COMMIT;
+ CREATE INDEX i1 ON t1(x);
+ PRAGMA integrity_check
+} {ok}
+
+do_execsql_test 1.7 {
+ BEGIN;
+ DROP TABLE t1;
+ CREATE TABLE t1(x);
+ INSERT INTO t1 VALUES('a');
+ COMMIT;
+ CREATE INDEX i1 ON t1(x);
+ PRAGMA integrity_check
+} {ok}
+
+do_execsql_test 1.8 {
+ BEGIN;
+ DROP TABLE t1;
+ CREATE TABLE t1(x);
+ COMMIT;
+ CREATE INDEX i1 ON t1(x);
+ PRAGMA integrity_check
+} {ok}
+
+do_execsql_test 2.1 {
+ BEGIN;
+ CREATE TABLE t2(x);
+ INSERT INTO t2 VALUES(14);
+ INSERT INTO t2 VALUES(35);
+ INSERT INTO t2 VALUES(15);
+ INSERT INTO t2 VALUES(35);
+ INSERT INTO t2 VALUES(16);
+ COMMIT;
+}
+do_catchsql_test 2.2 {
+ CREATE UNIQUE INDEX i3 ON t2(x);
+} {1 {UNIQUE constraint failed: t2.x}}
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/index5.test b/lang/sql/sqlite/test/index5.test
new file mode 100644
index 00000000..78953913
--- /dev/null
+++ b/lang/sql/sqlite/test/index5.test
@@ -0,0 +1,75 @@
+# 2012 August 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 index5
+
+do_test 1.1 {
+ execsql {
+ PRAGMA page_size = 1024;
+ CREATE TABLE t1(x);
+ BEGIN;
+ }
+ for {set i 0} {$i < 100000} {incr i} {
+ execsql { INSERT INTO t1 VALUES(randstr(100,100)) }
+ }
+ execsql COMMIT
+ execsql {
+ CREATE INDEX i1 ON t1(x);
+ DROP INDEX I1;
+ PRAGMA main.page_size;
+ }
+} {1024}
+
+db close
+testvfs tvfs
+tvfs filter xWrite
+tvfs script write_cb
+proc write_cb {xCall file handle iOfst args} {
+ if {[file tail $file]=="test.db"} {
+ lappend ::write_list [expr $iOfst/1024]
+ }
+}
+
+do_test 1.2 {
+ sqlite3 db test.db -vfs tvfs
+ set ::write_list [list]
+ execsql { CREATE INDEX i1 ON t1(x) }
+} {}
+
+do_test 1.3 {
+ set nForward 0
+ set nBackward 0
+ set nNoncont 0
+ set iPrev [lindex $::write_list 0]
+ for {set i 1} {$i < [llength $::write_list]} {incr i} {
+ set iNext [lindex $::write_list $i]
+ if {$iNext==($iPrev+1)} {
+ incr nForward
+ } elseif {$iNext==($iPrev-1)} {
+ incr nBackward
+ } else {
+ incr nNoncont
+ }
+ set iPrev $iNext
+ }
+ puts -nonewline \
+ " (forward=$nForward, back=$nBackward, noncontiguous=$nNoncont)"
+
+ expr {$nForward > 2*($nBackward + $nNoncont)}
+} {1}
+db close
+tvfs delete
+
+finish_test
diff --git a/lang/sql/sqlite/test/index6.test b/lang/sql/sqlite/test/index6.test
new file mode 100644
index 00000000..48706be3
--- /dev/null
+++ b/lang/sql/sqlite/test/index6.test
@@ -0,0 +1,251 @@
+# 2013-07-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.
+#
+#***********************************************************************
+#
+# Test cases for partial indices
+#
+
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+ifcapable !vtab {
+ finish_test
+ return
+}
+
+load_static_extension db wholenumber;
+do_test index6-1.1 {
+ # Able to parse and manage partial indices
+ execsql {
+ CREATE TABLE t1(a,b,c);
+ CREATE INDEX t1a ON t1(a) WHERE a IS NOT NULL;
+ CREATE INDEX t1b ON t1(b) WHERE b>10;
+ CREATE VIRTUAL TABLE nums USING wholenumber;
+ INSERT INTO t1(a,b,c)
+ SELECT CASE WHEN value%3!=0 THEN value END, value, value
+ FROM nums WHERE value<=20;
+ SELECT count(a), count(b) FROM t1;
+ PRAGMA integrity_check;
+ }
+} {14 20 ok}
+
+# Make sure the count(*) optimization works correctly with
+# partial indices. Ticket [a5c8ed66cae16243be6] 2013-10-03.
+#
+do_execsql_test index6-1.1.1 {
+ SELECT count(*) FROM t1;
+} {20}
+
+# Error conditions during parsing...
+#
+do_test index6-1.2 {
+ catchsql {
+ CREATE INDEX bad1 ON t1(a,b) WHERE x IS NOT NULL;
+ }
+} {1 {no such column: x}}
+do_test index6-1.3 {
+ catchsql {
+ CREATE INDEX bad1 ON t1(a,b) WHERE EXISTS(SELECT * FROM t1);
+ }
+} {1 {subqueries prohibited in partial index WHERE clauses}}
+do_test index6-1.4 {
+ catchsql {
+ CREATE INDEX bad1 ON t1(a,b) WHERE a!=?1;
+ }
+} {1 {parameters prohibited in partial index WHERE clauses}}
+do_test index6-1.5 {
+ catchsql {
+ CREATE INDEX bad1 ON t1(a,b) WHERE a!=random();
+ }
+} {1 {functions prohibited in partial index WHERE clauses}}
+do_test index6-1.6 {
+ catchsql {
+ CREATE INDEX bad1 ON t1(a,b) WHERE a NOT LIKE 'abc%';
+ }
+} {1 {functions prohibited in partial index WHERE clauses}}
+
+do_test index6-1.10 {
+ execsql {
+ ANALYZE;
+ SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
+ PRAGMA integrity_check;
+ }
+} {{} 20 t1a {14 1} t1b {10 1} ok}
+
+# STAT1 shows the partial indices have a reduced number of
+# rows.
+#
+do_test index6-1.11 {
+ execsql {
+ UPDATE t1 SET a=b;
+ ANALYZE;
+ SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
+ PRAGMA integrity_check;
+ }
+} {{} 20 t1a {20 1} t1b {10 1} ok}
+
+do_test index6-1.11 {
+ execsql {
+ UPDATE t1 SET a=NULL WHERE b%3!=0;
+ UPDATE t1 SET b=b+100;
+ ANALYZE;
+ SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
+ PRAGMA integrity_check;
+ }
+} {{} 20 t1a {6 1} t1b {20 1} ok}
+
+do_test index6-1.12 {
+ execsql {
+ UPDATE t1 SET a=CASE WHEN b%3!=0 THEN b END;
+ UPDATE t1 SET b=b-100;
+ ANALYZE;
+ SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
+ PRAGMA integrity_check;
+ }
+} {{} 20 t1a {13 1} t1b {10 1} ok}
+
+do_test index6-1.13 {
+ execsql {
+ DELETE FROM t1 WHERE b BETWEEN 8 AND 12;
+ ANALYZE;
+ SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
+ PRAGMA integrity_check;
+ }
+} {{} 15 t1a {10 1} t1b {8 1} ok}
+
+do_test index6-1.14 {
+ execsql {
+ REINDEX;
+ ANALYZE;
+ SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
+ PRAGMA integrity_check;
+ }
+} {{} 15 t1a {10 1} t1b {8 1} ok}
+
+do_test index6-1.15 {
+ execsql {
+ CREATE INDEX t1c ON t1(c);
+ ANALYZE;
+ SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
+ PRAGMA integrity_check;
+ }
+} {t1a {10 1} t1b {8 1} t1c {15 1} ok}
+
+# Queries use partial indices as appropriate times.
+#
+do_test index6-2.1 {
+ execsql {
+ CREATE TABLE t2(a,b);
+ INSERT INTO t2(a,b) SELECT value, value FROM nums WHERE value<1000;
+ UPDATE t2 SET a=NULL WHERE b%5==0;
+ CREATE INDEX t2a1 ON t2(a) WHERE a IS NOT NULL;
+ SELECT count(*) FROM t2 WHERE a IS NOT NULL;
+ }
+} {800}
+do_test index6-2.2 {
+ execsql {
+ EXPLAIN QUERY PLAN
+ SELECT * FROM t2 WHERE a=5;
+ }
+} {/.* TABLE t2 USING INDEX t2a1 .*/}
+ifcapable stat4||stat3 {
+ do_test index6-2.3stat4 {
+ execsql {
+ EXPLAIN QUERY PLAN
+ SELECT * FROM t2 WHERE a IS NOT NULL;
+ }
+ } {/.* TABLE t2 USING INDEX t2a1 .*/}
+} else {
+ do_test index6-2.3stat4 {
+ execsql {
+ EXPLAIN QUERY PLAN
+ SELECT * FROM t2 WHERE a IS NOT NULL AND a>0;
+ }
+ } {/.* TABLE t2 USING INDEX t2a1 .*/}
+}
+do_test index6-2.4 {
+ execsql {
+ EXPLAIN QUERY PLAN
+ SELECT * FROM t2 WHERE a IS NULL;
+ }
+} {~/.*INDEX t2a1.*/}
+
+do_execsql_test index6-2.101 {
+ DROP INDEX t2a1;
+ UPDATE t2 SET a=b, b=b+10000;
+ SELECT b FROM t2 WHERE a=15;
+} {10015}
+do_execsql_test index6-2.102 {
+ CREATE INDEX t2a2 ON t2(a) WHERE a<100 OR a>200;
+ SELECT b FROM t2 WHERE a=15;
+ PRAGMA integrity_check;
+} {10015 ok}
+do_execsql_test index6-2.102eqp {
+ EXPLAIN QUERY PLAN
+ SELECT b FROM t2 WHERE a=15;
+} {~/.*INDEX t2a2.*/}
+do_execsql_test index6-2.103 {
+ SELECT b FROM t2 WHERE a=15 AND a<100;
+} {10015}
+do_execsql_test index6-2.103eqp {
+ EXPLAIN QUERY PLAN
+ SELECT b FROM t2 WHERE a=15 AND a<100;
+} {/.*INDEX t2a2.*/}
+do_execsql_test index6-2.104 {
+ SELECT b FROM t2 WHERE a=515 AND a>200;
+} {10515}
+do_execsql_test index6-2.104eqp {
+ EXPLAIN QUERY PLAN
+ SELECT b FROM t2 WHERE a=515 AND a>200;
+} {/.*INDEX t2a2.*/}
+
+# Partial UNIQUE indices
+#
+do_execsql_test index6-3.1 {
+ CREATE TABLE t3(a,b);
+ INSERT INTO t3 SELECT value, value FROM nums WHERE value<200;
+ UPDATE t3 SET a=999 WHERE b%5!=0;
+ CREATE UNIQUE INDEX t3a ON t3(a) WHERE a<>999;
+} {}
+do_test index6-3.2 {
+ # unable to insert a duplicate row a-value that is not 999.
+ catchsql {
+ INSERT INTO t3(a,b) VALUES(150, 'test1');
+ }
+} {1 {UNIQUE constraint failed: t3.a}}
+do_test index6-3.3 {
+ # can insert multiple rows with a==999 because such rows are not
+ # part of the unique index.
+ catchsql {
+ INSERT INTO t3(a,b) VALUES(999, 'test1'), (999, 'test2');
+ }
+} {0 {}}
+do_execsql_test index6-3.4 {
+ SELECT count(*) FROM t3 WHERE a=999;
+} {162}
+integrity_check index6-3.5
+
+do_execsql_test index6-4.0 {
+ VACUUM;
+ PRAGMA integrity_check;
+} {ok}
+
+# Silently ignore database name qualifiers in partial indices.
+#
+do_execsql_test index6-5.0 {
+ CREATE INDEX t3b ON t3(b) WHERE xyzzy.t3.b BETWEEN 5 AND 10;
+ /* ^^^^^-- ignored */
+ ANALYZE;
+ SELECT count(*) FROM t3 WHERE t3.b BETWEEN 5 AND 10;
+ SELECT stat+0 FROM sqlite_stat1 WHERE idx='t3b';
+} {6 6}
+
+finish_test
diff --git a/lang/sql/sqlite/test/index7.test b/lang/sql/sqlite/test/index7.test
new file mode 100644
index 00000000..1c81f602
--- /dev/null
+++ b/lang/sql/sqlite/test/index7.test
@@ -0,0 +1,251 @@
+# 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.
+#
+#***********************************************************************
+#
+# Test cases for partial indices in WITHOUT ROWID tables
+#
+
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+ifcapable !vtab {
+ finish_test
+ return
+}
+
+load_static_extension db wholenumber;
+do_test index7-1.1 {
+ # Able to parse and manage partial indices
+ execsql {
+ CREATE TABLE t1(a,b,c PRIMARY KEY) WITHOUT rowid;
+ CREATE INDEX t1a ON t1(a) WHERE a IS NOT NULL;
+ CREATE INDEX t1b ON t1(b) WHERE b>10;
+ CREATE VIRTUAL TABLE nums USING wholenumber;
+ INSERT INTO t1(a,b,c)
+ SELECT CASE WHEN value%3!=0 THEN value END, value, value
+ FROM nums WHERE value<=20;
+ SELECT count(a), count(b) FROM t1;
+ PRAGMA integrity_check;
+ }
+} {14 20 ok}
+
+# Make sure the count(*) optimization works correctly with
+# partial indices. Ticket [a5c8ed66cae16243be6] 2013-10-03.
+#
+do_execsql_test index7-1.1.1 {
+ SELECT count(*) FROM t1;
+} {20}
+
+# Error conditions during parsing...
+#
+do_test index7-1.2 {
+ catchsql {
+ CREATE INDEX bad1 ON t1(a,b) WHERE x IS NOT NULL;
+ }
+} {1 {no such column: x}}
+do_test index7-1.3 {
+ catchsql {
+ CREATE INDEX bad1 ON t1(a,b) WHERE EXISTS(SELECT * FROM t1);
+ }
+} {1 {subqueries prohibited in partial index WHERE clauses}}
+do_test index7-1.4 {
+ catchsql {
+ CREATE INDEX bad1 ON t1(a,b) WHERE a!=?1;
+ }
+} {1 {parameters prohibited in partial index WHERE clauses}}
+do_test index7-1.5 {
+ catchsql {
+ CREATE INDEX bad1 ON t1(a,b) WHERE a!=random();
+ }
+} {1 {functions prohibited in partial index WHERE clauses}}
+do_test index7-1.6 {
+ catchsql {
+ CREATE INDEX bad1 ON t1(a,b) WHERE a NOT LIKE 'abc%';
+ }
+} {1 {functions prohibited in partial index WHERE clauses}}
+
+do_test index7-1.10 {
+ execsql {
+ ANALYZE;
+ SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
+ PRAGMA integrity_check;
+ }
+} {t1 {20 1} t1a {14 1} t1b {10 1} ok}
+
+# STAT1 shows the partial indices have a reduced number of
+# rows.
+#
+do_test index7-1.11 {
+ execsql {
+ UPDATE t1 SET a=b;
+ ANALYZE;
+ SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
+ PRAGMA integrity_check;
+ }
+} {t1 {20 1} t1a {20 1} t1b {10 1} ok}
+
+do_test index7-1.11b {
+ execsql {
+ UPDATE t1 SET a=NULL WHERE b%3!=0;
+ UPDATE t1 SET b=b+100;
+ ANALYZE;
+ SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
+ PRAGMA integrity_check;
+ }
+} {t1 {20 1} t1a {6 1} t1b {20 1} ok}
+
+do_test index7-1.12 {
+ execsql {
+ UPDATE t1 SET a=CASE WHEN b%3!=0 THEN b END;
+ UPDATE t1 SET b=b-100;
+ ANALYZE;
+ SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
+ PRAGMA integrity_check;
+ }
+} {t1 {20 1} t1a {13 1} t1b {10 1} ok}
+
+do_test index7-1.13 {
+ execsql {
+ DELETE FROM t1 WHERE b BETWEEN 8 AND 12;
+ ANALYZE;
+ SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
+ PRAGMA integrity_check;
+ }
+} {t1 {15 1} t1a {10 1} t1b {8 1} ok}
+
+do_test index7-1.14 {
+ execsql {
+ REINDEX;
+ ANALYZE;
+ SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
+ PRAGMA integrity_check;
+ }
+} {t1 {15 1} t1a {10 1} t1b {8 1} ok}
+
+do_test index7-1.15 {
+ execsql {
+ CREATE INDEX t1c ON t1(c);
+ ANALYZE;
+ SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
+ PRAGMA integrity_check;
+ }
+} {t1 {15 1} t1a {10 1} t1b {8 1} t1c {15 1} ok}
+
+# Queries use partial indices as appropriate times.
+#
+do_test index7-2.1 {
+ execsql {
+ CREATE TABLE t2(a,b PRIMARY KEY) without rowid;
+ INSERT INTO t2(a,b) SELECT value, value FROM nums WHERE value<1000;
+ UPDATE t2 SET a=NULL WHERE b%5==0;
+ CREATE INDEX t2a1 ON t2(a) WHERE a IS NOT NULL;
+ SELECT count(*) FROM t2 WHERE a IS NOT NULL;
+ }
+} {800}
+do_test index7-2.2 {
+ execsql {
+ EXPLAIN QUERY PLAN
+ SELECT * FROM t2 WHERE a=5;
+ }
+} {/.* TABLE t2 USING COVERING INDEX t2a1 .*/}
+ifcapable stat4||stat3 {
+ do_test index7-2.3stat4 {
+ execsql {
+ EXPLAIN QUERY PLAN
+ SELECT * FROM t2 WHERE a IS NOT NULL;
+ }
+ } {/.* TABLE t2 USING COVERING INDEX t2a1 .*/}
+} else {
+ do_test index7-2.3stat4 {
+ execsql {
+ EXPLAIN QUERY PLAN
+ SELECT * FROM t2 WHERE a IS NOT NULL AND a>0;
+ }
+ } {/.* TABLE t2 USING COVERING INDEX t2a1 .*/}
+}
+do_test index7-2.4 {
+ execsql {
+ EXPLAIN QUERY PLAN
+ SELECT * FROM t2 WHERE a IS NULL;
+ }
+} {~/.*INDEX t2a1.*/}
+
+do_execsql_test index7-2.101 {
+ DROP INDEX t2a1;
+ UPDATE t2 SET a=b, b=b+10000;
+ SELECT b FROM t2 WHERE a=15;
+} {10015}
+do_execsql_test index7-2.102 {
+ CREATE INDEX t2a2 ON t2(a) WHERE a<100 OR a>200;
+ SELECT b FROM t2 WHERE a=15;
+ PRAGMA integrity_check;
+} {10015 ok}
+do_execsql_test index7-2.102eqp {
+ EXPLAIN QUERY PLAN
+ SELECT b FROM t2 WHERE a=15;
+} {~/.*INDEX t2a2.*/}
+do_execsql_test index7-2.103 {
+ SELECT b FROM t2 WHERE a=15 AND a<100;
+} {10015}
+do_execsql_test index7-2.103eqp {
+ EXPLAIN QUERY PLAN
+ SELECT b FROM t2 WHERE a=15 AND a<100;
+} {/.*INDEX t2a2.*/}
+do_execsql_test index7-2.104 {
+ SELECT b FROM t2 WHERE a=515 AND a>200;
+} {10515}
+do_execsql_test index7-2.104eqp {
+ EXPLAIN QUERY PLAN
+ SELECT b FROM t2 WHERE a=515 AND a>200;
+} {/.*INDEX t2a2.*/}
+
+# Partial UNIQUE indices
+#
+do_execsql_test index7-3.1 {
+ CREATE TABLE t3(a,b PRIMARY KEY) without rowid;
+ INSERT INTO t3 SELECT value, value FROM nums WHERE value<200;
+ UPDATE t3 SET a=999 WHERE b%5!=0;
+ CREATE UNIQUE INDEX t3a ON t3(a) WHERE a<>999;
+} {}
+do_test index7-3.2 {
+ # unable to insert a duplicate row a-value that is not 999.
+ catchsql {
+ INSERT INTO t3(a,b) VALUES(150, 'test1');
+ }
+} {1 {UNIQUE constraint failed: t3.a}}
+do_test index7-3.3 {
+ # can insert multiple rows with a==999 because such rows are not
+ # part of the unique index.
+ catchsql {
+ INSERT INTO t3(a,b) VALUES(999, 'test1'), (999, 'test2');
+ }
+} {0 {}}
+do_execsql_test index7-3.4 {
+ SELECT count(*) FROM t3 WHERE a=999;
+} {162}
+integrity_check index7-3.5
+
+do_execsql_test index7-4.0 {
+ VACUUM;
+ PRAGMA integrity_check;
+} {ok}
+
+# Silently ignore database name qualifiers in partial indices.
+#
+do_execsql_test index7-5.0 {
+ CREATE INDEX t3b ON t3(b) WHERE xyzzy.t3.b BETWEEN 5 AND 10;
+ /* ^^^^^-- ignored */
+ ANALYZE;
+ SELECT count(*) FROM t3 WHERE t3.b BETWEEN 5 AND 10;
+ SELECT stat+0 FROM sqlite_stat1 WHERE idx='t3b';
+} {6 6}
+
+finish_test
diff --git a/lang/sql/sqlite/test/indexedby.test b/lang/sql/sqlite/test/indexedby.test
index 7ccc4de2..f95c167f 100644
--- a/lang/sql/sqlite/test/indexedby.test
+++ b/lang/sql/sqlite/test/indexedby.test
@@ -13,6 +13,7 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
+set ::testprefix indexedby
# Create a schema with some indexes.
#
@@ -42,15 +43,15 @@ proc EQP {sql} {
#
do_execsql_test indexedby-1.2 {
EXPLAIN QUERY PLAN select * from t1 WHERE a = 10;
-} {0 0 0 {SEARCH TABLE t1 USING INDEX i1 (a=?) (~10 rows)}}
+} {0 0 0 {SEARCH TABLE t1 USING INDEX i1 (a=?)}}
do_execsql_test indexedby-1.3 {
EXPLAIN QUERY PLAN select * from t1 ;
-} {0 0 0 {SCAN TABLE t1 (~1000000 rows)}}
+} {0 0 0 {SCAN TABLE t1}}
do_execsql_test indexedby-1.4 {
EXPLAIN QUERY PLAN select * from t1, t2 WHERE c = 10;
} {
- 0 0 1 {SEARCH TABLE t2 USING INDEX i3 (c=?) (~10 rows)}
- 0 1 0 {SCAN TABLE t1 (~1000000 rows)}
+ 0 0 1 {SEARCH TABLE t2 USING INDEX i3 (c=?)}
+ 0 1 0 {SCAN TABLE t1}
}
# Parser tests. Test that an INDEXED BY or NOT INDEX clause can be
@@ -85,21 +86,21 @@ do_test indexedby-2.7 {
#
do_execsql_test indexedby-3.1 {
EXPLAIN QUERY PLAN SELECT * FROM t1 NOT INDEXED WHERE a = 'one' AND b = 'two'
-} {0 0 0 {SCAN TABLE t1 (~10000 rows)}}
+} {0 0 0 {SCAN TABLE t1}}
do_execsql_test indexedby-3.2 {
EXPLAIN QUERY PLAN
SELECT * FROM t1 INDEXED BY i1 WHERE a = 'one' AND b = 'two'
-} {0 0 0 {SEARCH TABLE t1 USING INDEX i1 (a=?) (~2 rows)}}
+} {0 0 0 {SEARCH TABLE t1 USING INDEX i1 (a=?)}}
do_execsql_test indexedby-3.3 {
EXPLAIN QUERY PLAN
SELECT * FROM t1 INDEXED BY i2 WHERE a = 'one' AND b = 'two'
-} {0 0 0 {SEARCH TABLE t1 USING INDEX i2 (b=?) (~2 rows)}}
+} {0 0 0 {SEARCH TABLE t1 USING INDEX i2 (b=?)}}
do_test indexedby-3.4 {
catchsql { SELECT * FROM t1 INDEXED BY i2 WHERE a = 'one' }
-} {1 {cannot use index: i2}}
+} {1 {no query solution}}
do_test indexedby-3.5 {
catchsql { SELECT * FROM t1 INDEXED BY i2 ORDER BY a }
-} {1 {cannot use index: i2}}
+} {1 {no query solution}}
do_test indexedby-3.6 {
catchsql { SELECT * FROM t1 INDEXED BY i1 WHERE a = 'one' }
} {0 {}}
@@ -110,14 +111,14 @@ do_test indexedby-3.7 {
do_execsql_test indexedby-3.8 {
EXPLAIN QUERY PLAN
SELECT * FROM t3 INDEXED BY sqlite_autoindex_t3_1 ORDER BY e
-} {0 0 0 {SCAN TABLE t3 USING INDEX sqlite_autoindex_t3_1 (~1000000 rows)}}
+} {0 0 0 {SCAN TABLE t3 USING INDEX sqlite_autoindex_t3_1}}
do_execsql_test indexedby-3.9 {
EXPLAIN QUERY PLAN
SELECT * FROM t3 INDEXED BY sqlite_autoindex_t3_1 WHERE e = 10
-} {0 0 0 {SEARCH TABLE t3 USING INDEX sqlite_autoindex_t3_1 (e=?) (~1 rows)}}
+} {0 0 0 {SEARCH TABLE t3 USING INDEX sqlite_autoindex_t3_1 (e=?)}}
do_test indexedby-3.10 {
catchsql { SELECT * FROM t3 INDEXED BY sqlite_autoindex_t3_1 WHERE f = 10 }
-} {1 {cannot use index: sqlite_autoindex_t3_1}}
+} {1 {no query solution}}
do_test indexedby-3.11 {
catchsql { SELECT * FROM t3 INDEXED BY sqlite_autoindex_t3_2 WHERE f = 10 }
} {1 {no such index: sqlite_autoindex_t3_2}}
@@ -127,25 +128,25 @@ do_test indexedby-3.11 {
do_execsql_test indexedby-4.1 {
EXPLAIN QUERY PLAN SELECT * FROM t1, t2 WHERE a = c
} {
- 0 0 0 {SCAN TABLE t1 (~1000000 rows)}
- 0 1 1 {SEARCH TABLE t2 USING INDEX i3 (c=?) (~10 rows)}
+ 0 0 0 {SCAN TABLE t1}
+ 0 1 1 {SEARCH TABLE t2 USING INDEX i3 (c=?)}
}
do_execsql_test indexedby-4.2 {
EXPLAIN QUERY PLAN SELECT * FROM t1 INDEXED BY i1, t2 WHERE a = c
} {
- 0 0 1 {SCAN TABLE t2 (~1000000 rows)}
- 0 1 0 {SEARCH TABLE t1 USING INDEX i1 (a=?) (~10 rows)}
+ 0 0 1 {SCAN TABLE t2}
+ 0 1 0 {SEARCH TABLE t1 USING INDEX i1 (a=?)}
}
do_test indexedby-4.3 {
catchsql {
SELECT * FROM t1 INDEXED BY i1, t2 INDEXED BY i3 WHERE a=c
}
-} {1 {cannot use index: i1}}
+} {1 {no query solution}}
do_test indexedby-4.4 {
catchsql {
SELECT * FROM t2 INDEXED BY i3, t1 INDEXED BY i1 WHERE a=c
}
-} {1 {cannot use index: i3}}
+} {1 {no query solution}}
# Test embedding an INDEXED BY in a CREATE VIEW statement. This block
# also tests that nothing bad happens if an index refered to by
@@ -154,10 +155,10 @@ do_test indexedby-4.4 {
do_execsql_test indexedby-5.1 {
CREATE VIEW v2 AS SELECT * FROM t1 INDEXED BY i1 WHERE a > 5;
EXPLAIN QUERY PLAN SELECT * FROM v2
-} {0 0 0 {SEARCH TABLE t1 USING INDEX i1 (a>?) (~250000 rows)}}
+} {0 0 0 {SEARCH TABLE t1 USING INDEX i1 (a>?)}}
do_execsql_test indexedby-5.2 {
EXPLAIN QUERY PLAN SELECT * FROM v2 WHERE b = 10
-} {0 0 0 {SEARCH TABLE t1 USING INDEX i1 (a>?) (~25000 rows)}}
+} {0 0 0 {SEARCH TABLE t1 USING INDEX i1 (a>?)}}
do_test indexedby-5.3 {
execsql { DROP INDEX i1 }
catchsql { SELECT * FROM v2 }
@@ -166,7 +167,7 @@ do_test indexedby-5.4 {
# Recreate index i1 in such a way as it cannot be used by the view query.
execsql { CREATE INDEX i1 ON t1(b) }
catchsql { SELECT * FROM v2 }
-} {1 {cannot use index: i1}}
+} {1 {no query solution}}
do_test indexedby-5.5 {
# Drop and recreate index i1 again. This time, create it so that it can
# be used by the query.
@@ -178,54 +179,54 @@ do_test indexedby-5.5 {
#
do_execsql_test indexedby-6.1 {
EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE b = 10 ORDER BY rowid
-} {0 0 0 {SEARCH TABLE t1 USING INDEX i2 (b=?) (~10 rows)}}
+} {0 0 0 {SEARCH TABLE t1 USING INDEX i2 (b=?)}}
do_execsql_test indexedby-6.2 {
EXPLAIN QUERY PLAN SELECT * FROM t1 NOT INDEXED WHERE b = 10 ORDER BY rowid
-} {0 0 0 {SCAN TABLE t1 USING INTEGER PRIMARY KEY (~100000 rows)}}
+} {0 0 0 {SCAN TABLE t1}}
# Test that "INDEXED BY" can be used in a DELETE statement.
#
do_execsql_test indexedby-7.1 {
EXPLAIN QUERY PLAN DELETE FROM t1 WHERE a = 5
-} {0 0 0 {SEARCH TABLE t1 USING COVERING INDEX i1 (a=?) (~10 rows)}}
+} {0 0 0 {SEARCH TABLE t1 USING COVERING INDEX i1 (a=?)}}
do_execsql_test indexedby-7.2 {
EXPLAIN QUERY PLAN DELETE FROM t1 NOT INDEXED WHERE a = 5
-} {0 0 0 {SCAN TABLE t1 (~100000 rows)}}
+} {0 0 0 {SCAN TABLE t1}}
do_execsql_test indexedby-7.3 {
EXPLAIN QUERY PLAN DELETE FROM t1 INDEXED BY i1 WHERE a = 5
-} {0 0 0 {SEARCH TABLE t1 USING COVERING INDEX i1 (a=?) (~10 rows)}}
+} {0 0 0 {SEARCH TABLE t1 USING COVERING INDEX i1 (a=?)}}
do_execsql_test indexedby-7.4 {
EXPLAIN QUERY PLAN DELETE FROM t1 INDEXED BY i1 WHERE a = 5 AND b = 10
-} {0 0 0 {SEARCH TABLE t1 USING INDEX i1 (a=?) (~2 rows)}}
+} {0 0 0 {SEARCH TABLE t1 USING INDEX i1 (a=?)}}
do_execsql_test indexedby-7.5 {
EXPLAIN QUERY PLAN DELETE FROM t1 INDEXED BY i2 WHERE a = 5 AND b = 10
-} {0 0 0 {SEARCH TABLE t1 USING INDEX i2 (b=?) (~2 rows)}}
+} {0 0 0 {SEARCH TABLE t1 USING INDEX i2 (b=?)}}
do_test indexedby-7.6 {
catchsql { DELETE FROM t1 INDEXED BY i2 WHERE a = 5}
-} {1 {cannot use index: i2}}
+} {1 {no query solution}}
# Test that "INDEXED BY" can be used in an UPDATE statement.
#
do_execsql_test indexedby-8.1 {
EXPLAIN QUERY PLAN UPDATE t1 SET rowid=rowid+1 WHERE a = 5
-} {0 0 0 {SEARCH TABLE t1 USING COVERING INDEX i1 (a=?) (~10 rows)}}
+} {0 0 0 {SEARCH TABLE t1 USING COVERING INDEX i1 (a=?)}}
do_execsql_test indexedby-8.2 {
EXPLAIN QUERY PLAN UPDATE t1 NOT INDEXED SET rowid=rowid+1 WHERE a = 5
-} {0 0 0 {SCAN TABLE t1 (~100000 rows)}}
+} {0 0 0 {SCAN TABLE t1}}
do_execsql_test indexedby-8.3 {
EXPLAIN QUERY PLAN UPDATE t1 INDEXED BY i1 SET rowid=rowid+1 WHERE a = 5
-} {0 0 0 {SEARCH TABLE t1 USING COVERING INDEX i1 (a=?) (~10 rows)}}
+} {0 0 0 {SEARCH TABLE t1 USING COVERING INDEX i1 (a=?)}}
do_execsql_test indexedby-8.4 {
EXPLAIN QUERY PLAN
UPDATE t1 INDEXED BY i1 SET rowid=rowid+1 WHERE a = 5 AND b = 10
-} {0 0 0 {SEARCH TABLE t1 USING INDEX i1 (a=?) (~2 rows)}}
+} {0 0 0 {SEARCH TABLE t1 USING INDEX i1 (a=?)}}
do_execsql_test indexedby-8.5 {
EXPLAIN QUERY PLAN
UPDATE t1 INDEXED BY i2 SET rowid=rowid+1 WHERE a = 5 AND b = 10
-} {0 0 0 {SEARCH TABLE t1 USING INDEX i2 (b=?) (~2 rows)}}
+} {0 0 0 {SEARCH TABLE t1 USING INDEX i2 (b=?)}}
do_test indexedby-8.6 {
catchsql { UPDATE t1 INDEXED BY i2 SET rowid=rowid+1 WHERE a = 5}
-} {1 {cannot use index: i2}}
+} {1 {no query solution}}
# Test that bug #3560 is fixed.
#
@@ -243,10 +244,10 @@ do_test indexedby-9.2 {
joinme as j indexed by joinme_id_text_idx
on ( m.id = j.id_int)
}
-} {1 {cannot use index: joinme_id_text_idx}}
+} {1 {no query solution}}
do_test indexedby-9.3 {
catchsql { select * from maintable, joinme INDEXED by joinme_id_text_idx }
-} {1 {cannot use index: joinme_id_text_idx}}
+} {1 {no query solution}}
# Make sure we can still create tables, indices, and columns whose name
# is "indexed".
@@ -274,4 +275,50 @@ do_test indexedby-10.3 {
}
} {1}
+#-------------------------------------------------------------------------
+# Ensure that the rowid at the end of each index entry may be used
+# for equality constraints in the same way as other indexed fields.
+#
+do_execsql_test 11.1 {
+ CREATE TABLE x1(a, b TEXT);
+ CREATE INDEX x1i ON x1(a, b);
+ INSERT INTO x1 VALUES(1, 1);
+ INSERT INTO x1 VALUES(1, 1);
+ INSERT INTO x1 VALUES(1, 1);
+ INSERT INTO x1 VALUES(1, 1);
+}
+do_execsql_test 11.2 {
+ SELECT a,b,rowid FROM x1 INDEXED BY x1i WHERE a=1 AND b=1 AND rowid=3;
+} {1 1 3}
+do_execsql_test 11.3 {
+ SELECT a,b,rowid FROM x1 INDEXED BY x1i WHERE a=1 AND b=1 AND rowid='3';
+} {1 1 3}
+do_execsql_test 11.4 {
+ SELECT a,b,rowid FROM x1 INDEXED BY x1i WHERE a=1 AND b=1 AND rowid='3.0';
+} {1 1 3}
+do_eqp_test 11.5 {
+ SELECT a,b,rowid FROM x1 INDEXED BY x1i WHERE a=1 AND b=1 AND rowid='3.0';
+} {0 0 0 {SEARCH TABLE x1 USING COVERING INDEX x1i (a=? AND b=? AND rowid=?)}}
+
+do_execsql_test 11.6 {
+ CREATE TABLE x2(c INTEGER PRIMARY KEY, a, b TEXT);
+ CREATE INDEX x2i ON x2(a, b);
+ INSERT INTO x2 VALUES(1, 1, 1);
+ INSERT INTO x2 VALUES(2, 1, 1);
+ INSERT INTO x2 VALUES(3, 1, 1);
+ INSERT INTO x2 VALUES(4, 1, 1);
+}
+do_execsql_test 11.7 {
+ SELECT a,b,c FROM x2 INDEXED BY x2i WHERE a=1 AND b=1 AND c=3;
+} {1 1 3}
+do_execsql_test 11.8 {
+ SELECT a,b,c FROM x2 INDEXED BY x2i WHERE a=1 AND b=1 AND c='3';
+} {1 1 3}
+do_execsql_test 11.9 {
+ SELECT a,b,c FROM x2 INDEXED BY x2i WHERE a=1 AND b=1 AND c='3.0';
+} {1 1 3}
+do_eqp_test 11.10 {
+ SELECT a,b,c FROM x2 INDEXED BY x2i WHERE a=1 AND b=1 AND c='3.0';
+} {0 0 0 {SEARCH TABLE x2 USING COVERING INDEX x2i (a=? AND b=? AND rowid=?)}}
+
finish_test
diff --git a/lang/sql/sqlite/test/indexfault.test b/lang/sql/sqlite/test/indexfault.test
new file mode 100644
index 00000000..efe49321
--- /dev/null
+++ b/lang/sql/sqlite/test/indexfault.test
@@ -0,0 +1,342 @@
+# 2011 August 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.
+#
+#***********************************************************************
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+source $testdir/lock_common.tcl
+source $testdir/malloc_common.tcl
+
+ifcapable !mergesort {
+ finish_test
+ return
+}
+
+set testprefix indexfault
+
+# Set up the custom fault-injector. This is further configured by using
+# different values for $::custom_filter and different implementations
+# of Tcl proc [xCustom] for each test case.
+#
+proc install_custom_faultsim {} {
+ set ::FAULTSIM(custom) [list \
+ -injectinstall custom_injectinstall \
+ -injectstart custom_injectstart \
+ -injectstop custom_injectstop \
+ -injecterrlist {{1 {disk I/O error}}} \
+ -injectuninstall custom_injectuninstall \
+ ]
+ proc custom_injectinstall {} {
+ testvfs shmfault -default true
+ shmfault filter $::custom_filter
+ shmfault script xCustom
+ }
+ proc custom_injectuninstall {} {
+ catch {db close}
+ catch {db2 close}
+ shmfault delete
+ }
+ set ::custom_ifail -1
+ set ::custom_nfail -1
+ proc custom_injectstart {iFail} {
+ set ::custom_ifail $iFail
+ set ::custom_nfail 0
+ }
+ proc custom_injectstop {} {
+ set ::custom_ifail -1
+ return $::custom_nfail
+ }
+}
+proc uninstall_custom_faultsim {} {
+ unset -nocomplain ::FAULTSIM(custom)
+}
+
+
+#-------------------------------------------------------------------------
+# These tests - indexfault-1.* - Build an index on a smallish table with
+# all different kinds of fault-injection. The CREATE INDEX is run once
+# with default options and once with a 50KB soft-heap-limit.
+#
+do_execsql_test 1.0 {
+ BEGIN;
+ CREATE TABLE t1(x);
+ INSERT INTO t1 VALUES(randomblob(202));
+ INSERT INTO t1 SELECT randomblob(202) FROM t1; -- 2
+ INSERT INTO t1 SELECT randomblob(202) FROM t1; -- 4
+ INSERT INTO t1 SELECT randomblob(202) FROM t1; -- 8
+ INSERT INTO t1 SELECT randomblob(202) FROM t1; -- 16
+ INSERT INTO t1 SELECT randomblob(202) FROM t1; -- 32
+ INSERT INTO t1 SELECT randomblob(202) FROM t1; -- 64
+ INSERT INTO t1 SELECT randomblob(202) FROM t1; -- 128
+ INSERT INTO t1 SELECT randomblob(202) FROM t1; -- 256
+ COMMIT;
+}
+faultsim_save_and_close
+
+do_faultsim_test 1.1 -prep {
+ faultsim_restore_and_reopen
+} -body {
+ execsql { CREATE INDEX i1 ON t1(x) }
+ faultsim_test_result {0 {}}
+ faultsim_integrity_check
+}
+ifcapable memorymanage {
+ set soft_limit [sqlite3_soft_heap_limit 50000]
+ do_faultsim_test 2.1 -prep {
+ faultsim_restore_and_reopen
+ } -body {
+ execsql { CREATE INDEX i1 ON t1(x) }
+ faultsim_test_result {0 {}}
+ }
+ sqlite3_soft_heap_limit $soft_limit
+}
+
+#-------------------------------------------------------------------------
+# These are similar to the indexfault-1.* tests, except they create an
+# index with more than one column.
+#
+sqlite3 db test.db
+do_execsql_test 2.0 {
+ BEGIN;
+ DROP TABLE IF EXISTS t1;
+ CREATE TABLE t1(t,u,v,w,x,y,z);
+ INSERT INTO t1 VALUES(
+ randomblob(30), randomblob(30), randomblob(30), randomblob(30),
+ randomblob(30), randomblob(30), randomblob(30)
+ );
+ INSERT INTO t1 SELECT
+ randomblob(30), randomblob(30), randomblob(30), randomblob(30),
+ randomblob(30), randomblob(30), randomblob(30) FROM t1; -- 2
+ INSERT INTO t1 SELECT
+ randomblob(30), randomblob(30), randomblob(30), randomblob(30),
+ randomblob(30), randomblob(30), randomblob(30) FROM t1; -- 4
+ INSERT INTO t1 SELECT
+ randomblob(30), randomblob(30), randomblob(30), randomblob(30),
+ randomblob(30), randomblob(30), randomblob(30) FROM t1; -- 8
+ INSERT INTO t1 SELECT
+ randomblob(30), randomblob(30), randomblob(30), randomblob(30),
+ randomblob(30), randomblob(30), randomblob(30) FROM t1; -- 16
+ INSERT INTO t1 SELECT
+ randomblob(30), randomblob(30), randomblob(30), randomblob(30),
+ randomblob(30), randomblob(30), randomblob(30) FROM t1; -- 32
+ INSERT INTO t1 SELECT
+ randomblob(30), randomblob(30), randomblob(30), randomblob(30),
+ randomblob(30), randomblob(30), randomblob(30) FROM t1; -- 64
+ INSERT INTO t1 SELECT
+ randomblob(30), randomblob(30), randomblob(30), randomblob(30),
+ randomblob(30), randomblob(30), randomblob(30) FROM t1; -- 128
+ COMMIT;
+}
+faultsim_save_and_close
+
+do_faultsim_test 2.1 -prep {
+ faultsim_restore_and_reopen
+} -body {
+ execsql { CREATE INDEX i1 ON t1(t,u,v,w,x,y,z) }
+ faultsim_test_result {0 {}}
+ faultsim_integrity_check
+}
+ifcapable memorymanage {
+ set soft_limit [sqlite3_soft_heap_limit 50000]
+ do_faultsim_test 2.2 -prep {
+ faultsim_restore_and_reopen
+ } -body {
+ execsql { CREATE INDEX i1 ON t1(t,u,v,w,x,y,z) }
+ faultsim_test_result {0 {}}
+ }
+ sqlite3_soft_heap_limit $soft_limit
+}
+
+#-------------------------------------------------------------------------
+# The following tests - indexfault-2.* - all attempt to build a index
+# on table t1 in the main database with injected IO errors. Individual
+# test cases work as follows:
+#
+# 3.1: IO errors injected into xOpen() calls.
+# 3.2: As 7.1, but with a low (50KB) soft-heap-limit.
+#
+# 3.3: IO errors injected into the first 200 write() calls made on the
+# second temporary file.
+# 3.4: As 7.3, but with a low (50KB) soft-heap-limit.
+#
+# 3.5: After a certain amount of data has been read from the main database
+# file (and written into the temporary b-tree), sqlite3_release_memory()
+# is called to free as much memory as possible. This causes the temp
+# b-tree to be flushed to disk. So that before its contents can be
+# transfered to a PMA they must be read back from disk - creating extra
+# opportunities for IO errors.
+#
+install_custom_faultsim
+
+# Set up a table to build indexes on. Save the setup using the
+# [faultsim_save_and_close] mechanism.
+#
+sqlite3 db test.db
+do_execsql_test 3.0 {
+ BEGIN;
+ DROP TABLE IF EXISTS t1;
+ CREATE TABLE t1(x);
+ INSERT INTO t1 VALUES(randomblob(11000));
+ INSERT INTO t1 SELECT randomblob(11001) FROM t1; -- 2
+ INSERT INTO t1 SELECT randomblob(11002) FROM t1; -- 4
+ INSERT INTO t1 SELECT randomblob(11003) FROM t1; -- 8
+ INSERT INTO t1 SELECT randomblob(11004) FROM t1; -- 16
+ INSERT INTO t1 SELECT randomblob(11005) FROM t1; -- 32
+ INSERT INTO t1 SELECT randomblob(11006) FROM t1; -- 64
+ INSERT INTO t1 SELECT randomblob(11007) FROM t1; -- 128
+ INSERT INTO t1 SELECT randomblob(11008) FROM t1; -- 256
+ INSERT INTO t1 SELECT randomblob(11009) FROM t1; -- 512
+ COMMIT;
+}
+faultsim_save_and_close
+
+set ::custom_filter xOpen
+proc xCustom {args} {
+ incr ::custom_ifail -1
+ if {$::custom_ifail==0} {
+ incr ::custom_nfail
+ return "SQLITE_IOERR"
+ }
+ return "SQLITE_OK"
+}
+do_faultsim_test 3.1 -faults custom -prep {
+ faultsim_restore_and_reopen
+} -body {
+ execsql { CREATE INDEX i1 ON t1(x) }
+ faultsim_test_result {0 {}}
+}
+ifcapable memorymanage {
+ set soft_limit [sqlite3_soft_heap_limit 50000]
+ do_faultsim_test 3.2 -faults custom -prep {
+ faultsim_restore_and_reopen
+ } -body {
+ execsql { CREATE INDEX i1 ON t1(x) }
+ faultsim_test_result {0 {}}
+ }
+ sqlite3_soft_heap_limit $soft_limit
+}
+
+set ::custom_filter {xOpen xWrite}
+proc xCustom {method args} {
+ if {$method == "xOpen"} {
+ if {[lindex $args 0] == ""} {
+ incr ::nTmpOpen 1
+ if {$::nTmpOpen == 3} { return "failme" }
+ }
+ return "SQLITE_OK"
+ }
+ if {$::custom_ifail<200 && [lindex $args 1] == "failme"} {
+ incr ::custom_ifail -1
+ if {$::custom_ifail==0} {
+ incr ::custom_nfail
+ return "SQLITE_IOERR"
+ }
+ }
+ return "SQLITE_OK"
+}
+
+do_faultsim_test 3.3 -faults custom -prep {
+ faultsim_restore_and_reopen
+ set ::nTmpOpen 0
+} -body {
+ execsql { CREATE INDEX i1 ON t1(x) }
+ faultsim_test_result {0 {}}
+}
+
+ifcapable memorymanage {
+ set soft_limit [sqlite3_soft_heap_limit 50000]
+ do_faultsim_test 3.4 -faults custom -prep {
+ faultsim_restore_and_reopen
+ set ::nTmpOpen 0
+ } -body {
+ execsql { CREATE INDEX i1 ON t1(x) }
+ faultsim_test_result {0 {}}
+ }
+ sqlite3_soft_heap_limit $soft_limit
+}
+
+uninstall_custom_faultsim
+
+#-------------------------------------------------------------------------
+# Test 4: After a certain amount of data has been read from the main database
+# file (and written into the temporary b-tree), sqlite3_release_memory() is
+# called to free as much memory as possible. This causes the temp b-tree to be
+# flushed to disk. So that before its contents can be transfered to a PMA they
+# must be read back from disk - creating extra opportunities for IO errors.
+#
+install_custom_faultsim
+
+catch { db close }
+forcedelete test.db
+sqlite3 db test.db
+
+do_execsql_test 4.0 {
+ BEGIN;
+ DROP TABLE IF EXISTS t1;
+ CREATE TABLE t1(x);
+ INSERT INTO t1 VALUES(randomblob(11000));
+ INSERT INTO t1 SELECT randomblob(11001) FROM t1; -- 2
+ INSERT INTO t1 SELECT randomblob(11002) FROM t1; -- 4
+ INSERT INTO t1 SELECT randomblob(11003) FROM t1; -- 8
+ INSERT INTO t1 SELECT randomblob(11004) FROM t1; -- 16
+ INSERT INTO t1 SELECT randomblob(11005) FROM t1; -- 32
+ INSERT INTO t1 SELECT randomblob(11005) FROM t1; -- 64
+ COMMIT;
+}
+faultsim_save_and_close
+
+testvfs tvfs
+tvfs script xRead
+tvfs filter xRead
+set ::nRead 0
+proc xRead {method file args} {
+ if {[file tail $file] == "test.db"} { incr ::nRead }
+}
+
+do_test 4.1 {
+ sqlite3 db test.db -vfs tvfs
+ execsql { CREATE INDEX i1 ON t1(x) }
+} {}
+
+db close
+tvfs delete
+
+set ::custom_filter xRead
+proc xCustom {method file args} {
+ incr ::nReadCall
+ if {$::nReadCall >= ($::nRead/5)} {
+ if {$::nReadCall == ($::nRead/5)} {
+ set nByte [sqlite3_release_memory [expr 64*1024*1024]]
+ sqlite3_soft_heap_limit 20000
+ }
+ if {$file == ""} {
+ incr ::custom_ifail -1
+ if {$::custom_ifail==0} {
+ incr ::custom_nfail
+ return "SQLITE_IOERR"
+ }
+ }
+ }
+ return "SQLITE_OK"
+}
+
+do_faultsim_test 4.2 -faults custom -prep {
+ faultsim_restore_and_reopen
+ set ::nReadCall 0
+ sqlite3_soft_heap_limit 0
+} -body {
+ execsql { CREATE INDEX i1 ON t1(x) }
+ faultsim_test_result {0 {}}
+}
+
+uninstall_custom_faultsim
+
+finish_test
diff --git a/lang/sql/sqlite/test/insert.test b/lang/sql/sqlite/test/insert.test
index 9ea9cd72..e00b9a80 100644
--- a/lang/sql/sqlite/test/insert.test
+++ b/lang/sql/sqlite/test/insert.test
@@ -386,6 +386,23 @@ do_test insert-9.2 {
}
} {1 1 2 2 3 3 12 101 13 102 16 103}
+# Multiple VALUES clauses
+#
+ifcapable compound {
+ do_test insert-10.1 {
+ execsql {
+ CREATE TABLE t10(a,b,c);
+ INSERT INTO t10 VALUES(1,2,3), (4,5,6), (7,8,9);
+ SELECT * FROM t10;
+ }
+ } {1 2 3 4 5 6 7 8 9}
+ do_test insert-10.2 {
+ catchsql {
+ INSERT INTO t10 VALUES(11,12,13), (14,15);
+ }
+ } {1 {all VALUES must have the same number of terms}}
+}
+
integrity_check insert-99.0
finish_test
diff --git a/lang/sql/sqlite/test/insert4.test b/lang/sql/sqlite/test/insert4.test
index 0b069e99..343a08af 100644
--- a/lang/sql/sqlite/test/insert4.test
+++ b/lang/sql/sqlite/test/insert4.test
@@ -54,7 +54,7 @@ do_test insert4-1.1 {
catchsql {
INSERT INTO t1 SELECT * FROM t2;
}
-} {1 {constraint failed}}
+} {1 {CHECK constraint failed: t1}}
xferopt_test insert4-1.2 0
do_test insert4-1.3 {
execsql {
@@ -101,7 +101,7 @@ do_test insert4-2.3.3 {
INSERT INTO t1 SELECT * FROM t2 LIMIT 1;
SELECT * FROM t1;
}
-} {1 {constraint failed}}
+} {1 {CHECK constraint failed: t1}}
xferopt_test insert4-2.3.4 0
# Do not run the transfer optimization if there is a DISTINCT
@@ -112,14 +112,14 @@ do_test insert4-2.4.1 {
INSERT INTO t3 SELECT DISTINCT * FROM t2;
SELECT * FROM t3;
}
-} {1 9 9 1}
+} {9 1 1 9}
xferopt_test insert4-2.4.2 0
do_test insert4-2.4.3 {
catchsql {
DELETE FROM t1;
INSERT INTO t1 SELECT DISTINCT * FROM t2;
}
-} {1 {constraint failed}}
+} {1 {CHECK constraint failed: t1}}
xferopt_test insert4-2.4.4 0
# The following procedure constructs two tables then tries to transfer
@@ -315,7 +315,7 @@ do_test insert4-6.6 {
catchsql {
INSERT INTO t6b SELECT * FROM t6a;
}
-} {1 {constraint failed}}
+} {1 {CHECK constraint failed: t6b}}
do_test insert4-6.7 {
execsql {
DROP TABLE t6b;
@@ -324,6 +324,241 @@ do_test insert4-6.7 {
catchsql {
INSERT INTO t6b SELECT * FROM t6a;
}
-} {1 {constraint failed}}
+} {1 {CHECK constraint failed: t6b}}
+
+# Ticket [6284df89debdfa61db8073e062908af0c9b6118e]
+# Disable the xfer optimization if the destination table contains
+# a foreign key constraint
+#
+ifcapable foreignkey {
+ do_test insert4-7.1 {
+ set ::sqlite3_xferopt_count 0
+ execsql {
+ CREATE TABLE t7a(x INTEGER PRIMARY KEY); INSERT INTO t7a VALUES(123);
+ CREATE TABLE t7b(y INTEGER REFERENCES t7a);
+ CREATE TABLE t7c(z INT); INSERT INTO t7c VALUES(234);
+ INSERT INTO t7b SELECT * FROM t7c;
+ SELECT * FROM t7b;
+ }
+ } {234}
+ do_test insert4-7.2 {
+ set ::sqlite3_xferopt_count
+ } {1}
+ do_test insert4-7.3 {
+ set ::sqlite3_xferopt_count 0
+ execsql {
+ DELETE FROM t7b;
+ PRAGMA foreign_keys=ON;
+ }
+ catchsql {
+ INSERT INTO t7b SELECT * FROM t7c;
+ }
+ } {1 {FOREIGN KEY constraint failed}}
+ do_test insert4-7.4 {
+ execsql {SELECT * FROM t7b}
+ } {}
+ do_test insert4-7.5 {
+ set ::sqlite3_xferopt_count
+ } {0}
+ do_test insert4-7.6 {
+ set ::sqlite3_xferopt_count 0
+ execsql {
+ DELETE FROM t7b; DELETE FROM t7c;
+ INSERT INTO t7c VALUES(123);
+ INSERT INTO t7b SELECT * FROM t7c;
+ SELECT * FROM t7b;
+ }
+ } {123}
+ do_test insert4-7.7 {
+ set ::sqlite3_xferopt_count
+ } {0}
+ do_test insert4-7.7 {
+ set ::sqlite3_xferopt_count 0
+ execsql {
+ PRAGMA foreign_keys=OFF;
+ DELETE FROM t7b;
+ INSERT INTO t7b SELECT * FROM t7c;
+ SELECT * FROM t7b;
+ }
+ } {123}
+ do_test insert4-7.8 {
+ set ::sqlite3_xferopt_count
+ } {1}
+}
+
+# Ticket [676bc02b87176125635cb174d110b431581912bb]
+# Make sure INTEGER PRIMARY KEY ON CONFLICT ... works with the xfer
+# optimization.
+#
+do_test insert4-8.1 {
+ execsql {
+ DROP TABLE IF EXISTS t1;
+ DROP TABLE IF EXISTS t2;
+ CREATE TABLE t1(a INTEGER PRIMARY KEY ON CONFLICT REPLACE, b);
+ CREATE TABLE t2(x INTEGER PRIMARY KEY ON CONFLICT REPLACE, y);
+ INSERT INTO t1 VALUES(1,2);
+ INSERT INTO t2 VALUES(1,3);
+ INSERT INTO t1 SELECT * FROM t2;
+ SELECT * FROM t1;
+ }
+} {1 3}
+do_test insert4-8.2 {
+ execsql {
+ DROP TABLE IF EXISTS t1;
+ DROP TABLE IF EXISTS t2;
+ CREATE TABLE t1(a INTEGER PRIMARY KEY ON CONFLICT REPLACE, b);
+ CREATE TABLE t2(x, y);
+ INSERT INTO t1 VALUES(1,2);
+ INSERT INTO t2 VALUES(1,3);
+ INSERT INTO t1 SELECT * FROM t2;
+ SELECT * FROM t1;
+ }
+} {1 3}
+do_test insert4-8.3 {
+ execsql {
+ DROP TABLE IF EXISTS t1;
+ DROP TABLE IF EXISTS t2;
+ CREATE TABLE t1(a INTEGER PRIMARY KEY ON CONFLICT IGNORE, b);
+ CREATE TABLE t2(x INTEGER PRIMARY KEY ON CONFLICT IGNORE, y);
+ INSERT INTO t1 VALUES(1,2);
+ INSERT INTO t2 VALUES(1,3);
+ INSERT INTO t1 SELECT * FROM t2;
+ SELECT * FROM t1;
+ }
+} {1 2}
+do_test insert4-8.4 {
+ execsql {
+ DROP TABLE IF EXISTS t1;
+ DROP TABLE IF EXISTS t2;
+ CREATE TABLE t1(a INTEGER PRIMARY KEY ON CONFLICT IGNORE, b);
+ CREATE TABLE t2(x, y);
+ INSERT INTO t1 VALUES(1,2);
+ INSERT INTO t2 VALUES(1,3);
+ INSERT INTO t1 SELECT * FROM t2;
+ SELECT * FROM t1;
+ }
+} {1 2}
+do_test insert4-8.5 {
+ execsql {
+ DROP TABLE IF EXISTS t1;
+ DROP TABLE IF EXISTS t2;
+ CREATE TABLE t1(a INTEGER PRIMARY KEY ON CONFLICT FAIL, b);
+ CREATE TABLE t2(x INTEGER PRIMARY KEY ON CONFLICT FAIL, y);
+ INSERT INTO t1 VALUES(1,2);
+ INSERT INTO t2 VALUES(-99,100);
+ INSERT INTO t2 VALUES(1,3);
+ SELECT * FROM t1;
+ }
+ catchsql {
+ INSERT INTO t1 SELECT * FROM t2;
+ }
+} {1 {UNIQUE constraint failed: t1.a}}
+do_test insert4-8.6 {
+ execsql {
+ SELECT * FROM t1;
+ }
+} {-99 100 1 2}
+do_test insert4-8.7 {
+ execsql {
+ DROP TABLE IF EXISTS t1;
+ DROP TABLE IF EXISTS t2;
+ CREATE TABLE t1(a INTEGER PRIMARY KEY ON CONFLICT ABORT, b);
+ CREATE TABLE t2(x INTEGER PRIMARY KEY ON CONFLICT ABORT, y);
+ INSERT INTO t1 VALUES(1,2);
+ INSERT INTO t2 VALUES(-99,100);
+ INSERT INTO t2 VALUES(1,3);
+ SELECT * FROM t1;
+ }
+ catchsql {
+ INSERT INTO t1 SELECT * FROM t2;
+ }
+} {1 {UNIQUE constraint failed: t1.a}}
+do_test insert4-8.8 {
+ execsql {
+ SELECT * FROM t1;
+ }
+} {1 2}
+do_test insert4-8.9 {
+ execsql {
+ DROP TABLE IF EXISTS t1;
+ DROP TABLE IF EXISTS t2;
+ CREATE TABLE t1(a INTEGER PRIMARY KEY ON CONFLICT ROLLBACK, b);
+ CREATE TABLE t2(x INTEGER PRIMARY KEY ON CONFLICT ROLLBACK, y);
+ INSERT INTO t1 VALUES(1,2);
+ INSERT INTO t2 VALUES(-99,100);
+ INSERT INTO t2 VALUES(1,3);
+ SELECT * FROM t1;
+ }
+ catchsql {
+ BEGIN;
+ INSERT INTO t1 VALUES(2,3);
+ INSERT INTO t1 SELECT * FROM t2;
+ }
+} {1 {UNIQUE constraint failed: t1.a}}
+do_test insert4-8.10 {
+ catchsql {COMMIT}
+} {1 {cannot commit - no transaction is active}}
+do_test insert4-8.11 {
+ execsql {
+ SELECT * FROM t1;
+ }
+} {1 2}
+
+do_test insert4-8.21 {
+ execsql {
+ DROP TABLE IF EXISTS t1;
+ DROP TABLE IF EXISTS t2;
+ CREATE TABLE t1(a INTEGER PRIMARY KEY ON CONFLICT REPLACE, b);
+ CREATE TABLE t2(x INTEGER PRIMARY KEY ON CONFLICT REPLACE, y);
+ INSERT INTO t2 VALUES(1,3);
+ INSERT INTO t1 SELECT * FROM t2;
+ SELECT * FROM t1;
+ }
+} {1 3}
+do_test insert4-8.22 {
+ execsql {
+ DROP TABLE IF EXISTS t1;
+ DROP TABLE IF EXISTS t2;
+ CREATE TABLE t1(a INTEGER PRIMARY KEY ON CONFLICT IGNORE, b);
+ CREATE TABLE t2(x INTEGER PRIMARY KEY ON CONFLICT IGNORE, y);
+ INSERT INTO t2 VALUES(1,3);
+ INSERT INTO t1 SELECT * FROM t2;
+ SELECT * FROM t1;
+ }
+} {1 3}
+do_test insert4-8.23 {
+ execsql {
+ DROP TABLE IF EXISTS t1;
+ DROP TABLE IF EXISTS t2;
+ CREATE TABLE t1(a INTEGER PRIMARY KEY ON CONFLICT ABORT, b);
+ CREATE TABLE t2(x INTEGER PRIMARY KEY ON CONFLICT ABORT, y);
+ INSERT INTO t2 VALUES(1,3);
+ INSERT INTO t1 SELECT * FROM t2;
+ SELECT * FROM t1;
+ }
+} {1 3}
+do_test insert4-8.24 {
+ execsql {
+ DROP TABLE IF EXISTS t1;
+ DROP TABLE IF EXISTS t2;
+ CREATE TABLE t1(a INTEGER PRIMARY KEY ON CONFLICT FAIL, b);
+ CREATE TABLE t2(x INTEGER PRIMARY KEY ON CONFLICT FAIL, y);
+ INSERT INTO t2 VALUES(1,3);
+ INSERT INTO t1 SELECT * FROM t2;
+ SELECT * FROM t1;
+ }
+} {1 3}
+do_test insert4-8.25 {
+ execsql {
+ DROP TABLE IF EXISTS t1;
+ DROP TABLE IF EXISTS t2;
+ CREATE TABLE t1(a INTEGER PRIMARY KEY ON CONFLICT ROLLBACK, b);
+ CREATE TABLE t2(x INTEGER PRIMARY KEY ON CONFLICT ROLLBACK, y);
+ INSERT INTO t2 VALUES(1,3);
+ INSERT INTO t1 SELECT * FROM t2;
+ SELECT * FROM t1;
+ }
+} {1 3}
+
finish_test
diff --git a/lang/sql/sqlite/test/insert5.test b/lang/sql/sqlite/test/insert5.test
index e48c2c32..1e58902e 100644
--- a/lang/sql/sqlite/test/insert5.test
+++ b/lang/sql/sqlite/test/insert5.test
@@ -34,7 +34,7 @@ proc uses_temp_table {sql} {
# Construct the sample database.
#
do_test insert5-1.0 {
- file delete -force test2.db test2.db-journal
+ forcedelete test2.db test2.db-journal
execsql {
CREATE TABLE MAIN(Id INTEGER, Id1 INTEGER);
CREATE TABLE B(Id INTEGER, Id1 INTEGER);
diff --git a/lang/sql/sqlite/test/instr.test b/lang/sql/sqlite/test/instr.test
new file mode 100644
index 00000000..c8be4862
--- /dev/null
+++ b/lang/sql/sqlite/test/instr.test
@@ -0,0 +1,251 @@
+# 2012 October 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 built-in INSTR() functions.
+#
+# EVIDENCE-OF: R-27549-59611 The instr(X,Y) function finds the first
+# occurrence of string Y within string X and returns the number of prior
+# characters plus 1, or 0 if Y is nowhere found within X.
+#
+
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+# Create a table to work with.
+#
+do_test instr-1.1 {
+ db eval {SELECT instr('abcdefg','a');}
+} {1}
+do_test instr-1.2 {
+ db eval {SELECT instr('abcdefg','b');}
+} {2}
+do_test instr-1.3 {
+ db eval {SELECT instr('abcdefg','c');}
+} {3}
+do_test instr-1.4 {
+ db eval {SELECT instr('abcdefg','d');}
+} {4}
+do_test instr-1.5 {
+ db eval {SELECT instr('abcdefg','e');}
+} {5}
+do_test instr-1.6 {
+ db eval {SELECT instr('abcdefg','f');}
+} {6}
+do_test instr-1.7 {
+ db eval {SELECT instr('abcdefg','g');}
+} {7}
+do_test instr-1.8 {
+ db eval {SELECT instr('abcdefg','h');}
+} {0}
+do_test instr-1.9 {
+ db eval {SELECT instr('abcdefg','abcdefg');}
+} {1}
+do_test instr-1.10 {
+ db eval {SELECT instr('abcdefg','abcdefgh');}
+} {0}
+do_test instr-1.11 {
+ db eval {SELECT instr('abcdefg','bcdefg');}
+} {2}
+do_test instr-1.12 {
+ db eval {SELECT instr('abcdefg','bcdefgh');}
+} {0}
+do_test instr-1.13 {
+ db eval {SELECT instr('abcdefg','cdefg');}
+} {3}
+do_test instr-1.14 {
+ db eval {SELECT instr('abcdefg','cdefgh');}
+} {0}
+do_test instr-1.15 {
+ db eval {SELECT instr('abcdefg','defg');}
+} {4}
+do_test instr-1.16 {
+ db eval {SELECT instr('abcdefg','defgh');}
+} {0}
+do_test instr-1.17 {
+ db eval {SELECT instr('abcdefg','efg');}
+} {5}
+do_test instr-1.18 {
+ db eval {SELECT instr('abcdefg','efgh');}
+} {0}
+do_test instr-1.19 {
+ db eval {SELECT instr('abcdefg','fg');}
+} {6}
+do_test instr-1.20 {
+ db eval {SELECT instr('abcdefg','fgh');}
+} {0}
+do_test instr-1.21 {
+ db eval {SELECT coalesce(instr('abcdefg',NULL),'nil');}
+} {nil}
+do_test instr-1.22 {
+ db eval {SELECT coalesce(instr(NULL,'x'),'nil');}
+} {nil}
+do_test instr-1.23 {
+ db eval {SELECT instr(12345,34);}
+} {3}
+do_test instr-1.24 {
+ db eval {SELECT instr(123456.78,34);}
+} {3}
+do_test instr-1.25 {
+ db eval {SELECT instr(123456.78,x'3334');}
+} {3}
+do_test instr-1.26 {
+ db eval {SELECT instr('äbcdefg','efg');}
+} {5}
+do_test instr-1.27 {
+ db eval {SELECT instr('€xyzzy','xyz');}
+} {2}
+do_test instr-1.28 {
+ db eval {SELECT instr('abc€xyzzy','xyz');}
+} {5}
+do_test instr-1.29 {
+ db eval {SELECT instr('abc€xyzzy','€xyz');}
+} {4}
+do_test instr-1.30 {
+ db eval {SELECT instr('abc€xyzzy','c€xyz');}
+} {3}
+do_test instr-1.31 {
+ db eval {SELECT instr(x'0102030405',x'01');}
+} {1}
+do_test instr-1.32 {
+ db eval {SELECT instr(x'0102030405',x'02');}
+} {2}
+do_test instr-1.33 {
+ db eval {SELECT instr(x'0102030405',x'03');}
+} {3}
+do_test instr-1.34 {
+ db eval {SELECT instr(x'0102030405',x'04');}
+} {4}
+do_test instr-1.35 {
+ db eval {SELECT instr(x'0102030405',x'05');}
+} {5}
+do_test instr-1.36 {
+ db eval {SELECT instr(x'0102030405',x'06');}
+} {0}
+do_test instr-1.37 {
+ db eval {SELECT instr(x'0102030405',x'0102030405');}
+} {1}
+do_test instr-1.38 {
+ db eval {SELECT instr(x'0102030405',x'02030405');}
+} {2}
+do_test instr-1.39 {
+ db eval {SELECT instr(x'0102030405',x'030405');}
+} {3}
+do_test instr-1.40 {
+ db eval {SELECT instr(x'0102030405',x'0405');}
+} {4}
+do_test instr-1.41 {
+ db eval {SELECT instr(x'0102030405',x'0506');}
+} {0}
+do_test instr-1.42 {
+ db eval {SELECT instr(x'0102030405',x'');}
+} {1}
+do_test instr-1.43 {
+ db eval {SELECT instr(x'',x'');}
+} {1}
+do_test instr-1.44 {
+ db eval {SELECT instr('','');}
+} {1}
+do_test instr-1.45 {
+ db eval {SELECT instr('abcdefg','');}
+} {1}
+unset -nocomplain longstr
+set longstr abcdefghijklmonpqrstuvwxyz
+append longstr $longstr
+append longstr $longstr
+append longstr $longstr
+append longstr $longstr
+append longstr $longstr
+append longstr $longstr
+append longstr $longstr
+append longstr $longstr
+append longstr $longstr
+append longstr $longstr
+append longstr $longstr
+append longstr $longstr
+# puts [string length $longstr]
+append longstr Xabcde
+do_test instr-1.46 {
+ db eval {SELECT instr($longstr,'X');}
+} {106497}
+do_test instr-1.47 {
+ db eval {SELECT instr($longstr,'Y');}
+} {0}
+do_test instr-1.48 {
+ db eval {SELECT instr($longstr,'Xa');}
+} {106497}
+do_test instr-1.49 {
+ db eval {SELECT instr($longstr,'zXa');}
+} {106496}
+set longstr [string map {a ä} $longstr]
+do_test instr-1.50 {
+ db eval {SELECT instr($longstr,'X');}
+} {106497}
+do_test instr-1.51 {
+ db eval {SELECT instr($longstr,'Y');}
+} {0}
+do_test instr-1.52 {
+ db eval {SELECT instr($longstr,'Xä');}
+} {106497}
+do_test instr-1.53 {
+ db eval {SELECT instr($longstr,'zXä');}
+} {106496}
+do_test instr-1.54 {
+ db eval {SELECT instr(x'78c3a4e282ac79','x');}
+} {1}
+do_test instr-1.55 {
+ db eval {SELECT instr(x'78c3a4e282ac79','y');}
+} {4}
+
+# EVIDENCE-OF: R-46421-32541 Or, if X and Y are both BLOBs, then
+# instr(X,Y) returns one more than the number bytes prior to the first
+# occurrence of Y, or 0 if Y does not occur anywhere within X.
+#
+do_test instr-1.56.1 {
+ db eval {SELECT instr(x'78c3a4e282ac79',x'79');}
+} {7}
+do_test instr-1.56.2 {
+ db eval {SELECT instr(x'78c3a4e282ac79',x'7a');}
+} {0}
+do_test instr-1.56.3 {
+ db eval {SELECT instr(x'78c3a4e282ac79',x'78');}
+} {1}
+do_test instr-1.56.3 {
+ db eval {SELECT instr(x'78c3a4e282ac79',x'a4');}
+} {3}
+
+# EVIDENCE-OF: R-17329-35644 If both arguments X and Y to instr(X,Y) are
+# non-NULL and are not BLOBs then both are interpreted as strings.
+#
+do_test instr-1.57.1 {
+ db eval {SELECT instr('xä€y',x'79');}
+} {4}
+do_test instr-1.57.2 {
+ db eval {SELECT instr('xä€y',x'a4');}
+} {0}
+do_test instr-1.57.3 {
+ db eval {SELECT instr(x'78c3a4e282ac79','y');}
+} {4}
+
+# EVIDENCE-OF: R-14708-27487 If either X or Y are NULL in instr(X,Y)
+# then the result is NULL.
+#
+do_execsql_test instr-1.60 {
+ SELECT coalesce(instr(NULL,'abc'), 999);
+} {999}
+do_execsql_test instr-1.61 {
+ SELECT coalesce(instr('abc',NULL), 999);
+} {999}
+do_execsql_test instr-1.62 {
+ SELECT coalesce(instr(NULL,NULL), 999);
+} {999}
+
+finish_test
diff --git a/lang/sql/sqlite/test/interrupt.test b/lang/sql/sqlite/test/interrupt.test
index b311cbb4..92ab4c32 100644
--- a/lang/sql/sqlite/test/interrupt.test
+++ b/lang/sql/sqlite/test/interrupt.test
@@ -166,6 +166,8 @@ for {set i 1} {$i<$max_count-5} {incr i 1} {
} {1 interrupted}
}
+if {0} { # This doesn't work anymore since the collation factor is
+ # no longer called during schema parsing.
# Interrupt during parsing
#
do_test interrupt-5.1 {
@@ -179,5 +181,5 @@ do_test interrupt-5.1 {
CREATE INDEX fake ON fake1(a COLLATE fake_collation, b, c DESC);
}
} {1 interrupt}
-
+}
finish_test
diff --git a/lang/sql/sqlite/test/intpkey.test b/lang/sql/sqlite/test/intpkey.test
index 05b6cdf0..41858e5d 100644
--- a/lang/sql/sqlite/test/intpkey.test
+++ b/lang/sql/sqlite/test/intpkey.test
@@ -76,7 +76,7 @@ do_test intpkey-1.6 {
INSERT INTO t1 VALUES(5,'second','entry');
}} msg]
lappend r $msg
-} {1 {PRIMARY KEY must be unique}}
+} {1 {UNIQUE constraint failed: t1.a}}
do_test intpkey-1.7 {
execsql {
SELECT rowid, * FROM t1;
@@ -125,8 +125,11 @@ do_test intpkey-1.12.1 {
}
} {4 one two}
do_test intpkey-1.12.2 {
- set sqlite_query_plan
-} {t1 *}
+ execsql {
+ EXPLAIN QUERY PLAN
+ SELECT * FROM t1 WHERE a==4;
+ }
+} {/SEARCH TABLE t1 /}
# Try to insert a non-integer value into the primary key field. This
# should result in a data type mismatch.
@@ -376,7 +379,7 @@ do_test intpkey-5.1 {
} {0 zero entry 0}
do_test intpkey-5.2 {
execsql {
- SELECT rowid, a FROM t1
+ SELECT rowid, a FROM t1 ORDER BY rowid
}
} {-4 -4 0 0 5 5 6 6 11 11}
diff --git a/lang/sql/sqlite/test/io.test b/lang/sql/sqlite/test/io.test
index 0cc26eff..c5086c10 100644
--- a/lang/sql/sqlite/test/io.test
+++ b/lang/sql/sqlite/test/io.test
@@ -16,6 +16,7 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
+set ::testprefix io
db close
sqlite3_simulate_device
@@ -38,6 +39,10 @@ sqlite3 db test.db -vfs devsym
#
# io-5.* - Test that the default page size is selected and used
# correctly.
+#
+# io-6.* - Test that the pager-cache is not being flushed unnecessarily
+# after a transaction that uses the special atomic-write path
+# is committed.
#
set ::nWrite 0
@@ -146,11 +151,15 @@ do_test io-2.2 {
# written because page 1 - the change-counter page - is written using
# an out-of-band method that bypasses the write counter.
#
+# UPDATE: As of [05f98d4eec] (adding SQLITE_DBSTATUS_CACHE_WRITE), the
+# second write is also counted. So this now reports two writes and a
+# single fsync.
+#
sqlite3_simulate_device -char atomic
do_test io-2.3 {
execsql { INSERT INTO abc VALUES(3, 4) }
list [nWrite db] [nSync]
-} {1 1}
+} {2 1}
# Test that the journal file is not created and the change-counter is
# updated when the atomic-write optimization is used.
@@ -203,7 +212,7 @@ do_test io-2.5.3 {
# Changed 2010-03-27: The size of the database is now stored in
# bytes 28..31 and so when a page is added to the database, page 1
# is immediately modified and the journal file immediately comes into
-# existance. To fix this test, the BEGIN is changed into a a
+# existence. To fix this test, the BEGIN is changed into a a
# BEGIN IMMEDIATE and the INSERT is omitted.
#
do_test io-2.6.1 {
@@ -225,7 +234,7 @@ do_test io-2.6.2 {
}
} {1 {unable to open database file}}
do_test io-2.6.3 {
- file delete -force test.db-journal
+ forcedelete test.db-journal
catchsql { COMMIT }
} {0 {}}
do_test io-2.6.4 {
@@ -237,7 +246,7 @@ do_test io-2.6.4 {
# is created during execution of the COMMIT statement, so we have to
# use the same technique to check that it is created as in the above
# block.
-file delete -force test2.db test2.db-journal
+forcedelete test2.db test2.db-journal
ifcapable attach {
do_test io-2.7.1 {
execsql {
@@ -261,7 +270,7 @@ ifcapable attach {
catchsql { COMMIT }
} {1 {unable to open database file}}
do_test io-2.7.5 {
- file delete -force test2.db-journal
+ forcedelete test2.db-journal
catchsql { COMMIT }
} {1 {cannot commit - no transaction is active}}
do_test io-2.7.6 {
@@ -304,7 +313,7 @@ do_test io-2.9.1 {
do_test io-2.9.2 {
execsql { ROLLBACK; }
db close
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db test.db -vfs devsym
execsql {
PRAGMA auto_vacuum = OFF;
@@ -375,7 +384,7 @@ sqlite3_simulate_device -char sequential -sectorsize 0
ifcapable pager_pragmas {
do_test io-3.1 {
db close
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db test.db -vfs devsym
db eval {
PRAGMA auto_vacuum=OFF;
@@ -544,7 +553,7 @@ foreach {char sectorsize pgsize} {
incr tn
if {$pgsize>$::SQLITE_MAX_PAGE_SIZE} continue
db close
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3_simulate_device -char $char -sectorsize $sectorsize
sqlite3 db test.db -vfs devsym
db eval {
@@ -561,5 +570,74 @@ foreach {char sectorsize pgsize} {
} $pgsize
}
+#----------------------------------------------------------------------
+#
+do_test io-6.1 {
+ db close
+ sqlite3_simulate_device -char atomic
+ forcedelete test.db
+ sqlite3 db test.db -vfs devsym
+ execsql {
+ PRAGMA mmap_size = 0;
+ PRAGMA page_size = 1024;
+ PRAGMA cache_size = 2000;
+ CREATE TABLE t1(x);
+ CREATE TABLE t2(x);
+ CREATE TABLE t3(x);
+ CREATE INDEX i3 ON t3(x);
+ INSERT INTO t3 VALUES(randomblob(100));
+ INSERT INTO t3 SELECT randomblob(100) FROM t3;
+ INSERT INTO t3 SELECT randomblob(100) FROM t3;
+ INSERT INTO t3 SELECT randomblob(100) FROM t3;
+ INSERT INTO t3 SELECT randomblob(100) FROM t3;
+ INSERT INTO t3 SELECT randomblob(100) FROM t3;
+ INSERT INTO t3 SELECT randomblob(100) FROM t3;
+ INSERT INTO t3 SELECT randomblob(100) FROM t3;
+ INSERT INTO t3 SELECT randomblob(100) FROM t3;
+ INSERT INTO t3 SELECT randomblob(100) FROM t3;
+ INSERT INTO t3 SELECT randomblob(100) FROM t3;
+ INSERT INTO t3 SELECT randomblob(100) FROM t3;
+ }
+
+ db_save_and_close
+} {}
+
+foreach {tn sql} {
+ 1 { BEGIN;
+ INSERT INTO t1 VALUES('123');
+ INSERT INTO t2 VALUES('456');
+ COMMIT;
+ }
+ 2 { BEGIN;
+ INSERT INTO t1 VALUES('123');
+ COMMIT;
+ }
+} {
+
+ # These tests don't work with memsubsys1, as it causes the effective page
+ # cache size to become too small to hold the entire db in memory.
+ if {[permutation] == "memsubsys1"} continue
+
+ db_restore
+ sqlite3 db test.db -vfs devsym
+ execsql {
+ PRAGMA cache_size = 2000;
+ PRAGMA mmap_size = 0;
+ SELECT x FROM t3 ORDER BY rowid;
+ SELECT x FROM t3 ORDER BY x;
+ }
+ do_execsql_test 6.2.$tn.1 { PRAGMA integrity_check } {ok}
+ do_execsql_test 6.2.$tn.2 $sql
+
+ # Corrupt the database file on disk. This should not matter for the
+ # purposes of the following "PRAGMA integrity_check", as the entire
+ # database should be cached in the pager-cache. If corruption is
+ # reported, it indicates that executing $sql caused the pager cache
+ # to be flushed. Which is a bug.
+ hexio_write test.db [expr 1024 * 5] [string repeat 00 2048]
+ do_execsql_test 6.2.$tn.3 { PRAGMA integrity_check } {ok}
+ db close
+}
+
sqlite3_simulate_device -char {} -sectorsize 0
finish_test
diff --git a/lang/sql/sqlite/test/ioerr.test b/lang/sql/sqlite/test/ioerr.test
index f9b95555..e59647fe 100644
--- a/lang/sql/sqlite/test/ioerr.test
+++ b/lang/sql/sqlite/test/ioerr.test
@@ -183,8 +183,8 @@ if {$tcl_platform(platform)!="windows"} {
BEGIN;
INSERT INTO t1 VALUES(3, 4);
}
- copy_file test2.db test.db
- copy_file test2.db-journal test.db-journal
+ forcecopy test2.db test.db
+ forcecopy test2.db-journal test.db-journal
db2 close
} -tclbody {
sqlite3 db test.db
@@ -219,11 +219,11 @@ if {$tcl_platform(platform)=="unix"} {
BEGIN;
INSERT INTO t1 VALUES(randstr(200,200), randstr(1000,1000), 2);
}
- copy_file test.db-journal test2.db-journal
+ forcecopy test.db-journal test2.db-journal
execsql {
COMMIT;
}
- copy_file test2.db-journal test.db-journal
+ forcecopy test2.db-journal test.db-journal
set f [open test.db-journal a]
fconfigure $f -encoding binary
puts -nonewline $f "hello"
@@ -258,7 +258,7 @@ do_ioerr_test ioerr-10 -ckrefcount true -tclprep {
INSERT INTO t1 SELECT (a+500)%900, 'good string' FROM t1;
}} msg
- if {$msg != "column a is not unique"} {
+ if {$msg != "UNIQUE constraint failed: t1.a"} {
error $msg
}
}
diff --git a/lang/sql/sqlite/test/ioerr2.test b/lang/sql/sqlite/test/ioerr2.test
index 325c0bad..5150ace3 100644
--- a/lang/sql/sqlite/test/ioerr2.test
+++ b/lang/sql/sqlite/test/ioerr2.test
@@ -130,7 +130,7 @@ do_test ioerr2-5 {
}
} msg]
list $rc $msg
-} {1 {callback requested query abort}}
+} {1 {abort due to ROLLBACK}}
if {$::tcl_platform(platform) == "unix"} {
# Cause the call to xAccess used by [pragma temp_store_directory] to
diff --git a/lang/sql/sqlite/test/ioerr4.test b/lang/sql/sqlite/test/ioerr4.test
index 3a74a88a..defa3268 100644
--- a/lang/sql/sqlite/test/ioerr4.test
+++ b/lang/sql/sqlite/test/ioerr4.test
@@ -31,7 +31,7 @@ do_test ioerr4-1.1 {
set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
} {0}
do_test ioerr4-1.2 {
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db test.db
sqlite3 db2 test.db
db eval {
@@ -79,12 +79,12 @@ do_test ioerr4-1.6 {
#
db close
db2 close
-file copy -force test.db test.db-bu
+forcecopy test.db test.db-bu
do_ioerr_test ioerr4-2 -tclprep {
catch {db2 close}
db close
- file delete -force test.db test.db-journal
- file copy -force test.db-bu test.db
+ forcedelete test.db test.db-journal
+ forcecopy test.db-bu test.db
sqlite3_enable_shared_cache 1
set ::DB [sqlite3 db test.db; sqlite3_connection_pointer db]
db eval {PRAGMA auto_vacuum=INCREMENTAL}
@@ -94,7 +94,7 @@ do_ioerr_test ioerr4-2 -tclprep {
}
db2 close
-file delete -force test.db-bu
+forcedelete test.db-bu
sqlite3_enable_shared_cache $::enable_shared_cache
finish_test
diff --git a/lang/sql/sqlite/test/ioerr6.test b/lang/sql/sqlite/test/ioerr6.test
new file mode 100644
index 00000000..d1847b28
--- /dev/null
+++ b/lang/sql/sqlite/test/ioerr6.test
@@ -0,0 +1,91 @@
+# 2012 December 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 ioerr6
+
+ifcapable !atomicwrite {
+ puts "skipping tests - not compiled with SQLITE_ENABLE_ATOMIC_WRITE..."
+ finish_test
+ return
+}
+
+if {[permutation]=="inmemory_journal"} {
+ # These tests will not work with in-memory journals (as persistent VFS
+ # errors commencing after a transaction has started to write to the db
+ # cannot be recovered from).
+ finish_test
+ return
+}
+
+faultsim_save_and_close
+
+do_test 1.1 {
+ testvfs shmfault -default true
+ shmfault devchar atomic
+ sqlite3 db test.db
+ execsql {
+ CREATE TABLE t1(a, b);
+ CREATE INDEX i1 ON t1(a, b);
+ INSERT INTO t1 VALUES(1, 2);
+ INSERT INTO t1 VALUES(2, 4);
+ INSERT INTO t1 VALUES(3, 6);
+ INSERT INTO t1 VALUES(4, 8);
+ }
+
+ # Cause the first call to xWrite() to fail with SQLITE_FULL.
+ shmfault full 2 1
+ catchsql { INSERT INTO t1 VALUES(5, 10) }
+} {1 {database or disk is full}}
+
+do_test 1.2 {
+ execsql { PRAGMA integrity_check }
+} {ok}
+
+db close
+shmfault delete
+
+do_faultsim_test 2 -faults full* -prep {
+ shmfault devchar atomic
+ faultsim_restore
+ sqlite3 db test.db
+} -body {
+ db eval {
+ CREATE TABLE t1(x PRIMARY KEY);
+ INSERT INTO t1 VALUES('abc');
+ }
+} -test {
+ set res [db one { PRAGMA integrity_check }]
+ if {$res != "ok"} {
+ error "integrity check: $res"
+ }
+}
+
+do_faultsim_test 3 -faults full* -prep {
+ shmfault devchar atomic
+ faultsim_restore
+ sqlite3 db test.db
+} -body {
+ db eval {
+ CREATE TABLE t1(x);
+ CREATE TABLE t2(x);
+ }
+} -test {
+ db eval { CREATE TABLE t3(x) }
+ if {[db one { PRAGMA integrity_check }] != "ok"} {
+ error "integrity check failed"
+ }
+}
+
+finish_test
diff --git a/lang/sql/sqlite/test/join6.test b/lang/sql/sqlite/test/join6.test
index 4f65dcb4..7fbf508e 100644
--- a/lang/sql/sqlite/test/join6.test
+++ b/lang/sql/sqlite/test/join6.test
@@ -124,26 +124,28 @@ do_test join6-3.6 {
}
} {1 91 92 3 93 5 91 2 93 94 4 95 6 99}
-do_test join6-4.1 {
- execsql {
- SELECT * FROM
- (SELECT 1 AS a, 91 AS x, 92 AS y UNION SELECT 2, 93, 94)
- NATURAL JOIN t2 NATURAL JOIN t3
- }
-} {1 91 92 3 93 5}
-do_test join6-4.2 {
- execsql {
- SELECT * FROM t1 NATURAL JOIN
- (SELECT 3 AS b, 92 AS y, 93 AS z UNION SELECT 4, 94, 95)
- NATURAL JOIN t3
- }
-} {1 91 92 3 93 5}
-do_test join6-4.3 {
- execsql {
- SELECT * FROM t1 NATURAL JOIN t2 NATURAL JOIN
- (SELECT 5 AS c, 91 AS x, 93 AS z UNION SELECT 6, 99, 95)
- }
-} {1 91 92 3 93 5}
+ifcapable compound {
+ do_test join6-4.1 {
+ execsql {
+ SELECT * FROM
+ (SELECT 1 AS a, 91 AS x, 92 AS y UNION SELECT 2, 93, 94)
+ NATURAL JOIN t2 NATURAL JOIN t3
+ }
+ } {1 91 92 3 93 5}
+ do_test join6-4.2 {
+ execsql {
+ SELECT * FROM t1 NATURAL JOIN
+ (SELECT 3 AS b, 92 AS y, 93 AS z UNION SELECT 4, 94, 95)
+ NATURAL JOIN t3
+ }
+ } {1 91 92 3 93 5}
+ do_test join6-4.3 {
+ execsql {
+ SELECT * FROM t1 NATURAL JOIN t2 NATURAL JOIN
+ (SELECT 5 AS c, 91 AS x, 93 AS z UNION SELECT 6, 99, 95)
+ }
+ } {1 91 92 3 93 5}
+}
diff --git a/lang/sql/sqlite/test/journal1.test b/lang/sql/sqlite/test/journal1.test
index a1b17b41..c89dd2b4 100644
--- a/lang/sql/sqlite/test/journal1.test
+++ b/lang/sql/sqlite/test/journal1.test
@@ -20,7 +20,7 @@ set testdir [file dirname $argv0]
source $testdir/tester.tcl
# These tests will not work on windows because windows uses
-# manditory file locking which breaks the file copy command.
+# manditory file locking which breaks the copy_file command.
#
if {$tcl_platform(platform)=="windows"} {
finish_test
@@ -41,7 +41,7 @@ do_test journal1-1.1 {
} 8
# Make changes to the database and save the journal file.
-# Then delete the database. Replace the the journal file
+# Then delete the database. Replace the journal file
# and try to create a new database with the same name. The
# old journal should not attempt to rollback into the new
# database.
@@ -51,13 +51,13 @@ do_test journal1-1.2 {
BEGIN;
DELETE FROM t1;
}
- file copy -force test.db-journal test.db-journal-bu
+ forcecopy test.db-journal test.db-journal-bu
execsql {
ROLLBACK;
}
db close
- file delete test.db
- file copy test.db-journal-bu test.db-journal
+ delete_file test.db
+ copy_file test.db-journal-bu test.db-journal
sqlite3 db test.db
catchsql {
SELECT * FROM sqlite_master
diff --git a/lang/sql/sqlite/test/journal2.test b/lang/sql/sqlite/test/journal2.test
index 2b5d8fa8..8f9b4d0b 100644
--- a/lang/sql/sqlite/test/journal2.test
+++ b/lang/sql/sqlite/test/journal2.test
@@ -34,7 +34,7 @@ proc a_string {n} {
# characteristics flags to "SAFE_DELETE".
#
testvfs tvfs -default 1
-tvfs devchar undeletable_when_open
+tvfs devchar {undeletable_when_open powersafe_overwrite}
# Set up a hook so that each time a journal file is opened, closed or
# deleted, the method name ("xOpen", "xClose" or "xDelete") and the final
@@ -167,7 +167,7 @@ do_test journal2-1.13 {
} {1 {disk I/O error}}
db2 close
unset ::tvfs_error_on_write
-file copy -force test.db testX.db
+forcecopy test.db testX.db
do_test journal2-1.14 { file exists test.db-journal } 1
do_test journal2-1.15 {
@@ -231,4 +231,3 @@ ifcapable wal {
tvfs delete
finish_test
-
diff --git a/lang/sql/sqlite/test/journal3.test b/lang/sql/sqlite/test/journal3.test
index 7d297222..939cc27c 100644
--- a/lang/sql/sqlite/test/journal3.test
+++ b/lang/sql/sqlite/test/journal3.test
@@ -22,7 +22,9 @@ source $testdir/malloc_common.tcl
#
if {$::tcl_platform(platform) == "unix"} {
- set umask [exec /bin/sh -c umask]
+ # Changed on 2012-02-13: umask is deliberately ignored for -wal, -journal,
+ # and -shm files.
+ #set umask [exec /bin/sh -c umask]
faultsim_delete_and_reopen
do_test journal3-1.1 { execsql { CREATE TABLE tx(y, z) } } {}
@@ -33,9 +35,10 @@ if {$::tcl_platform(platform) == "unix"} {
4 00755
} {
db close
- set effective [format %.5o [expr $permissions & ~$umask]]
+ #set effective [format %.5o [expr $permissions & ~$umask]]
+ set effective $permissions
do_test journal3-1.2.$tn.1 {
- catch { file delete -force test.db-journal }
+ catch { forcedelete test.db-journal }
file attributes test.db -permissions $permissions
file attributes test.db -permissions
} $permissions
diff --git a/lang/sql/sqlite/test/jrnlmode.test b/lang/sql/sqlite/test/jrnlmode.test
index eab74d65..b1007c49 100644
--- a/lang/sql/sqlite/test/jrnlmode.test
+++ b/lang/sql/sqlite/test/jrnlmode.test
@@ -200,7 +200,7 @@ ifcapable attach {
}
ifcapable attach {
- file delete -force test2.db
+ forcedelete test2.db
do_test jrnlmode-2.1 {
execsql {
ATTACH 'test2.db' AS aux;
@@ -242,8 +242,8 @@ ifcapable attach {
# Test caes jrnlmode-3.X verify that ticket #3127 has been fixed.
#
db close
- file delete -force test2.db
- file delete -force test.db
+ forcedelete test2.db
+ forcedelete test.db
sqlite3 db test.db
do_test jrnlmode-3.1 {
@@ -270,7 +270,7 @@ ifcapable attach {
ifcapable autovacuum&&pragma {
db close
- file delete -force test.db
+ forcedelete test.db
sqlite3 db test.db
do_test jrnlmode-4.1 {
execsql {
@@ -303,7 +303,7 @@ ifcapable autovacuum&&pragma {
# pragma.
ifcapable pragma {
db close
- file delete -force test.db test2.db test3.db
+ forcedelete test.db test2.db test3.db
sqlite3 db test.db
do_test jrnlmode-5.1 {
@@ -511,7 +511,7 @@ ifcapable pragma {
ifcapable pragma {
catch { db close }
do_test jrnlmode-7.1 {
- foreach f [glob -nocomplain test.db*] { file delete -force $f }
+ foreach f [glob -nocomplain test.db*] { forcedelete $f }
sqlite3 db test.db
execsql {
PRAGMA journal_mode = memory;
diff --git a/lang/sql/sqlite/test/jrnlmode2.test b/lang/sql/sqlite/test/jrnlmode2.test
index dc3bc270..6ea87d70 100644
--- a/lang/sql/sqlite/test/jrnlmode2.test
+++ b/lang/sql/sqlite/test/jrnlmode2.test
@@ -112,7 +112,7 @@ do_test jrnlmode2-2.4 {
do_test jrnlmode2-2.5 {
db close
- file delete test.db-journal
+ delete_file test.db-journal
} {}
do_test jrnlmode2-2.6 {
sqlite3 db2 test.db -readonly 1
diff --git a/lang/sql/sqlite/test/jrnlmode3.test b/lang/sql/sqlite/test/jrnlmode3.test
index 6ae1346e..43da6579 100644
--- a/lang/sql/sqlite/test/jrnlmode3.test
+++ b/lang/sql/sqlite/test/jrnlmode3.test
@@ -48,7 +48,7 @@ do_test jrnlmode3-1.2 {
} {1}
db close
-file delete -force test.db test.db-journal
+forcedelete test.db test.db-journal
sqlite3 db test.db
do_test jrnlmode3-2.1 {
@@ -85,7 +85,7 @@ foreach fromjmode $all_journal_modes {
# Start with a fresh database connection an empty database file.
#
db close
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db test.db
# Initialize the journal mode.
diff --git a/lang/sql/sqlite/test/keyword1.test b/lang/sql/sqlite/test/keyword1.test
index 94831201..2bc1ff54 100644
--- a/lang/sql/sqlite/test/keyword1.test
+++ b/lang/sql/sqlite/test/keyword1.test
@@ -65,6 +65,7 @@ set kwlist {
pragma
query
raise
+ recursive
regexp
reindex
release
@@ -80,6 +81,8 @@ set kwlist {
vacuum
view
virtual
+ with
+ without
};
set exprkw {
cast
diff --git a/lang/sql/sqlite/test/lastinsert.test b/lang/sql/sqlite/test/lastinsert.test
index adeb7986..c5bc267d 100644
--- a/lang/sql/sqlite/test/lastinsert.test
+++ b/lang/sql/sqlite/test/lastinsert.test
@@ -36,6 +36,17 @@ do_test lastinsert-1.1 {
}
} {0 3}
+# EVIDENCE-OF: R-47220-63683 The sqlite3_last_insert_rowid() function
+# does not work for WITHOUT ROWID tables.
+#
+do_test lastinsert-1.1w {
+ catchsql {
+ create table t1w (k integer primary key) WITHOUT ROWID;
+ insert into t1w values (123456);
+ select last_insert_rowid(); -- returns 3 from above.
+ }
+} {0 3}
+
# LIRID unchanged after an update on a table
do_test lastinsert-1.2 {
catchsql {
diff --git a/lang/sql/sqlite/test/like.test b/lang/sql/sqlite/test/like.test
index bd9a6c39..923272cf 100644
--- a/lang/sql/sqlite/test/like.test
+++ b/lang/sql/sqlite/test/like.test
@@ -70,12 +70,15 @@ do_test like-1.4 {
}
} {ABC abc}
do_test like-1.5.1 {
+ # Use sqlite3_exec() to verify fix for ticket [25ee81271091] 2011-06-26
+ sqlite3_exec db {PRAGMA case_sensitive_like=on}
+} {0 {}}
+do_test like-1.5.2 {
execsql {
- PRAGMA case_sensitive_like=on;
SELECT x FROM t1 WHERE x LIKE 'abc' ORDER BY 1;
}
} {abc}
-do_test like-1.5.2 {
+do_test like-1.5.3 {
execsql {
PRAGMA case_sensitive_like; -- no argument; does not change setting
SELECT x FROM t1 WHERE x LIKE 'abc' ORDER BY 1;
@@ -153,14 +156,27 @@ ifcapable !like_opt {
# This procedure executes the SQL. Then it appends to the result the
# "sort" or "nosort" keyword (as in the cksort procedure above) then
-# it appends the ::sqlite_query_plan variable.
+# 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
- return [concat $data $::sqlite_query_plan]
+ set eqp [execsql "EXPLAIN QUERY PLAN $sql"]
+ # puts eqp=$eqp
+ foreach {a b c x} $eqp {
+ if {[regexp { TABLE (\w+ AS )?(\w+) USING COVERING INDEX (\w+)\y} \
+ $x all as tab idx]} {
+ lappend data {} $idx
+ } elseif {[regexp { TABLE (\w+ AS )?(\w+) USING.* INDEX (\w+)\y} \
+ $x all as tab idx]} {
+ lappend data $tab $idx
+ } elseif {[regexp { TABLE (\w+ AS )?(\w+)\y} $x all as tab]} {
+ lappend data $tab *
+ }
+ }
+ return $data
}
# Perform tests on the like optimization.
@@ -173,7 +189,7 @@ do_test like-3.1 {
queryplan {
SELECT x FROM t1 WHERE x LIKE 'abc%' ORDER BY 1;
}
-} {ABC {ABC abc xyz} abc abcd sort t1 {}}
+} {ABC {ABC abc xyz} abc abcd sort t1 *}
do_test like-3.2 {
set sqlite_like_count
} {12}
@@ -266,8 +282,8 @@ do_test like-3.12 {
#
do_test like-3.13 {
set sqlite_like_count 0
+ db eval {PRAGMA case_sensitive_like=off;}
queryplan {
- PRAGMA case_sensitive_like=off;
SELECT x FROM t1 WHERE x LIKE 'abc%' ORDER BY 1;
}
} {ABC {ABC abc xyz} abc abcd nosort {} i1}
@@ -279,12 +295,14 @@ do_test like-3.14 {
#
do_test like-3.15 {
set sqlite_like_count 0
- queryplan {
+ db eval {
PRAGMA case_sensitive_like=on;
DROP INDEX i1;
+ }
+ queryplan {
SELECT x FROM t1 WHERE x LIKE 'abc%' ORDER BY 1;
}
-} {abc abcd sort t1 {}}
+} {abc abcd sort t1 *}
do_test like-3.16 {
set sqlite_like_count
} 12
@@ -296,7 +314,7 @@ do_test like-3.17 {
queryplan {
SELECT x FROM t1 WHERE x GLOB 'abc*' ORDER BY 1;
}
-} {abc abcd sort t1 {}}
+} {abc abcd sort t1 *}
do_test like-3.18 {
set sqlite_like_count
} 12
@@ -305,8 +323,8 @@ do_test like-3.18 {
#
do_test like-3.19 {
set sqlite_like_count 0
+ db eval {CREATE INDEX i1 ON t1(x);}
queryplan {
- CREATE INDEX i1 ON t1(x);
SELECT x FROM t1 WHERE x GLOB 'abc*' ORDER BY 1;
}
} {abc abcd nosort {} i1}
@@ -315,8 +333,8 @@ do_test like-3.20 {
} 0
do_test like-3.21 {
set sqlite_like_count 0
+ db eval {PRAGMA case_sensitive_like=on;}
queryplan {
- PRAGMA case_sensitive_like=on;
SELECT x FROM t1 WHERE x GLOB 'abc*' ORDER BY 1;
}
} {abc abcd nosort {} i1}
@@ -325,8 +343,8 @@ do_test like-3.22 {
} 0
do_test like-3.23 {
set sqlite_like_count 0
+ db eval {PRAGMA case_sensitive_like=off;}
queryplan {
- PRAGMA case_sensitive_like=off;
SELECT x FROM t1 WHERE x GLOB 'a[bc]d' ORDER BY 1;
}
} {abd acd nosort {} i1}
@@ -403,7 +421,7 @@ do_test like-5.2 {
do_test like-5.3 {
execsql {
CREATE TABLE t2(x TEXT COLLATE NOCASE);
- INSERT INTO t2 SELECT * FROM t1;
+ INSERT INTO t2 SELECT * FROM t1 ORDER BY rowid;
CREATE INDEX i2 ON t2(x COLLATE NOCASE);
}
set sqlite_like_count 0
@@ -519,7 +537,7 @@ do_test like-5.24 {
}
} {zz-lower-lower zZ-lower-upper Zz-upper-lower ZZ-upper-upper nosort {} i2}
do_test like-5.25 {
- queryplan {
+ db eval {
PRAGMA case_sensitive_like=on;
CREATE TABLE t3(x TEXT);
CREATE INDEX i3 ON t3(x);
@@ -527,6 +545,8 @@ do_test like-5.25 {
INSERT INTO t3 VALUES('zZ-lower-upper');
INSERT INTO t3 VALUES('Zz-upper-lower');
INSERT INTO t3 VALUES('zz-lower-lower');
+ }
+ queryplan {
SELECT x FROM t3 WHERE x LIKE 'zz%';
}
} {zz-lower-lower nosort {} i3}
@@ -657,8 +677,8 @@ ifcapable like_opt&&!icu {
set res [sqlite3_exec_hex db {
EXPLAIN QUERY PLAN SELECT x FROM t2 WHERE x LIKE '%ff%25'
}]
- regexp {INDEX i2} $res
- } {0}
+ regexp {SCAN TABLE t2} $res
+ } {1}
}
do_test like-9.5.1 {
set res [sqlite3_exec_hex db {
@@ -804,60 +824,66 @@ do_test like-11.0 {
}
} {12}
do_test like-11.1 {
+ db eval {PRAGMA case_sensitive_like=OFF;}
queryplan {
- PRAGMA case_sensitive_like=OFF;
SELECT b FROM t11 WHERE b LIKE 'abc%' ORDER BY a;
}
} {abc abcd ABC ABCD nosort t11 *}
do_test like-11.2 {
+ db eval {PRAGMA case_sensitive_like=ON;}
queryplan {
- PRAGMA case_sensitive_like=ON;
SELECT b FROM t11 WHERE b LIKE 'abc%' ORDER BY a;
}
} {abc abcd nosort t11 *}
do_test like-11.3 {
- queryplan {
+ db eval {
PRAGMA case_sensitive_like=OFF;
CREATE INDEX t11b ON t11(b);
+ }
+ queryplan {
SELECT b FROM t11 WHERE b LIKE 'abc%' ORDER BY +a;
}
} {abc abcd ABC ABCD sort {} t11b}
do_test like-11.4 {
+ db eval {PRAGMA case_sensitive_like=ON;}
queryplan {
- PRAGMA case_sensitive_like=ON;
SELECT b FROM t11 WHERE b LIKE 'abc%' ORDER BY a;
}
} {abc abcd nosort t11 *}
do_test like-11.5 {
- queryplan {
+ db eval {
PRAGMA case_sensitive_like=OFF;
DROP INDEX t11b;
CREATE INDEX t11bnc ON t11(b COLLATE nocase);
+ }
+ queryplan {
SELECT b FROM t11 WHERE b LIKE 'abc%' ORDER BY +a;
}
} {abc abcd ABC ABCD sort {} t11bnc}
do_test like-11.6 {
+ db eval {CREATE INDEX t11bb ON t11(b COLLATE binary);}
queryplan {
- CREATE INDEX t11bb ON t11(b COLLATE binary);
SELECT b FROM t11 WHERE b LIKE 'abc%' ORDER BY +a;
}
} {abc abcd ABC ABCD sort {} t11bnc}
do_test like-11.7 {
+ db eval {PRAGMA case_sensitive_like=ON;}
queryplan {
- PRAGMA case_sensitive_like=ON;
SELECT b FROM t11 WHERE b LIKE 'abc%' ORDER BY +a;
}
} {abc abcd sort {} t11bb}
do_test like-11.8 {
+ db eval {PRAGMA case_sensitive_like=OFF;}
queryplan {
- PRAGMA case_sensitive_like=OFF;
SELECT b FROM t11 WHERE b GLOB 'abc*' ORDER BY +a;
}
} {abc abcd sort {} t11bb}
do_test like-11.9 {
- queryplan {
+ db eval {
CREATE INDEX t11cnc ON t11(c COLLATE nocase);
CREATE INDEX t11cb ON t11(c COLLATE binary);
+ }
+ queryplan {
SELECT c FROM t11 WHERE c LIKE 'abc%' ORDER BY +a;
}
} {abc abcd ABC ABCD sort {} t11cnc}
@@ -867,5 +893,60 @@ do_test like-11.10 {
}
} {abc abcd sort {} t11cb}
+# A COLLATE clause on the pattern does not change the result of a
+# LIKE operator.
+#
+do_execsql_test like-12.1 {
+ CREATE TABLE t12nc(id INTEGER, x TEXT UNIQUE COLLATE nocase);
+ INSERT INTO t12nc VALUES(1,'abcde'),(2,'uvwxy'),(3,'ABCDEF');
+ CREATE TABLE t12b(id INTEGER, x TEXT UNIQUE COLLATE binary);
+ INSERT INTO t12b VALUES(1,'abcde'),(2,'uvwxy'),(3,'ABCDEF');
+ SELECT id FROM t12nc WHERE x LIKE 'abc%' ORDER BY +id;
+} {1 3}
+do_execsql_test like-12.2 {
+ SELECT id FROM t12b WHERE x LIKE 'abc%' ORDER BY +id;
+} {1 3}
+do_execsql_test like-12.3 {
+ SELECT id FROM t12nc WHERE x LIKE 'abc%' COLLATE binary ORDER BY +id;
+} {1 3}
+do_execsql_test like-12.4 {
+ SELECT id FROM t12b WHERE x LIKE 'abc%' COLLATE binary ORDER BY +id;
+} {1 3}
+do_execsql_test like-12.5 {
+ SELECT id FROM t12nc WHERE x LIKE 'abc%' COLLATE nocase ORDER BY +id;
+} {1 3}
+do_execsql_test like-12.6 {
+ SELECT id FROM t12b WHERE x LIKE 'abc%' COLLATE nocase ORDER BY +id;
+} {1 3}
+
+# Adding a COLLATE clause to the pattern of a LIKE operator does nothing
+# to change the suitability of using an index to satisfy that LIKE
+# operator.
+#
+do_execsql_test like-12.11 {
+ EXPLAIN QUERY PLAN
+ SELECT id FROM t12nc WHERE x LIKE 'abc%' ORDER BY +id;
+} {/SEARCH/}
+do_execsql_test like-12.12 {
+ EXPLAIN QUERY PLAN
+ SELECT id FROM t12b WHERE x LIKE 'abc%' ORDER BY +id;
+} {/SCAN/}
+do_execsql_test like-12.13 {
+ EXPLAIN QUERY PLAN
+ SELECT id FROM t12nc WHERE x LIKE 'abc%' COLLATE nocase ORDER BY +id;
+} {/SEARCH/}
+do_execsql_test like-12.14 {
+ EXPLAIN QUERY PLAN
+ SELECT id FROM t12b WHERE x LIKE 'abc%' COLLATE nocase ORDER BY +id;
+} {/SCAN/}
+do_execsql_test like-12.15 {
+ EXPLAIN QUERY PLAN
+ SELECT id FROM t12nc WHERE x LIKE 'abc%' COLLATE binary ORDER BY +id;
+} {/SEARCH/}
+do_execsql_test like-12.16 {
+ EXPLAIN QUERY PLAN
+ SELECT id FROM t12b WHERE x LIKE 'abc%' COLLATE binary ORDER BY +id;
+} {/SCAN/}
+
finish_test
diff --git a/lang/sql/sqlite/test/limit.test b/lang/sql/sqlite/test/limit.test
index e5aac70d..c5b75c2b 100644
--- a/lang/sql/sqlite/test/limit.test
+++ b/lang/sql/sqlite/test/limit.test
@@ -468,5 +468,152 @@ do_test limit-12.4 {
}
} {1 {no such column: x}}
+# Ticket [db4d96798da8b]
+# LIMIT does not work with nested views containing UNION ALL
+#
+do_test limit-13.1 {
+ db eval {
+ CREATE TABLE t13(x);
+ INSERT INTO t13 VALUES(1),(2);
+ CREATE VIEW v13a AS SELECT x AS y FROM t13;
+ CREATE VIEW v13b AS SELECT y AS z FROM v13a UNION ALL SELECT y+10 FROM v13a;
+ CREATE VIEW v13c AS SELECT z FROM v13b UNION ALL SELECT z+20 FROM v13b;
+ }
+} {}
+do_test limit-13.2 {
+ db eval {SELECT z FROM v13c LIMIT 1}
+} {1}
+do_test limit-13.3 {
+ db eval {SELECT z FROM v13c LIMIT 2}
+} {1 2}
+do_test limit-13.4 {
+ db eval {SELECT z FROM v13c LIMIT 3}
+} {1 2 11}
+do_test limit-13.5 {
+ db eval {SELECT z FROM v13c LIMIT 4}
+} {1 2 11 12}
+do_test limit-13.6 {
+ db eval {SELECT z FROM v13c LIMIT 5}
+} {1 2 11 12 21}
+do_test limit-13.7 {
+ db eval {SELECT z FROM v13c LIMIT 6}
+} {1 2 11 12 21 22}
+do_test limit-13.8 {
+ db eval {SELECT z FROM v13c LIMIT 7}
+} {1 2 11 12 21 22 31}
+do_test limit-13.9 {
+ db eval {SELECT z FROM v13c LIMIT 8}
+} {1 2 11 12 21 22 31 32}
+do_test limit-13.10 {
+ db eval {SELECT z FROM v13c LIMIT 9}
+} {1 2 11 12 21 22 31 32}
+do_test limit-13.11 {
+ db eval {SELECT z FROM v13c LIMIT 1 OFFSET 1}
+} {2}
+do_test limit-13.12 {
+ db eval {SELECT z FROM v13c LIMIT 2 OFFSET 1}
+} {2 11}
+do_test limit-13.13 {
+ db eval {SELECT z FROM v13c LIMIT 3 OFFSET 1}
+} {2 11 12}
+do_test limit-13.14 {
+ db eval {SELECT z FROM v13c LIMIT 4 OFFSET 1}
+} {2 11 12 21}
+do_test limit-13.15 {
+ db eval {SELECT z FROM v13c LIMIT 5 OFFSET 1}
+} {2 11 12 21 22}
+do_test limit-13.16 {
+ db eval {SELECT z FROM v13c LIMIT 6 OFFSET 1}
+} {2 11 12 21 22 31}
+do_test limit-13.17 {
+ db eval {SELECT z FROM v13c LIMIT 7 OFFSET 1}
+} {2 11 12 21 22 31 32}
+do_test limit-13.18 {
+ db eval {SELECT z FROM v13c LIMIT 8 OFFSET 1}
+} {2 11 12 21 22 31 32}
+do_test limit-13.21 {
+ db eval {SELECT z FROM v13c LIMIT 1 OFFSET 2}
+} {11}
+do_test limit-13.22 {
+ db eval {SELECT z FROM v13c LIMIT 2 OFFSET 2}
+} {11 12}
+do_test limit-13.23 {
+ db eval {SELECT z FROM v13c LIMIT 3 OFFSET 2}
+} {11 12 21}
+do_test limit-13.24 {
+ db eval {SELECT z FROM v13c LIMIT 4 OFFSET 2}
+} {11 12 21 22}
+do_test limit-13.25 {
+ db eval {SELECT z FROM v13c LIMIT 5 OFFSET 2}
+} {11 12 21 22 31}
+do_test limit-13.26 {
+ db eval {SELECT z FROM v13c LIMIT 6 OFFSET 2}
+} {11 12 21 22 31 32}
+do_test limit-13.27 {
+ db eval {SELECT z FROM v13c LIMIT 7 OFFSET 2}
+} {11 12 21 22 31 32}
+do_test limit-13.31 {
+ db eval {SELECT z FROM v13c LIMIT 1 OFFSET 3}
+} {12}
+do_test limit-13.32 {
+ db eval {SELECT z FROM v13c LIMIT 2 OFFSET 3}
+} {12 21}
+do_test limit-13.33 {
+ db eval {SELECT z FROM v13c LIMIT 3 OFFSET 3}
+} {12 21 22}
+do_test limit-13.34 {
+ db eval {SELECT z FROM v13c LIMIT 4 OFFSET 3}
+} {12 21 22 31}
+do_test limit-13.35 {
+ db eval {SELECT z FROM v13c LIMIT 5 OFFSET 3}
+} {12 21 22 31 32}
+do_test limit-13.36 {
+ db eval {SELECT z FROM v13c LIMIT 6 OFFSET 3}
+} {12 21 22 31 32}
+do_test limit-13.41 {
+ db eval {SELECT z FROM v13c LIMIT 1 OFFSET 4}
+} {21}
+do_test limit-13.42 {
+ db eval {SELECT z FROM v13c LIMIT 2 OFFSET 4}
+} {21 22}
+do_test limit-13.43 {
+ db eval {SELECT z FROM v13c LIMIT 3 OFFSET 4}
+} {21 22 31}
+do_test limit-13.44 {
+ db eval {SELECT z FROM v13c LIMIT 4 OFFSET 4}
+} {21 22 31 32}
+do_test limit-13.45 {
+ db eval {SELECT z FROM v13c LIMIT 5 OFFSET 4}
+} {21 22 31 32}
+do_test limit-13.51 {
+ db eval {SELECT z FROM v13c LIMIT 1 OFFSET 5}
+} {22}
+do_test limit-13.52 {
+ db eval {SELECT z FROM v13c LIMIT 2 OFFSET 5}
+} {22 31}
+do_test limit-13.53 {
+ db eval {SELECT z FROM v13c LIMIT 3 OFFSET 5}
+} {22 31 32}
+do_test limit-13.54 {
+ db eval {SELECT z FROM v13c LIMIT 4 OFFSET 5}
+} {22 31 32}
+do_test limit-13.61 {
+ db eval {SELECT z FROM v13c LIMIT 1 OFFSET 6}
+} {31}
+do_test limit-13.62 {
+ db eval {SELECT z FROM v13c LIMIT 2 OFFSET 6}
+} {31 32}
+do_test limit-13.63 {
+ db eval {SELECT z FROM v13c LIMIT 3 OFFSET 6}
+} {31 32}
+do_test limit-13.71 {
+ db eval {SELECT z FROM v13c LIMIT 1 OFFSET 7}
+} {32}
+do_test limit-13.72 {
+ db eval {SELECT z FROM v13c LIMIT 2 OFFSET 7}
+} {32}
+do_test limit-13.81 {
+ db eval {SELECT z FROM v13c LIMIT 1 OFFSET 8}
+} {}
finish_test
diff --git a/lang/sql/sqlite/test/loadext.test b/lang/sql/sqlite/test/loadext.test
index db5745b4..0d5b8419 100644
--- a/lang/sql/sqlite/test/loadext.test
+++ b/lang/sql/sqlite/test/loadext.test
@@ -23,7 +23,7 @@ ifcapable !load_ext {
# The name of the test extension varies by operating system.
#
-if {$::tcl_platform(platform) eq "windows" || $::tcl_platform(platform) eq "os2"} {
+if {$::tcl_platform(platform) eq "windows"} {
set testextension ./testloadext.dll
} else {
set testextension ./libtestloadext.so
@@ -134,25 +134,27 @@ sqlite3_enable_load_extension db 1
# Try to load an extension for which the file does not exist.
#
do_test loadext-2.1 {
- file delete -force ${testextension}xx
+ forcedelete ${testextension}xx
set rc [catch {
sqlite3_load_extension db "${testextension}xx"
} msg]
list $rc $msg
-} [list 1 [format $dlerror_nosuchfile ${testextension}xx]]
+} /[list 1 [format $dlerror_nosuchfile ${testextension}xx.*]]/
# Try to load an extension for which the file is not a shared object
#
do_test loadext-2.2 {
- set fd [open "${testextension}xx" w]
+ set fd [open "./notasharedlib.so" w]
+ puts $fd blah
+ close $fd
+ set fd [open "./notasharedlib.dll" w]
puts $fd blah
close $fd
set rc [catch {
- sqlite3_load_extension db "${testextension}xx"
+ sqlite3_load_extension db "./notasharedlib"
} msg]
- set expected_error_pattern [format $dlerror_notadll ${testextension}xx]
- list $rc [string match $expected_error_pattern $msg]
-} [list 1 1]
+ list $rc $msg
+} /[list 1 [format $dlerror_notadll ./notasharedlib.*]]/
# Try to load an extension for which the file is present but the
# entry point is not.
@@ -196,7 +198,7 @@ do_test loadext-3.2 {
regsub {0x[1234567890abcdefABCDEF]*} $res XXX res
}
set res
-} [list 1 [format $dlerror_nosymbol $testextension sqlite3_extension_init]]
+} /[list 1 [format $dlerror_nosymbol $testextension sqlite3_.*_init]]/
do_test loadext-3.3 {
catchsql {
SELECT load_extension($::testextension,'testloadext_init')
diff --git a/lang/sql/sqlite/test/loadext2.test b/lang/sql/sqlite/test/loadext2.test
index 3d01539b..d5b6ea8d 100644
--- a/lang/sql/sqlite/test/loadext2.test
+++ b/lang/sql/sqlite/test/loadext2.test
@@ -43,6 +43,19 @@ do_test loadext2-1.2 {
}
} {1 {no such function: cube}}
+# Extensions loaders not currently registered
+#
+do_test loadext2-1.2.1 {
+ sqlite3_cancel_auto_extension_sqr
+} {0}
+do_test loadext2-1.2.2 {
+ sqlite3_cancel_auto_extension_sqr
+} {0}
+do_test loadext2-1.2.3 {
+ sqlite3_cancel_auto_extension_sqr
+} {0}
+
+
# Register auto-loaders. Still functions do not exist.
#
do_test loadext2-1.3 {
@@ -76,8 +89,19 @@ do_test loadext2-1.6 {
# Reset extension auto loading. Existing extensions still exist.
#
-do_test loadext2-1.7 {
- sqlite3_reset_auto_extension
+do_test loadext2-1.7.1 {
+ sqlite3_cancel_auto_extension_sqr
+} {1}
+do_test loadext2-1.7.2 {
+ sqlite3_cancel_auto_extension_sqr
+} {0}
+do_test loadext2-1.7.3 {
+ sqlite3_cancel_auto_extension_cube
+} {1}
+do_test loadext2-1.7.4 {
+ sqlite3_cancel_auto_extension_cube
+} {0}
+do_test loadext2-1.7.5 {
catchsql {
SELECT sqr(2)
}
diff --git a/lang/sql/sqlite/test/lock.test b/lang/sql/sqlite/test/lock.test
index 22f359c1..6ec85eea 100644
--- a/lang/sql/sqlite/test/lock.test
+++ b/lang/sql/sqlite/test/lock.test
@@ -247,11 +247,34 @@ do_test lock-2.8 {
execsql {UPDATE t1 SET a = 0 WHERE 0}
catchsql {BEGIN EXCLUSIVE;} db2
} {1 {database is locked}}
+do_test lock-2.8b {
+ db2 eval {PRAGMA busy_timeout}
+} {400}
do_test lock-2.9 {
db2 timeout 0
execsql COMMIT
} {}
+do_test lock-2.9b {
+ db2 eval {PRAGMA busy_timeout}
+} {0}
integrity_check lock-2.10
+do_test lock-2.11 {
+ db2 eval {PRAGMA busy_timeout(400)}
+ execsql BEGIN
+ execsql {UPDATE t1 SET a = 0 WHERE 0}
+ catchsql {BEGIN EXCLUSIVE;} db2
+} {1 {database is locked}}
+do_test lock-2.11b {
+ db2 eval {PRAGMA busy_timeout}
+} {400}
+do_test lock-2.12 {
+ db2 eval {PRAGMA busy_timeout(0)}
+ execsql COMMIT
+} {}
+do_test lock-2.12b {
+ db2 eval {PRAGMA busy_timeout}
+} {0}
+integrity_check lock-2.13
# Try to start two transactions in a row
#
diff --git a/lang/sql/sqlite/test/lock4.test b/lang/sql/sqlite/test/lock4.test
index 06ee88df..b0b1c74f 100644
--- a/lang/sql/sqlite/test/lock4.test
+++ b/lang/sql/sqlite/test/lock4.test
@@ -26,7 +26,7 @@ do_test lock4-1.1 {
PRAGMA auto_vacuum=OFF;
CREATE TABLE t1(x);
}
- file delete -force test2.db test2.db-journal
+ forcedelete test2.db test2.db-journal
sqlite3 db2 test2.db
db2 eval {
PRAGMA auto_vacuum=OFF;
diff --git a/lang/sql/sqlite/test/lock5.test b/lang/sql/sqlite/test/lock5.test
index 6ec86ba7..f0d49550 100644
--- a/lang/sql/sqlite/test/lock5.test
+++ b/lang/sql/sqlite/test/lock5.test
@@ -24,7 +24,7 @@ if {[catch {sqlite3 db test.db -vfs unix-none} msg]} {
return
}
db close
-file delete -force test.db.lock
+forcedelete test.db.lock
ifcapable lock_proxy_pragmas {
set ::using_proxy 0
@@ -100,7 +100,7 @@ do_test lock5-dotfile.X {
#####################################################################
-file delete -force test.db
+forcedelete test.db
if {[catch {sqlite3 db test.db -vfs unix-flock} msg]} {
finish_test
return
diff --git a/lang/sql/sqlite/test/lock7.test b/lang/sql/sqlite/test/lock7.test
index 49bc147a..02f2c6c6 100644
--- a/lang/sql/sqlite/test/lock7.test
+++ b/lang/sql/sqlite/test/lock7.test
@@ -58,4 +58,3 @@ db1 close
db2 close
finish_test
-
diff --git a/lang/sql/sqlite/test/lock_common.tcl b/lang/sql/sqlite/test/lock_common.tcl
index 21f58426..bc1eb86b 100644
--- a/lang/sql/sqlite/test/lock_common.tcl
+++ b/lang/sql/sqlite/test/lock_common.tcl
@@ -55,8 +55,8 @@ proc do_multiclient_test {varname script} {
uplevel set $varname $tn
uplevel $script
- code2 { db2 close }
- code3 { db3 close }
+ catch { code2 { db2 close } }
+ catch { code3 { db3 close } }
catch { close $::code2_chan }
catch { close $::code3_chan }
catch { db close }
diff --git a/lang/sql/sqlite/test/main.test b/lang/sql/sqlite/test/main.test
index dbf90410..5bbc52b8 100644
--- a/lang/sql/sqlite/test/main.test
+++ b/lang/sql/sqlite/test/main.test
@@ -301,7 +301,7 @@ ifcapable {trigger} {
if {[permutation] == ""} {
do_test main-2.0 {
catch {db close}
- file delete -force test.db
+ forcedelete test.db
set fd [open test.db w]
puts $fd hi!
close $fd
@@ -314,16 +314,16 @@ if {[permutation] == ""} {
#
do_test main-3.1 {
catch {db close}
- foreach f [glob -nocomplain testdb/*] {file delete -force $f}
- file delete -force testdb
+ foreach f [glob -nocomplain testdb/*] {forcedelete $f}
+ forcedelete testdb
sqlite3 db testdb
set v [catch {execsql {SELECT * from T1 where x!!5}} msg]
lappend v $msg
} {1 {unrecognized token: "!!"}}
do_test main-3.2 {
catch {db close}
- foreach f [glob -nocomplain testdb/*] {file delete -force $f}
- file delete -force testdb
+ foreach f [glob -nocomplain testdb/*] {forcedelete $f}
+ forcedelete testdb
sqlite3 db testdb
set v [catch {execsql {SELECT * from T1 where ^x}} msg]
lappend v $msg
@@ -442,8 +442,8 @@ do_test main-3.2.30 {
do_test main-3.3 {
catch {db close}
- foreach f [glob -nocomplain testdb/*] {file delete -force $f}
- file delete -force testdb
+ foreach f [glob -nocomplain testdb/*] {forcedelete $f}
+ forcedelete testdb
sqlite3 db testdb
execsql {
create table T1(X REAL); /* C-style comments allowed */
diff --git a/lang/sql/sqlite/test/malloc.test b/lang/sql/sqlite/test/malloc.test
index e808dab6..7c4af254 100644
--- a/lang/sql/sqlite/test/malloc.test
+++ b/lang/sql/sqlite/test/malloc.test
@@ -270,7 +270,7 @@ do_malloc_test 9 -sqlprep {
do_malloc_test 10 -tclprep {
catch {db2 close}
db close
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db test.db
sqlite3_extended_result_codes db 1
db eval {CREATE TABLE abc(a, b, c)}
@@ -341,8 +341,8 @@ if {$tcl_platform(platform)!="windows"} {
BEGIN;
INSERT INTO t1 VALUES(3, 4);
}
- copy_file test2.db test.db
- copy_file test2.db-journal test.db-journal
+ forcecopy test2.db test.db
+ forcecopy test2.db-journal test.db-journal
db2 close
} -tclbody {
sqlite3 db test.db
@@ -499,7 +499,7 @@ unset static_string
ifcapable attach {
do_malloc_test 20 -tclprep {
db close
- file delete -force test2.db test2.db-journal
+ forcedelete test2.db test2.db-journal
sqlite3 db test2.db
sqlite3_extended_result_codes db 1
db eval {CREATE TABLE t1(x);}
@@ -842,7 +842,7 @@ do_malloc_test 36 -sqlprep {
SELECT test_agg_errmsg16(), group_concat(a) FROM t1
}
-# At one point, if an OOM occured immediately after obtaining a shared lock
+# At one point, if an OOM occurred immediately after obtaining a shared lock
# on the database file, the file remained locked. This test case ensures
# that bug has been fixed.i
if {[db eval {PRAGMA locking_mode}]!="exclusive"} {
@@ -867,31 +867,17 @@ if {[db eval {PRAGMA locking_mode}]!="exclusive"} {
catch { db2 close }
}
-ifcapable stat2&&utf16 {
- do_malloc_test 38 -tclprep {
- add_test_collate db 0 0 1
- execsql {
- ANALYZE;
- CREATE TABLE t4(x COLLATE test_collate);
- CREATE INDEX t4x ON t4(x);
- INSERT INTO sqlite_stat2 VALUES('t4', 't4x', 0, 'aaa');
- INSERT INTO sqlite_stat2 VALUES('t4', 't4x', 1, 'aaa');
- INSERT INTO sqlite_stat2 VALUES('t4', 't4x', 2, 'aaa');
- INSERT INTO sqlite_stat2 VALUES('t4', 't4x', 3, 'aaa');
- INSERT INTO sqlite_stat2 VALUES('t4', 't4x', 4, 'aaa');
- INSERT INTO sqlite_stat2 VALUES('t4', 't4x', 5, 'aaa');
- INSERT INTO sqlite_stat2 VALUES('t4', 't4x', 6, 'aaa');
- INSERT INTO sqlite_stat2 VALUES('t4', 't4x', 7, 'aaa');
- INSERT INTO sqlite_stat2 VALUES('t4', 't4x', 8, 'aaa');
- INSERT INTO sqlite_stat2 VALUES('t4', 't4x', 9, 'aaa');
- }
- db close
- sqlite3 db test.db
- sqlite3_db_config_lookaside db 0 0 0
- add_test_collate db 0 0 1
- } -sqlbody {
- SELECT * FROM t4 AS t41, t4 AS t42 WHERE t41.x>'ddd' AND t42.x>'ccc'
- }
+
+# Test that if an OOM error occurs, aux-data is still correctly destroyed.
+# This test case was causing either a memory-leak or an assert() failure
+# at one point, depending on the configuration.
+#
+do_malloc_test 39 -tclprep {
+ sqlite3 db test.db
+} -sqlbody {
+ SELECT test_auxdata('abc', 'def');
+} -cleanup {
+ db close
}
# Ensure that no file descriptors were leaked.
diff --git a/lang/sql/sqlite/test/malloc3.test b/lang/sql/sqlite/test/malloc3.test
index 73d2d396..f4a6c3bb 100644
--- a/lang/sql/sqlite/test/malloc3.test
+++ b/lang/sql/sqlite/test/malloc3.test
@@ -27,6 +27,24 @@ if {!$MEMDEBUG} {
return
}
+
+# Do not run these tests with an in-memory journal.
+#
+# In the pager layer, if an IO or OOM error occurs during a ROLLBACK, or
+# when flushing a page to disk due to cache-stress, the pager enters an
+# "error state". The only way out of the error state is to unlock the
+# database file and end the transaction, leaving whatever journal and
+# database files happen to be on disk in place. The next time the current
+# (or any other) connection opens a read transaction, hot-journal rollback
+# is performed if necessary.
+#
+# Of course, this doesn't work with an in-memory journal.
+#
+if {[permutation]=="inmemory_journal"} {
+ finish_test
+ return
+}
+
#--------------------------------------------------------------------------
# NOTES ON RECOVERING FROM A MALLOC FAILURE
#
@@ -147,6 +165,7 @@ if {!$MEMDEBUG} {
# ::run_test_script. At the end of this file, the proc [run_test] is used
# to execute the program (and all test cases contained therein).
#
+set ::run_test_sql_id 0
set ::run_test_script [list]
proc TEST {id t} {lappend ::run_test_script -test [list $id $t]}
proc PREP {p} {lappend ::run_test_script -prep [string trim $p]}
@@ -162,13 +181,14 @@ proc DEBUG {s} {lappend ::run_test_script -debug $s}
# transaction only.
#
proc SQL {a1 {a2 ""}} {
- # An SQL primitive parameter is a list of two elements, a boolean value
- # indicating if the statement may cause transaction rollback when malloc()
- # fails, and the sql statement itself.
+ # An SQL primitive parameter is a list of three elements, an id, a boolean
+ # value indicating if the statement may cause transaction rollback when
+ # malloc() fails, and the sql statement itself.
+ set id [incr ::run_test_sql_id]
if {$a2 == ""} {
- lappend ::run_test_script -sql [list true [string trim $a1]]
+ lappend ::run_test_script -sql [list $id true [string trim $a1]]
} else {
- lappend ::run_test_script -sql [list false [string trim $a2]]
+ lappend ::run_test_script -sql [list $id false [string trim $a2]]
}
}
@@ -258,7 +278,7 @@ TEST 5 {
set sql {
BEGIN;DELETE FROM abc;
}
-for {set i 1} {$i < 15} {incr i} {
+for {set i 1} {$i < 100} {incr i} {
set a $i
set b "String value $i"
set c [string repeat X $i]
@@ -463,7 +483,7 @@ TEST 29 {
# Test a simple multi-file transaction
#
-file delete -force test2.db
+forcedelete test2.db
ifcapable attach {
SQL {ATTACH 'test2.db' AS aux;}
SQL {BEGIN}
@@ -529,12 +549,13 @@ proc run_test {arglist iRepeat {pcstart 0} {iFailStart 1}} {
}
for {set i 0} {$i < $pcstart} {incr i} {
- set k2 [lindex $arglist [expr 2 * $i]]
- set v2 [lindex $arglist [expr 2 * $i + 1]]
+ set k2 [lindex $arglist [expr {2 * $i}]]
+ set v2 [lindex $arglist [expr {2 * $i + 1}]]
set ac [sqlite3_get_autocommit $::DB] ;# Auto-Commit
switch -- $k2 {
- -sql {db eval [lindex $v2 1]}
+ -sql {db eval [lindex $v2 2]}
-prep {db eval $v2}
+ -debug {eval $v2}
}
set nac [sqlite3_get_autocommit $::DB] ;# New Auto-Commit
if {$ac && !$nac} {set begin_pc $i}
@@ -545,33 +566,39 @@ proc run_test {arglist iRepeat {pcstart 0} {iFailStart 1}} {
set iFail $iFailStart
set pc $pcstart
while {$pc*2 < [llength $arglist]} {
+ # Fetch the current instruction type and payload.
+ set k [lindex $arglist [expr {2 * $pc}]]
+ set v [lindex $arglist [expr {2 * $pc + 1}]]
# Id of this iteration:
- set k [lindex $arglist [expr 2 * $pc]]
set iterid "pc=$pc.iFail=$iFail$k"
- set v [lindex $arglist [expr 2 * $pc + 1]]
switch -- $k {
-test {
foreach {id script} $v {}
+ set testid "malloc3-(test $id).$iterid"
+ eval $script
incr pc
}
-sql {
set ::rollback_hook_count 0
+ set id [lindex $v 0]
+ set testid "malloc3-(integrity $id).$iterid"
+
set ac [sqlite3_get_autocommit $::DB] ;# Auto-Commit
sqlite3_memdebug_fail $iFail -repeat 0
- set rc [catch {db eval [lindex $v 1]} msg] ;# True error occurs
+ set rc [catch {db eval [lindex $v 2]} msg] ;# True error occurs
set nac [sqlite3_get_autocommit $::DB] ;# New Auto-Commit
if {$rc != 0 && $nac && !$ac} {
# Before [db eval] the auto-commit flag was clear. Now it
- # is set. Since an error occured we assume this was not a
- # commit - therefore a rollback occured. Check that the
+ # is set. Since an error occurred we assume this was not a
+ # commit - therefore a rollback occurred. Check that the
# rollback-hook was invoked.
- do_test malloc3-rollback_hook.$iterid {
+ do_test malloc3-rollback_hook_count.$iterid {
set ::rollback_hook_count
} {1}
}
@@ -582,8 +609,9 @@ proc run_test {arglist iRepeat {pcstart 0} {iFailStart 1}} {
# calls should be equal to the number of benign failures.
# Otherwise a malloc() failed and the error was not reported.
#
- if {$nFail!=$nBenign} {
- error "Unreported malloc() failure"
+ set expr {$nFail!=$nBenign}
+ if {[expr $expr]} {
+ error "Unreported malloc() failure, test \"$testid\", $expr"
}
if {$ac && !$nac} {
@@ -595,24 +623,23 @@ proc run_test {arglist iRepeat {pcstart 0} {iFailStart 1}} {
incr pc
set iFail 1
- integrity_check "malloc3-(integrity).$iterid"
+ integrity_check $testid
} elseif {[regexp {.*out of memory} $msg] || [db errorcode] == 3082} {
# Out of memory error, as expected.
#
- integrity_check "malloc3-(integrity).$iterid"
+ integrity_check $testid
incr iFail
if {$nac && !$ac} {
-
- if {![lindex $v 0] && [db errorcode] != 3082} {
- # error "Statement \"[lindex $v 1]\" caused a rollback"
+ if {![lindex $v 1] && [db errorcode] != 3082} {
+ # error "Statement \"[lindex $v 2]\" caused a rollback"
}
for {set i $begin_pc} {$i < $pc} {incr i} {
- set k2 [lindex $arglist [expr 2 * $i]]
- set v2 [lindex $arglist [expr 2 * $i + 1]]
+ set k2 [lindex $arglist [expr {2 * $i}]]
+ set v2 [lindex $arglist [expr {2 * $i + 1}]]
set catchupsql ""
switch -- $k2 {
- -sql {set catchupsql [lindex $v2 1]}
+ -sql {set catchupsql [lindex $v2 2]}
-prep {set catchupsql $v2}
}
db eval $catchupsql
@@ -622,7 +649,8 @@ proc run_test {arglist iRepeat {pcstart 0} {iFailStart 1}} {
error $msg
}
- while {[lindex $arglist [expr 2 * ($pc -1)]] == "-test"} {
+ # back up to the previous "-test" block.
+ while {[lindex $arglist [expr {2 * ($pc - 1)}]] == "-test"} {
incr pc -1
}
}
@@ -642,7 +670,7 @@ proc run_test {arglist iRepeat {pcstart 0} {iFailStart 1}} {
}
}
-# Turn of the Tcl interface's prepared statement caching facility. Then
+# Turn off the Tcl interface's prepared statement caching facility. Then
# run the tests with "persistent" malloc failures.
sqlite3_extended_result_codes db 1
db cache size 0
@@ -650,7 +678,7 @@ run_test $::run_test_script 1
# Close and reopen the db.
db close
-file delete -force test.db test.db-journal test2.db test2.db-journal
+forcedelete test.db test.db-journal test2.db test2.db-journal
sqlite3 db test.db
sqlite3_extended_result_codes db 1
set ::DB [sqlite3_connection_pointer db]
diff --git a/lang/sql/sqlite/test/malloc5.test b/lang/sql/sqlite/test/malloc5.test
index 73885b22..6abedf79 100644
--- a/lang/sql/sqlite/test/malloc5.test
+++ b/lang/sql/sqlite/test/malloc5.test
@@ -205,6 +205,7 @@ do_test malloc5-4.1 {
execsql "INSERT INTO abc VALUES($i, $i, '[string repeat X 100]');"
}
execsql {COMMIT;}
+ db cache flush
sqlite3_release_memory
sqlite3_memory_highwater 1
execsql {SELECT * FROM abc}
@@ -213,13 +214,14 @@ do_test malloc5-4.1 {
expr $nMaxBytes > 1000000
} {1}
do_test malloc5-4.2 {
+ db cache flush
sqlite3_release_memory
sqlite3_soft_heap_limit 100000
sqlite3_memory_highwater 1
execsql {SELECT * FROM abc}
set nMaxBytes [sqlite3_memory_highwater 1]
puts -nonewline " (Highwater mark: $nMaxBytes) "
- expr $nMaxBytes <= 100000
+ expr $nMaxBytes <= 110000
} {1}
do_test malloc5-4.3 {
# Check that the content of table abc is at least roughly as expected.
@@ -275,7 +277,7 @@ proc nPage {db} {
set stats(page)
}
db close
-file delete -force test.db test.db-journal test2.db test2.db-journal
+forcedelete test.db test.db-journal test2.db test2.db-journal
# This block of test-cases (malloc5-6.1.*) prepares two database files
# for the subsequent tests.
@@ -304,7 +306,7 @@ do_test malloc5-6.1.1 {
SELECT randstr(50,50), randstr(75,75), randstr(100,100) FROM abc;
COMMIT;
}
- copy_file test.db test2.db
+ forcecopy test.db test2.db
sqlite3 db2 test2.db
list \
[expr ([file size test.db]/1024)>20] [expr ([file size test2.db]/1024)>20]
@@ -352,7 +354,7 @@ do_test malloc5-6.3.1 {
do_test malloc5-6.3.2 {
# Try to release 7700 bytes. This should release all the
# non-dirty pages held by db2.
- sqlite3_release_memory [expr 7*1100]
+ sqlite3_release_memory [expr 7*1132]
list [nPage db] [nPage db2]
} {10 3}
do_test malloc5-6.3.3 {
@@ -366,7 +368,7 @@ do_test malloc5-6.3.4 {
# the rest of the db cache. But the db2 cache remains intact, because
# SQLite tries to avoid calling sync().
if {$::tcl_platform(wordSize)==8} {
- sqlite3_release_memory 10177
+ sqlite3_release_memory 10500
} else {
sqlite3_release_memory 9900
}
diff --git a/lang/sql/sqlite/test/mallocA.test b/lang/sql/sqlite/test/mallocA.test
index 08f69302..61e88a61 100644
--- a/lang/sql/sqlite/test/mallocA.test
+++ b/lang/sql/sqlite/test/mallocA.test
@@ -15,6 +15,7 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
source $testdir/malloc_common.tcl
+set testprefix mallocA
# Only run these tests if memory debugging is turned on.
#
@@ -27,7 +28,7 @@ if {!$MEMDEBUG} {
# Construct a test database
#
-file delete -force test.db.bu
+forcedelete test.db.bu
db eval {
CREATE TABLE t1(a COLLATE NOCASE,b,c);
INSERT INTO t1 VALUES(1,2,3);
@@ -38,8 +39,7 @@ db eval {
CREATE TABLE t2(x,y,z);
}
db close
-file copy test.db test.db.bu
-
+copy_file test.db test.db.bu
do_malloc_test mallocA-1 -testdb test.db.bu -sqlbody {
ANALYZE
@@ -53,6 +53,7 @@ do_malloc_test mallocA-1.2 -testdb test.db.bu -sqlbody {
do_malloc_test mallocA-1.3 -testdb test.db.bu -sqlbody {
ANALYZE main.t1
}
+
ifcapable reindex {
do_malloc_test mallocA-2 -testdb test.db.bu -sqlbody {
REINDEX;
@@ -68,11 +69,58 @@ ifcapable reindex {
}
}
+reset_db
+sqlite3_db_config_lookaside db 0 0 0
+do_execsql_test 6-prep {
+ CREATE TABLE t1(a, b);
+ CREATE INDEX i1 ON t1(a, b);
+ INSERT INTO t1 VALUES('abc', 'w'); -- rowid=1
+ INSERT INTO t1 VALUES('abc', 'x'); -- rowid=2
+ INSERT INTO t1 VALUES('abc', 'y'); -- rowid=3
+ INSERT INTO t1 VALUES('abc', 'z'); -- rowid=4
+
+ INSERT INTO t1 VALUES('def', 'w'); -- rowid=5
+ INSERT INTO t1 VALUES('def', 'x'); -- rowid=6
+ INSERT INTO t1 VALUES('def', 'y'); -- rowid=7
+ INSERT INTO t1 VALUES('def', 'z'); -- rowid=8
+
+ ANALYZE;
+}
+
+do_faultsim_test 6.1 -faults oom* -body {
+ execsql { SELECT rowid FROM t1 WHERE a='abc' AND b='x' }
+} -test {
+ faultsim_test_result [list 0 2]
+}
+do_faultsim_test 6.2 -faults oom* -body {
+ execsql { SELECT rowid FROM t1 WHERE a='abc' AND b<'y' }
+} -test {
+ faultsim_test_result [list 0 {1 2}]
+}
+ifcapable stat3 {
+ do_test 6.3-prep {
+ execsql {
+ PRAGMA writable_schema = 1;
+ CREATE TABLE sqlite_stat4 AS
+ SELECT tbl, idx, neq, nlt, ndlt, sqlite_record(sample) AS sample
+ FROM sqlite_stat3;
+ }
+ } {}
+ do_faultsim_test 6.3 -faults oom* -body {
+ execsql {
+ ANALYZE sqlite_master;
+ SELECT rowid FROM t1 WHERE a='abc' AND b<'y';
+ }
+ } -test {
+ faultsim_test_result [list 0 {1 2}]
+ }
+}
+
# Ensure that no file descriptors were leaked.
do_test malloc-99.X {
catch {db close}
set sqlite_open_file_count
} {0}
-file delete -force test.db.bu
+forcedelete test.db.bu
finish_test
diff --git a/lang/sql/sqlite/test/mallocG.test b/lang/sql/sqlite/test/mallocG.test
index eab533b5..4f2395db 100644
--- a/lang/sql/sqlite/test/mallocG.test
+++ b/lang/sql/sqlite/test/mallocG.test
@@ -53,6 +53,11 @@ do_malloc_test mallocG-3 -sqlprep {
AND x BETWEEN 'i' AND 'm'
}
+ifcapable !utf16 {
+ finish_test
+ return
+}
+
proc utf16 {utf8} {
set utf16 [encoding convertto unicode $utf8]
append utf16 "\x00\x00"
diff --git a/lang/sql/sqlite/test/malloc_common.tcl b/lang/sql/sqlite/test/malloc_common.tcl
index e7f61564..16089705 100644
--- a/lang/sql/sqlite/test/malloc_common.tcl
+++ b/lang/sql/sqlite/test/malloc_common.tcl
@@ -93,6 +93,14 @@ set FAULTSIM(cantopen-persistent) [list \
-injectuninstall cantopen_injectuninstall \
]
+set FAULTSIM(interrupt) [list \
+ -injectinstall interrupt_injectinstall \
+ -injectstart interrupt_injectstart \
+ -injectstop interrupt_injectstop \
+ -injecterrlist {{1 interrupted} {1 interrupt}} \
+ -injectuninstall interrupt_injectuninstall \
+]
+
#--------------------------------------------------------------------------
@@ -113,7 +121,9 @@ set FAULTSIM(cantopen-persistent) [list \
proc do_faultsim_test {name args} {
global FAULTSIM
- set DEFAULT(-faults) [array names FAULTSIM]
+ foreach n [array names FAULTSIM] {
+ if {$n != "interrupt"} {lappend DEFAULT(-faults) $n}
+ }
set DEFAULT(-prep) ""
set DEFAULT(-body) ""
set DEFAULT(-test) ""
@@ -255,6 +265,22 @@ proc cantopen_injectstop {} {
shmfault cantopen
}
+# The following procs are used as [do_one_faultsim_test] callbacks
+# when injecting SQLITE_INTERRUPT error faults into test cases.
+#
+proc interrupt_injectinstall {} {
+}
+proc interrupt_injectuninstall {} {
+}
+proc interrupt_injectstart {iFail} {
+ set ::sqlite_interrupt_count $iFail
+}
+proc interrupt_injectstop {} {
+ set res [expr $::sqlite_interrupt_count<=0]
+ set ::sqlite_interrupt_count 0
+ set res
+}
+
# This command is not called directly. It is used by the
# [faultsim_test_result] command created by [do_faultsim_test] and used
# by -test scripts.
@@ -264,7 +290,7 @@ proc faultsim_test_result_int {args} {
set t [list $testrc $testresult]
set r $args
if { ($testnfail==0 && $t != [lindex $r 0]) || [lsearch $r $t]<0 } {
- error "nfail=$testnfail rc=$testrc result=$testresult"
+ error "nfail=$testnfail rc=$testrc result=$testresult list=$r"
}
}
@@ -408,7 +434,7 @@ proc do_malloc_test {tn args} {
set zRepeat "transient"
if {$::iRepeat} {set zRepeat "persistent"}
restore_prng_state
- foreach file [glob -nocomplain test.db-mj*] {file delete -force $file}
+ foreach file [glob -nocomplain test.db-mj*] {forcedelete $file}
do_test ${tn}.${zRepeat}.${::n} {
@@ -425,7 +451,7 @@ proc do_malloc_test {tn args} {
forcedelete test2.db-journal
forcedelete test2.db-wal
if {[info exists ::mallocopts(-testdb)]} {
- file copy $::mallocopts(-testdb) test.db
+ copy_file $::mallocopts(-testdb) test.db
}
catch { sqlite3 db test.db }
if {[info commands db] ne ""} {
diff --git a/lang/sql/sqlite/test/manydb.test b/lang/sql/sqlite/test/manydb.test
index aa47be09..ebdf36f4 100644
--- a/lang/sql/sqlite/test/manydb.test
+++ b/lang/sql/sqlite/test/manydb.test
@@ -18,7 +18,7 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
-set N 100
+set N 50
# if we're using proxy locks, we use 5 filedescriptors for a db
# that is open and in the middle of writing changes, normally
# sqlite uses 3 (proxy locking adds the conch and the local lock)
@@ -44,7 +44,7 @@ foreach fd $filehandles {
close $fd
}
catch {
- file delete -force testfile.1
+ forcedelete testfile.1
}
set N [expr $i / $num_fd_per_openwrite_db]
@@ -93,7 +93,7 @@ for {set i 0} {$i<$N} {incr i} {
for {set i 0} {$i<$N} {incr i} {
do_test manydb-3.$i {
db$i close
- file delete -force $dbname($i)
+ forcedelete $dbname($i)
} {}
}
diff --git a/lang/sql/sqlite/test/memdb.test b/lang/sql/sqlite/test/memdb.test
index 1da3d7c5..a2efc036 100644
--- a/lang/sql/sqlite/test/memdb.test
+++ b/lang/sql/sqlite/test/memdb.test
@@ -240,7 +240,7 @@ foreach {i conf1 conf2 cmd t0 t1 t2} {
if {$i>1} break
}
- if {$t0} {set t1 {column a is not unique}}
+ if {$t0} {set t1 {UNIQUE constraint failed: t1.a}}
do_test memdb-5.$i {
if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"}
if {$conf2!=""} {set conf2 "ON CONFLICT $conf2"}
@@ -365,7 +365,7 @@ do_test memdb-6.15 {
ifcapable subquery&&vtab {
do_test memdb-7.1 {
- register_wholenumber_module db
+ load_static_extension db wholenumber
execsql {
CREATE TABLE t6(x);
CREATE VIRTUAL TABLE nums USING wholenumber;
diff --git a/lang/sql/sqlite/test/memsubsys1.test b/lang/sql/sqlite/test/memsubsys1.test
index 3bb2cc71..76b79d00 100644
--- a/lang/sql/sqlite/test/memsubsys1.test
+++ b/lang/sql/sqlite/test/memsubsys1.test
@@ -32,7 +32,7 @@ if {[permutation] == "memsubsys1"} {
#
proc build_test_db {testname pragmas} {
catch {db close}
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db test.db
sqlite3_db_config_lookaside db 0 0 0
db eval $pragmas
@@ -68,7 +68,7 @@ proc reset_highwater_marks {} {
sqlite3_status SQLITE_STATUS_PARSER_STACK 1
}
-set xtra_size 256
+set xtra_size 290
# Test 1: Both PAGECACHE and SCRATCH are shut down.
#
@@ -94,12 +94,14 @@ sqlite3_shutdown
sqlite3_config_pagecache [expr 1024+$xtra_size] 20
sqlite3_initialize
reset_highwater_marks
-build_test_db memsubsys1-2 {PRAGMA page_size=1024}
+build_test_db memsubsys1-2 {PRAGMA page_size=1024; PRAGMA mmap_size=0}
#show_memstats
set MEMORY_MANAGEMENT $sqlite_options(memorymanage)
-do_test memsubsys1-2.3 {
- set pg_ovfl [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_OVERFLOW 0] 2]
-} [expr ($TEMP_STORE>1 || $MEMORY_MANAGEMENT==0)*1024]
+ifcapable !malloc_usable_size {
+ do_test memsubsys1-2.3 {
+ set pg_ovfl [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_OVERFLOW 0] 2]
+ } [expr ($TEMP_STORE>1 || $MEMORY_MANAGEMENT==0)*1024]
+}
do_test memsubsys1-2.4 {
set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2]
} 20
diff --git a/lang/sql/sqlite/test/memsubsys2.test b/lang/sql/sqlite/test/memsubsys2.test
index ec554775..a40f4e4f 100644
--- a/lang/sql/sqlite/test/memsubsys2.test
+++ b/lang/sql/sqlite/test/memsubsys2.test
@@ -24,7 +24,7 @@ sqlite3_reset_auto_extension
#
proc build_test_db {testname pragmas} {
catch {db close}
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db test.db
db eval $pragmas
db eval {
diff --git a/lang/sql/sqlite/test/minmax.test b/lang/sql/sqlite/test/minmax.test
index 59902450..fb9bbb38 100644
--- a/lang/sql/sqlite/test/minmax.test
+++ b/lang/sql/sqlite/test/minmax.test
@@ -17,6 +17,7 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
+set ::testprefix minmax
do_test minmax-1.0 {
execsql {
@@ -299,7 +300,7 @@ ifcapable {compound && subquery} {
SELECT max(rowid) FROM t4 UNION SELECT max(rowid) FROM t5
)
}
- } {1}
+ } {{}}
do_test minmax-9.2 {
execsql {
SELECT max(rowid) FROM (
@@ -536,7 +537,96 @@ do_test minmax-12.17 {
}
} {5}
+#-------------------------------------------------------------------------
+reset_db
+
+proc do_test_13 {op name sql1 sql2 res} {
+ set ::sqlite_search_count 0
+ uplevel [list do_execsql_test $name.1 $sql1 $res]
+ set a $::sqlite_search_count
+
+ set ::sqlite_search_count 0
+ uplevel [list do_execsql_test $name.2 $sql2 $res]
+ set b $::sqlite_search_count
+
+ uplevel [list do_test $name.3 [list expr "$a $op $b"] 1]
+}
+
+# Run a test named $name. Check that SQL statements $sql1 and $sql2 both
+# return the same result, but that $sql2 increments the $sqlite_search_count
+# variable more often (indicating that it is visiting more rows to determine
+# the result).
+#
+proc do_test_13_opt {name sql1 sql2 res} {
+ uplevel [list do_test_13 < $name $sql1 $sql2 $res]
+}
+
+# Like [do_test_13_noopt], except this time check that the $sqlite_search_count
+# variable is incremented the same number of times by both SQL statements.
+#
+proc do_test_13_noopt {name sql1 sql2 res} {
+ uplevel [list do_test_13 == $name $sql1 $sql2 $res]
+}
+
+do_execsql_test 13.1 {
+ CREATE TABLE t1(a, b, c);
+ INSERT INTO t1 VALUES('a', 1, 1);
+ INSERT INTO t1 VALUES('b', 6, 6);
+ INSERT INTO t1 VALUES('c', 5, 5);
+ INSERT INTO t1 VALUES('a', 4, 4);
+ INSERT INTO t1 VALUES('a', 5, 5);
+ INSERT INTO t1 VALUES('c', 6, 6);
+ INSERT INTO t1 VALUES('b', 4, 4);
+ INSERT INTO t1 VALUES('c', 7, 7);
+ INSERT INTO t1 VALUES('b', 2, 2);
+ INSERT INTO t1 VALUES('b', 3, 3);
+ INSERT INTO t1 VALUES('a', 3, 3);
+ INSERT INTO t1 VALUES('b', 5, 5);
+ INSERT INTO t1 VALUES('c', 4, 4);
+ INSERT INTO t1 VALUES('c', 3, 3);
+ INSERT INTO t1 VALUES('a', 2, 2);
+ SELECT * FROM t1 ORDER BY a, b, c;
+} {a 1 1 a 2 2 a 3 3 a 4 4 a 5 5
+ b 2 2 b 3 3 b 4 4 b 5 5 b 6 6
+ c 3 3 c 4 4 c 5 5 c 6 6 c 7 7
+}
+do_execsql_test 13.2 { CREATE INDEX i1 ON t1(a, b, c) }
+
+do_test_13_opt 13.3 {
+ SELECT min(b) FROM t1 WHERE a='b'
+} {
+ SELECT min(c) FROM t1 WHERE a='b'
+} {2}
+
+do_test_13_opt 13.4 {
+ SELECT a, min(b) FROM t1 WHERE a='b'
+} {
+ SELECT a, min(c) FROM t1 WHERE a='b'
+} {b 2}
+
+do_test_13_opt 13.4 {
+ SELECT a||c, max(b)+4 FROM t1 WHERE a='c'
+} {
+ SELECT a||c, max(c)+4 FROM t1 WHERE a='c'
+} {c7 11}
+
+do_test_13_noopt 13.5 {
+ SELECT a||c, max(b+1) FROM t1 WHERE a='c'
+} {
+ SELECT a||c, max(c+1) FROM t1 WHERE a='c'
+} {c7 8}
+
+do_test_13_noopt 13.6 {
+ SELECT count(b) FROM t1 WHERE a='c'
+} {
+ SELECT count(c) FROM t1 WHERE a='c'
+} {5}
+do_test_13_noopt 13.7 {
+ SELECT min(b), count(b) FROM t1 WHERE a='a';
+} {
+ SELECT min(c), count(c) FROM t1 WHERE a='a';
+} {1 5}
finish_test
diff --git a/lang/sql/sqlite/test/minmax2.test b/lang/sql/sqlite/test/minmax2.test
index 2f504d49..da8fec30 100644
--- a/lang/sql/sqlite/test/minmax2.test
+++ b/lang/sql/sqlite/test/minmax2.test
@@ -289,7 +289,7 @@ ifcapable {compound && subquery} {
SELECT max(rowid) FROM t4 UNION SELECT max(rowid) FROM t5
)
}
- } {1}
+ } {{}}
do_test minmax2-9.2 {
execsql {
SELECT max(rowid) FROM (
diff --git a/lang/sql/sqlite/test/minmax4.test b/lang/sql/sqlite/test/minmax4.test
new file mode 100644
index 00000000..0d8305b5
--- /dev/null
+++ b/lang/sql/sqlite/test/minmax4.test
@@ -0,0 +1,150 @@
+# 2012 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.
+#
+#***********************************************************************
+#
+# Test for queries of the form:
+#
+# SELECT p, max(q) FROM t1;
+#
+# Demonstration that the value returned for p is on the same row as
+# the maximum q.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+ifcapable !compound {
+ finish_test
+ return
+}
+
+do_test minmax4-1.1 {
+ db eval {
+ CREATE TABLE t1(p,q);
+ SELECT p, max(q) FROM t1;
+ }
+} {{} {}}
+do_test minmax4-1.2 {
+ db eval {
+ SELECT p, min(q) FROM t1;
+ }
+} {{} {}}
+do_test minmax4-1.3 {
+ db eval {
+ INSERT INTO t1 VALUES(1,2);
+ SELECT p, max(q) FROM t1;
+ }
+} {1 2}
+do_test minmax4-1.4 {
+ db eval {
+ SELECT p, min(q) FROM t1;
+ }
+} {1 2}
+do_test minmax4-1.5 {
+ db eval {
+ INSERT INTO t1 VALUES(3,4);
+ SELECT p, max(q) FROM t1;
+ }
+} {3 4}
+do_test minmax4-1.6 {
+ db eval {
+ SELECT p, min(q) FROM t1;
+ }
+} {1 2}
+do_test minmax4-1.7 {
+ db eval {
+ INSERT INTO t1 VALUES(5,0);
+ SELECT p, max(q) FROM t1;
+ }
+} {3 4}
+do_test minmax4-1.8 {
+ db eval {
+ SELECT p, min(q) FROM t1;
+ }
+} {5 0}
+do_test minmax4-1.9 {
+ db eval {
+ INSERT INTO t1 VALUES(6,1);
+ SELECT p, max(q) FROM t1;
+ }
+} {3 4}
+do_test minmax4-1.10 {
+ db eval {
+ SELECT p, min(q) FROM t1;
+ }
+} {5 0}
+do_test minmax4-1.11 {
+ db eval {
+ INSERT INTO t1 VALUES(7,NULL);
+ SELECT p, max(q) FROM t1;
+ }
+} {3 4}
+do_test minmax4-1.12 {
+ db eval {
+ SELECT p, min(q) FROM t1;
+ }
+} {5 0}
+do_test minmax4-1.13 {
+ db eval {
+ DELETE FROM t1 WHERE q IS NOT NULL;
+ SELECT p, max(q) FROM t1;
+ }
+} {7 {}}
+do_test minmax4-1.14 {
+ db eval {
+ SELECT p, min(q) FROM t1;
+ }
+} {7 {}}
+
+do_test minmax4-2.1 {
+ db eval {
+ CREATE TABLE t2(a,b,c);
+ INSERT INTO t2 VALUES
+ (1,null,2),
+ (1,2,3),
+ (1,1,4),
+ (2,3,5);
+ SELECT a, max(b), c FROM t2 GROUP BY a ORDER BY a;
+ }
+} {1 2 3 2 3 5}
+do_test minmax4-2.2 {
+ db eval {
+ SELECT a, min(b), c FROM t2 GROUP BY a ORDER BY a;
+ }
+} {1 1 4 2 3 5}
+do_test minmax4-2.3 {
+ db eval {
+ SELECT a, min(b), avg(b), count(b), c FROM t2 GROUP BY a ORDER BY a DESC;
+ }
+} {2 3 3.0 1 5 1 1 1.5 2 4}
+do_test minmax4-2.4 {
+ db eval {
+ SELECT a, min(b), max(b), c FROM t2 GROUP BY a ORDER BY a;
+ }
+} {1 1 2 3 2 3 3 5}
+do_test minmax4-2.5 {
+ db eval {
+ SELECT a, max(b), min(b), c FROM t2 GROUP BY a ORDER BY a;
+ }
+} {1 2 1 4 2 3 3 5}
+do_test minmax4-2.6 {
+ db eval {
+ SELECT a, max(b), b, max(c), c FROM t2 GROUP BY a ORDER BY a;
+ }
+} {1 2 1 4 4 2 3 3 5 5}
+do_test minmax4-2.7 {
+ db eval {
+ SELECT a, min(b), b, min(c), c FROM t2 GROUP BY a ORDER BY a;
+ }
+} {1 1 {} 2 2 2 3 3 5 5}
+
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/misc1.test b/lang/sql/sqlite/test/misc1.test
index a78e4884..f886f896 100644
--- a/lang/sql/sqlite/test/misc1.test
+++ b/lang/sql/sqlite/test/misc1.test
@@ -235,7 +235,7 @@ do_test misc1-7.4 {
catchsql {
INSERT INTO t5 VALUES(1,2,4);
}
-} {1 {columns a, b are not unique}}
+} {1 {UNIQUE constraint failed: t5.a, t5.b}}
do_test misc1-7.5 {
catchsql {
INSERT INTO t5 VALUES(0,2,4);
@@ -472,6 +472,11 @@ ifcapable subquery {
} {1 2 3 4 5 6 7 8 9 10 11}
}
+#
+# The following tests can only work if the current SQLite VFS has the concept
+# of a current directory.
+#
+ifcapable curdir {
# Make sure a database connection still works after changing the
# working directory.
#
@@ -491,10 +496,11 @@ do_test misc1-14.2b {
} {1}
do_test misc1-14.3 {
cd ..
- file delete -force tempdir
+ forcedelete tempdir
execsql {COMMIT}
file exists ./test.db-journal
} {0}
+}
# A failed create table should not leave the table in the internal
# data structures. Ticket #238.
@@ -586,4 +592,17 @@ do_test misc1-18.1 {
expr {$n>=100}
} {1}
+# 2014-01-10: In a CREATE TABLE AS, if one or more of the column names
+# are an empty string, that is still OK.
+#
+do_execsql_test misc1-19.1 {
+ CREATE TABLE t19 AS SELECT 1, 2 AS '', 3;
+ SELECT * FROM t19;
+} {1 2 3}
+do_execsql_test misc1-19.2 {
+ CREATE TABLE t19b AS SELECT 4 AS '', 5 AS '', 6 AS '';
+ SELECT * FROM t19b;
+} {4 5 6}
+
+
finish_test
diff --git a/lang/sql/sqlite/test/misc2.test b/lang/sql/sqlite/test/misc2.test
index f6fc3833..bb544c5f 100644
--- a/lang/sql/sqlite/test/misc2.test
+++ b/lang/sql/sqlite/test/misc2.test
@@ -165,7 +165,7 @@ do_test misc2-6.1 {
ifcapable tclvar {
do_test misc2-7.1 {
db close
- file delete -force test.db
+ forcedelete test.db
sqlite3 db test.db
execsql {
CREATE TABLE t1(x);
@@ -265,7 +265,7 @@ ifcapable tclvar {
#
do_test misc2-7.11 {
db close
- file delete -force test.db
+ forcedelete test.db
sqlite3 db test.db
execsql {
CREATE TABLE t1(x);
@@ -361,7 +361,7 @@ ifcapable tclvar {
}
db close
-file delete -force test.db
+forcedelete test.db
sqlite3 db test.db
catchsql { pragma recursive_triggers = off }
diff --git a/lang/sql/sqlite/test/misc3.test b/lang/sql/sqlite/test/misc3.test
index 94a43c43..bc1f0ff9 100644
--- a/lang/sql/sqlite/test/misc3.test
+++ b/lang/sql/sqlite/test/misc3.test
@@ -270,7 +270,11 @@ ifcapable {explain} {
CREATE UNIQUE INDEX ex1i1 ON ex1(a);
EXPLAIN REINDEX;
}]
- regexp { IsUnique \d+ \d+ \d+ \d+ } $x
+ ifcapable mergesort {
+ regexp { SorterCompare \d+ \d+ \d+ } $x
+ } else {
+ regexp { IsUnique \d+ \d+ \d+ \d+ } $x
+ }
} {1}
if {[regexp {16} [db one {PRAGMA encoding}]]} {
do_test misc3-6.11-utf16 {
@@ -279,7 +283,7 @@ ifcapable {explain} {
}]
set y [regexp { 123456789012 } $x]
lappend y [regexp { 4.5678 } $x]
- lappend y [regexp {,-BINARY} $x]
+ lappend y [regexp {,-B} $x]
} {1 1 1}
} else {
do_test misc3-6.11-utf8 {
@@ -289,7 +293,7 @@ ifcapable {explain} {
set y [regexp { 123456789012 } $x]
lappend y [regexp { 4.5678 } $x]
lappend y [regexp { hello } $x]
- lappend y [regexp {,-BINARY} $x]
+ lappend y [regexp {,-B} $x]
} {1 1 1 1}
}
}
diff --git a/lang/sql/sqlite/test/misc5.test b/lang/sql/sqlite/test/misc5.test
index 34b2284b..14ba44ea 100644
--- a/lang/sql/sqlite/test/misc5.test
+++ b/lang/sql/sqlite/test/misc5.test
@@ -505,7 +505,7 @@ ifcapable subquery {
)
ORDER BY LOWER(artist) ASC;
}
- } {one}
+ } {two}
}
# Ticket #1370. Do not overwrite small files (less than 1024 bytes)
@@ -514,7 +514,7 @@ ifcapable subquery {
if {[permutation] == ""} {
do_test misc5-4.1 {
db close
- file delete -force test.db
+ forcedelete test.db
set fd [open test.db w]
puts $fd "This is not really a database"
close $fd
@@ -544,7 +544,7 @@ do_test misc5-5.4 {
# a UNION ALL query causes an error, not a crash.
#
db close
-file delete -force test.db
+forcedelete test.db
sqlite3 db test.db
ifcapable subquery&&compound {
do_test misc5-6.1 {
diff --git a/lang/sql/sqlite/test/misc7.test b/lang/sql/sqlite/test/misc7.test
index 7d2ba6e8..8fd5fe75 100644
--- a/lang/sql/sqlite/test/misc7.test
+++ b/lang/sql/sqlite/test/misc7.test
@@ -15,9 +15,11 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
-do_test misc7-1-misuse {
- c_misuse_test
-} {}
+if {[clang_sanitize_address]==0} {
+ do_test misc7-1-misuse {
+ c_misuse_test
+ } {}
+}
do_test misc7-2 {
c_realloc_test
@@ -30,7 +32,7 @@ do_test misc7-3 {
# Try to open a directory:
#
do_test misc7-4 {
- file delete mydir
+ delete_file mydir
file mkdir mydir
set rc [catch {
sqlite3 db2 ./mydir
@@ -41,7 +43,7 @@ do_test misc7-4 {
# Try to open a file with a directory where its journal file should be.
#
do_test misc7-5 {
- file delete mydir
+ delete_file mydir
file mkdir mydir-journal
sqlite3 db2 ./mydir
catchsql {
@@ -151,9 +153,15 @@ db2 close
# Test that nothing goes horribly wrong when attaching a database
# after the omit_readlock pragma has been exercised.
#
+# Note: The PRAGMA omit_readlock was an early hack to disable the
+# fcntl() calls for read-only databases so that read-only databases could
+# be read on broken NFS systems. That pragma has now been removed.
+# (Use the unix-none VFS as a replacement, if needed.) But these tests
+# do not really depend on omit_readlock, so we left them in place.
+#
do_test misc7-7.1 {
- file delete -force test2.db
- file delete -force test2.db-journal
+ forcedelete test2.db
+ forcedelete test2.db-journal
execsql {
PRAGMA omit_readlock = 1;
ATTACH 'test2.db' AS aux;
@@ -254,8 +262,8 @@ ifcapable vtab {
}
db close
-file delete -force test.db
-file delete -force test.db-journal
+forcedelete test.db
+forcedelete test.db-journal
sqlite3 db test.db
ifcapable explain {
@@ -263,23 +271,23 @@ ifcapable explain {
CREATE TABLE abc(a PRIMARY KEY, b, c);
EXPLAIN QUERY PLAN SELECT * FROM abc AS t2 WHERE rowid = 1;
} {
- 0 0 0 {SEARCH TABLE abc AS t2 USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)}
+ 0 0 0 {SEARCH TABLE abc AS t2 USING INTEGER PRIMARY KEY (rowid=?)}
}
do_execsql_test misc7-14.2 {
EXPLAIN QUERY PLAN SELECT * FROM abc AS t2 WHERE a = 1;
} {0 0 0
- {SEARCH TABLE abc AS t2 USING INDEX sqlite_autoindex_abc_1 (a=?) (~1 rows)}
+ {SEARCH TABLE abc AS t2 USING INDEX sqlite_autoindex_abc_1 (a=?)}
}
do_execsql_test misc7-14.3 {
EXPLAIN QUERY PLAN SELECT * FROM abc AS t2 ORDER BY a;
} {0 0 0
- {SCAN TABLE abc AS t2 USING INDEX sqlite_autoindex_abc_1 (~1000000 rows)}
+ {SCAN TABLE abc AS t2 USING INDEX sqlite_autoindex_abc_1}
}
}
db close
-file delete -force test.db
-file delete -force test.db-journal
+forcedelete test.db
+forcedelete test.db-journal
sqlite3 db test.db
#--------------------------------------------------------------------
@@ -323,8 +331,8 @@ do_test misc7-15.2 {
} {}
db close
-file delete -force test.db
-file delete -force test.db-journal
+forcedelete test.db
+forcedelete test.db-journal
sqlite3 db test.db
do_ioerr_test misc7-16 -sqlprep {
@@ -349,7 +357,7 @@ do_ioerr_test misc7-16 -sqlprep {
COMMIT;
}} msg]
- if {!$rc || ($rc && [string first "columns" $msg]==0)} {
+ if {!$rc || ($rc && [string first "UNIQUE" $msg]==0)} {
set msg
} else {
error $msg
@@ -371,7 +379,7 @@ do_test misc7-16.X {
# These tests do not work on windows due to restrictions in the
# windows file system.
#
-if {$tcl_platform(platform)!="windows" && $tcl_platform(platform)!="os2"} {
+if {$tcl_platform(platform)!="windows"} {
# Some network filesystems (ex: AFP) do not support setting read-only
# permissions. Only run these tests if full unix permission setting
@@ -385,15 +393,15 @@ if {$tcl_platform(platform)!="windows" && $tcl_platform(platform)!="os2"} {
BEGIN;
DELETE FROM t3 WHERE (oid%3)==0;
}
- copy_file test.db bak.db
- copy_file test.db-journal bak.db-journal
+ forcecopy test.db bak.db
+ forcecopy test.db-journal bak.db-journal
execsql {
COMMIT;
}
db close
- copy_file bak.db test.db
- copy_file bak.db-journal test.db-journal
+ forcecopy bak.db test.db
+ forcecopy bak.db-journal test.db-journal
sqlite3 db test.db
catch {file attributes test.db-journal -permissions r--------}
@@ -477,13 +485,41 @@ do_test misc7-20.1 {
# Try to open a really long file name.
#
do_test misc7-21.1 {
- set zFile [file join [pwd] "[string repeat abcde 104].db"]
+ set zFile [file join [get_pwd] "[string repeat abcde 104].db"]
set rc [catch {sqlite3 db2 $zFile} msg]
list $rc $msg
} {1 {unable to open database file}}
+# Try to do hot-journal rollback with a read-only connection. The
+# error code should be SQLITE_READONLY_ROLLBACK.
+#
+do_test misc7-22.1 {
+ db close
+ forcedelete test.db copy.db-journal
+ sqlite3 db test.db
+ execsql {
+ CREATE TABLE t1(a, b);
+ INSERT INTO t1 VALUES(1, 2);
+ INSERT INTO t1 VALUES(3, 4);
+ }
+ db close
+ sqlite3 db test.db -readonly 1
+ catchsql {
+ INSERT INTO t1 VALUES(5, 6);
+ }
+} {1 {attempt to write a readonly database}}
+do_test misc7-22.2 { execsql { SELECT * FROM t1 } } {1 2 3 4}
+do_test misc7-22.3 {
+ set fd [open test.db-journal w]
+ puts $fd [string repeat abc 1000]
+ close $fd
+ catchsql { SELECT * FROM t1 }
+} {1 {attempt to write a readonly database}}
+do_test misc7-22.4 {
+ sqlite3_extended_errcode db
+} SQLITE_READONLY_ROLLBACK
db close
-file delete -force test.db
+forcedelete test.db
finish_test
diff --git a/lang/sql/sqlite/test/misuse.test b/lang/sql/sqlite/test/misuse.test
index 3734aa01..d5d836cb 100644
--- a/lang/sql/sqlite/test/misuse.test
+++ b/lang/sql/sqlite/test/misuse.test
@@ -39,8 +39,8 @@ proc catchsql2 {sql} {
#
do_test misuse-1.1 {
db close
- catch {file delete -force test2.db}
- catch {file delete -force test2.db-journal}
+ catch {forcedelete test2.db}
+ catch {forcedelete test2.db-journal}
sqlite3 db test2.db; set ::DB [sqlite3_connection_pointer db]
execsql {
CREATE TABLE t1(a,b);
@@ -171,37 +171,40 @@ do_test misuse-4.3 {
} msg]
lappend v $msg $r
} {0 {} SQLITE_BUSY}
-do_test misuse-4.4 {
+
+if {[clang_sanitize_address]==0} {
+ do_test misuse-4.4 {
# Flush the TCL statement cache here, otherwise the sqlite3_close() will
# fail because there are still un-finalized() VDBEs.
- db cache flush
- sqlite3_close $::DB
- catchsql2 {SELECT * FROM t1}
-} {1 {library routine called out of sequence}}
-do_test misuse-4.5 {
- catchsql {
- SELECT * FROM t1
- }
-} {1 {library routine called out of sequence}}
+ db cache flush
+ sqlite3_close $::DB
+ catchsql2 {SELECT * FROM t1}
+ } {1 {library routine called out of sequence}}
+ do_test misuse-4.5 {
+ catchsql {
+ SELECT * FROM t1
+ }
+ } {1 {library routine called out of sequence}}
-# Attempt to use a database after it has been closed.
-#
-do_test misuse-5.1 {
- db close
- sqlite3 db test2.db; set ::DB [sqlite3_connection_pointer db]
- execsql {
- SELECT * FROM t1
- }
-} {1 2}
-do_test misuse-5.2 {
- catchsql2 {SELECT * FROM t1}
-} {0 {a b 1 2}}
-do_test misuse-5.3 {
- db close
- set r [catch {
- sqlite3_prepare $::DB {SELECT * FROM t1} -1 TAIL
- } msg]
- lappend r $msg
-} {1 {(21) library routine called out of sequence}}
+ # Attempt to use a database after it has been closed.
+ #
+ do_test misuse-5.1 {
+ db close
+ sqlite3 db test2.db; set ::DB [sqlite3_connection_pointer db]
+ execsql {
+ SELECT * FROM t1
+ }
+ } {1 2}
+ do_test misuse-5.2 {
+ catchsql2 {SELECT * FROM t1}
+ } {0 {a b 1 2}}
+ do_test misuse-5.3 {
+ db close
+ set r [catch {
+ sqlite3_prepare $::DB {SELECT * FROM t1} -1 TAIL
+ } msg]
+ lappend r $msg
+ } {1 {(21) library routine called out of sequence}}
+}
finish_test
diff --git a/lang/sql/sqlite/test/mmap1.test b/lang/sql/sqlite/test/mmap1.test
new file mode 100644
index 00000000..ece3e020
--- /dev/null
+++ b/lang/sql/sqlite/test/mmap1.test
@@ -0,0 +1,331 @@
+# 2013 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.
+#
+#***********************************************************************
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+ifcapable !mmap {
+ finish_test
+ return
+}
+source $testdir/lock_common.tcl
+set testprefix mmap1
+
+proc nRead {db} {
+ set bt [btree_from_db $db]
+ db_enter $db
+ array set stats [btree_pager_stats $bt]
+ db_leave $db
+ # puts [array get stats]
+ return $stats(read)
+}
+
+proc register_rblob_code {dbname seed} {
+ return [subst -nocommands {
+ set ::rcnt $seed
+ proc rblob {n} {
+ set ::rcnt [expr (([set ::rcnt] << 3) + [set ::rcnt] + 456) & 0xFFFFFFFF]
+ set str [format %.8x [expr [set ::rcnt] ^ 0xbdf20da3]]
+ string range [string repeat [set str] [expr [set n]/4]] 1 [set n]
+ }
+ $dbname func rblob rblob
+ }]
+}
+
+# For cases 1.1 and 1.4, the number of pages read using xRead() is 4 on
+# unix and 9 on windows. The difference is that windows only ever maps
+# an integer number of OS pages (i.e. creates mappings that are a multiple
+# of 4KB in size). Whereas on unix any sized mapping may be created.
+#
+foreach {t mmap_size nRead c2init} {
+ 1.1 { PRAGMA mmap_size = 67108864 } /[49]/ {PRAGMA mmap_size = 0}
+ 1.2 { PRAGMA mmap_size = 53248 } 150 {PRAGMA mmap_size = 0}
+ 1.3 { PRAGMA mmap_size = 0 } 344 {PRAGMA mmap_size = 0}
+ 1.4 { PRAGMA mmap_size = 67108864 } /[49]/ {PRAGMA mmap_size = 67108864 }
+ 1.5 { PRAGMA mmap_size = 53248 } 150 {PRAGMA mmap_size = 67108864 }
+ 1.6 { PRAGMA mmap_size = 0 } 344 {PRAGMA mmap_size = 67108864 }
+} {
+
+ do_multiclient_test tn {
+ sql1 {PRAGMA cache_size=2000}
+ sql2 {PRAGMA cache_size=2000}
+
+ sql1 {PRAGMA page_size=1024}
+ sql1 $mmap_size
+ sql2 $c2init
+
+ code2 [register_rblob_code db2 0]
+
+ sql2 {
+ PRAGMA page_size=1024;
+ PRAGMA auto_vacuum = 1;
+ CREATE TABLE t1(a, b, UNIQUE(a, b));
+ INSERT INTO t1 VALUES(rblob(500), rblob(500));
+ INSERT INTO t1 SELECT rblob(500), rblob(500) FROM t1; -- 2
+ INSERT INTO t1 SELECT rblob(500), rblob(500) FROM t1; -- 4
+ INSERT INTO t1 SELECT rblob(500), rblob(500) FROM t1; -- 8
+ INSERT INTO t1 SELECT rblob(500), rblob(500) FROM t1; -- 16
+ INSERT INTO t1 SELECT rblob(500), rblob(500) FROM t1; -- 32
+ }
+ do_test $t.$tn.1 {
+ sql1 "SELECT count(*) FROM t1; PRAGMA integrity_check ; PRAGMA page_count"
+ } {32 ok 77}
+
+ # Have connection 2 shrink the file. Check connection 1 can still read it.
+ sql2 { DELETE FROM t1 WHERE rowid%2; }
+ do_test $t.$tn.2 {
+ sql1 "SELECT count(*) FROM t1; PRAGMA integrity_check ; PRAGMA page_count"
+ } {16 ok 42}
+
+ # Have connection 2 grow the file. Check connection 1 can still read it.
+ sql2 { INSERT INTO t1 SELECT rblob(500), rblob(500) FROM t1 }
+ do_test $t.$tn.3 {
+ sql1 "SELECT count(*) FROM t1; PRAGMA integrity_check ; PRAGMA page_count"
+ } {32 ok 79}
+
+ # Have connection 2 grow the file again. Check connection 1 is still ok.
+ sql2 { INSERT INTO t1 SELECT rblob(500), rblob(500) FROM t1 }
+ do_test $t.$tn.4 {
+ sql1 "SELECT count(*) FROM t1; PRAGMA integrity_check ; PRAGMA page_count"
+ } {64 ok 149}
+
+ # Check that the number of pages read by connection 1 indicates that the
+ # "PRAGMA mmap_size" command worked.
+ do_test $t.$tn.5 { nRead db } $nRead
+ }
+}
+
+set ::rcnt 0
+proc rblob {n} {
+ set ::rcnt [expr (($::rcnt << 3) + $::rcnt + 456) & 0xFFFFFFFF]
+ set str [format %.8x [expr $::rcnt ^ 0xbdf20da3]]
+ string range [string repeat $str [expr $n/4]] 1 $n
+}
+
+reset_db
+db func rblob rblob
+
+do_execsql_test 2.1 {
+ PRAGMA auto_vacuum = 1;
+ PRAGMA mmap_size = 67108864;
+ PRAGMA journal_mode = wal;
+ CREATE TABLE t1(a, b, UNIQUE(a, b));
+ INSERT INTO t1 VALUES(rblob(500), rblob(500));
+ INSERT INTO t1 SELECT rblob(500), rblob(500) FROM t1; -- 2
+ INSERT INTO t1 SELECT rblob(500), rblob(500) FROM t1; -- 4
+ INSERT INTO t1 SELECT rblob(500), rblob(500) FROM t1; -- 8
+ INSERT INTO t1 SELECT rblob(500), rblob(500) FROM t1; -- 16
+ INSERT INTO t1 SELECT rblob(500), rblob(500) FROM t1; -- 32
+ PRAGMA wal_checkpoint;
+} {67108864 wal 0 103 103}
+
+do_execsql_test 2.2 {
+ PRAGMA auto_vacuum;
+ SELECT count(*) FROM t1;
+} {1 32}
+
+if {[permutation] != "inmemory_journal"} {
+ do_test 2.3 {
+ sqlite3 db2 test.db
+ db2 func rblob rblob
+ db2 eval {
+ DELETE FROM t1 WHERE (rowid%4);
+ PRAGMA wal_checkpoint;
+ }
+ db2 eval {
+ INSERT INTO t1 SELECT rblob(500), rblob(500) FROM t1; -- 16
+ SELECT count(*) FROM t1;
+ }
+ } {16}
+
+ do_execsql_test 2.4 {
+ PRAGMA wal_checkpoint;
+ } {0 24 24}
+ db2 close
+}
+
+reset_db
+execsql { PRAGMA mmap_size = 67108864; }
+db func rblob rblob
+do_execsql_test 3.1 {
+ PRAGMA auto_vacuum = 1;
+
+ CREATE TABLE t1(a, b, UNIQUE(a, b));
+ INSERT INTO t1 VALUES(rblob(500), rblob(500));
+ INSERT INTO t1 SELECT rblob(500), rblob(500) FROM t1; -- 2
+ INSERT INTO t1 SELECT rblob(500), rblob(500) FROM t1; -- 4
+ INSERT INTO t1 SELECT rblob(500), rblob(500) FROM t1; -- 8
+
+ CREATE TABLE t2(a, b, UNIQUE(a, b));
+ INSERT INTO t2 SELECT * FROM t1;
+} {}
+
+do_test 3.2 {
+ set nRow 0
+ db eval {SELECT * FROM t2 ORDER BY a, b} {
+ if {$nRow==4} { db eval { DELETE FROM t1 } }
+ incr nRow
+ }
+ set nRow
+} {8}
+
+#-------------------------------------------------------------------------
+# Ensure that existing cursors using xFetch() pages see changes made
+# to rows using the incrblob API.
+#
+reset_db
+execsql { PRAGMA mmap_size = 67108864; }
+set aaa [string repeat a 400]
+set bbb [string repeat b 400]
+set ccc [string repeat c 400]
+set ddd [string repeat d 400]
+set eee [string repeat e 400]
+
+do_execsql_test 4.1 {
+ PRAGMA page_size = 1024;
+ CREATE TABLE t1(x);
+ INSERT INTO t1 VALUES($aaa);
+ INSERT INTO t1 VALUES($bbb);
+ INSERT INTO t1 VALUES($ccc);
+ INSERT INTO t1 VALUES($ddd);
+ SELECT * FROM t1;
+ BEGIN;
+} [list $aaa $bbb $ccc $ddd]
+
+do_test 4.2 {
+ set ::STMT [sqlite3_prepare db "SELECT * FROM t1 ORDER BY rowid" -1 dummy]
+ sqlite3_step $::STMT
+ sqlite3_column_text $::STMT 0
+} $aaa
+
+do_test 4.3 {
+ foreach r {2 3 4} {
+ set fd [db incrblob t1 x $r]
+ puts -nonewline $fd $eee
+ close $fd
+ }
+
+ set res [list]
+ while {"SQLITE_ROW" == [sqlite3_step $::STMT]} {
+ lappend res [sqlite3_column_text $::STMT 0]
+ }
+ set res
+} [list $eee $eee $eee]
+
+do_test 4.4 {
+ sqlite3_finalize $::STMT
+} SQLITE_OK
+
+do_execsql_test 4.5 { COMMIT }
+
+#-------------------------------------------------------------------------
+# Ensure that existing cursors holding xFetch() references are not
+# confused if those pages are moved to make way for the root page of a
+# new table or index.
+#
+reset_db
+execsql { PRAGMA mmap_size = 67108864; }
+do_execsql_test 5.1 {
+ PRAGMA auto_vacuum = 2;
+ PRAGMA page_size = 1024;
+ CREATE TABLE t1(x);
+ INSERT INTO t1 VALUES($aaa);
+ INSERT INTO t1 VALUES($bbb);
+ INSERT INTO t1 VALUES($ccc);
+ INSERT INTO t1 VALUES($ddd);
+
+ PRAGMA auto_vacuum;
+ SELECT * FROM t1;
+} [list 2 $aaa $bbb $ccc $ddd]
+
+do_test 5.2 {
+ set ::STMT [sqlite3_prepare db "SELECT * FROM t1 ORDER BY rowid" -1 dummy]
+ sqlite3_step $::STMT
+ sqlite3_column_text $::STMT 0
+} $aaa
+
+do_execsql_test 5.3 {
+ CREATE TABLE t2(x);
+ INSERT INTO t2 VALUES('tricked you!');
+ INSERT INTO t2 VALUES('tricked you!');
+}
+
+do_test 5.4 {
+ sqlite3_step $::STMT
+ sqlite3_column_text $::STMT 0
+} $bbb
+
+do_test 5.5 {
+ sqlite3_finalize $::STMT
+} SQLITE_OK
+
+#-------------------------------------------------------------------------
+# Test various mmap_size settings.
+#
+foreach {tn1 mmap1 mmap2} {
+ 1 6144 167773
+ 2 18432 140399
+ 3 43008 401302
+ 4 92160 253899
+ 5 190464 2
+ 6 387072 752431
+ 7 780288 291143
+ 8 1566720 594306
+ 9 3139584 829137
+ 10 6285312 793963
+ 11 12576768 1015590
+} {
+ do_multiclient_test tn {
+ sql1 {
+ CREATE TABLE t1(a PRIMARY KEY);
+ CREATE TABLE t2(x);
+ INSERT INTO t2 VALUES('');
+ }
+
+ code1 [register_rblob_code db 0]
+ code2 [register_rblob_code db2 444]
+
+ sql1 "PRAGMA mmap_size = $mmap1"
+ sql2 "PRAGMA mmap_size = $mmap2"
+
+ do_test $tn1.$tn {
+ for {set i 1} {$i <= 100} {incr i} {
+ if {$i % 2} {
+ set c1 sql1
+ set c2 sql2
+ } else {
+ set c1 sql2
+ set c2 sql1
+ }
+
+ $c1 {
+ INSERT INTO t1 VALUES( rblob(5000) );
+ UPDATE t2 SET x = (SELECT md5sum(a) FROM t1);
+ }
+
+ set res [$c2 {
+ SELECT count(*) FROM t1;
+ SELECT x == (SELECT md5sum(a) FROM t1) FROM t2;
+ PRAGMA integrity_check;
+ }]
+ if {$res != [list $i 1 ok]} {
+ do_test $tn1.$tn.$i {
+ set ::res
+ } [list $i 1 ok]
+ }
+ }
+ set res 1
+ } {1}
+ }
+}
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/mmap2.test b/lang/sql/sqlite/test/mmap2.test
new file mode 100644
index 00000000..1f8346b9
--- /dev/null
+++ b/lang/sql/sqlite/test/mmap2.test
@@ -0,0 +1,87 @@
+# 2013 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.
+#
+#***********************************************************************
+#
+# This file tests the effect of the mmap() or mremap() system calls
+# returning an error on the library.
+#
+# If either mmap() or mremap() fails, SQLite should log an error
+# message, then continue accessing the database using read() and
+# write() exclusively.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix mmap2
+
+if {$::tcl_platform(platform)!="unix" || [test_syscall defaultvfs] != "unix"} {
+ finish_test
+ return
+}
+ifcapable !mmap {
+ finish_test
+ return
+}
+
+db close
+sqlite3_shutdown
+test_sqlite3_log xLog
+proc xLog {error_code msg} {
+ if {[string match os_unix.c* $msg]} {
+ lappend ::log $msg
+ }
+}
+
+foreach syscall {mmap mremap} {
+ test_syscall uninstall
+ if {[catch {test_syscall install $syscall}]} continue
+
+ for {set i 1} {$i < 20} {incr i} {
+ reset_db
+ execsql { PRAGMA mmap_size = 8000000 }
+
+ test_syscall fault $i 1
+ test_syscall errno $syscall ENOMEM
+ set ::log ""
+
+ do_execsql_test 1.$syscall.$i.1 {
+ CREATE TABLE t1(a, b, UNIQUE(a, b));
+ INSERT INTO t1 VALUES(randomblob(1000), randomblob(1000));
+ 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;
+ INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
+ INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
+ }
+
+ set nFail [test_syscall fault 0 0]
+
+ do_execsql_test 1.$syscall.$i.2 {
+ SELECT count(*) FROM t1;
+ PRAGMA integrity_check;
+ } {64 ok}
+
+ do_test 1.$syscall.$i.3 {
+ expr {$nFail==0 || $nFail==1}
+ } {1}
+
+ do_test 1.$syscall.$i.4.nFail=$nFail {
+ regexp ".*${syscall}.*" $::log
+ } [expr $nFail>0]
+ }
+}
+
+db close
+test_syscall uninstall
+sqlite3_shutdown
+test_sqlite3_log
+sqlite3_initialize
+finish_test
diff --git a/lang/sql/sqlite/test/mmap3.test b/lang/sql/sqlite/test/mmap3.test
new file mode 100644
index 00000000..07b51529
--- /dev/null
+++ b/lang/sql/sqlite/test/mmap3.test
@@ -0,0 +1,98 @@
+# 2013-05-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
+ifcapable !mmap||!vtab {
+ finish_test
+ return
+}
+source $testdir/lock_common.tcl
+set testprefix mmap3
+
+do_test mmap3-1.0 {
+ load_static_extension db wholenumber
+ db eval {
+ PRAGMA mmap_size=100000;
+ CREATE TABLE t1(x, y);
+ CREATE VIRTUAL TABLE nums USING wholenumber;
+ INSERT INTO t1 SELECT value, randomblob(value) FROM nums
+ WHERE value BETWEEN 1 and 1000;
+ SELECT sum(x), sum(length(y)) from t1;
+ PRAGMA mmap_size;
+ }
+} {100000 500500 500500 100000}
+do_test mmap3-1.2 {
+ db eval {
+ PRAGMA mmap_size=50000;
+ CREATE TABLE t2(a,b);
+ SELECT name FROM sqlite_master WHERE type='table' ORDER BY 1;
+ PRAGMA quick_check;
+ PRAGMA mmap_size;
+ }
+} {50000 nums t1 t2 ok 50000}
+do_test mmap3-1.3 {
+ db eval {
+ PRAGMA mmap_size=250000;
+ DROP TABLE t2;
+ SELECT name FROM sqlite_master WHERE type='table' ORDER BY 1;
+ PRAGMA quick_check;
+ PRAGMA mmap_size;
+ }
+} {250000 nums t1 ok 250000}
+do_test mmap3-1.4 {
+ db eval {SELECT x FROM t1 WHERE +x BETWEEN 10 AND 15} {
+ db eval {PRAGMA mmap_size=150000}
+ }
+ db eval {
+ PRAGMA quick_check;
+ PRAGMA mmap_size;
+ }
+} {ok 250000}
+do_test mmap3-1.5 {
+ db eval {SELECT x FROM t1 WHERE +x BETWEEN 10 AND 15} {
+ db eval {PRAGMA mmap_size=0}
+ }
+ db eval {
+ PRAGMA quick_check;
+ PRAGMA mmap_size;
+ }
+} {ok 250000}
+do_test mmap3-1.6 {
+ db eval {SELECT x FROM t1 WHERE +x BETWEEN 10 AND 15} {
+ set x [db one {PRAGMA mmap_size}]
+ }
+ set x [concat $x [db eval {
+ PRAGMA quick_check;
+ PRAGMA mmap_size;
+ }]]
+} {250000 ok 250000}
+do_test mmap3-1.7 {
+ db eval {
+ PRAGMA mmap_size(0);
+ CREATE TABLE t3(a,b,c);
+ SELECT name FROM sqlite_master WHERE type='table' ORDER BY 1;
+ PRAGMA quick_check;
+ PRAGMA mmap_size;
+ }
+} {0 nums t1 t3 ok 0}
+do_test mmap3-1.8 {
+ db eval {SELECT x FROM t1 WHERE +x BETWEEN 10 AND 15} {
+ db eval {PRAGMA mmap_size=75000}
+ }
+ db eval {
+ PRAGMA quick_check;
+ PRAGMA mmap_size;
+ }
+} {ok 75000}
+
+finish_test
diff --git a/lang/sql/sqlite/test/mmapfault.test b/lang/sql/sqlite/test/mmapfault.test
new file mode 100644
index 00000000..10c5e258
--- /dev/null
+++ b/lang/sql/sqlite/test/mmapfault.test
@@ -0,0 +1,76 @@
+# 2013-05-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 !mmap {
+ finish_test
+ return
+}
+set testprefix mmapfault
+
+set a_string_counter 1
+proc a_string {n} {
+ global a_string_counter
+ incr a_string_counter
+ string range [string repeat "${a_string_counter}." $n] 1 $n
+}
+db func a_string a_string
+
+do_test 1-pre {
+ execsql {
+ CREATE TABLE t1(a UNIQUE, b UNIQUE);
+ INSERT INTO t1 VALUES(a_string(200), a_string(300));
+ INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
+ INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
+ }
+ faultsim_save_and_close
+} {}
+
+
+do_faultsim_test 1 -prep {
+ faultsim_restore_and_reopen
+ db func a_string a_string
+ execsql {
+ PRAGMA mmap_size = 1000000;
+ PRAGMA cache_size = 5;
+ BEGIN;
+ INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
+ INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
+ INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
+ INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
+ }
+} -body {
+ execsql { INSERT INTO t1 VALUES(a_string(200), a_string(300)) }
+} -test {
+ faultsim_test_result {0 {}}
+
+ if {[sqlite3_get_autocommit db]} {
+ sqlite3 db2 test.db
+ set nRow [db2 one {SELECT count(*) FROM t1}]
+ if {$nRow!=4} { error "Database content appears incorrect (1)" }
+ db2 close
+ }
+
+ execsql { INSERT INTO t1 VALUES(a_string(201), a_string(301)) }
+ set nRow [db one {SELECT count(*) FROM t1}]
+ if {$nRow!=5 && $nRow!=66 && $nRow!=65} {
+ error "Database content appears incorrect (2) ($nRow)"
+ }
+
+ catch { execsql COMMIT }
+}
+
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/multiplex.test b/lang/sql/sqlite/test/multiplex.test
index 518cbe37..32c87d9a 100644
--- a/lang/sql/sqlite/test/multiplex.test
+++ b/lang/sql/sqlite/test/multiplex.test
@@ -14,6 +14,16 @@ set testdir [file dirname $argv0]
source $testdir/tester.tcl
source $testdir/malloc_common.tcl
+# The tests in this file assume that SQLite is compiled without
+# ENABLE_8_3_NAMES.
+#
+ifcapable 8_3_names {
+ puts -nonewline "SQLite compiled with SQLITE_ENABLE_8_3_NAMES. "
+ puts "Skipping tests multiplex-*."
+ finish_test
+ return
+}
+
set g_chunk_size [ expr ($::SQLITE_MAX_PAGE_SIZE*16384) ]
set g_max_chunks 32
@@ -24,7 +34,7 @@ set g_max_chunks 32
# file name with the chunk number.
proc multiplex_name {name chunk} {
if {$chunk==0} { return $name }
- set num [format "%02d" $chunk]
+ set num [format "%03d" $chunk]
ifcapable {multiplex_ext_overwrite} {
set name [string range $name 0 [expr [string length $name]-2-1]]
}
@@ -49,6 +59,7 @@ proc multiplex_set {db name chunk_size max_chunks} {
# and files with the chunk extension.
proc multiplex_delete {name} {
global g_max_chunks
+ forcedelete $name
for {set i 0} {$i<$g_max_chunks} {incr i} {
forcedelete [multiplex_name $name $i]
forcedelete [multiplex_name $name-journal $i]
@@ -78,10 +89,9 @@ do_test multiplex-1.8 { sqlite3_multiplex_shutdown } {SQLITE_OK}
do_test multiplex-1.9.1 { sqlite3_multiplex_initialize "" 1 } {SQLITE_OK}
do_test multiplex-1.9.2 { sqlite3 db test.db } {}
do_test multiplex-1.9.3 { multiplex_set db main 32768 16 } {SQLITE_OK}
-do_test multiplex-1.9.4 { multiplex_set db main 32768 -1 } {SQLITE_MISUSE}
-do_test multiplex-1.9.5 { multiplex_set db main -1 16 } {SQLITE_MISUSE}
+do_test multiplex-1.9.4 { multiplex_set db main 32768 -1 } {SQLITE_OK}
do_test multiplex-1.9.6 { multiplex_set db main 31 16 } {SQLITE_OK}
-do_test multiplex-1.9.7 { multiplex_set db main 32768 100 } {SQLITE_MISUSE}
+do_test multiplex-1.9.7 { multiplex_set db main 32768 100 } {SQLITE_OK}
do_test multiplex-1.9.8 { multiplex_set db main 1073741824 1 } {SQLITE_OK}
do_test multiplex-1.9.9 { db close } {}
do_test multiplex-1.9.10 { sqlite3_multiplex_shutdown } {SQLITE_OK}
@@ -89,10 +99,9 @@ do_test multiplex-1.9.10 { sqlite3_multiplex_shutdown } {SQLITE_OK}
do_test multiplex-1.10.1 { sqlite3_multiplex_initialize "" 1 } {SQLITE_OK}
do_test multiplex-1.10.2 { sqlite3 db test.db } {}
do_test multiplex-1.10.3 { lindex [ catchsql { SELECT multiplex_control(2, 32768); } ] 0 } {0}
-do_test multiplex-1.10.4 { lindex [ catchsql { SELECT multiplex_control(3, -1); } ] 0 } {1}
-do_test multiplex-1.10.5 { lindex [ catchsql { SELECT multiplex_control(2, -1); } ] 0 } {1}
+do_test multiplex-1.10.4 { lindex [ catchsql { SELECT multiplex_control(3, -1); } ] 0 } {0}
do_test multiplex-1.10.6 { lindex [ catchsql { SELECT multiplex_control(2, 31); } ] 0 } {0}
-do_test multiplex-1.10.7 { lindex [ catchsql { SELECT multiplex_control(3, 100); } ] 0 } {1}
+do_test multiplex-1.10.7 { lindex [ catchsql { SELECT multiplex_control(3, 100); } ] 0 } {0}
do_test multiplex-1.10.8 { lindex [ catchsql { SELECT multiplex_control(2, 1073741824); } ] 0 } {0}
do_test multiplex-1.10.9 { db close } {}
do_test multiplex-1.10.10 { sqlite3_multiplex_shutdown } {SQLITE_OK}
@@ -146,8 +155,12 @@ do_test multiplex-1.13.7 { sqlite3_multiplex_shutdown }
sqlite3_multiplex_initialize "" 1
multiplex_set db main 32768 16
+forcedelete test.x
+foreach f [glob -nocomplain {test.x*[0-9][0-9][0-9]}] {
+ forcedelete $f
+}
do_test multiplex-2.1.2 {
- sqlite3 db test.db
+ sqlite3 db test.x
execsql {
PRAGMA page_size=1024;
PRAGMA auto_vacuum=OFF;
@@ -159,7 +172,7 @@ do_test multiplex-2.1.2 {
INSERT INTO t1 VALUES(2, randomblob(1100));
}
} {}
-do_test multiplex-2.1.3 { file size [multiplex_name test.db 0] } {4096}
+do_test multiplex-2.1.3 { file size [multiplex_name test.x 0] } {4096}
do_test multiplex-2.1.4 {
execsql { INSERT INTO t1 VALUES(3, randomblob(1100)) }
} {}
@@ -167,10 +180,10 @@ do_test multiplex-2.1.4 {
do_test multiplex-2.2.1 {
execsql { INSERT INTO t1 VALUES(3, randomblob(1100)) }
} {}
-do_test multiplex-2.2.3 { file size [multiplex_name test.db 0] } {6144}
+do_test multiplex-2.2.3 { file size [multiplex_name test.x 0] } {6144}
do_test multiplex-2.3.1 {
- sqlite3 db2 test2.db
+ sqlite3 db2 test2.x
db2 close
} {}
@@ -181,17 +194,22 @@ do_test multiplex-2.4.1 {
do_test multiplex-2.4.2 {
execsql { INSERT INTO t1 VALUES(3, randomblob(1100)) }
} {}
-do_test multiplex-2.4.4 { file size [multiplex_name test.db 0] } {7168}
-do_test multiplex-2.4.99 {
+do_test multiplex-2.4.4 { file size [multiplex_name test.x 0] } {7168}
+do_test multiplex-2.4.5 {
db close
+ sqlite3 db test.x
+ db eval vacuum
+ db close
+ glob test.x*
+} {test.x}
+do_test multiplex-2.4.99 {
sqlite3_multiplex_shutdown
} {SQLITE_OK}
-
do_test multiplex-2.5.1 {
- multiplex_delete test.db
+ multiplex_delete test.x
sqlite3_multiplex_initialize "" 1
- sqlite3 db test.db
+ sqlite3 db test.x
multiplex_set db main 4096 16
} {SQLITE_OK}
@@ -236,8 +254,8 @@ do_test multiplex-2.5.8 {
db eval {SELECT a,length(b) FROM t1 WHERE a=4}
} {4 4000}
-do_test multiplex-2.5.9 { file size [multiplex_name test.db 0] } [list $g_chunk_size]
-do_test multiplex-2.5.10 { file size [multiplex_name test.db 1] } [list $g_chunk_size]
+do_test multiplex-2.5.9 { file size [multiplex_name test.x 0] } [list $g_chunk_size]
+do_test multiplex-2.5.10 { file size [multiplex_name test.x 1] } [list $g_chunk_size]
do_test multiplex-2.5.99 {
db close
@@ -514,7 +532,7 @@ do_test multiplex-5.4.1 {
file mkdir test.db
list [catch { sqlite3 db test.db } msg] $msg
} {1 {unable to open database file}}
-catch { file delete test.db }
+catch { delete_file test.db }
do_faultsim_test multiplex-5.5 -prep {
catch { sqlite3_multiplex_shutdown }
@@ -523,49 +541,47 @@ do_faultsim_test multiplex-5.5 -prep {
multiplex_set db main 32768 16
}
-# test that mismatch filesize is detected
-#
-# Do not run this test if $::G(perm:presql) is set. If it is set, then the
-# expected IO error will occur within the Tcl [sqlite3] wrapper, not within
-# the first SQL statement executed below. This breaks the test case.
-#
-if {0==[info exists ::G(perm:presql)] || $::G(perm:presql) == ""} {
- set all_journal_modes {delete persist truncate memory off}
- foreach jmode $all_journal_modes {
- do_test multiplex-5.6.1.$jmode {
- sqlite3_multiplex_shutdown
- multiplex_delete test.db
- sqlite3 db test.db
- db eval {
- PRAGMA page_size = 1024;
- PRAGMA auto_vacuum = off;
- }
- db eval "PRAGMA journal_mode = $jmode;"
- } $jmode
- do_test multiplex-5.6.2.$jmode {
- execsql {
- CREATE TABLE t1(a, b);
- INSERT INTO t1 VALUES(1, randomblob(15000));
- INSERT INTO t1 VALUES(2, randomblob(15000));
- INSERT INTO t1 VALUES(3, randomblob(15000));
- INSERT INTO t1 VALUES(4, randomblob(15000));
- INSERT INTO t1 VALUES(5, randomblob(15000));
- }
- db close
- sqlite3_multiplex_initialize "" 1
- sqlite3 db test.db
- multiplex_set db main 4096 16
- } {SQLITE_OK}
- do_test multiplex-5.6.3.$jmode {
- catchsql {
- INSERT INTO t1 VALUES(6, randomblob(15000));
- }
- } {1 {disk I/O error}}
- do_test multiplex-5.6.4.$jmode {
- db close
- } {}
+#-------------------------------------------------------------------------
+# Test that you can vacuum a multiplex'ed DB.
+
+ifcapable vacuum {
+
+sqlite3_multiplex_shutdown
+do_test multiplex-6.0.0 {
+ multiplex_delete test.db
+ multiplex_delete test.x
+ sqlite3_multiplex_initialize "" 1
+ sqlite3 db test.x
+ multiplex_set db main 4096 16
+} {SQLITE_OK}
+
+do_test multiplex-6.1.0 {
+ execsql {
+ PRAGMA page_size=1024;
+ PRAGMA journal_mode=DELETE;
+ PRAGMA auto_vacuum=OFF;
+ }
+ execsql {
+ CREATE TABLE t1(a, b);
+ INSERT INTO t1 VALUES(1, randomblob($g_chunk_size));
+ INSERT INTO t1 VALUES(2, randomblob($g_chunk_size));
}
+} {}
+do_test multiplex-6.2.1 { file size [multiplex_name test.x 0] } [list $g_chunk_size]
+do_test multiplex-6.2.2 { file size [multiplex_name test.x 1] } [list $g_chunk_size]
+
+do_test multiplex-6.3.0 {
+ execsql { VACUUM }
+} {}
+
+do_test multiplex-6.99 {
+ db close
+ multiplex_delete test.x
+ sqlite3_multiplex_shutdown
+} {SQLITE_OK}
+
}
+
catch { sqlite3_multiplex_shutdown }
finish_test
diff --git a/lang/sql/sqlite/test/multiplex2.test b/lang/sql/sqlite/test/multiplex2.test
new file mode 100644
index 00000000..bdfc05b8
--- /dev/null
+++ b/lang/sql/sqlite/test/multiplex2.test
@@ -0,0 +1,70 @@
+# 2010 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.
+#
+#***********************************************************************
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+source $testdir/malloc_common.tcl
+source $testdir/lock_common.tcl
+
+
+do_multiclient_test tn {
+ code1 { catch { sqlite3_multiplex_initialize "" 0 } }
+ code2 { catch { sqlite3_multiplex_initialize "" 0 } }
+
+ code1 { db close }
+ code2 { db2 close }
+
+ code1 { sqlite3 db test.db -vfs multiplex }
+ code2 { sqlite3 db2 test.db -vfs multiplex }
+
+ code1 { sqlite3_multiplex_control db main chunk_size [expr 1024*1024] }
+ code2 { sqlite3_multiplex_control db2 main chunk_size [expr 1024*1024] }
+
+ sql1 {
+ CREATE TABLE t1(a, b);
+ INSERT INTO t1 VALUES(randomblob(10), randomblob(4000)); -- 1
+ INSERT INTO t1 SELECT randomblob(10), randomblob(4000) FROM t1; -- 2
+ INSERT INTO t1 SELECT randomblob(10), randomblob(4000) FROM t1; -- 4
+ INSERT INTO t1 SELECT randomblob(10), randomblob(4000) FROM t1; -- 8
+ INSERT INTO t1 SELECT randomblob(10), randomblob(4000) FROM t1; -- 16
+ INSERT INTO t1 SELECT randomblob(10), randomblob(4000) FROM t1; -- 32
+ INSERT INTO t1 SELECT randomblob(10), randomblob(4000) FROM t1; -- 64
+ INSERT INTO t1 SELECT randomblob(10), randomblob(4000) FROM t1; -- 128
+ INSERT INTO t1 SELECT randomblob(10), randomblob(4000) FROM t1; -- 256
+ INSERT INTO t1 SELECT randomblob(10), randomblob(4000) FROM t1; -- 512
+ SELECT count(*) FROM t1;
+ }
+
+ do_test multiplex-1.$tn.1 { sql1 { SELECT count(*) FROM t1 } } 512
+ do_test multiplex-1.$tn.2 { sql2 { SELECT count(*) FROM t1 } } 512
+ sql2 { DELETE FROM t1 ; VACUUM }
+ do_test multiplex-1.$tn.3 { sql1 { SELECT count(*) FROM t1 } } 0
+
+ sql1 {
+ INSERT INTO t1 VALUES(randomblob(10), randomblob(4000)); -- 1
+ INSERT INTO t1 SELECT randomblob(10), randomblob(4000) FROM t1; -- 2
+ INSERT INTO t1 SELECT randomblob(10), randomblob(4000) FROM t1; -- 4
+ INSERT INTO t1 SELECT randomblob(10), randomblob(4000) FROM t1; -- 8
+ INSERT INTO t1 SELECT randomblob(10), randomblob(4000) FROM t1; -- 16
+ INSERT INTO t1 SELECT randomblob(10), randomblob(4000) FROM t1; -- 32
+ INSERT INTO t1 SELECT randomblob(10), randomblob(4000) FROM t1; -- 64
+ INSERT INTO t1 SELECT randomblob(10), randomblob(4000) FROM t1; -- 128
+ INSERT INTO t1 SELECT randomblob(10), randomblob(4000) FROM t1; -- 256
+ INSERT INTO t1 SELECT randomblob(10), randomblob(4000) FROM t1; -- 512
+ SELECT count(*) FROM t1;
+ }
+
+ do_test multiplex-1.$tn.4 { sql2 { SELECT count(*) FROM t1 } } 512
+}
+
+catch { sqlite3_multiplex_shutdown }
+finish_test
diff --git a/lang/sql/sqlite/test/multiplex3.test b/lang/sql/sqlite/test/multiplex3.test
new file mode 100644
index 00000000..c1e741ac
--- /dev/null
+++ b/lang/sql/sqlite/test/multiplex3.test
@@ -0,0 +1,166 @@
+
+# 2011 December 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 contains tests for error (IO, OOM etc.) handling when using
+# the multiplexor extension with 8.3 filenames.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+source $testdir/malloc_common.tcl
+set ::testprefix multiplex3
+
+ifcapable !8_3_names {
+ puts -nonewline "SQLite compiled without SQLITE_ENABLE_8_3_NAMES. "
+ puts "Skipping tests multiplex3-*."
+ finish_test
+ return
+}
+
+db close
+sqlite3_shutdown
+sqlite3_config_uri 1
+autoinstall_test_functions
+
+sqlite3_multiplex_initialize "" 1
+
+proc destroy_vfs_stack {} {
+ generic_unregister stack
+ sqlite3_multiplex_shutdown
+}
+
+proc multiplex_delete_db {} {
+ forcedelete test.db
+ for {set i 1} {$i <= 1000} {incr i} {
+ forcedelete test.[format %03d $i]
+ }
+}
+
+# Procs to save and restore the current muliplexed database.
+#
+proc multiplex_save_db {} {
+ foreach f [glob -nocomplain sv_test.*] { forcedelete $f }
+ foreach f [glob -nocomplain test.*] { forcecopy $f "sv_$f" }
+}
+proc multiplex_restore_db {} {
+ foreach f [glob -nocomplain test.*] {forcedelete $f}
+ foreach f [glob -nocomplain sv_test.*] {forcecopy $f [string range $f 3 end]} }
+
+proc setup_and_save_db {} {
+ multiplex_delete_db
+ sqlite3 db file:test.db?8_3_names=1
+ sqlite3_multiplex_control db main chunk_size [expr 256*1024]
+ execsql {
+ CREATE TABLE t1(a PRIMARY KEY, b);
+ INSERT INTO t1 VALUES(randomblob(15), randomblob(2000));
+ INSERT INTO t1 SELECT randomblob(15), randomblob(2000) FROM t1; -- 2
+ INSERT INTO t1 SELECT randomblob(15), randomblob(2000) FROM t1; -- 4
+ INSERT INTO t1 SELECT randomblob(15), randomblob(2000) FROM t1; -- 8
+ INSERT INTO t1 SELECT randomblob(15), randomblob(2000) FROM t1; -- 16
+ INSERT INTO t1 SELECT randomblob(15), randomblob(2000) FROM t1; -- 32
+ INSERT INTO t1 SELECT randomblob(15), randomblob(2000) FROM t1; -- 64
+ INSERT INTO t1 SELECT randomblob(15), randomblob(2000) FROM t1; -- 128
+ INSERT INTO t1 SELECT randomblob(15), randomblob(2000) FROM t1; -- 256
+ INSERT INTO t1 SELECT randomblob(15), randomblob(2000) FROM t1; -- 512
+ }
+ set ::cksum1 [execsql {SELECT md5sum(a, b) FROM t1 ORDER BY a}]
+ db close
+ multiplex_save_db
+}
+
+do_test 1.0 { setup_and_save_db } {}
+do_faultsim_test 1 -prep {
+ multiplex_restore_db
+ sqlite3 db file:test.db?8_3_names=1
+ sqlite3_multiplex_control db main chunk_size [expr 256*1024]
+} -body {
+ execsql {
+ UPDATE t1 SET a=randomblob(12), b=randomblob(1500) WHERE (rowid%32)=0
+ }
+} -test {
+ faultsim_test_result {0 {}}
+ if {$testrc!=0} {
+ set cksum2 [execsql {SELECT md5sum(a, b) FROM t1 ORDER BY a}]
+ if {$cksum2 != $::cksum1} { error "data mismatch" }
+ }
+}
+
+#-------------------------------------------------------------------------
+# The following tests verify that hot-journal rollback works. As follows:
+#
+# 1. Create a large database.
+# 2. Set the pager cache to be very small.
+# 3. Open a transaction.
+# 4. Run the following 100 times:
+# a. Update a row.
+# b. Copy all files on disk to a new db location, including the journal.
+# c. Verify that the new db can be opened and that the content matches
+# the database created in step 1 (proving the journal was rolled
+# back).
+
+do_test 2.0 {
+ setup_and_save_db
+ multiplex_restore_db
+ sqlite3 db file:test.db?8_3_names=1
+ execsql { PRAGMA cache_size = 10 }
+ execsql { BEGIN }
+} {}
+
+for {set iTest 1} {$iTest<=100} {incr iTest} {
+ do_test 2.$iTest {
+ execsql {
+ UPDATE t1 SET a=randomblob(12), b=randomblob(1400) WHERE rowid=5*$iTest
+ }
+ foreach f [glob -nocomplain test.*] {forcecopy $f "xx_$f"}
+ sqlite3 db2 file:xx_test.db?8_3_names=1
+ execsql {SELECT md5sum(a, b) FROM t1 ORDER BY a} db2
+ } $::cksum1
+
+ db2 close
+}
+catch { db close }
+
+
+do_test 3.0 { setup_and_save_db } {}
+do_faultsim_test 3 -faults ioerr-trans* -prep {
+
+ forcedelete test2.db
+ set fd [open test2.wal w]
+ seek $fd 4095
+ puts -nonewline $fd x
+ close $fd
+
+ multiplex_restore_db
+ sqlite3 db file:test.db?8_3_names=1
+ sqlite3 db2 file:test2.db?8_3_names=1
+ sqlite3_multiplex_control db main chunk_size [expr 256*1024]
+ sqlite3_multiplex_control db2 main chunk_size [expr 256*1024]
+} -body {
+ sqlite3_backup B db2 main db main
+ B step 100000
+ set rc [B finish]
+ if { [string match SQLITE_IOERR_* $rc] } {error "disk I/O error"}
+ set rc
+} -test {
+ faultsim_test_result {0 SQLITE_OK}
+ if {$testrc==0} {
+ set cksum2 [execsql {SELECT md5sum(a, b) FROM t1 ORDER BY a} db2]
+ if {$cksum2 != $::cksum1} { error "data mismatch" }
+ }
+ catch { B finish }
+ catch { db close }
+ catch { db2 close }
+}
+
+catch { db close }
+sqlite3_multiplex_shutdown
+finish_test
diff --git a/lang/sql/sqlite/test/nan.test b/lang/sql/sqlite/test/nan.test
index 0e9462fc..df3f65b8 100644
--- a/lang/sql/sqlite/test/nan.test
+++ b/lang/sql/sqlite/test/nan.test
@@ -42,31 +42,31 @@ do_test nan-1.1.1 {
db eval {SELECT x, typeof(x) FROM t1}
} {{} null}
if {$tcl_platform(platform) != "symbian"} {
- do_test nan-1.1.2 {
+ do_realnum_test nan-1.1.2 {
sqlite3_bind_double $::STMT 1 +Inf
sqlite3_step $::STMT
sqlite3_reset $::STMT
db eval {SELECT x, typeof(x) FROM t1}
} {{} null inf real}
- do_test nan-1.1.3 {
+ do_realnum_test nan-1.1.3 {
sqlite3_bind_double $::STMT 1 -Inf
sqlite3_step $::STMT
sqlite3_reset $::STMT
db eval {SELECT x, typeof(x) FROM t1}
} {{} null inf real -inf real}
- do_test nan-1.1.4 {
+ do_realnum_test nan-1.1.4 {
sqlite3_bind_double $::STMT 1 -NaN
sqlite3_step $::STMT
sqlite3_reset $::STMT
db eval {SELECT x, typeof(x) FROM t1}
} {{} null inf real -inf real {} null}
- do_test nan-1.1.5 {
+ do_realnum_test nan-1.1.5 {
sqlite3_bind_double $::STMT 1 NaN0
sqlite3_step $::STMT
sqlite3_reset $::STMT
db eval {SELECT x, typeof(x) FROM t1}
} {{} null inf real -inf real {} null {} null}
- do_test nan-1.1.6 {
+ do_realnum_test nan-1.1.6 {
sqlite3_bind_double $::STMT 1 -NaN0
sqlite3_step $::STMT
sqlite3_reset $::STMT
@@ -231,12 +231,12 @@ if {$tcl_platform(platform) != "symbian"} {
# Do not run these tests on Symbian, as the Tcl port doesn't like to
# convert from floating point value "-inf" to a string.
#
- do_test nan-4.7 {
+ do_realnum_test nan-4.7 {
db eval {DELETE FROM t1}
db eval "INSERT INTO t1 VALUES([string repeat 9 309].0)"
db eval {SELECT x, typeof(x) FROM t1}
} {inf real}
- do_test nan-4.8 {
+ do_realnum_test nan-4.8 {
db eval {DELETE FROM t1}
db eval "INSERT INTO t1 VALUES(-[string repeat 9 309].0)"
db eval {SELECT x, typeof(x) FROM t1}
@@ -313,13 +313,59 @@ do_test nan-4.18 {
db eval {SELECT CAST(x AS text), typeof(x) FROM t1}
} {-9.88131291682493e-324 real}
-do_test nan-4.20 {
+do_realnum_test nan-4.20 {
db eval {DELETE FROM t1}
set big [string repeat 9 10000].0e-9000
db eval "INSERT INTO t1 VALUES($big)"
db eval {SELECT x, typeof(x) FROM t1}
} {inf real}
+do_realnum_test nan-4.30 {
+ db eval {
+ DELETE FROM t1;
+ INSERT INTO t1 VALUES('2.5e+9999');
+ SELECT x, typeof(x) FROM t1;
+ }
+} {inf real}
+do_realnum_test nan-4.31 {
+ db eval {
+ DELETE FROM t1;
+ INSERT INTO t1 VALUES('2.5e+10000');
+ SELECT x, typeof(x) FROM t1;
+ }
+} {inf real}
+
+do_realnum_test nan-4.32 {
+ db eval {
+ DELETE FROM t1;
+ INSERT INTO t1 VALUES('2.5e-9999');
+ SELECT x, typeof(x) FROM t1;
+ }
+} {0.0 real}
+do_realnum_test nan-4.33 {
+ db eval {
+ DELETE FROM t1;
+ INSERT INTO t1 VALUES('2.5e-10000');
+ SELECT x, typeof(x) FROM t1;
+ }
+} {0.0 real}
+do_realnum_test nan-4.34 {
+ db eval {
+ DELETE FROM t1;
+ INSERT INTO t1 VALUES('2.5e2147483650');
+ SELECT x, typeof(x) FROM t1;
+ }
+} {inf real}
+do_realnum_test nan-4.35 {
+ db eval {
+ DELETE FROM t1;
+ INSERT INTO t1 VALUES('2.5e-2147483650');
+ SELECT x, typeof(x) FROM t1;
+ }
+} {0.0 real}
+
+
+
finish_test
diff --git a/lang/sql/sqlite/test/notify1.test b/lang/sql/sqlite/test/notify1.test
index 1cfb36fe..be6a1225 100644
--- a/lang/sql/sqlite/test/notify1.test
+++ b/lang/sql/sqlite/test/notify1.test
@@ -140,7 +140,7 @@ do_test notify1-2.2.5 {
do_test notify1-2.3.1 {
db close
db2 close
- file delete -force test.db test2.db test3.db
+ forcedelete test.db test2.db test3.db
foreach con {db db2 db3} {
sqlite3 $con test.db
$con eval { ATTACH 'test2.db' AS aux2 }
@@ -294,7 +294,7 @@ do_malloc_test notify1-5 -tclprep {
#
db close
do_test notify1-6.1.1 {
- file delete -force test.db test2.db
+ forcedelete test.db test2.db
foreach conn {db db2 db3} {
sqlite3 $conn test.db
execsql { ATTACH 'test2.db' AS two } $conn
diff --git a/lang/sql/sqlite/test/notify2.test b/lang/sql/sqlite/test/notify2.test
index bfb9af81..9e40ed69 100644
--- a/lang/sql/sqlite/test/notify2.test
+++ b/lang/sql/sqlite/test/notify2.test
@@ -150,9 +150,9 @@ set sql $zSql
# Hit some other kind of error. This is a malfunction.
error $msg
} else {
- # No error occured. Check that any SELECT statements in the transaction
+ # No error occurred. Check that any SELECT statements in the transaction
# returned "1". Otherwise, the invariant was false, indicating that
- # some malfunction has occured.
+ # some malfunction has occurred.
foreach r $msg { if {$r != 1} { puts "Invariant check failed: $msg" } }
}
}
@@ -167,7 +167,7 @@ foreach {iTest xStep xPrepare} {
1 sqlite3_blocking_step sqlite3_blocking_prepare_v2
2 sqlite3_step sqlite3_nonblocking_prepare_v2
} {
- file delete -force test.db test2.db test3.db
+ forcedelete test.db test2.db test3.db
set ThreadSetup "set xStep $xStep;set xPrepare $xPrepare;set nSecond $nSecond"
diff --git a/lang/sql/sqlite/test/notify3.test b/lang/sql/sqlite/test/notify3.test
index 0d06ce19..4b5e8016 100644
--- a/lang/sql/sqlite/test/notify3.test
+++ b/lang/sql/sqlite/test/notify3.test
@@ -25,7 +25,7 @@ ifcapable !unlock_notify||!shared_cache {
set esc [sqlite3_enable_shared_cache 1]
sqlite3 db test.db
-file delete -force test.db2 test.db2-journal test.db2-wal
+forcedelete test.db2 test.db2-journal test.db2-wal
sqlite3 db2 test.db2
do_test notify3-1.1 {
@@ -150,4 +150,3 @@ catch { db2 close }
sqlite3_enable_shared_cache $esc
finish_test
-
diff --git a/lang/sql/sqlite/test/notnull.test b/lang/sql/sqlite/test/notnull.test
index 240aaba9..23fd33d4 100644
--- a/lang/sql/sqlite/test/notnull.test
+++ b/lang/sql/sqlite/test/notnull.test
@@ -47,7 +47,8 @@ do_test notnull-1.2 {
INSERT INTO t1(b,c,d,e) VALUES(2,3,4,5);
SELECT * FROM t1 order by a;
}
-} {1 {t1.a may not be NULL}}
+} {1 {NOT NULL constraint failed: t1.a}}
+verify_ex_errcode notnull-1.2b SQLITE_CONSTRAINT_NOTNULL
do_test notnull-1.3 {
catchsql {
DELETE FROM t1;
@@ -61,14 +62,16 @@ do_test notnull-1.4 {
INSERT OR REPLACE INTO t1(b,c,d,e) VALUES(2,3,4,5);
SELECT * FROM t1 order by a;
}
-} {1 {t1.a may not be NULL}}
+} {1 {NOT NULL constraint failed: t1.a}}
+verify_ex_errcode notnull-1.4b SQLITE_CONSTRAINT_NOTNULL
do_test notnull-1.5 {
catchsql {
DELETE FROM t1;
INSERT OR ABORT INTO t1(b,c,d,e) VALUES(2,3,4,5);
SELECT * FROM t1 order by a;
}
-} {1 {t1.a may not be NULL}}
+} {1 {NOT NULL constraint failed: t1.a}}
+verify_ex_errcode notnull-1.5b SQLITE_CONSTRAINT_NOTNULL
do_test notnull-1.6 {
catchsql {
DELETE FROM t1;
@@ -103,7 +106,8 @@ do_test notnull-1.10 {
INSERT INTO t1(a,b,c,d,e) VALUES(1,null,3,4,5);
SELECT * FROM t1 order by a;
}
-} {1 {t1.b may not be NULL}}
+} {1 {NOT NULL constraint failed: t1.b}}
+verify_ex_errcode notnull-1.10b SQLITE_CONSTRAINT_NOTNULL
do_test notnull-1.11 {
catchsql {
DELETE FROM t1;
@@ -145,14 +149,16 @@ do_test notnull-1.16 {
INSERT OR ABORT INTO t1(a,b,c,d,e) VALUES(1,2,null,4,5);
SELECT * FROM t1 order by a;
}
-} {1 {t1.c may not be NULL}}
+} {1 {NOT NULL constraint failed: t1.c}}
+verify_ex_errcode notnull-1.16b SQLITE_CONSTRAINT_NOTNULL
do_test notnull-1.17 {
catchsql {
DELETE FROM t1;
INSERT OR ABORT INTO t1(a,b,c,d,e) VALUES(1,2,3,null,5);
SELECT * FROM t1 order by a;
}
-} {1 {t1.d may not be NULL}}
+} {1 {NOT NULL constraint failed: t1.d}}
+verify_ex_errcode notnull-1.17b SQLITE_CONSTRAINT_NOTNULL
do_test notnull-1.18 {
catchsql {
DELETE FROM t1;
@@ -173,7 +179,8 @@ do_test notnull-1.20 {
INSERT INTO t1(a,b,c,d,e) VALUES(1,2,3,4,null);
SELECT * FROM t1 order by a;
}
-} {1 {t1.e may not be NULL}}
+} {1 {NOT NULL constraint failed: t1.e}}
+verify_ex_errcode notnull-1.20b SQLITE_CONSTRAINT_NOTNULL
do_test notnull-1.21 {
catchsql {
DELETE FROM t1;
@@ -189,7 +196,8 @@ do_test notnull-2.1 {
UPDATE t1 SET a=null;
SELECT * FROM t1 ORDER BY a;
}
-} {1 {t1.a may not be NULL}}
+} {1 {NOT NULL constraint failed: t1.a}}
+verify_ex_errcode notnull-2.1b SQLITE_CONSTRAINT_NOTNULL
do_test notnull-2.2 {
catchsql {
DELETE FROM t1;
@@ -197,7 +205,8 @@ do_test notnull-2.2 {
UPDATE OR REPLACE t1 SET a=null;
SELECT * FROM t1 ORDER BY a;
}
-} {1 {t1.a may not be NULL}}
+} {1 {NOT NULL constraint failed: t1.a}}
+verify_ex_errcode notnull-2.2b SQLITE_CONSTRAINT_NOTNULL
do_test notnull-2.3 {
catchsql {
DELETE FROM t1;
@@ -213,7 +222,8 @@ do_test notnull-2.4 {
UPDATE OR ABORT t1 SET a=null;
SELECT * FROM t1 ORDER BY a;
}
-} {1 {t1.a may not be NULL}}
+} {1 {NOT NULL constraint failed: t1.a}}
+verify_ex_errcode notnull-2.4b SQLITE_CONSTRAINT_NOTNULL
do_test notnull-2.5 {
catchsql {
DELETE FROM t1;
@@ -221,7 +231,8 @@ do_test notnull-2.5 {
UPDATE t1 SET b=null;
SELECT * FROM t1 ORDER BY a;
}
-} {1 {t1.b may not be NULL}}
+} {1 {NOT NULL constraint failed: t1.b}}
+verify_ex_errcode notnull-2.6b SQLITE_CONSTRAINT_NOTNULL
do_test notnull-2.6 {
catchsql {
DELETE FROM t1;
@@ -261,7 +272,8 @@ do_test notnull-2.10 {
UPDATE t1 SET e=null, a=b, b=a;
SELECT * FROM t1 ORDER BY a;
}
-} {1 {t1.e may not be NULL}}
+} {1 {NOT NULL constraint failed: t1.e}}
+verify_ex_errcode notnull-2.10b SQLITE_CONSTRAINT_NOTNULL
do_test notnull-3.0 {
execsql {
@@ -286,7 +298,8 @@ do_test notnull-3.2 {
INSERT INTO t1(b,c,d,e) VALUES(2,3,4,5);
SELECT * FROM t1 order by a;
}
-} {1 {t1.a may not be NULL}}
+} {1 {NOT NULL constraint failed: t1.a}}
+verify_ex_errcode notnull-3.2b SQLITE_CONSTRAINT_NOTNULL
do_test notnull-3.3 {
catchsql {
DELETE FROM t1;
@@ -300,14 +313,16 @@ do_test notnull-3.4 {
INSERT OR REPLACE INTO t1(b,c,d,e) VALUES(2,3,4,5);
SELECT * FROM t1 order by a;
}
-} {1 {t1.a may not be NULL}}
+} {1 {NOT NULL constraint failed: t1.a}}
+verify_ex_errcode notnull-3.4b SQLITE_CONSTRAINT_NOTNULL
do_test notnull-3.5 {
catchsql {
DELETE FROM t1;
INSERT OR ABORT INTO t1(b,c,d,e) VALUES(2,3,4,5);
SELECT * FROM t1 order by a;
}
-} {1 {t1.a may not be NULL}}
+} {1 {NOT NULL constraint failed: t1.a}}
+verify_ex_errcode notnull-3.5b SQLITE_CONSTRAINT_NOTNULL
do_test notnull-3.6 {
catchsql {
DELETE FROM t1;
@@ -342,7 +357,8 @@ do_test notnull-3.10 {
INSERT INTO t1(a,b,c,d,e) VALUES(1,null,3,4,5);
SELECT * FROM t1 order by a;
}
-} {1 {t1.b may not be NULL}}
+} {1 {NOT NULL constraint failed: t1.b}}
+verify_ex_errcode notnull-3.10b SQLITE_CONSTRAINT_NOTNULL
do_test notnull-3.11 {
catchsql {
DELETE FROM t1;
@@ -384,14 +400,16 @@ do_test notnull-3.16 {
INSERT OR ABORT INTO t1(a,b,c,d,e) VALUES(1,2,null,4,5);
SELECT * FROM t1 order by a;
}
-} {1 {t1.c may not be NULL}}
+} {1 {NOT NULL constraint failed: t1.c}}
+verify_ex_errcode notnull-3.16b SQLITE_CONSTRAINT_NOTNULL
do_test notnull-3.17 {
catchsql {
DELETE FROM t1;
INSERT OR ABORT INTO t1(a,b,c,d,e) VALUES(1,2,3,null,5);
SELECT * FROM t1 order by a;
}
-} {1 {t1.d may not be NULL}}
+} {1 {NOT NULL constraint failed: t1.d}}
+verify_ex_errcode notnull-3.17b SQLITE_CONSTRAINT_NOTNULL
do_test notnull-3.18 {
catchsql {
DELETE FROM t1;
@@ -412,7 +430,8 @@ do_test notnull-3.20 {
INSERT INTO t1(a,b,c,d,e) VALUES(1,2,3,4,null);
SELECT * FROM t1 order by a;
}
-} {1 {t1.e may not be NULL}}
+} {1 {NOT NULL constraint failed: t1.e}}
+verify_ex_errcode notnull-3.20b SQLITE_CONSTRAINT_NOTNULL
do_test notnull-3.21 {
catchsql {
DELETE FROM t1;
@@ -428,7 +447,8 @@ do_test notnull-4.1 {
UPDATE t1 SET a=null;
SELECT * FROM t1 ORDER BY a;
}
-} {1 {t1.a may not be NULL}}
+} {1 {NOT NULL constraint failed: t1.a}}
+verify_ex_errcode notnull-4.1b SQLITE_CONSTRAINT_NOTNULL
do_test notnull-4.2 {
catchsql {
DELETE FROM t1;
@@ -436,7 +456,8 @@ do_test notnull-4.2 {
UPDATE OR REPLACE t1 SET a=null;
SELECT * FROM t1 ORDER BY a;
}
-} {1 {t1.a may not be NULL}}
+} {1 {NOT NULL constraint failed: t1.a}}
+verify_ex_errcode notnull-4.2b SQLITE_CONSTRAINT_NOTNULL
do_test notnull-4.3 {
catchsql {
DELETE FROM t1;
@@ -452,7 +473,8 @@ do_test notnull-4.4 {
UPDATE OR ABORT t1 SET a=null;
SELECT * FROM t1 ORDER BY a;
}
-} {1 {t1.a may not be NULL}}
+} {1 {NOT NULL constraint failed: t1.a}}
+verify_ex_errcode notnull-4.4b SQLITE_CONSTRAINT_NOTNULL
do_test notnull-4.5 {
catchsql {
DELETE FROM t1;
@@ -460,7 +482,8 @@ do_test notnull-4.5 {
UPDATE t1 SET b=null;
SELECT * FROM t1 ORDER BY a;
}
-} {1 {t1.b may not be NULL}}
+} {1 {NOT NULL constraint failed: t1.b}}
+verify_ex_errcode notnull-4.5b SQLITE_CONSTRAINT_NOTNULL
do_test notnull-4.6 {
catchsql {
DELETE FROM t1;
@@ -500,7 +523,8 @@ do_test notnull-4.10 {
UPDATE t1 SET e=null, a=b, b=a;
SELECT * FROM t1 ORDER BY a;
}
-} {1 {t1.e may not be NULL}}
+} {1 {NOT NULL constraint failed: t1.e}}
+verify_ex_errcode notnull-4.10b SQLITE_CONSTRAINT_NOTNULL
# Test that bug 29ab7be99f is fixed.
#
@@ -518,7 +542,8 @@ do_test notnull-5.2 {
INSERT INTO t1 VALUES(1, 2);
INSERT INTO t1 SELECT * FROM t2;
}
-} {1 {t1.b may not be NULL}}
+} {1 {NOT NULL constraint failed: t1.b}}
+verify_ex_errcode notnull-5.2b SQLITE_CONSTRAINT_NOTNULL
do_test notnull-5.3 {
execsql { SELECT * FROM t1 }
} {1 2}
@@ -530,10 +555,10 @@ do_test notnull-5.4 {
INSERT INTO t1 SELECT * FROM t2;
COMMIT;
}
-} {1 {t1.b may not be NULL}}
+} {1 {NOT NULL constraint failed: t1.b}}
+verify_ex_errcode notnull-5.4b SQLITE_CONSTRAINT_NOTNULL
do_test notnull-5.5 {
execsql { SELECT * FROM t1 }
} {1 2}
finish_test
-
diff --git a/lang/sql/sqlite/test/numcast.test b/lang/sql/sqlite/test/numcast.test
new file mode 100644
index 00000000..926bbe4b
--- /dev/null
+++ b/lang/sql/sqlite/test/numcast.test
@@ -0,0 +1,46 @@
+# 2013 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.
+#
+#***********************************************************************
+# This file implements regression tests for SQLite library.
+# This particular file does testing of casting strings into numeric
+# values.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+foreach enc {utf8 utf16le utf16be} {
+ do_test numcast-$enc.0 {
+ db close
+ sqlite3 db :memory:
+ db eval "PRAGMA encoding='$enc'"
+ set x [db eval {PRAGMA encoding}]
+ string map {- {}} [string tolower $x]
+ } $enc
+ foreach {idx str rval ival} {
+ 1 12345.0 12345.0 12345
+ 2 12345.0e0 12345.0 12345
+ 3 -12345.0e0 -12345.0 -12345
+ 4 -12345.25 -12345.25 -12345
+ 5 { -12345.0} -12345.0 -12345
+ 6 { 876xyz} 876.0 876
+ 7 { 456Ä·89} 456.0 456
+ 8 { Ä  321.5} 0.0 0
+ } {
+ do_test numcast-$enc.$idx.1 {
+ db eval {SELECT CAST($str AS real)}
+ } $rval
+ do_test numcast-$enc.$idx.2 {
+ db eval {SELECT CAST($str AS integer)}
+ } $ival
+ }
+}
+
+finish_test
diff --git a/lang/sql/sqlite/test/openv2.test b/lang/sql/sqlite/test/openv2.test
index 843f8919..2a9e22d6 100644
--- a/lang/sql/sqlite/test/openv2.test
+++ b/lang/sql/sqlite/test/openv2.test
@@ -17,7 +17,7 @@ set testdir [file dirname $argv0]
source $testdir/tester.tcl
db close
-file delete -force test.db test.db-journal
+forcedelete test.db test.db-journal
do_test openv2-1.1 {
set rc [catch {sqlite3 db test.db -create 0} msg]
lappend rc $msg
diff --git a/lang/sql/sqlite/test/orderby1.test b/lang/sql/sqlite/test/orderby1.test
new file mode 100644
index 00000000..d4795671
--- /dev/null
+++ b/lang/sql/sqlite/test/orderby1.test
@@ -0,0 +1,457 @@
+# 2012 Sept 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 the optimizations that disable
+# ORDER BY clauses when the natural order of a query is correct.
+#
+
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set ::testprefix orderby1
+
+# Generate test data for a join. Verify that the join gets the
+# correct answer.
+#
+do_test 1.0 {
+ db eval {
+ BEGIN;
+ CREATE TABLE album(
+ aid INTEGER PRIMARY KEY,
+ title TEXT UNIQUE NOT NULL
+ );
+ CREATE TABLE track(
+ tid INTEGER PRIMARY KEY,
+ aid INTEGER NOT NULL REFERENCES album,
+ tn INTEGER NOT NULL,
+ name TEXT,
+ UNIQUE(aid, tn)
+ );
+ INSERT INTO album VALUES(1, '1-one'), (2, '2-two'), (3, '3-three');
+ INSERT INTO track VALUES
+ (NULL, 1, 1, 'one-a'),
+ (NULL, 2, 2, 'two-b'),
+ (NULL, 3, 3, 'three-c'),
+ (NULL, 1, 3, 'one-c'),
+ (NULL, 2, 1, 'two-a'),
+ (NULL, 3, 1, 'three-a');
+ COMMIT;
+ }
+} {}
+do_test 1.1a {
+ db eval {
+ SELECT name FROM album JOIN track USING (aid) ORDER BY title, tn
+ }
+} {one-a one-c two-a two-b three-a three-c}
+
+# Verify that the ORDER BY clause is optimized out
+#
+do_test 1.1b {
+ db eval {
+ EXPLAIN QUERY PLAN
+ SELECT name FROM album CROSS JOIN track USING (aid) ORDER BY title, tn
+ }
+} {~/ORDER BY/} ;# ORDER BY optimized out
+
+# The same query with ORDER BY clause optimization disabled via + operators
+# should give exactly the same answer.
+#
+do_test 1.2a {
+ db eval {
+ SELECT name FROM album JOIN track USING (aid) ORDER BY +title, +tn
+ }
+} {one-a one-c two-a two-b three-a three-c}
+
+# The output is sorted manually in this case.
+#
+do_test 1.2b {
+ db eval {
+ EXPLAIN QUERY PLAN
+ SELECT name FROM album JOIN track USING (aid) ORDER BY +title, +tn
+ }
+} {/ORDER BY/} ;# separate sorting pass due to "+" on ORDER BY terms
+
+# The same query with ORDER BY optimizations turned off via built-in test.
+#
+do_test 1.3a {
+ optimization_control db order-by-idx-join 0
+ db cache flush
+ db eval {
+ SELECT name FROM album JOIN track USING (aid) ORDER BY title, tn
+ }
+} {one-a one-c two-a two-b three-a three-c}
+do_test 1.3b {
+ db eval {
+ EXPLAIN QUERY PLAN
+ SELECT name FROM album JOIN track USING (aid) ORDER BY title, tn
+ }
+} {/ORDER BY/} ;# separate sorting pass due to disabled optimization
+optimization_control db all 1
+db cache flush
+
+# Reverse order sorts
+#
+do_test 1.4a {
+ db eval {
+ SELECT name FROM album JOIN track USING (aid) ORDER BY title DESC, tn
+ }
+} {three-a three-c two-a two-b one-a one-c}
+do_test 1.4b {
+ db eval {
+ SELECT name FROM album JOIN track USING (aid) ORDER BY +title DESC, +tn
+ }
+} {three-a three-c two-a two-b one-a one-c} ;# verify same order after sorting
+do_test 1.4c {
+ db eval {
+ EXPLAIN QUERY PLAN
+ SELECT name FROM album JOIN track USING (aid) ORDER BY title DESC, tn
+ }
+} {~/ORDER BY/} ;# ORDER BY suppressed due to uniqueness constraints
+
+do_test 1.5a {
+ db eval {
+ SELECT name FROM album JOIN track USING (aid) ORDER BY title, tn DESC
+ }
+} {one-c one-a two-b two-a three-c three-a}
+do_test 1.5b {
+ db eval {
+ SELECT name FROM album JOIN track USING (aid) ORDER BY +title, +tn DESC
+ }
+} {one-c one-a two-b two-a three-c three-a} ;# verify same order after sorting
+do_test 1.5c {
+ db eval {
+ EXPLAIN QUERY PLAN
+ SELECT name FROM album JOIN track USING (aid) ORDER BY title, tn DESC
+ }
+} {~/ORDER BY/} ;# ORDER BY suppressed due to uniqueness constraints
+
+do_test 1.6a {
+ db eval {
+ SELECT name FROM album CROSS JOIN track USING (aid)
+ ORDER BY title DESC, tn DESC
+ }
+} {three-c three-a two-b two-a one-c one-a}
+do_test 1.6b {
+ db eval {
+ SELECT name FROM album CROSS JOIN track USING (aid)
+ ORDER BY +title DESC, +tn DESC
+ }
+} {three-c three-a two-b two-a one-c one-a} ;# verify same order after sorting
+do_test 1.6c {
+ db eval {
+ EXPLAIN QUERY PLAN
+ SELECT name FROM album CROSS JOIN track USING (aid)
+ ORDER BY title DESC, tn DESC
+ }
+} {~/ORDER BY/} ;# ORDER BY
+
+
+# Reconstruct the test data to use indices rather than integer primary keys.
+#
+do_test 2.0 {
+ db eval {
+ BEGIN;
+ DROP TABLE album;
+ DROP TABLE track;
+ CREATE TABLE album(
+ aid INT PRIMARY KEY,
+ title TEXT NOT NULL
+ );
+ CREATE INDEX album_i1 ON album(title, aid);
+ CREATE TABLE track(
+ aid INTEGER NOT NULL REFERENCES album,
+ tn INTEGER NOT NULL,
+ name TEXT,
+ UNIQUE(aid, tn)
+ );
+ INSERT INTO album VALUES(1, '1-one'), (20, '2-two'), (3, '3-three');
+ INSERT INTO track VALUES
+ (1, 1, 'one-a'),
+ (20, 2, 'two-b'),
+ (3, 3, 'three-c'),
+ (1, 3, 'one-c'),
+ (20, 1, 'two-a'),
+ (3, 1, 'three-a');
+ COMMIT;
+ }
+} {}
+do_test 2.1a {
+ db eval {
+ SELECT name FROM album JOIN track USING (aid) ORDER BY title, tn
+ }
+} {one-a one-c two-a two-b three-a three-c}
+
+# Verify that the ORDER BY clause is optimized out
+#
+do_test 2.1b {
+ db eval {
+ EXPLAIN QUERY PLAN
+ SELECT name FROM album JOIN track USING (aid) ORDER BY title, tn
+ }
+} {/ORDER BY/} ;# ORDER BY required because of missing aid term in ORDER BY
+
+do_test 2.1c {
+ db eval {
+ SELECT name FROM album JOIN track USING (aid) ORDER BY title, aid, tn
+ }
+} {one-a one-c two-a two-b three-a three-c}
+do_test 2.1d {
+ db eval {
+ EXPLAIN QUERY PLAN
+ SELECT name FROM album JOIN track USING (aid) ORDER BY title, aid, tn
+ }
+} {/ORDER BY/} ;# ORDER BY required in this case
+
+# The same query with ORDER BY clause optimization disabled via + operators
+# should give exactly the same answer.
+#
+do_test 2.2a {
+ db eval {
+ SELECT name FROM album JOIN track USING (aid) ORDER BY +title, +tn
+ }
+} {one-a one-c two-a two-b three-a three-c}
+
+# The output is sorted manually in this case.
+#
+do_test 2.2b {
+ db eval {
+ EXPLAIN QUERY PLAN
+ SELECT name FROM album JOIN track USING (aid) ORDER BY +title, +tn
+ }
+} {/ORDER BY/} ;# separate sorting pass due to "+" on ORDER BY terms
+
+# The same query with ORDER BY optimizations turned off via built-in test.
+#
+do_test 2.3a {
+ optimization_control db order-by-idx-join 0
+ db cache flush
+ db eval {
+ SELECT name FROM album JOIN track USING (aid) ORDER BY title, tn
+ }
+} {one-a one-c two-a two-b three-a three-c}
+do_test 2.3b {
+ db eval {
+ EXPLAIN QUERY PLAN
+ SELECT name FROM album JOIN track USING (aid) ORDER BY title, tn
+ }
+} {/ORDER BY/} ;# separate sorting pass due to disabled optimization
+optimization_control db all 1
+db cache flush
+
+# Reverse order sorts
+#
+do_test 2.4a {
+ db eval {
+ SELECT name FROM album JOIN track USING (aid) ORDER BY title DESC, tn
+ }
+} {three-a three-c two-a two-b one-a one-c}
+do_test 2.4b {
+ db eval {
+ SELECT name FROM album JOIN track USING (aid) ORDER BY +title DESC, +tn
+ }
+} {three-a three-c two-a two-b one-a one-c} ;# verify same order after sorting
+do_test 2.4c {
+ db eval {
+ EXPLAIN QUERY PLAN
+ SELECT name FROM album JOIN track USING (aid) ORDER BY title DESC, tn
+ }
+} {/ORDER BY/} ;# separate sorting pass due to mixed DESC/ASC
+
+
+do_test 2.5a {
+ db eval {
+ SELECT name FROM album JOIN track USING (aid) ORDER BY title, tn DESC
+ }
+} {one-c one-a two-b two-a three-c three-a}
+do_test 2.5b {
+ db eval {
+ SELECT name FROM album JOIN track USING (aid) ORDER BY +title, +tn DESC
+ }
+} {one-c one-a two-b two-a three-c three-a} ;# verify same order after sorting
+do_test 2.5c {
+ db eval {
+ EXPLAIN QUERY PLAN
+ SELECT name FROM album JOIN track USING (aid) ORDER BY title, tn DESC
+ }
+} {/ORDER BY/} ;# separate sorting pass due to mixed ASC/DESC
+
+do_test 2.6a {
+ db eval {
+ SELECT name FROM album JOIN track USING (aid) ORDER BY title DESC, tn DESC
+ }
+} {three-c three-a two-b two-a one-c one-a}
+do_test 2.6b {
+ db eval {
+ SELECT name FROM album JOIN track USING (aid) ORDER BY +title DESC, +tn DESC
+ }
+} {three-c three-a two-b two-a one-c one-a} ;# verify same order after sorting
+do_test 2.6c {
+ db eval {
+ EXPLAIN QUERY PLAN
+ SELECT name FROM album JOIN track USING (aid) ORDER BY title DESC, tn DESC
+ }
+} {/ORDER BY/} ;# ORDER BY required
+
+
+# Generate another test dataset, but this time using mixed ASC/DESC indices.
+#
+do_test 3.0 {
+ db eval {
+ BEGIN;
+ DROP TABLE album;
+ DROP TABLE track;
+ CREATE TABLE album(
+ aid INTEGER PRIMARY KEY,
+ title TEXT UNIQUE NOT NULL
+ );
+ CREATE TABLE track(
+ tid INTEGER PRIMARY KEY,
+ aid INTEGER NOT NULL REFERENCES album,
+ tn INTEGER NOT NULL,
+ name TEXT,
+ UNIQUE(aid ASC, tn DESC)
+ );
+ INSERT INTO album VALUES(1, '1-one'), (2, '2-two'), (3, '3-three');
+ INSERT INTO track VALUES
+ (NULL, 1, 1, 'one-a'),
+ (NULL, 2, 2, 'two-b'),
+ (NULL, 3, 3, 'three-c'),
+ (NULL, 1, 3, 'one-c'),
+ (NULL, 2, 1, 'two-a'),
+ (NULL, 3, 1, 'three-a');
+ COMMIT;
+ }
+} {}
+do_test 3.1a {
+ db eval {
+ SELECT name FROM album CROSS JOIN track USING (aid) ORDER BY title, tn DESC
+ }
+} {one-c one-a two-b two-a three-c three-a}
+
+# Verify that the ORDER BY clause is optimized out
+#
+do_test 3.1b {
+ db eval {
+ EXPLAIN QUERY PLAN
+ SELECT name FROM album CROSS JOIN track USING (aid) ORDER BY title, tn DESC
+ }
+} {~/ORDER BY/} ;# ORDER BY optimized out
+
+# The same query with ORDER BY clause optimization disabled via + operators
+# should give exactly the same answer.
+#
+do_test 3.2a {
+ db eval {
+ SELECT name FROM album JOIN track USING (aid) ORDER BY +title, +tn DESC
+ }
+} {one-c one-a two-b two-a three-c three-a}
+
+# The output is sorted manually in this case.
+#
+do_test 3.2b {
+ db eval {
+ EXPLAIN QUERY PLAN
+ SELECT name FROM album JOIN track USING (aid) ORDER BY +title, +tn DESC
+ }
+} {/ORDER BY/} ;# separate sorting pass due to "+" on ORDER BY terms
+
+# The same query with ORDER BY optimizations turned off via built-in test.
+#
+do_test 3.3a {
+ optimization_control db order-by-idx-join 0
+ db cache flush
+ db eval {
+ SELECT name FROM album JOIN track USING (aid) ORDER BY title, tn DESC
+ }
+} {one-c one-a two-b two-a three-c three-a}
+do_test 3.3b {
+ db eval {
+ EXPLAIN QUERY PLAN
+ SELECT name FROM album JOIN track USING (aid) ORDER BY title, tn DESC
+ }
+} {/ORDER BY/} ;# separate sorting pass due to disabled optimization
+optimization_control db all 1
+db cache flush
+
+# Without the mixed ASC/DESC on ORDER BY
+#
+do_test 3.4a {
+ db eval {
+ SELECT name FROM album JOIN track USING (aid) ORDER BY title, tn
+ }
+} {one-a one-c two-a two-b three-a three-c}
+do_test 3.4b {
+ db eval {
+ SELECT name FROM album JOIN track USING (aid) ORDER BY +title, +tn
+ }
+} {one-a one-c two-a two-b three-a three-c} ;# verify same order after sorting
+do_test 3.4c {
+ db eval {
+ EXPLAIN QUERY PLAN
+ SELECT name FROM album JOIN track USING (aid) ORDER BY title, tn
+ }
+} {~/ORDER BY/} ;# ORDER BY suppressed by uniqueness constraints
+
+do_test 3.5a {
+ db eval {
+ SELECT name FROM album JOIN track USING (aid) ORDER BY title DESC, tn DESC
+ }
+} {three-c three-a two-b two-a one-c one-a}
+do_test 3.5b {
+ db eval {
+ SELECT name FROM album JOIN track USING (aid) ORDER BY +title DESC, +tn DESC
+ }
+} {three-c three-a two-b two-a one-c one-a} ;# verify same order after sorting
+do_test 3.5c {
+ db eval {
+ EXPLAIN QUERY PLAN
+ SELECT name FROM album JOIN track USING (aid) ORDER BY title DESC, tn DESC
+ }
+} {~/ORDER BY/} ;# ORDER BY suppressed by uniqueness constraints
+
+
+do_test 3.6a {
+ db eval {
+ SELECT name FROM album CROSS JOIN track USING (aid) ORDER BY title DESC, tn
+ }
+} {three-a three-c two-a two-b one-a one-c}
+do_test 3.6b {
+ db eval {
+ SELECT name FROM album CROSS JOIN track USING (aid)
+ ORDER BY +title DESC, +tn
+ }
+} {three-a three-c two-a two-b one-a one-c} ;# verify same order after sorting
+do_test 3.6c {
+ db eval {
+ EXPLAIN QUERY PLAN
+ SELECT name FROM album CROSS JOIN track USING (aid) ORDER BY title DESC, tn
+ }
+} {~/ORDER BY/} ;# inverted ASC/DESC is optimized out
+
+# Ticket 5ed1772895bf3deeab78c5e3519b1da9165c541b (2013-06-04)
+# Incorrect ORDER BY on an indexed JOIN
+#
+do_test 4.0 {
+ db eval {
+ CREATE TABLE t41(a INT UNIQUE NOT NULL, b INT NOT NULL);
+ CREATE INDEX t41ba ON t41(b,a);
+ CREATE TABLE t42(x INT NOT NULL REFERENCES t41(a), y INT NOT NULL);
+ CREATE UNIQUE INDEX t42xy ON t42(x,y);
+ INSERT INTO t41 VALUES(1,1),(3,1);
+ INSERT INTO t42 VALUES(1,13),(1,15),(3,14),(3,16);
+
+ SELECT b, y FROM t41 CROSS JOIN t42 ON x=a ORDER BY b, y;
+ }
+} {1 13 1 14 1 15 1 16}
+
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/orderby2.test b/lang/sql/sqlite/test/orderby2.test
new file mode 100644
index 00000000..cfd64771
--- /dev/null
+++ b/lang/sql/sqlite/test/orderby2.test
@@ -0,0 +1,117 @@
+# 2012 Sept 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 the optimizations that disable
+# ORDER BY clauses when the natural order of a query is correct.
+#
+
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set ::testprefix orderby2
+
+# Generate test data for a join. Verify that the join gets the
+# correct answer.
+#
+do_test 1.0 {
+ db eval {
+ CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
+ INSERT INTO t1 VALUES(1,11), (2,22);
+ CREATE TABLE t2(d, e, UNIQUE(d,e));
+ INSERT INTO t2 VALUES(10, 'ten'), (11,'eleven'), (12,'twelve'),
+ (11, 'oneteen');
+ }
+} {}
+
+do_test 1.1a {
+ db eval {
+ SELECT e FROM t1, t2 WHERE a=1 AND d=b ORDER BY d, e;
+ }
+} {eleven oneteen}
+do_test 1.1b {
+ db eval {
+ EXPLAIN QUERY PLAN
+ SELECT e FROM t1, t2 WHERE a=1 AND d=b ORDER BY d, e;
+ }
+} {~/ORDER BY/}
+
+do_test 1.2a {
+ db eval {
+ SELECT e FROM t1, t2 WHERE a=1 AND d=b ORDER BY e;
+ }
+} {eleven oneteen}
+do_test 1.2b {
+ db eval {
+ EXPLAIN QUERY PLAN
+ SELECT e FROM t1, t2 WHERE a=1 AND d=b ORDER BY e;
+ }
+} {~/ORDER BY/}
+
+do_test 1.3a {
+ db eval {
+ SELECT e, b FROM t1, t2 WHERE a=1 ORDER BY d, e;
+ }
+} {ten 11 eleven 11 oneteen 11 twelve 11}
+do_test 1.3b {
+ db eval {
+ EXPLAIN QUERY PLAN
+ SELECT e, b FROM t1, t2 WHERE a=1 ORDER BY d, e;
+ }
+} {~/ORDER BY/}
+
+# The following tests derived from TH3 test module cov1/where34.test
+#
+do_test 2.0 {
+ db eval {
+ CREATE TABLE t31(a,b); CREATE INDEX t31ab ON t31(a,b);
+ CREATE TABLE t32(c,d); CREATE INDEX t32cd ON t32(c,d);
+ CREATE TABLE t33(e,f); CREATE INDEX t33ef ON t33(e,f);
+ CREATE TABLE t34(g,h); CREATE INDEX t34gh ON t34(g,h);
+
+ INSERT INTO t31 VALUES(1,4), (2,3), (1,3);
+ INSERT INTO t32 VALUES(4,5), (3,6), (3,7), (4,8);
+ INSERT INTO t33 VALUES(5,9), (7,10), (6,11), (8,12), (8,13), (7,14);
+ INSERT INTO t34 VALUES(11,20), (10,21), (12,22), (9,23), (13,24),
+ (14,25), (12,26);
+ SELECT a||','||c||','||e||','||g FROM t31, t32, t33, t34
+ WHERE c=b AND e=d AND g=f
+ ORDER BY a ASC, c ASC, e DESC, g ASC;
+ }
+} {1,3,7,10 1,3,7,14 1,3,6,11 1,4,8,12 1,4,8,12 1,4,8,13 1,4,5,9 2,3,7,10 2,3,7,14 2,3,6,11}
+do_test 2.1 {
+ db eval {
+ SELECT a||','||c||','||e||','||g FROM t31, t32, t33, t34
+ WHERE c=b AND e=d AND g=f
+ ORDER BY +a ASC, +c ASC, +e DESC, +g ASC;
+ }
+} {1,3,7,10 1,3,7,14 1,3,6,11 1,4,8,12 1,4,8,12 1,4,8,13 1,4,5,9 2,3,7,10 2,3,7,14 2,3,6,11}
+do_test 2.2 {
+ db eval {
+ SELECT a||','||c||','||e||','||g FROM t31, t32, t33, t34
+ WHERE c=b AND e=d AND g=f
+ ORDER BY a ASC, c ASC, e ASC, g ASC;
+ }
+} {1,3,6,11 1,3,7,10 1,3,7,14 1,4,5,9 1,4,8,12 1,4,8,12 1,4,8,13 2,3,6,11 2,3,7,10 2,3,7,14}
+do_test 2.3 {
+ optimization_control db cover-idx-scan off
+ db cache flush
+ db eval {
+ SELECT a||','||c||','||e||','||g FROM t31, t32, t33, t34
+ WHERE c=b AND e=d AND g=f
+ ORDER BY a ASC, c ASC, e ASC, g ASC;
+ }
+} {1,3,6,11 1,3,7,10 1,3,7,14 1,4,5,9 1,4,8,12 1,4,8,12 1,4,8,13 2,3,6,11 2,3,7,10 2,3,7,14}
+optimization_control db all on
+db cache flush
+
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/orderby3.test b/lang/sql/sqlite/test/orderby3.test
new file mode 100644
index 00000000..f005f0d2
--- /dev/null
+++ b/lang/sql/sqlite/test/orderby3.test
@@ -0,0 +1,123 @@
+# 2013 January 09
+#
+# The author disclaims copyright to this source code. In place of
+# a legal notice, here is a blessing:
+#
+# May you 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 optimizations that disable
+# ORDER BY clauses work correctly on a 3-way join. See ticket
+# http://www.sqlite.org/src/956e4d7f89
+#
+
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set ::testprefix orderby3
+
+# Generate test data for a join. Verify that the join gets the
+# correct answer.
+#
+do_execsql_test 1.0 {
+ CREATE TABLE t1(a INTEGER PRIMARY KEY);
+ CREATE TABLE t2(b INTEGER PRIMARY KEY, c INTEGER);
+ CREATE TABLE t3(d INTEGER);
+
+ INSERT INTO t1 VALUES(1),(2),(3);
+
+ INSERT INTO t2 VALUES(3, 1);
+ INSERT INTO t2 VALUES(4, 2);
+ INSERT INTO t2 VALUES(5, 3);
+
+ INSERT INTO t3 VALUES(4),(3),(5);
+} {}
+do_execsql_test 1.1.asc {
+ SELECT t1.a
+ FROM t1, t2, t3
+ WHERE t1.a=t2.c AND t2.b=t3.d
+ ORDER BY t1.a;
+} {1 2 3}
+do_execsql_test 1.1.desc {
+ SELECT t1.a
+ FROM t1, t2, t3
+ WHERE t1.a=t2.c AND t2.b=t3.d
+ ORDER BY t1.a DESC;
+} {3 2 1}
+do_execsql_test 1.123.asc {
+ SELECT t1.a
+ FROM t1 CROSS JOIN t2 CROSS JOIN t3
+ WHERE t1.a=t2.c AND t2.b=t3.d
+ ORDER BY t1.a;
+} {1 2 3}
+do_execsql_test 1.123.desc {
+ SELECT t1.a
+ FROM t1 CROSS JOIN t2 CROSS JOIN t3
+ WHERE t1.a=t2.c AND t2.b=t3.d
+ ORDER BY t1.a DESC;
+} {3 2 1}
+do_execsql_test 1.132.asc {
+ SELECT t1.a
+ FROM t1 CROSS JOIN t3 CROSS JOIN t2
+ WHERE t1.a=t2.c AND t2.b=t3.d
+ ORDER BY t1.a;
+} {1 2 3}
+do_execsql_test 1.132.desc {
+ SELECT t1.a
+ FROM t1 CROSS JOIN t3 CROSS JOIN t2
+ WHERE t1.a=t2.c AND t2.b=t3.d
+ ORDER BY t1.a DESC;
+} {3 2 1}
+do_execsql_test 1.213.asc {
+ SELECT t1.a
+ FROM t2 CROSS JOIN t1 CROSS JOIN t3
+ WHERE t1.a=t2.c AND t2.b=t3.d
+ ORDER BY t1.a;
+} {1 2 3}
+do_execsql_test 1.213.desc {
+ SELECT t1.a
+ FROM t2 CROSS JOIN t1 CROSS JOIN t3
+ WHERE t1.a=t2.c AND t2.b=t3.d
+ ORDER BY t1.a DESC;
+} {3 2 1}
+do_execsql_test 1.231.asc {
+ SELECT t1.a
+ FROM t2 CROSS JOIN t3 CROSS JOIN t1
+ WHERE t1.a=t2.c AND t2.b=t3.d
+ ORDER BY t1.a;
+} {1 2 3}
+do_execsql_test 1.231.desc {
+ SELECT t1.a
+ FROM t2 CROSS JOIN t3 CROSS JOIN t1
+ WHERE t1.a=t2.c AND t2.b=t3.d
+ ORDER BY t1.a DESC;
+} {3 2 1}
+do_execsql_test 1.312.asc {
+ SELECT t1.a
+ FROM t3 CROSS JOIN t1 CROSS JOIN t2
+ WHERE t1.a=t2.c AND t2.b=t3.d
+ ORDER BY t1.a;
+} {1 2 3}
+do_execsql_test 1.312.desc {
+ SELECT t1.a
+ FROM t3 CROSS JOIN t1 CROSS JOIN t2
+ WHERE t1.a=t2.c AND t2.b=t3.d
+ ORDER BY t1.a DESC;
+} {3 2 1}
+do_execsql_test 1.321.asc {
+ SELECT t1.a
+ FROM t3 CROSS JOIN t2 CROSS JOIN t1
+ WHERE t1.a=t2.c AND t2.b=t3.d
+ ORDER BY t1.a;
+} {1 2 3}
+do_execsql_test 1.321.desc {
+ SELECT t1.a
+ FROM t3 CROSS JOIN t2 CROSS JOIN t1
+ WHERE t1.a=t2.c AND t2.b=t3.d
+ ORDER BY t1.a DESC;
+} {3 2 1}
+
+finish_test
diff --git a/lang/sql/sqlite/test/orderby4.test b/lang/sql/sqlite/test/orderby4.test
new file mode 100644
index 00000000..ec6eb041
--- /dev/null
+++ b/lang/sql/sqlite/test/orderby4.test
@@ -0,0 +1,56 @@
+# 2013 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 file is testing that the optimizations that disable
+# ORDER BY clauses work correctly on multi-value primary keys and
+# unique indices when only some prefix of the terms in the key are
+# used. See ticket http://www.sqlite.org/src/info/a179fe74659
+#
+
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set ::testprefix orderby4
+
+# Generate test data for a join. Verify that the join gets the
+# correct answer.
+#
+do_execsql_test 1.1 {
+ CREATE TABLE t1(a, b, PRIMARY KEY(a,b));
+ INSERT INTO t1 VALUES(1,1),(1,2);
+ CREATE TABLE t2(x, y, PRIMARY KEY(x,y));
+ INSERT INTO t2 VALUES(3,3),(4,4);
+ SELECT a, x FROM t1, t2 ORDER BY 1, 2;
+} {1 3 1 3 1 4 1 4}
+do_execsql_test 1.2 {
+ SELECT a, x FROM t1 CROSS JOIN t2 ORDER BY 1, 2;
+} {1 3 1 3 1 4 1 4}
+do_execsql_test 1.3 {
+ SELECT a, x FROM t2 CROSS JOIN t1 ORDER BY 1, 2;
+} {1 3 1 3 1 4 1 4}
+
+do_execsql_test 2.1 {
+ CREATE TABLE t3(a);
+ INSERT INTO t3 VALUES(1),(1);
+ CREATE INDEX t3a ON t3(a);
+ CREATE TABLE t4(x);
+ INSERT INTO t4 VALUES(3),(4);
+ CREATE INDEX t4x ON t4(x);
+ SELECT a, x FROM t3, t4 ORDER BY 1, 2;
+} {1 3 1 3 1 4 1 4}
+do_execsql_test 2.2 {
+ SELECT a, x FROM t3 CROSS JOIN t4 ORDER BY 1, 2;
+} {1 3 1 3 1 4 1 4}
+do_execsql_test 2.3 {
+ SELECT a, x FROM t4 CROSS JOIN t3 ORDER BY 1, 2;
+} {1 3 1 3 1 4 1 4}
+
+finish_test
diff --git a/lang/sql/sqlite/test/orderby5.test b/lang/sql/sqlite/test/orderby5.test
new file mode 100644
index 00000000..6da0dd4e
--- /dev/null
+++ b/lang/sql/sqlite/test/orderby5.test
@@ -0,0 +1,112 @@
+# 2013-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 file implements regression tests for SQLite library. The
+# focus of this file is testing that the optimizations that disable
+# ORDER BY clauses work correctly
+#
+
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set ::testprefix orderby5
+
+# Generate test data for a join. Verify that the join gets the
+# correct answer.
+#
+do_execsql_test 1.1 {
+ CREATE TABLE t1(a,b,c);
+ CREATE INDEX t1bc ON t1(b,c);
+
+ EXPLAIN QUERY PLAN
+ SELECT DISTINCT a, b, c FROM t1 WHERE a=0;
+} {~/B-TREE/}
+do_execsql_test 1.2.1 {
+ EXPLAIN QUERY PLAN
+ SELECT DISTINCT a, c, b FROM t1 WHERE a=0;
+} {~/B-TREE/}
+do_execsql_test 1.2.2 {
+ EXPLAIN QUERY PLAN
+ SELECT DISTINCT a, c, b FROM t1 WHERE a='xyz' COLLATE nocase;
+} {/B-TREE/}
+do_execsql_test 1.2.3 {
+ EXPLAIN QUERY PLAN
+ SELECT DISTINCT a COLLATE nocase, c, b FROM t1 WHERE a='xyz';
+} {/B-TREE/}
+do_execsql_test 1.2.4 {
+ EXPLAIN QUERY PLAN
+ SELECT DISTINCT a COLLATE nocase, c, b FROM t1 WHERE a='xyz' COLLATE nocase;
+} {~/B-TREE/}
+do_execsql_test 1.3 {
+ EXPLAIN QUERY PLAN
+ SELECT DISTINCT b, a, c FROM t1 WHERE a=0;
+} {~/B-TREE/}
+do_execsql_test 1.4 {
+ EXPLAIN QUERY PLAN
+ SELECT DISTINCT b, c, a FROM t1 WHERE a=0;
+} {~/B-TREE/}
+do_execsql_test 1.5 {
+ EXPLAIN QUERY PLAN
+ SELECT DISTINCT c, a, b FROM t1 WHERE a=0;
+} {~/B-TREE/}
+do_execsql_test 1.6 {
+ EXPLAIN QUERY PLAN
+ SELECT DISTINCT c, b, a FROM t1 WHERE a=0;
+} {~/B-TREE/}
+do_execsql_test 1.7 {
+ EXPLAIN QUERY PLAN
+ SELECT DISTINCT c, b, a FROM t1 WHERE +a=0;
+} {/B-TREE/}
+do_execsql_test 2.1 {
+ EXPLAIN QUERY PLAN
+ SELECT * FROM t1 WHERE a=0 ORDER BY a, b, c;
+} {~/B-TREE/}
+do_execsql_test 2.2 {
+ EXPLAIN QUERY PLAN
+ SELECT * FROM t1 WHERE +a=0 ORDER BY a, b, c;
+} {/B-TREE/}
+do_execsql_test 2.3 {
+ EXPLAIN QUERY PLAN
+ SELECT * FROM t1 WHERE a=0 ORDER BY b, a, c;
+} {~/B-TREE/}
+do_execsql_test 2.4 {
+ EXPLAIN QUERY PLAN
+ SELECT * FROM t1 WHERE a=0 ORDER BY b, c, a;
+} {~/B-TREE/}
+do_execsql_test 2.5 {
+ EXPLAIN QUERY PLAN
+ SELECT * FROM t1 WHERE a=0 ORDER BY a, c, b;
+} {/B-TREE/}
+do_execsql_test 2.6 {
+ EXPLAIN QUERY PLAN
+ SELECT * FROM t1 WHERE a=0 ORDER BY c, a, b;
+} {/B-TREE/}
+do_execsql_test 2.7 {
+ EXPLAIN QUERY PLAN
+ SELECT * FROM t1 WHERE a=0 ORDER BY c, b, a;
+} {/B-TREE/}
+
+
+do_execsql_test 3.0 {
+ CREATE TABLE t3(a INTEGER PRIMARY KEY, b, c, d, e, f);
+ CREATE INDEX t3bcde ON t3(b, c, d, e);
+ EXPLAIN QUERY PLAN
+ SELECT a FROM t3 WHERE b=2 AND c=3 ORDER BY d DESC, e DESC, b, c, a DESC;
+} {~/B-TREE/}
+do_execsql_test 3.1 {
+ DROP TABLE t3;
+ CREATE TABLE t3(a INTEGER PRIMARY KEY, b, c, d, e, f) WITHOUT rowid;
+ CREATE INDEX t3bcde ON t3(b, c, d, e);
+ EXPLAIN QUERY PLAN
+ SELECT a FROM t3 WHERE b=2 AND c=3 ORDER BY d DESC, e DESC, b, c, a DESC;
+} {~/B-TREE/}
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/oserror.test b/lang/sql/sqlite/test/oserror.test
index 2d3a24a8..40d2966b 100644
--- a/lang/sql/sqlite/test/oserror.test
+++ b/lang/sql/sqlite/test/oserror.test
@@ -51,6 +51,7 @@ proc do_re_test {tn script expression} {
# a call to getcwd() may fail if there are no free file descriptors. So
# an error may be reported for either open() or getcwd() here.
#
+puts "Possible valgrind error about invalid file descriptor follows:"
do_test 1.1.1 {
set ::log [list]
list [catch {
@@ -96,23 +97,25 @@ do_re_test 1.4.2 { lindex $::log 0 } {^os_unix.c:\d*: \(\d+\) open\(.*test.db\)
#--------------------------------------------------------------------------
# Tests oserror-1.* test failures in the unlink() system call.
#
-do_test 2.1.1 {
- set ::log [list]
- file mkdir test.db-wal
- forcedelete test.db
- list [catch {
- sqlite3 dbh test.db
- execsql { SELECT * FROM sqlite_master } dbh
- } msg] $msg
-} {1 {disk I/O error}}
-
-do_re_test 2.1.2 {
- lindex $::log 0
-} {^os_unix.c:\d+: \(\d+\) unlink\(.*test.db-wal\) - }
-do_test 2.1.3 {
- catch { dbh close }
- forcedelete test.db-wal
-} {}
+ifcapable wal {
+ do_test 2.1.1 {
+ set ::log [list]
+ file mkdir test.db-wal
+ forcedelete test.db
+ list [catch {
+ sqlite3 dbh test.db
+ execsql { SELECT * FROM sqlite_master } dbh
+ } msg] $msg
+ } {1 {disk I/O error}}
+
+ do_re_test 2.1.2 {
+ lindex $::log 0
+ } {^os_unix.c:\d+: \(\d+\) unlink\(.*test.db-wal\) - }
+ do_test 2.1.3 {
+ catch { dbh close }
+ forcedelete test.db-wal
+ } {}
+}
test_syscall reset
diff --git a/lang/sql/sqlite/test/pager1.test b/lang/sql/sqlite/test/pager1.test
index 8c31e153..005b3560 100644
--- a/lang/sql/sqlite/test/pager1.test
+++ b/lang/sql/sqlite/test/pager1.test
@@ -15,6 +15,7 @@ source $testdir/tester.tcl
source $testdir/lock_common.tcl
source $testdir/malloc_common.tcl
source $testdir/wal_common.tcl
+set testprefix pager1
# 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).
@@ -54,6 +55,8 @@ do_not_use_codec
# pager1-16.*: Varying sqlite3_vfs.mxPathname
#
# pager1-17.*: Tests related to "PRAGMA omit_readlock"
+# (The omit_readlock pragma has been removed and so have
+# these tests.)
#
# pager1-18.*: Test that the pager layer responds correctly if the b-tree
# requests an invalid page number (due to db corruption).
@@ -268,7 +271,7 @@ do_execsql_test pager1-3.1.2 {
} {3 0}
do_catchsql_test pager1-3.1.3 {
INSERT INTO t1 SELECT a+3, randomblob(1500) FROM t1
-} {1 {constraint failed}}
+} {1 {CHECK constraint failed: counter}}
do_execsql_test pager1-3.4 { SELECT * FROM counter } {3 0}
do_execsql_test pager1-3.5 { SELECT a FROM t1 } {1 2 3}
do_execsql_test pager1-3.6 { COMMIT } {}
@@ -441,6 +444,8 @@ do_test pager1.4.2.1 {
db close
tstvfs delete
} {}
+
+if {$::tcl_platform(platform)!="windows"} {
do_test pager1.4.2.2 {
faultsim_restore_and_reopen
execsql {
@@ -450,7 +455,7 @@ do_test pager1.4.2.2 {
} {4 ok}
do_test pager1.4.2.3 {
faultsim_restore_and_reopen
- foreach f [glob test.db-mj*] { file delete -force $f }
+ foreach f [glob test.db-mj*] { forcedelete $f }
execsql {
SELECT count(*) FROM t1;
PRAGMA integrity_check;
@@ -458,7 +463,7 @@ do_test pager1.4.2.3 {
} {64 ok}
do_test pager1.4.2.4 {
faultsim_restore_and_reopen
- hexio_write test.db-journal [expr [file size test.db-journal]-20] 123456
+ hexio_write test.db-journal [expr [file size test.db-journal]-30] 123456
execsql {
SELECT count(*) FROM t1;
PRAGMA integrity_check;
@@ -466,13 +471,14 @@ do_test pager1.4.2.4 {
} {4 ok}
do_test pager1.4.2.5 {
faultsim_restore_and_reopen
- hexio_write test.db-journal [expr [file size test.db-journal]-20] 123456
- foreach f [glob test.db-mj*] { file delete -force $f }
+ hexio_write test.db-journal [expr [file size test.db-journal]-30] 123456
+ foreach f [glob test.db-mj*] { forcedelete $f }
execsql {
SELECT count(*) FROM t1;
PRAGMA integrity_check;
}
} {4 ok}
+}
do_test pager1.4.3.1 {
testvfs tstvfs -default 1
@@ -519,18 +525,27 @@ db close
# file-system is saved just before the xDelete() call to remove the
# master journal file from the file-system.
#
+set pwd [get_pwd]
testvfs tv -default 1
tv script copy_on_mj_delete
set ::mj_filename_length 0
proc copy_on_mj_delete {method filename args} {
if {[string match *mj* [file tail $filename]]} {
- set ::mj_filename_length [string length $filename]
+ #
+ # NOTE: Is the file name relative? If so, add the length of the current
+ # directory.
+ #
+ if {[is_relative_file $filename]} {
+ set ::mj_filename_length \
+ [expr {[string length $filename] + [string length $::pwd]}]
+ } else {
+ set ::mj_filename_length [string length $filename]
+ }
faultsim_save
}
return SQLITE_OK
}
-set pwd [pwd]
foreach {tn1 tcl} {
1 { set prefix "test.db" }
2 {
@@ -646,7 +661,7 @@ foreach {tn1 tcl} {
#
do_test pager1-4.4.$tn.7 {
faultsim_restore_and_reopen $prefix
- foreach f [glob ${prefix}-mj*] { file delete -force $f }
+ foreach f [glob ${prefix}-mj*] { forcedelete $f }
execsql "ATTACH '${prefix}2' AS aux"
} {}
do_execsql_test pager1-4.4.$tn.8 {
@@ -661,7 +676,7 @@ foreach {tn1 tcl} {
}
db close
tv delete
-file delete -force $dirname
+forcedelete $dirname
# Set up a VFS to make a copy of the file-system just before deleting a
@@ -738,7 +753,7 @@ sqlite3 db test.db -readonly 1
do_catchsql_test pager1.4.5.6 {
SELECT * FROM t1;
SELECT * FROM t2;
-} {1 {disk I/O error}}
+} {1 {attempt to write a readonly database}}
db close
# Snapshot the file-system just before multi-file commit. Save the name
@@ -869,19 +884,45 @@ do_execsql_test pager1.4.7.1 {
tv filter {}
db close
tv delete
+catch {
+ test_syscall install fchmod
+ test_syscall fault 1 1
+}
do_test pager1.4.7.2 {
faultsim_restore_and_reopen
catch {file attributes test.db-journal -permissions r--------}
catch {file attributes test.db-journal -readonly 1}
catchsql { SELECT * FROM t1 }
} {1 {unable to open database file}}
+catch {
+ test_syscall reset
+ test_syscall fault 0 0
+}
do_test pager1.4.7.3 {
db close
catch {file attributes test.db-journal -permissions rw-rw-rw-}
catch {file attributes test.db-journal -readonly 0}
- file delete test.db-journal
+ delete_file test.db-journal
file exists test.db-journal
} {0}
+do_test pager1.4.8.1 {
+ catch {file attributes test.db -permissions r--------}
+ catch {file attributes test.db -readonly 1}
+ sqlite3 db test.db
+ db eval { SELECT * FROM t1 }
+ sqlite3_db_readonly db main
+} {1}
+do_test pager1.4.8.2 {
+ sqlite3_db_readonly db xyz
+} {-1}
+do_test pager1.4.8.3 {
+ db close
+ catch {file attributes test.db -readonly 0}
+ catch {file attributes test.db -permissions rw-rw-rw-} msg
+ sqlite3 db test.db
+ db eval { SELECT * FROM t1 }
+ sqlite3_db_readonly db main
+} {0}
#-------------------------------------------------------------------------
# The following tests deal with multi-file commits.
@@ -987,8 +1028,28 @@ do_test pager1-5.4.1 {
INSERT INTO t2 VALUES(85, 'Gorbachev');
COMMIT;
}
- set ::max_journal
-} [expr 2615+[string length [pwd]]]
+
+ # The size of the journal file is now:
+ #
+ # 1) 512 byte header +
+ # 2) 2 * (1024+8) byte records +
+ # 3) 20+N bytes of master-journal pointer, where N is the size of
+ # the master-journal name encoded as utf-8 with no nul term.
+ #
+ set mj_pointer [expr {
+ 20 + [string length "test.db-mjXXXXXX9XX"]
+ }]
+ #
+ # NOTE: For item 3 above, if the current SQLite VFS lacks the concept of a
+ # current directory, the length of the current directory name plus 1
+ # character for the directory separator character are NOT counted as
+ # part of the total size; otherwise, they are.
+ #
+ ifcapable curdir {
+ set mj_pointer [expr {$mj_pointer + [string length [get_pwd]] + 1}]
+ }
+ expr {$::max_journal==(512+2*(1024+8)+$mj_pointer)}
+} 1
do_test pager1-5.4.2 {
set ::max_journal 0
execsql {
@@ -998,8 +1059,25 @@ do_test pager1-5.4.2 {
DELETE FROM t2 WHERE b = 'Lenin';
COMMIT;
}
- set ::max_journal
-} [expr 3111+[string length [pwd]]]
+
+ # In synchronous=full mode, the master-journal pointer is not written
+ # directly after the last record in the journal file. Instead, it is
+ # written starting at the next (in this case 512 byte) sector boundary.
+ #
+ set mj_pointer [expr {
+ 20 + [string length "test.db-mjXXXXXX9XX"]
+ }]
+ #
+ # NOTE: If the current SQLite VFS lacks the concept of a current directory,
+ # the length of the current directory name plus 1 character for the
+ # directory separator character are NOT counted as part of the total
+ # size; otherwise, they are.
+ #
+ ifcapable curdir {
+ set mj_pointer [expr {$mj_pointer + [string length [get_pwd]] + 1}]
+ }
+ expr {$::max_journal==(((512+2*(1024+8)+511)/512)*512 + $mj_pointer)}
+} 1
db close
tv delete
@@ -1296,7 +1374,7 @@ do_test pager1-9.4.1 {
} {SQLITE_DONE SQLITE_OK}
do_test pager1-9.4.2 {
list [file size test.db2] [file size test.db]
-} {0 0}
+} {1024 0}
db2 close
#-------------------------------------------------------------------------
@@ -1305,10 +1383,12 @@ db2 close
#
testvfs tv -default 1
foreach sectorsize {
+ 16
32 64 128 256 512 1024 2048
4096 8192 16384 32768 65536 131072 262144
} {
tv sectorsize $sectorsize
+ tv devchar {}
set eff $sectorsize
if {$sectorsize < 512} { set eff 512 }
if {$sectorsize > 65536} { set eff 65536 }
@@ -1326,7 +1406,7 @@ foreach sectorsize {
COMMIT;
}
file size test.db-journal
- } [expr $sectorsize > 65536 ? 65536 : $sectorsize]
+ } [expr $sectorsize > 65536 ? 65536 : ($sectorsize<32 ? 512 : $sectorsize)]
do_test pager1-10.$sectorsize.2 {
execsql {
@@ -1548,6 +1628,7 @@ do_execsql_test pager1-13.1.1 {
UPDATE t1 SET b = a_string(400);
} {persist}
+if {$::tcl_platform(platform)!="windows"} {
# Run transactions of increasing sizes. Eventually, one (or more than one)
# of these will write just enough content that one of the old headers created
# by the transaction in the block above lies immediately after the content
@@ -1570,7 +1651,9 @@ for {set nUp 1} {$nUp<64} {incr nUp} {
} {ok}
db2 close
}
+}
+if {$::tcl_platform(platform)!="windows"} {
# Same test as above. But this time with an index on the table.
#
do_execsql_test pager1-13.2.1 {
@@ -1591,6 +1674,7 @@ for {set nUp 1} {$nUp<64} {incr nUp} {
} {ok}
db2 close
}
+}
db close
tv delete
@@ -1619,7 +1703,7 @@ do_catchsql_test pager1-14.1.4 {
BEGIN;
INSERT INTO t1(rowid, a, b) SELECT a+3, b, b FROM t1;
INSERT INTO t1(rowid, a, b) SELECT a+3, b, b FROM t1;
-} {1 {PRIMARY KEY must be unique}}
+} {1 {UNIQUE constraint failed: t1.rowid}}
do_execsql_test pager1-14.1.5 {
COMMIT;
SELECT * FROM t1;
@@ -1653,7 +1737,7 @@ for {set i 0} {$i<513} {incr i 3} {
testvfs tv -default 1
tv script xOpenCb
tv filter xOpen
-proc xOpenCb {method filename} {
+proc xOpenCb {method filename args} {
set ::file_len [string length $filename]
}
sqlite3 db test.db
@@ -1681,75 +1765,6 @@ for {set ii [expr $::file_len-5]} {$ii < [expr $::file_len+20]} {incr ii} {
tv delete
}
-#-------------------------------------------------------------------------
-# Test "PRAGMA omit_readlock".
-#
-# pager1-17.$tn.1.*: Test that if a second connection has an open
-# read-transaction, it is not usually possible to write
-# the database.
-#
-# pager1-17.$tn.2.*: Test that if the second connection was opened with
-# the SQLITE_OPEN_READONLY flag, and
-# "PRAGMA omit_readlock = 1" is executed before attaching
-# the database and opening a read-transaction on it, it is
-# possible to write the db.
-#
-# pager1-17.$tn.3.*: Test that if the second connection was *not* opened with
-# the SQLITE_OPEN_READONLY flag, executing
-# "PRAGMA omit_readlock = 1" has no effect.
-#
-do_multiclient_test tn {
- do_test pager1-17.$tn.1.1 {
- sql1 {
- CREATE TABLE t1(a, b);
- INSERT INTO t1 VALUES(1, 2);
- }
- sql2 {
- BEGIN;
- SELECT * FROM t1;
- }
- } {1 2}
- do_test pager1-17.$tn.1.2 {
- csql1 { INSERT INTO t1 VALUES(3, 4) }
- } {1 {database is locked}}
- do_test pager1-17.$tn.1.3 {
- sql2 { COMMIT }
- sql1 { INSERT INTO t1 VALUES(3, 4) }
- } {}
-
- do_test pager1-17.$tn.2.1 {
- code2 {
- db2 close
- sqlite3 db2 :memory: -readonly 1
- }
- sql2 {
- PRAGMA omit_readlock = 1;
- ATTACH 'test.db' AS two;
- BEGIN;
- SELECT * FROM t1;
- }
- } {1 2 3 4}
- do_test pager1-17.$tn.2.2 { sql1 "INSERT INTO t1 VALUES(5, 6)" } {}
- do_test pager1-17.$tn.2.3 { sql2 "SELECT * FROM t1" } {1 2 3 4}
- do_test pager1-17.$tn.2.4 { sql2 "COMMIT ; SELECT * FROM t1" } {1 2 3 4 5 6}
-
- do_test pager1-17.$tn.3.1 {
- code2 {
- db2 close
- sqlite3 db2 :memory:
- }
- sql2 {
- PRAGMA omit_readlock = 1;
- ATTACH 'test.db' AS two;
- BEGIN;
- SELECT * FROM t1;
- }
- } {1 2 3 4 5 6}
- do_test pager1-17.$tn.3.2 {
- csql1 { INSERT INTO t1 VALUES(3, 4) }
- } {1 {database is locked}}
- do_test pager1-17.$tn.3.3 { sql2 COMMIT } {}
-}
#-------------------------------------------------------------------------
# Test the pagers response to the b-tree layer requesting illegal page
@@ -1759,6 +1774,10 @@ do_multiclient_test tn {
# + Page 0,
# + A page with a page number greater than (2^31-1).
#
+# These tests will not work if SQLITE_DIRECT_OVERFLOW_READ is defined. In
+# that case IO errors are sometimes reported instead of SQLITE_CORRUPT.
+#
+ifcapable !direct_read {
do_test pager1-18.1 {
faultsim_delete_and_reopen
db func a_string a_string
@@ -1786,7 +1805,7 @@ do_test pager1-18.2 {
catchsql { SELECT count(*) FROM t1 } db2
} {1 {database disk image is malformed}}
db2 close
-do_test pager1-18.3 {
+do_test pager1-18.3.1 {
execsql {
CREATE TABLE t2(x);
INSERT INTO t2 VALUES(a_string(5000));
@@ -1794,13 +1813,38 @@ do_test pager1-18.3 {
set pgno [expr ([file size test.db] / 1024)-2]
hexio_write test.db [expr ($pgno-1)*1024] 00000000
sqlite3 db2 test.db
- catchsql { SELECT length(x) FROM t2 } db2
+ # even though x is malformed, because typeof() does
+ # not load the content of x, the error is not noticed.
+ catchsql { SELECT typeof(x) FROM t2 } db2
+} {0 text}
+do_test pager1-18.3.2 {
+ # in this case, the value of x is loaded and so the error is
+ # detected
+ catchsql { SELECT length(x||'') FROM t2 } db2
+} {1 {database disk image is malformed}}
+db2 close
+do_test pager1-18.3.3 {
+ execsql {
+ DELETE FROM t2;
+ INSERT INTO t2 VALUES(randomblob(5000));
+ }
+ set pgno [expr ([file size test.db] / 1024)-2]
+ hexio_write test.db [expr ($pgno-1)*1024] 00000000
+ sqlite3 db2 test.db
+ # even though x is malformed, because length() and typeof() do
+ # not load the content of x, the error is not noticed.
+ catchsql { SELECT length(x), typeof(x) FROM t2 } db2
+} {0 {5000 blob}}
+do_test pager1-18.3.4 {
+ # in this case, the value of x is loaded and so the error is
+ # detected
+ catchsql { SELECT length(x||'') FROM t2 } db2
} {1 {database disk image is malformed}}
db2 close
do_test pager1-18.4 {
hexio_write test.db [expr ($pgno-1)*1024] 90000000
sqlite3 db2 test.db
- catchsql { SELECT length(x) FROM t2 } db2
+ catchsql { SELECT length(x||'') FROM t2 } db2
} {1 {database disk image is malformed}}
db2 close
do_test pager1-18.5 {
@@ -1834,6 +1878,7 @@ do_test pager1-18.6 {
sqlite3 db test.db
catchsql { SELECT length(x) FROM t1 }
} {1 {database disk image is malformed}}
+}
do_test pager1-19.1 {
sqlite3 db ""
@@ -1985,31 +2030,33 @@ ifcapable wal {
# pager1-22.1.*: is a no-op on a non-WAL db, and
# pager1-22.2.*: does not cause xSync calls with a synchronous=off db.
#
-do_test pager1-22.1.1 {
- faultsim_delete_and_reopen
- execsql {
- CREATE TABLE ko(c DEFAULT 'abc', b DEFAULT 'def');
- INSERT INTO ko DEFAULT VALUES;
- }
- execsql { PRAGMA wal_checkpoint }
-} {0 -1 -1}
-do_test pager1-22.2.1 {
- testvfs tv -default 1
- tv filter xSync
- tv script xSyncCb
- proc xSyncCb {args} {incr ::synccount}
- set ::synccount 0
- sqlite3 db test.db
- execsql {
- PRAGMA synchronous = off;
- PRAGMA journal_mode = WAL;
- INSERT INTO ko DEFAULT VALUES;
- }
- execsql { PRAGMA wal_checkpoint }
- set synccount
-} {0}
-db close
-tv delete
+ifcapable wal {
+ do_test pager1-22.1.1 {
+ faultsim_delete_and_reopen
+ execsql {
+ CREATE TABLE ko(c DEFAULT 'abc', b DEFAULT 'def');
+ INSERT INTO ko DEFAULT VALUES;
+ }
+ execsql { PRAGMA wal_checkpoint }
+ } {0 -1 -1}
+ do_test pager1-22.2.1 {
+ testvfs tv -default 1
+ tv filter xSync
+ tv script xSyncCb
+ proc xSyncCb {args} {incr ::synccount}
+ set ::synccount 0
+ sqlite3 db test.db
+ execsql {
+ PRAGMA synchronous = off;
+ PRAGMA journal_mode = WAL;
+ INSERT INTO ko DEFAULT VALUES;
+ }
+ execsql { PRAGMA wal_checkpoint }
+ set synccount
+ } {0}
+ db close
+ tv delete
+}
#-------------------------------------------------------------------------
# Tests for changing journal mode.
@@ -2198,7 +2245,6 @@ do_test pager1-25-1 {
}
db close
} {}
-breakpoint
do_test pager1-25-2 {
faultsim_delete_and_reopen
execsql {
@@ -2361,8 +2407,8 @@ do_test pager1-29.2 {
#
do_test pager1-30.1 {
db close
- file delete test.db
- file delete test.db-journal
+ delete_file test.db
+ delete_file test.db-journal
set fd [open test.db-journal w]
seek $fd [expr 512+1032*2]
puts -nonewline $fd x
@@ -2381,6 +2427,7 @@ do_test pager1-30.1 {
# file can still be rolled back. This is required for backward compatibility -
# versions of SQLite prior to 3.5.8 always set this field to zero.
#
+if {$tcl_platform(platform)=="unix"} {
do_test pager1-31.1 {
faultsim_delete_and_reopen
execsql {
@@ -2401,14 +2448,370 @@ do_test pager1-31.1 {
BEGIN;
UPDATE t1 SET y = randomblob(1499);
}
- file copy test.db test.db2
- file copy test.db-journal test.db2-journal
+ copy_file test.db test.db2
+ copy_file test.db-journal test.db2-journal
hexio_write test.db2-journal 24 00000000
sqlite3 db2 test.db2
execsql { PRAGMA integrity_check } db2
} {ok}
+}
+
+#-------------------------------------------------------------------------
+# Test that a database file can be "pre-hinted" to a certain size and that
+# subsequent spilling of the pager cache does not result in the database
+# file being shrunk.
+#
+catch {db close}
+forcedelete test.db
+
+do_test pager1-32.1 {
+ sqlite3 db test.db
+ execsql {
+ CREATE TABLE t1(x, y);
+ }
+ db close
+ sqlite3 db test.db
+ execsql {
+ BEGIN;
+ INSERT INTO t1 VALUES(1, randomblob(10000));
+ }
+ file_control_chunksize_test db main 1024
+ file_control_sizehint_test db main 20971520; # 20MB
+ execsql {
+ PRAGMA cache_size = 10;
+ INSERT INTO t1 VALUES(1, randomblob(10000));
+ INSERT INTO t1 VALUES(2, randomblob(10000));
+ INSERT INTO t1 SELECT x+2, randomblob(10000) from t1;
+ INSERT INTO t1 SELECT x+4, randomblob(10000) from t1;
+ INSERT INTO t1 SELECT x+8, randomblob(10000) from t1;
+ INSERT INTO t1 SELECT x+16, randomblob(10000) from t1;
+ SELECT count(*) FROM t1;
+ COMMIT;
+ }
+ db close
+ file size test.db
+} {20971520}
+
+# Cleanup 20MB file left by the previous test.
+forcedelete test.db
+
+#-------------------------------------------------------------------------
+# Test that if a transaction is committed in journal_mode=DELETE mode,
+# and the call to unlink() returns an ENOENT error, the COMMIT does not
+# succeed.
+#
+if {$::tcl_platform(platform)=="unix"} {
+ do_test pager1-33.1 {
+ sqlite3 db test.db
+ execsql {
+ CREATE TABLE t1(x);
+ INSERT INTO t1 VALUES('one');
+ INSERT INTO t1 VALUES('two');
+ BEGIN;
+ INSERT INTO t1 VALUES('three');
+ INSERT INTO t1 VALUES('four');
+ }
+ forcedelete bak-journal
+ file rename test.db-journal bak-journal
+
+ catchsql COMMIT
+ } {1 {disk I/O error}}
+
+ do_test pager1-33.2 {
+ file rename bak-journal test.db-journal
+ execsql { SELECT * FROM t1 }
+ } {one two}
+}
+
+#-------------------------------------------------------------------------
+# Test that appending pages to the database file then moving those pages
+# to the free-list before the transaction is committed does not cause
+# an error.
+#
+foreach {tn pragma strsize} {
+ 1 { PRAGMA mmap_size = 0 } 2400
+ 2 { } 2400
+ 3 { PRAGMA mmap_size = 0 } 4400
+ 4 { } 4400
+} {
+ reset_db
+ db func a_string a_string
+ db eval $pragma
+ do_execsql_test 34.$tn.1 {
+ CREATE TABLE t1(a, b);
+ INSERT INTO t1 VALUES(1, 2);
+ }
+ do_execsql_test 34.$tn.2 {
+ BEGIN;
+ INSERT INTO t1 VALUES(2, a_string($strsize));
+ DELETE FROM t1 WHERE oid=2;
+ COMMIT;
+ PRAGMA integrity_check;
+ } {ok}
+}
+
+#-------------------------------------------------------------------------
+#
+reset_db
+do_test 35 {
+ sqlite3 db test.db
+
+ execsql {
+ CREATE TABLE t1(x, y);
+ PRAGMA journal_mode = WAL;
+ INSERT INTO t1 VALUES(1, 2);
+ }
+
+ execsql {
+ BEGIN;
+ CREATE TABLE t2(a, b);
+ }
+
+ hexio_write test.db-shm [expr 16*1024] [string repeat 0055 8192]
+ catchsql ROLLBACK
+} {0 {}}
+
+do_multiclient_test tn {
+ sql1 {
+ PRAGMA auto_vacuum = 0;
+ CREATE TABLE t1(x, y);
+ INSERT INTO t1 VALUES(1, 2);
+ }
+
+ do_test 36.$tn.1 {
+ sql2 { PRAGMA max_page_count = 2 }
+ list [catch { sql2 { CREATE TABLE t2(x) } } msg] $msg
+ } {1 {database or disk is full}}
+
+ sql1 { PRAGMA checkpoint_fullfsync = 1 }
+ sql1 { CREATE TABLE t2(x) }
+
+ do_test 36.$tn.2 {
+ sql2 { INSERT INTO t2 VALUES('xyz') }
+ list [catch { sql2 { CREATE TABLE t3(x) } } msg] $msg
+ } {1 {database or disk is full}}
+}
+
+forcedelete test1 test2
+foreach {tn uri} {
+ 1 {file:?mode=memory&cache=shared}
+ 2 {file:one?mode=memory&cache=shared}
+ 3 {file:test1?cache=shared}
+ 4 {file:test2?another=parameter&yet=anotherone}
+} {
+ do_test 37.$tn {
+ catch { db close }
+ sqlite3_shutdown
+ sqlite3_config_uri 1
+ sqlite3 db $uri
+
+ db eval {
+ CREATE TABLE t1(x);
+ INSERT INTO t1 VALUES(1);
+ SELECT * FROM t1;
+ }
+ } {1}
+
+ do_execsql_test 37.$tn.2 {
+ VACUUM;
+ SELECT * FROM t1;
+ } {1}
+
+ db close
+ sqlite3_shutdown
+ sqlite3_config_uri 0
+}
+
+do_test 38.1 {
+ catch { db close }
+ forcedelete test.db
+ set fd [open test.db w]
+ puts $fd "hello world"
+ close $fd
+ sqlite3 db test.db
+ catchsql { CREATE TABLE t1(x) }
+} {1 {file is encrypted or is not a database}}
+do_test 38.2 {
+ catch { db close }
+ forcedelete test.db
+} {}
+
+do_test 39.1 {
+ sqlite3 db test.db
+ execsql {
+ PRAGMA auto_vacuum = 1;
+ CREATE TABLE t1(x);
+ INSERT INTO t1 VALUES('xxx');
+ INSERT INTO t1 VALUES('two');
+ INSERT INTO t1 VALUES(randomblob(400));
+ INSERT INTO t1 VALUES(randomblob(400));
+ INSERT INTO t1 VALUES(randomblob(400));
+ INSERT INTO t1 VALUES(randomblob(400));
+ BEGIN;
+ UPDATE t1 SET x = 'one' WHERE rowid=1;
+ }
+ set ::stmt [sqlite3_prepare db "SELECT * FROM t1 ORDER BY rowid" -1 dummy]
+ sqlite3_step $::stmt
+ sqlite3_column_text $::stmt 0
+} {one}
+do_test 39.2 {
+ execsql { CREATE TABLE t2(x) }
+ sqlite3_step $::stmt
+ sqlite3_column_text $::stmt 0
+} {two}
+do_test 39.3 {
+ sqlite3_finalize $::stmt
+ execsql COMMIT
+} {}
+
+do_execsql_test 39.4 {
+ PRAGMA auto_vacuum = 2;
+ CREATE TABLE t3(x);
+ CREATE TABLE t4(x);
+
+ DROP TABLE t2;
+ DROP TABLE t3;
+ DROP TABLE t4;
+}
+do_test 39.5 {
+ db close
+ sqlite3 db test.db
+ execsql {
+ PRAGMA cache_size = 1;
+ PRAGMA incremental_vacuum;
+ PRAGMA integrity_check;
+ }
+} {ok}
+
+do_test 40.1 {
+ reset_db
+ execsql {
+ PRAGMA auto_vacuum = 1;
+ CREATE TABLE t1(x PRIMARY KEY);
+ INSERT INTO t1 VALUES(randomblob(1200));
+ PRAGMA page_count;
+ }
+} {6}
+do_test 40.2 {
+ execsql {
+ INSERT INTO t1 VALUES(randomblob(1200));
+ INSERT INTO t1 VALUES(randomblob(1200));
+ INSERT INTO t1 VALUES(randomblob(1200));
+ }
+} {}
+do_test 40.3 {
+ db close
+ sqlite3 db test.db
+ execsql {
+ PRAGMA cache_size = 1;
+ CREATE TABLE t2(x);
+ PRAGMA integrity_check;
+ }
+} {ok}
+
+do_test 41.1 {
+ reset_db
+ execsql {
+ CREATE TABLE t1(x PRIMARY KEY);
+ 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;
+ INSERT INTO t1 SELECT randomblob(200) FROM t1;
+ }
+} {}
+do_test 41.2 {
+ testvfs tv -default 1
+ tv sectorsize 16384;
+ tv devchar [list]
+ db close
+ sqlite3 db test.db
+ execsql {
+ PRAGMA cache_size = 1;
+ DELETE FROM t1 WHERE rowid%4;
+ PRAGMA integrity_check;
+ }
+} {ok}
+db close
+tv delete
+
+set pending_prev [sqlite3_test_control_pending_byte 0x1000000]
+do_test 42.1 {
+ reset_db
+ execsql {
+ CREATE TABLE t1(x, y);
+ INSERT INTO t1 VALUES(randomblob(200), randomblob(200));
+ INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1;
+ INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1;
+ INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1;
+ INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1;
+ INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1;
+ INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1;
+ INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1;
+ INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1;
+ INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1;
+ }
+ db close
+ sqlite3_test_control_pending_byte 0x0010000
+ sqlite3 db test.db
+ db eval { PRAGMA mmap_size = 0 }
+ catchsql { SELECT sum(length(y)) FROM t1 }
+} {1 {database disk image is malformed}}
+do_test 42.2 {
+ reset_db
+ execsql {
+ CREATE TABLE t1(x, y);
+ INSERT INTO t1 VALUES(randomblob(200), randomblob(200));
+ INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1;
+ INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1;
+ INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1;
+ INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1;
+ INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1;
+ INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1;
+ INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1;
+ INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1;
+ }
+ db close
+
+ testvfs tv -default 1
+ tv sectorsize 16384;
+ tv devchar [list]
+ sqlite3 db test.db -vfs tv
+ execsql { UPDATE t1 SET x = randomblob(200) }
+} {}
+db close
+tv delete
+sqlite3_test_control_pending_byte $pending_prev
+
+do_test 43.1 {
+ reset_db
+ execsql {
+ CREATE TABLE t1(x, y);
+ INSERT INTO t1 VALUES(1, 2);
+ CREATE TABLE t2(x, y);
+ INSERT INTO t2 VALUES(1, 2);
+ CREATE TABLE t3(x, y);
+ INSERT INTO t3 VALUES(1, 2);
+ }
+ db close
+ sqlite3 db test.db
+
+ db eval { PRAGMA mmap_size = 0 }
+ db eval { SELECT * FROM t1 }
+ sqlite3_db_status db CACHE_MISS 0
+} {0 2 0}
+do_test 43.2 {
+ db eval { SELECT * FROM t2 }
+ sqlite3_db_status db CACHE_MISS 1
+} {0 3 0}
+do_test 43.3 {
+ db eval { SELECT * FROM t3 }
+ sqlite3_db_status db CACHE_MISS 0
+} {0 1 0}
finish_test
diff --git a/lang/sql/sqlite/test/pager2.test b/lang/sql/sqlite/test/pager2.test
index fa5f7b96..0e2b33b8 100644
--- a/lang/sql/sqlite/test/pager2.test
+++ b/lang/sql/sqlite/test/pager2.test
@@ -118,7 +118,6 @@ tv delete
#-------------------------------------------------------------------------
-#
# pager2-2.1: Test a ROLLBACK with journal_mode=off.
# pager2-2.2: Test shrinking the database (auto-vacuum) with
# journal_mode=off
@@ -148,4 +147,22 @@ do_test pager2-2.2 {
file size test.db
} {3072}
+#-------------------------------------------------------------------------
+# Test that shared in-memory databases seem to work.
+#
+db close
+do_test pager2-3.1 {
+ forcedelete test.db
+ sqlite3_shutdown
+ sqlite3_config_uri 1
+
+ sqlite3 db1 {file:test.db?mode=memory&cache=shared}
+ sqlite3 db2 {file:test.db?mode=memory&cache=shared}
+ sqlite3 db3 test.db
+
+ db1 eval { CREATE TABLE t1(a, b) }
+ db2 eval { INSERT INTO t1 VALUES(1, 2) }
+ list [catch { db3 eval { INSERT INTO t1 VALUES(3, 4) } } msg] $msg
+} {1 {no such table: t1}}
+
finish_test
diff --git a/lang/sql/sqlite/test/pager4.test b/lang/sql/sqlite/test/pager4.test
new file mode 100644
index 00000000..2cf73d1b
--- /dev/null
+++ b/lang/sql/sqlite/test/pager4.test
@@ -0,0 +1,99 @@
+# 2013-12-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 the SQLITE_READONLY_DBMOVED error condition: the database file
+# is unlinked or renamed out from under SQLite.
+#
+
+if {$tcl_platform(platform)!="unix"} return
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+if {[permutation]=="inmemory_journal"} {
+ finish_test
+ return
+}
+
+# Create a database file for testing
+#
+do_execsql_test pager4-1.1 {
+ CREATE TABLE t1(a,b,c);
+ INSERT INTO t1 VALUES(673,'stone','philips');
+ SELECT * FROM t1;
+} {673 stone philips}
+
+# After renaming the database file while it is open, one can still
+# read from the database, but writing returns a READONLY error.
+#
+file delete -force test-xyz.db
+file rename test.db test-xyz.db
+do_catchsql_test pager4-1.2 {
+ SELECT * FROM t1;
+} {0 {673 stone philips}}
+do_catchsql_test pager4-1.3 {
+ UPDATE t1 SET a=537;
+} {1 {attempt to write a readonly database}}
+
+# Creating a different database file with the same name of the original
+# is detected and still leaves the database read-only.
+#
+sqlite3 db2 test.db
+db2 eval {CREATE TABLE t2(x,y,z)}
+do_catchsql_test pager4-1.4 {
+ UPDATE t1 SET a=948;
+} {1 {attempt to write a readonly database}}
+
+# Changing the name back clears the READONLY error
+#
+db2 close
+file delete -force test.db
+file rename test-xyz.db test.db
+do_catchsql_test pager4-1.5 {
+ SELECT * FROM t1;
+} {0 {673 stone philips}}
+do_catchsql_test pager4-1.6 {
+ UPDATE t1 SET a=537;
+ SELECT * FROM t1;
+} {0 {537 stone philips}}
+
+# We can write to a renamed database if journal_mode=OFF or
+# journal_mode=MEMORY.
+#
+file rename test.db test-xyz.db
+do_catchsql_test pager4-1.7 {
+ PRAGMA journal_mode=OFF;
+ UPDATE t1 SET a=107;
+ SELECT * FROM t1;
+} {0 {off 107 stone philips}}
+do_catchsql_test pager4-1.8 {
+ PRAGMA journal_mode=MEMORY;
+ UPDATE t1 SET b='magpie';
+ SELECT * FROM t1;
+} {0 {memory 107 magpie philips}}
+
+# Any other journal mode gives a READONLY error
+#
+do_catchsql_test pager4-1.9 {
+ PRAGMA journal_mode=DELETE;
+ UPDATE t1 SET c='jaguar';
+} {1 {attempt to write a readonly database}}
+do_catchsql_test pager4-1.10 {
+ PRAGMA journal_mode=TRUNCATE;
+ UPDATE t1 SET c='jaguar';
+} {1 {attempt to write a readonly database}}
+do_catchsql_test pager4-1.11 {
+ PRAGMA journal_mode=PERSIST;
+ UPDATE t1 SET c='jaguar';
+} {1 {attempt to write a readonly database}}
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/pagerfault.test b/lang/sql/sqlite/test/pagerfault.test
index c5c7d3b3..c0f5de69 100644
--- a/lang/sql/sqlite/test/pagerfault.test
+++ b/lang/sql/sqlite/test/pagerfault.test
@@ -20,6 +20,11 @@ if {[permutation] == "inmemory_journal"} {
return
}
+if {$::tcl_platform(platform)=="windows"} {
+ finish_test
+ return
+}
+
set a_string_counter 1
proc a_string {n} {
global a_string_counter
@@ -228,7 +233,7 @@ do_faultsim_test pagerfault-5.2 -prep {
do_faultsim_test pagerfault-5.3 -faults oom-transient -prep {
faultsim_restore_and_reopen
db func a_string a_string
- file delete -force test2.db test2.db-journal test2.db-wal
+ forcedelete test2.db test2.db-journal test2.db-wal
execsql {
PRAGMA journal_mode = PERSIST;
ATTACH 'test2.db' AS aux;
@@ -636,7 +641,7 @@ do_test pagerfault-13-pre1 {
COMMIT;
}
db close
- file delete -force test.db
+ forcedelete test.db
faultsim_save
} {}
do_faultsim_test pagerfault-13 -prep {
@@ -1101,7 +1106,7 @@ do_faultsim_test pagerfault-22 -prep {
#
do_faultsim_test pagerfault-23 -prep {
sqlite3 db :memory:
- foreach f [glob -nocomplain test.db*] { file delete -force $f }
+ foreach f [glob -nocomplain test.db*] { forcedelete $f }
db eval {
ATTACH 'test.db2' AS aux;
CREATE TABLE t1(a, b);
@@ -1241,5 +1246,304 @@ do_faultsim_test pagerfault-27 -faults ioerr-persistent -prep {
faultsim_integrity_check
}
-finish_test
+#-------------------------------------------------------------------------
+#
+do_test pagerfault-28-pre {
+ faultsim_delete_and_reopen
+ db func a_string a_string
+ execsql {
+ PRAGMA page_size = 512;
+
+ PRAGMA journal_mode = wal;
+ PRAGMA wal_autocheckpoint = 0;
+ PRAGMA cache_size = 100000;
+
+ BEGIN;
+ CREATE TABLE t2(a UNIQUE, b UNIQUE);
+ INSERT INTO t2 VALUES( a_string(800), a_string(800) );
+ INSERT INTO t2 SELECT a_string(800), a_string(800) FROM t2;
+ INSERT INTO t2 SELECT a_string(800), a_string(800) FROM t2;
+ INSERT INTO t2 SELECT a_string(800), a_string(800) FROM t2;
+ INSERT INTO t2 SELECT a_string(800), a_string(800) FROM t2;
+ INSERT INTO t2 SELECT a_string(800), a_string(800) FROM t2;
+ INSERT INTO t2 SELECT a_string(800), a_string(800) FROM t2;
+ INSERT INTO t2 SELECT a_string(800), a_string(800) FROM t2;
+ INSERT INTO t2 SELECT a_string(800), a_string(800) FROM t2;
+ INSERT INTO t2 SELECT a_string(800), a_string(800) FROM t2;
+ INSERT INTO t2 SELECT a_string(800), a_string(800) FROM t2;
+ INSERT INTO t2 SELECT a_string(800), a_string(800) FROM t2;
+ COMMIT;
+ CREATE TABLE t1(a PRIMARY KEY, b);
+ }
+ expr {[file size test.db-shm] >= 96*1024}
+} {1}
+faultsim_save_and_close
+
+do_faultsim_test pagerfault-28a -faults oom* -prep {
+ faultsim_restore_and_reopen
+ execsql { PRAGMA mmap_size=0 }
+
+ sqlite3 db2 test.db
+ db2 eval { SELECT count(*) FROM t2 }
+
+ db func a_string a_string
+ execsql {
+ BEGIN;
+ INSERT INTO t1 VALUES(a_string(2000), a_string(2000));
+ INSERT INTO t1 VALUES(a_string(2000), a_string(2000));
+ }
+ set ::STMT [sqlite3_prepare db "SELECT * FROM t1 ORDER BY a" -1 DUMMY]
+ sqlite3_step $::STMT
+} -body {
+ execsql { ROLLBACK }
+} -test {
+ db2 close
+ sqlite3_finalize $::STMT
+ catchsql { ROLLBACK }
+ faultsim_integrity_check
+}
+
+faultsim_restore_and_reopen
+sqlite3 db2 test.db
+db2 eval {SELECT count(*) FROM t2}
+db close
+
+do_faultsim_test pagerfault-28b -faults oom* -prep {
+ sqlite3 db test.db
+} -body {
+ execsql { SELECT count(*) FROM t2 }
+} -test {
+ faultsim_test_result {0 2048}
+ db close
+}
+
+db2 close
+
+#-------------------------------------------------------------------------
+# Try this:
+#
+# 1) Put the pager in ERROR state (error during rollback)
+#
+# 2) Next time the connection is used inject errors into all xWrite() and
+# xUnlock() calls. This causes the hot-journal rollback to fail and
+# the pager to declare its locking state UNKNOWN.
+#
+# 3) Same again.
+#
+# 4a) Stop injecting errors. Allow the rollback to succeed. Check that
+# the database is Ok. Or,
+#
+# 4b) Close and reopen the db. Check that the db is Ok.
+#
+proc custom_injectinstall {} {
+ testvfs custom -default true
+ custom filter {xWrite xUnlock}
+}
+proc custom_injectuninstall {} {
+ catch {db close}
+ catch {db2 close}
+ custom delete
+}
+proc custom_injectstart {iFail} {
+ custom ioerr $iFail 1
+}
+proc custom_injectstop {} {
+ custom ioerr
+}
+set ::FAULTSIM(custom) [list \
+ -injectinstall custom_injectinstall \
+ -injectstart custom_injectstart \
+ -injectstop custom_injectstop \
+ -injecterrlist {{1 {disk I/O error}}} \
+ -injectuninstall custom_injectuninstall \
+]
+
+do_test pagerfault-29-pre {
+ faultsim_delete_and_reopen
+ db func a_string a_string
+ execsql {
+ PRAGMA page_size = 1024;
+ PRAGMA cache_size = 5;
+
+ BEGIN;
+ CREATE TABLE t2(a UNIQUE, b UNIQUE);
+ INSERT INTO t2 VALUES( a_string(800), a_string(800) );
+ INSERT INTO t2 SELECT a_string(800), a_string(800) FROM t2;
+ INSERT INTO t2 SELECT a_string(800), a_string(800) FROM t2;
+ INSERT INTO t2 SELECT a_string(800), a_string(800) FROM t2;
+ INSERT INTO t2 SELECT a_string(800), a_string(800) FROM t2;
+ COMMIT;
+ }
+ expr {[file size test.db] >= 50*1024}
+} {1}
+faultsim_save_and_close
+foreach {tn tt} {
+ 29 { catchsql ROLLBACK }
+ 30 { db close ; sqlite3 db test.db }
+} {
+ do_faultsim_test pagerfault-$tn -faults custom -prep {
+ faultsim_restore_and_reopen
+ db func a_string a_string
+ execsql {
+ PRAGMA cache_size = 5;
+ BEGIN;
+ UPDATE t2 SET a = a_string(799);
+ }
+ } -body {
+ catchsql ROLLBACK
+ catchsql ROLLBACK
+ catchsql ROLLBACK
+ } -test {
+ eval $::tt
+ if {"ok" != [db one {PRAGMA integrity_check}]} {
+ error "integrity check failed"
+ }
+ }
+}
+
+do_test pagerfault-31-pre {
+ sqlite3_shutdown
+ sqlite3_config_uri 1
+} {SQLITE_OK}
+do_faultsim_test pagerfault-31 -faults oom* -body {
+ sqlite3 db {file:one?mode=memory&cache=shared}
+ db eval {
+ CREATE TABLE t1(x);
+ INSERT INTO t1 VALUES(1);
+ SELECT * FROM t1;
+ }
+} -test {
+ faultsim_test_result {0 1} {1 {}}
+ catch { db close }
+}
+sqlite3_shutdown
+sqlite3_config_uri 0
+
+do_test pagerfault-32-pre {
+ reset_db
+ execsql {
+ CREATE TABLE t1(x);
+ INSERT INTO t1 VALUES('one');
+ }
+} {}
+faultsim_save_and_close
+
+do_faultsim_test pagerfault-32 -prep {
+ faultsim_restore_and_reopen
+ db eval { SELECT * FROM t1; }
+} -body {
+ execsql { SELECT * FROM t1; }
+} -test {
+ faultsim_test_result {0 one}
+}
+sqlite3_shutdown
+sqlite3_config_uri 0
+
+do_faultsim_test pagerfault-33a -prep {
+ sqlite3 db :memory:
+ execsql {
+ CREATE TABLE t1(a, b);
+ INSERT INTO t1 VALUES(1, 2);
+ }
+} -body {
+ execsql { VACUUM }
+} -test {
+ faultsim_test_result {0 {}}
+}
+do_faultsim_test pagerfault-33b -prep {
+ sqlite3 db ""
+ execsql {
+ CREATE TABLE t1(a, b);
+ INSERT INTO t1 VALUES(1, 2);
+ }
+} -body {
+ execsql { VACUUM }
+} -test {
+ faultsim_test_result {0 {}}
+}
+
+do_test pagerfault-34-pre {
+ reset_db
+ execsql {
+ CREATE TABLE t1(x PRIMARY KEY);
+ }
+} {}
+faultsim_save_and_close
+do_faultsim_test pagerfault-34 -prep {
+ faultsim_restore_and_reopen
+ execsql {
+ BEGIN;
+ INSERT INTO t1 VALUES( randomblob(4000) );
+ DELETE FROM t1;
+ }
+} -body {
+ execsql COMMIT
+} -test {
+ faultsim_test_result {0 {}}
+}
+
+do_test pagerfault-35-pre {
+ faultsim_delete_and_reopen
+ execsql {
+ CREATE TABLE t1(x PRIMARY KEY, y);
+ INSERT INTO t1 VALUES(randomblob(200), randomblob(200));
+ INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1;
+ INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1;
+ INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1;
+ }
+ faultsim_save_and_close
+} {}
+testvfs tv -default 1
+tv sectorsize 8192;
+tv devchar [list]
+do_faultsim_test pagerfault-35 -prep {
+ faultsim_restore_and_reopen
+} -body {
+ execsql { UPDATE t1 SET x=randomblob(200) }
+} -test {
+ faultsim_test_result {0 {}}
+}
+catch {db close}
+tv delete
+
+sqlite3_shutdown
+sqlite3_config_uri 1
+do_test pagerfault-36-pre {
+ faultsim_delete_and_reopen
+ execsql {
+ CREATE TABLE t1(x PRIMARY KEY, y);
+ INSERT INTO t1 VALUES(randomblob(200), randomblob(200));
+ INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1;
+ INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1;
+ INSERT INTO t1 SELECT randomblob(200), randomblob(200) FROM t1;
+ }
+ faultsim_save_and_close
+} {}
+do_faultsim_test pagerfault-36 -prep {
+ faultsim_restore
+ sqlite3 db file:test.db?cache=shared
+ sqlite3 db2 file:test.db?cache=shared
+ db2 eval {
+ BEGIN;
+ SELECT count(*) FROM sqlite_master;
+ }
+ db eval {
+ PRAGMA cache_size = 1;
+ BEGIN;
+ UPDATE t1 SET x = randomblob(200);
+ }
+} -body {
+ execsql ROLLBACK db
+} -test {
+ catch { db eval {UPDATE t1 SET x = randomblob(200)} }
+ faultsim_test_result {0 {}}
+ catch { db close }
+ catch { db2 close }
+}
+
+sqlite3_shutdown
+sqlite3_config_uri 0
+sqlite3_initialize
+
+finish_test
diff --git a/lang/sql/sqlite/test/pagerfault2.test b/lang/sql/sqlite/test/pagerfault2.test
index 6cdb99a3..7f6c995e 100644
--- a/lang/sql/sqlite/test/pagerfault2.test
+++ b/lang/sql/sqlite/test/pagerfault2.test
@@ -96,4 +96,3 @@ do_faultsim_test pagerfault2-2 -faults oom-transient -prep {
sqlite3_memdebug_vfs_oom_test 1
finish_test
-
diff --git a/lang/sql/sqlite/test/pagerfault3.test b/lang/sql/sqlite/test/pagerfault3.test
index 3d192e6d..a4301cd1 100644
--- a/lang/sql/sqlite/test/pagerfault3.test
+++ b/lang/sql/sqlite/test/pagerfault3.test
@@ -61,4 +61,3 @@ do_faultsim_test pagerfault3-1 -faults ioerr-transient -prep {
}
finish_test
-
diff --git a/lang/sql/sqlite/test/pageropt.test b/lang/sql/sqlite/test/pageropt.test
index 1c634f64..7191661b 100644
--- a/lang/sql/sqlite/test/pageropt.test
+++ b/lang/sql/sqlite/test/pageropt.test
@@ -17,7 +17,7 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
-ifcapable {!pager_pragmas||secure_delete} {
+ifcapable {!pager_pragmas||secure_delete||direct_read} {
finish_test
return
}
@@ -87,12 +87,17 @@ do_test pageropt-1.4 {
# But if the other thread modifies the database, then the cache
# must refill.
#
+ifcapable mmap {
+ set x [expr {[permutation]=="mmap" ? 1 : 6}]
+} else {
+ set x 6
+}
do_test pageropt-1.5 {
db2 eval {CREATE TABLE t2(y)}
pagercount_sql {
SELECT hex(x) FROM t1
}
-} [list 6 0 0 $blobcontent]
+} [list $x 0 0 $blobcontent]
do_test pageropt-1.6 {
pagercount_sql {
SELECT hex(x) FROM t1
diff --git a/lang/sql/sqlite/test/pagesize.test b/lang/sql/sqlite/test/pagesize.test
index af2c017b..0eebbbb7 100644
--- a/lang/sql/sqlite/test/pagesize.test
+++ b/lang/sql/sqlite/test/pagesize.test
@@ -42,7 +42,7 @@ do_test pagesize-1.3 {
do_test pagesize-1.4 {
db close
- file delete -force test.db
+ forcedelete test.db
sqlite3 db test.db
execsql {
PRAGMA page_size=511;
@@ -99,7 +99,7 @@ foreach PGSZ {512 2048 4096 8192} {
}
do_test pagesize-2.$PGSZ.1 {
db close
- file delete -force test.db
+ forcedelete test.db
sqlite3 db test.db
execsql "PRAGMA page_size=$PGSZ"
execsql {
@@ -190,7 +190,7 @@ foreach PGSZ {512 2048 4096 8192} {
integrity_check pagesize-2.$PGSZ.17
db close
- file delete -force test.db
+ forcedelete test.db
sqlite3 db test.db
do_test pagesize-2.$PGSZ.30 {
execsql "
@@ -203,7 +203,7 @@ foreach PGSZ {512 2048 4096 8192} {
} [list 1024 $PGSZ]
db close
- file delete -force test.db
+ forcedelete test.db
sqlite3 db test.db
do_test pagesize-2.$PGSZ.40 {
execsql "
diff --git a/lang/sql/sqlite/test/pcache.test b/lang/sql/sqlite/test/pcache.test
index 5dc3059c..0766fce0 100644
--- a/lang/sql/sqlite/test/pcache.test
+++ b/lang/sql/sqlite/test/pcache.test
@@ -44,6 +44,7 @@ do_test pcache-1.2 {
execsql {
PRAGMA cache_size=12;
PRAGMA auto_vacuum=0;
+ PRAGMA mmap_size=0;
}
pcache_stats
} {current 1 max 12 min 10 recyclable 1}
diff --git a/lang/sql/sqlite/test/pcache2.test b/lang/sql/sqlite/test/pcache2.test
index 14df52eb..77e7a261 100644
--- a/lang/sql/sqlite/test/pcache2.test
+++ b/lang/sql/sqlite/test/pcache2.test
@@ -16,7 +16,6 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
-
# Set up a pcache memory pool so that we can easily track how many
# pages are being used for cache.
#
@@ -34,13 +33,13 @@ do_test pcache2-1.1 {
# Open up two database connections to separate files.
#
do_test pcache2-1.2 {
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db test.db
db eval {PRAGMA cache_size=10}
lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 1
} {2}
do_test pcache2-1.3 {
- file delete -force test2.db test2.db-journal
+ forcedelete test2.db test2.db-journal
sqlite3 db2 test2.db
db2 eval {PRAGMA cache_size=50}
lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 1
diff --git a/lang/sql/sqlite/test/percentile.test b/lang/sql/sqlite/test/percentile.test
new file mode 100644
index 00000000..9d471dfc
--- /dev/null
+++ b/lang/sql/sqlite/test/percentile.test
@@ -0,0 +1,209 @@
+# 2013-05-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 percentile.c extension
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+# Basic test of the percentile() function.
+#
+do_test percentile-1.0 {
+ load_static_extension db percentile
+ execsql {
+ CREATE TABLE t1(x);
+ INSERT INTO t1 VALUES(1),(4),(6),(7),(8),(9),(11),(11),(11);
+ }
+ execsql {SELECT percentile(x,0) FROM t1}
+} {1.0}
+foreach {in out} {
+ 100 11.0
+ 50 8.0
+ 12.5 4.0
+ 15 4.4
+ 20 5.2
+ 80 11.0
+ 89 11.0
+} {
+ do_test percentile-1.1.$in {
+ execsql {SELECT percentile(x,$in) FROM t1}
+ } $out
+}
+
+# Add some NULL values.
+#
+do_test percentile-1.2 {
+ execsql {INSERT INTO t1 VALUES(NULL),(NULL);}
+} {}
+foreach {in out} {
+ 100 11.0
+ 50 8.0
+ 12.5 4.0
+ 15 4.4
+ 20 5.2
+ 80 11.0
+ 89 11.0
+} {
+ do_test percentile-1.3.$in {
+ execsql {SELECT percentile(x,$in) FROM t1}
+ } $out
+}
+
+# The second argument to percentile can change some, but not much.
+#
+do_test percentile-1.4 {
+ catchsql {SELECT round(percentile(x, 15+0.000001*rowid),1) FROM t1}
+} {0 4.4}
+do_test percentile-1.5 {
+ catchsql {SELECT round(percentile(x, 15+0.1*rowid),1) FROM t1}
+} {1 {2nd argument to percentile() is not the same for all input rows}}
+
+# Input values in a random order
+#
+do_test percentile-1.6 {
+ execsql {
+ CREATE TABLE t2(x);
+ INSERT INTO t2 SELECT x+0.0 FROM t1 ORDER BY random();
+ }
+} {}
+foreach {in out} {
+ 100 11.0
+ 50 8.0
+ 12.5 4.0
+ 15 4.4
+ 20 5.2
+ 80 11.0
+ 89 11.0
+} {
+ do_test percentile-1.7.$in {
+ execsql {SELECT percentile(x,$in) FROM t2}
+ } $out
+}
+
+# Wrong number of arguments
+#
+do_test percentile-1.8 {
+ catchsql {SELECT percentile(x,0,1) FROM t1}
+} {1 {wrong number of arguments to function percentile()}}
+do_test percentile-1.9 {
+ catchsql {SELECT percentile(x) FROM t1}
+} {1 {wrong number of arguments to function percentile()}}
+
+# Second argument must be numeric
+#
+do_test percentile-1.10 {
+ catchsql {SELECT percentile(x,null) FROM t1}
+} {1 {2nd argument to percentile() is not a number between 0.0 and 100.0}}
+do_test percentile-1.11 {
+ catchsql {SELECT percentile(x,'fifty') FROM t1}
+} {1 {2nd argument to percentile() is not a number between 0.0 and 100.0}}
+do_test percentile-1.12 {
+ catchsql {SELECT percentile(x,x'3530') FROM t1}
+} {1 {2nd argument to percentile() is not a number between 0.0 and 100.0}}
+
+# Second argument is out of range
+#
+do_test percentile-1.13 {
+ catchsql {SELECT percentile(x,-0.0000001) FROM t1}
+} {1 {2nd argument to percentile() is not a number between 0.0 and 100.0}}
+do_test percentile-1.14 {
+ catchsql {SELECT percentile(x,100.0000001) FROM t1}
+} {1 {2nd argument to percentile() is not a number between 0.0 and 100.0}}
+
+# First argument is not NULL and is not NUMERIC
+#
+do_test percentile-1.15 {
+ catchsql {
+ BEGIN;
+ UPDATE t1 SET x='50' WHERE x IS NULL;
+ SELECT percentile(x, 50) FROM t1;
+ }
+} {1 {1st argument to percentile() is not numeric}}
+do_test percentile-1.16 {
+ catchsql {
+ ROLLBACK;
+ BEGIN;
+ UPDATE t1 SET x=x'3530' WHERE x IS NULL;
+ SELECT percentile(x, 50) FROM t1;
+ }
+} {1 {1st argument to percentile() is not numeric}}
+do_test percentile-1.17 {
+ catchsql {
+ ROLLBACK;
+ SELECT percentile(x, 50) FROM t1;
+ }
+} {0 8.0}
+
+# No non-NULL entries.
+#
+do_test percentile-1.18 {
+ execsql {
+ UPDATE t1 SET x=NULL;
+ SELECT ifnull(percentile(x, 50),'NULL') FROM t1
+ }
+} {NULL}
+
+# Exactly one non-NULL entry
+#
+do_test percentile-1.19 {
+ execsql {
+ UPDATE t1 SET x=12345 WHERE rowid=5;
+ SELECT percentile(x, 0), percentile(x, 50), percentile(x,100) FROM t1
+ }
+} {12345.0 12345.0 12345.0}
+
+# Infinity as an input
+#
+do_test percentile-1.20 {
+ catchsql {
+ DELETE FROM t1;
+ INSERT INTO t1 SELECT x+0.0 FROM t2;
+ UPDATE t1 SET x=1.0e300*1.0e300 WHERE rowid=5;
+ SELECT percentile(x,50) from t1;
+ }
+} {1 {Inf input to percentile()}}
+do_test percentile-1.21 {
+ catchsql {
+ UPDATE t1 SET x=-1.0e300*1.0e300 WHERE rowid=5;
+ SELECT percentile(x,50) from t1;
+ }
+} {1 {Inf input to percentile()}}
+
+# Million-row Inputs
+#
+ifcapable vtab {
+ do_test percentile-2.0 {
+ load_static_extension db wholenumber
+ execsql {
+ CREATE VIRTUAL TABLE nums USING wholenumber;
+ CREATE TABLE t3(x);
+ INSERT INTO t3 SELECT value-1 FROM nums WHERE value BETWEEN 1 AND 500000;
+ INSERT INTO t3 SELECT value*10 FROM nums
+ WHERE value BETWEEN 500000 AND 999999;
+ SELECT count(*) FROM t3;
+ }
+ } {1000000}
+ foreach {in out} {
+ 0 0.0
+ 100 9999990.0
+ 50 2749999.5
+ 10 99999.9
+ } {
+ do_test percentile-2.1.$in {
+ execsql {
+ SELECT percentile(x, $in) from t3;
+ }
+ } $out
+ }
+}
+
+finish_test
diff --git a/lang/sql/sqlite/test/permutations.test b/lang/sql/sqlite/test/permutations.test
index 09a5d18b..32d25f50 100644
--- a/lang/sql/sqlite/test/permutations.test
+++ b/lang/sql/sqlite/test/permutations.test
@@ -96,7 +96,7 @@ if {$::tcl_platform(platform)!="unix"} {
set alltests [test_set $alltests -exclude {
all.test async.test quick.test veryquick.test
memleak.test permutations.test soak.test fts3.test
- mallocAll.test rtree.test
+ mallocAll.test rtree.test full.test
}]
set allquicktests [test_set $alltests -exclude {
@@ -110,8 +110,8 @@ set allquicktests [test_set $alltests -exclude {
speed4p.test sqllimits1.test tkt2686.test thread001.test thread002.test
thread003.test thread004.test thread005.test trans2.test vacuum3.test
incrvacuum_ioerr.test autovacuum_crash.test btree8.test shared_err.test
- vtab_err.test walslow.test walcrash.test
- walthread.test rtree3.test
+ vtab_err.test walslow.test walcrash.test walcrash3.test
+ walthread.test rtree3.test indexfault.test securedel2.test
}]
if {[info exists ::env(QUICKTEST_INCLUDE)]} {
set allquicktests [concat $allquicktests $::env(QUICKTEST_INCLUDE)]
@@ -138,11 +138,19 @@ test_suite "veryquick" -prefix "" -description {
test_set $allquicktests -exclude *malloc* *ioerr* *fault*
]
+test_suite "mmap" -prefix "mm-" -description {
+ Similar to veryquick. Except with memory mapping disabled.
+} -presql {
+ pragma mmap_size = 268435456;
+} -files [
+ test_set $allquicktests -exclude *malloc* *ioerr* *fault* -include malloc.test
+]
+
test_suite "valgrind" -prefix "" -description {
Run the "veryquick" test suite with a couple of multi-process tests (that
fail under valgrind) omitted.
} -files [
- test_set $allquicktests -exclude *malloc* *ioerr* *fault*
+ test_set $allquicktests -exclude *malloc* *ioerr* *fault* wal.test atof1.test
] -initialize {
set ::G(valgrind) 1
} -shutdown {
@@ -183,13 +191,120 @@ test_suite "fts3" -prefix "" -description {
fts3ak.test fts3al.test fts3am.test fts3an.test fts3ao.test
fts3atoken.test fts3b.test fts3c.test fts3cov.test fts3d.test
fts3e.test fts3expr.test fts3expr2.test
- fts3near.test fts3query.test fts3shared.test fts3snippet.test
-
+ fts3expr3.test
+ fts3near.test fts3query.test fts3snippet.test
+ fts3sort.test
fts3malloc.test fts3matchinfo.test
+ fts3aux1.test fts3comp1.test fts3auto.test
+ fts4aa.test fts4content.test
+ fts3conf.test fts3prefix.test fts3corrupt.test
+ fts3corrupt2.test fts3first.test fts4langid.test fts4merge.test
+ fts4check.test fts4unicode.test fts4noti.test
+ fts3varint.test
+}
+
+test_suite "nofaultsim" -prefix "" -description {
+ "Very" quick test suite. Runs in less than 5 minutes on a workstation.
+ This test suite is the same as the "quick" tests, except that some files
+ that test malloc and IO errors are omitted.
+} -files [
+ test_set $allquicktests -exclude *malloc* *ioerr* *fault*
+] -initialize {
+ catch {db close}
+ sqlite3_shutdown
+ install_malloc_faultsim 0
+ sqlite3_initialize
+ autoinstall_test_functions
+} -shutdown {
+ unset -nocomplain ::G(valgrind)
+}
- fts3aux1.test fts3comp1.test
+test_suite "queryplanner" -prefix "" -description {
+ Tests of the query planner and query optimizer
+} -files {
+ alter2.test alter3.test alter4.test alter.test analyze3.test
+ analyze4.test analyze5.test analyze6.test analyze7.test analyze8.test
+ analyze.test attach2.test attach3.test attach4.test
+ attach.test autoinc.test autoindex1.test between.test cast.test
+ check.test closure01.test coalesce.test collate1.test collate2.test
+ collate3.test collate4.test collate5.test collate6.test collate7.test
+ collate8.test collate9.test collateA.test colmeta.test colname.test
+ conflict.test count.test coveridxscan.test createtab.test cse.test
+ date.test dbstatus2.test dbstatus.test default.test delete2.test
+ delete3.test delete.test descidx1.test descidx2.test descidx3.test
+ distinctagg.test distinct.test e_createtable.test e_delete.test
+ e_droptrigger.test e_dropview.test e_expr.test e_insert.test
+ eqp.test e_reindex.test e_resolve.test e_select2.test e_select.test
+ e_update.test exists.test expr.test fkey1.test fkey2.test fkey3.test
+ fkey4.test fkey5.test func2.test func3.test func.test
+ in3.test in4.test in5.test index2.test index3.test
+ index4.test index5.test indexedby.test index.test
+ insert2.test insert3.test insert4.test insert5.test insert.test
+ instr.test in.test intpkey.test join2.test join3.test join4.test
+ join5.test join6.test join.test like2.test like.test limit.test
+ minmax2.test minmax3.test minmax4.test minmax.test misc1.test misc2.test
+ misc3.test misc4.test misc5.test misc6.test misc7.test orderby1.test
+ orderby2.test orderby3.test orderby4.test randexpr1.test regexp1.test
+ reindex.test rowhash.test rowid.test schema2.test schema3.test
+ schema4.test schema5.test schema.test
+ select1.test select2.test select3.test select4.test select5.test
+ select6.test select7.test select8.test select9.test selectA.test
+ selectB.test selectC.test selectD.test selectE.test sidedelete.test
+ sort.test spellfix.test subquery2.test subquery.test subselect.test
+ substr.test tkt-02a8e81d44.test tkt1435.test tkt1443.test tkt1444.test
+ tkt1449.test tkt1473.test tkt1501.test tkt1512.test tkt1514.test
+ tkt1536.test tkt1537.test tkt1567.test tkt1644.test tkt1667.test
+ tkt1873.test tkt2141.test tkt2192.test tkt2213.test tkt2251.test
+ tkt2285.test tkt2332.test tkt2339.test tkt2391.test tkt2409.test
+ tkt2450.test tkt2565.test tkt2640.test tkt2643.test tkt2686.test
+ tkt-26ff0c2d1e.test tkt2767.test tkt2817.test tkt2820.test tkt2822.test
+ tkt2832.test tkt2854.test tkt2920.test tkt2927.test tkt2942.test
+ tkt-2a5629202f.test tkt-2d1a5c67d.test tkt-2ea2425d34.test tkt3080.test
+ tkt3093.test tkt3121.test tkt-31338dca7e.test tkt-313723c356.test
+ tkt3201.test tkt3292.test tkt3298.test tkt3334.test tkt3346.test
+ tkt3357.test tkt3419.test tkt3424.test tkt3442.test tkt3457.test
+ tkt3461.test tkt3493.test tkt3508.test tkt3522.test tkt3527.test
+ tkt3541.test tkt3554.test tkt3581.test tkt35xx.test tkt3630.test
+ tkt3718.test tkt3731.test tkt3757.test tkt3761.test tkt3762.test
+ tkt3773.test tkt3791.test tkt3793.test tkt3810.test tkt3824.test
+ tkt3832.test tkt3838.test tkt3841.test tkt-385a5b56b9.test tkt3871.test
+ tkt3879.test tkt-38cb5df375.test tkt3911.test tkt3918.test tkt3922.test
+ tkt3929.test tkt3935.test tkt3992.test tkt3997.test tkt-3998683a16.test
+ tkt-3a77c9714e.test tkt-3fe897352e.test tkt4018.test tkt-4a03edc4c8.test
+ tkt-4dd95f6943.test tkt-54844eea3f.test tkt-5d863f876e.test
+ tkt-5e10420e8d.test tkt-5ee23731f.test tkt-6bfb98dfc0.test
+ tkt-752e1646fc.test tkt-78e04e52ea.test tkt-7a31705a7e6.test
+ tkt-7bbfb7d442.test tkt-80ba201079.test tkt-80e031a00f.test
+ tkt-8454a207b9.test tkt-91e2e8ba6f.test tkt-94c04eaadb.test
+ tkt-9d68c883.test tkt-a7b7803e.test tkt-b1d3a2e531.test
+ tkt-b351d95f9.test tkt-b72787b1.test tkt-bd484a090c.test
+ tkt-bdc6bbbb38.test tkt-c48d99d690.test tkt-cbd054fa6b.test
+ tkt-d11f09d36e.test tkt-d635236375.test tkt-d82e3f3721.test
+ tkt-f3e5abed55.test tkt-f777251dc7a.test tkt-f7b4edec.test
+ tkt-f973c7ac31.test tkt-fa7bf5ec.test tkt-fc62af4523.test
+ tkt-fc7bd6358f.test trigger1.test trigger2.test trigger3.test
+ trigger4.test trigger5.test trigger6.test trigger7.test trigger8.test
+ trigger9.test triggerA.test triggerB.test triggerC.test triggerD.test
+ types2.test types3.test types.test unique.test unordered.test
+ update.test view.test vtab1.test vtab2.test vtab3.test vtab4.test
+ vtab5.test vtab6.test vtab7.test vtab8.test vtab9.test vtab_alter.test
+ vtabA.test vtabB.test vtabC.test vtabD.test vtabE.test
+ vtabF.test where2.test where3.test where4.test where5.test where6.test
+ where7.test where8m.test where8.test where9.test whereA.test whereB.test
+ whereC.test whereD.test whereE.test whereF.test wherelimit.test
+ where.test
}
+test_suite "vfslog" -prefix "" -description {
+ "Vfslog" quick test suite. Like "veryquick" except does not omits
+ a few tests that do not work with a version 1 VFS. And the quota* tests,
+ which do not work with a VFS that uses the pVfs argument passed to
+ sqlite3_vfs methods.
+} -files [
+ test_set $allquicktests -exclude *malloc* *ioerr* *fault* oserror.test \
+ pager1.test syscall.test sysfault.test tkt3457.test quota* superlock* \
+ wal* mmap*
+]
lappend ::testsuitelist xxx
#-------------------------------------------------------------------------
@@ -213,6 +328,14 @@ test_suite "coverage-pager" -description {
walfault.test walbak.test journal2.test tkt-9d68c883.test
}
+test_suite "coverage-analyze" -description {
+ Coverage tests for file analyze.c.
+} -files {
+ analyze3.test analyze4.test analyze5.test analyze6.test
+ analyze7.test analyze8.test analyze9.test analyzeA.test
+ analyze.test analyzeB.test mallocA.test
+}
+
lappend ::testsuitelist xxx
#-------------------------------------------------------------------------
@@ -221,10 +344,14 @@ lappend ::testsuitelist xxx
# Run some tests using pre-allocated page and scratch blocks.
#
+# mmap1.test is excluded because a good number of its tests depend on
+# the page-cache being larger than the database. But this permutation
+# causes the effective limit on the page-cache to be just 24 pages.
+#
test_suite "memsubsys1" -description {
Tests using pre-allocated page and scratch blocks
} -files [
- test_set $::allquicktests -exclude ioerr5.test malloc5.test
+ test_set $::allquicktests -exclude ioerr5.test malloc5.test mmap1.test
] -initialize {
catch {db close}
sqlite3_shutdown
@@ -398,6 +525,8 @@ test_suite "utf16" -description {
pragma encoding = 'UTF-16'
} -files {
alter.test alter3.test
+ analyze.test analyze3.test analyze4.test analyze5.test analyze6.test
+ analyze7.test analyze8.test analyze9.test analyzeA.test analyzeB.test
auth.test bind.test blob.test capi2.test capi3.test collate1.test
collate2.test collate3.test collate4.test collate5.test collate6.test
conflict.test date.test delete.test expr.test fkey1.test func.test
@@ -413,6 +542,29 @@ test_suite "utf16" -description {
vacuum.test view.test where.test
}
+# Run tests appropriate to the BDB SQL API using UTF-16 databases.
+#
+test_suite "bdb-utf16" -description {
+ Run tests using UTF-16 databases
+} -presql {
+ pragma encoding = 'UTF-16'
+} -files {
+ alter.test alter3.test
+ auth.test bind.test blob.test collate1.test
+ collate2.test collate3.test collate4.test collate6.test
+ date.test delete.test expr.test fkey1.test
+ index.test insert2.test insert.test interrupt.test in.test
+ intpkey.test join2.test join.test lastinsert.test
+ laststmtchanges.test limit.test main.test
+ memdb.test minmax.test misc2.test misc3.test notnull.test
+ null.test quote.test rowid.test select1.test select2.test
+ select3.test select4.test select6.test sort.test
+ subselect.test tableapi.test table.test temptable.test
+ trace.test trigger1.test trigger2.test trigger3.test
+ trigger4.test types2.test types.test unique.test update.test
+ view.test where.test
+}
+
# Run some tests in exclusive locking mode.
#
test_suite "exclusive" -description {
@@ -518,13 +670,13 @@ test_suite "inmemory_journal" -description {
ioerr.test ioerr2.test ioerr3.test ioerr4.test ioerr5.test
vacuum3.test incrblob_err.test diskfull.test backup_ioerr.test
e_fts3.test fts3cov.test fts3malloc.test fts3rnd.test
- fts3snippet.test
+ fts3snippet.test mmapfault.test
# Exclude test scripts that use tcl IO to access journal files or count
# the number of fsync() calls.
pager.test exclusive.test jrnlmode.test sync.test misc1.test
journal1.test conflict.test crash8.test tkt3457.test io.test
- journal3.test
+ journal3.test 8_3_names.test
pager1.test async4.test corrupt.test filefmt.test pager2.test
corrupt5.test corruptA.test pageropt.test
@@ -532,8 +684,10 @@ test_suite "inmemory_journal" -description {
# Exclude stmt.test, which expects sub-journals to use temporary files.
stmt.test
+ zerodamage.test
+
# WAL mode is different.
- wal*
+ wal* tkt-2d1a5c67d.test backcompat.test
}]
ifcapable mem3 {
@@ -730,7 +884,7 @@ test_suite "journaltest" -description {
unregister_jt_vfs
} -files [test_set $::allquicktests -exclude {
wal* incrvacuum.test ioerr.test corrupt4.test io.test crash8.test
- async4.test bigfile.test
+ async4.test bigfile.test backcompat.test
}]
if {[info commands register_demovfs] != ""} {
@@ -780,6 +934,15 @@ test_suite "no_optimization" -description {
optimization_control $::dbhandle all 0
}
+test_suite "prepare" -description {
+ Run tests with the db connection using sqlite3_prepare() instead of _v2().
+} -dbconfig {
+ db_use_legacy_prepare $::dbhandle 1
+ #$::dbhandle cache size 0
+} -files [
+ test_set $allquicktests -exclude *malloc* *ioerr* *fault*
+]
+
# End of tests
#############################################################################
@@ -860,4 +1023,3 @@ if {[info script] == $argv0} {
main $argv
finish_test
}
-
diff --git a/lang/sql/sqlite/test/pragma.test b/lang/sql/sqlite/test/pragma.test
index 4b441829..10431703 100644
--- a/lang/sql/sqlite/test/pragma.test
+++ b/lang/sql/sqlite/test/pragma.test
@@ -16,6 +16,7 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
+set testprefix pragma
# 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).
@@ -40,6 +41,9 @@ do_not_use_codec
# pragma-15.*: Test that the value set using the cache_size pragma is not
# reset when the schema is reloaded.
# pragma-16.*: Test proxy locking
+# pragma-20.*: Test data_store_directory.
+# pragma-22.*: Test that "PRAGMA [db].integrity_check" respects the "db"
+# directive - if it is present.
#
ifcapable !pragma {
@@ -51,8 +55,8 @@ ifcapable !pragma {
# that the "all.test" script does.
#
db close
-file delete test.db test.db-journal
-file delete test3.db test3.db-journal
+delete_file test.db test.db-journal
+delete_file test3.db test3.db-journal
sqlite3 db test.db; set DB [sqlite3_connection_pointer db]
@@ -99,7 +103,7 @@ do_test pragma-1.5 {
PRAGMA default_cache_size;
PRAGMA synchronous;
}
-} [list 4321 $DFLT_CACHE_SZ 0]
+} [list -4321 $DFLT_CACHE_SZ 0]
do_test pragma-1.6 {
execsql {
PRAGMA synchronous=ON;
@@ -107,7 +111,7 @@ do_test pragma-1.6 {
PRAGMA default_cache_size;
PRAGMA synchronous;
}
-} [list 4321 $DFLT_CACHE_SZ 1]
+} [list -4321 $DFLT_CACHE_SZ 1]
do_test pragma-1.7 {
db close
sqlite3 db test.db
@@ -221,8 +225,8 @@ do_test pragma-1.18 {
# Test modifying the safety_level of an attached database.
ifcapable pager_pragmas&&attach {
do_test pragma-2.1 {
- file delete -force test2.db
- file delete -force test2.db-journal
+ forcedelete test2.db
+ forcedelete test2.db-journal
execsql {
ATTACH 'test2.db' AS aux;
}
@@ -255,7 +259,7 @@ ifcapable pager_pragmas&&attach {
#
do_test pragma-3.1 {
db close
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db test.db
execsql {
PRAGMA auto_vacuum=OFF;
@@ -281,38 +285,38 @@ ifcapable attach {
db close
sqlite3 db test.db
execsql {PRAGMA integrity_check}
- } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}}
+ } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}}
do_test pragma-3.3 {
execsql {PRAGMA integrity_check=1}
- } {{rowid 1 missing from index i2}}
+ } {{row 1 missing from index i2}}
do_test pragma-3.4 {
execsql {
ATTACH DATABASE 'test.db' AS t2;
PRAGMA integrity_check
}
- } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}}
+ } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}}
do_test pragma-3.5 {
execsql {
PRAGMA integrity_check=4
}
- } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2}}
+ } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {row 1 missing from index i2}}
do_test pragma-3.6 {
execsql {
PRAGMA integrity_check=xyz
}
- } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}}
+ } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}}
do_test pragma-3.7 {
execsql {
PRAGMA integrity_check=0
}
- } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}}
+ } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}}
# Add additional corruption by appending unused pages to the end of
# the database file testerr.db
#
do_test pragma-3.8 {
execsql {DETACH t2}
- file delete -force testerr.db testerr.db-journal
+ forcedelete testerr.db testerr.db-journal
set out [open testerr.db w]
fconfigure $out -translation binary
set in [open test.db r]
@@ -329,6 +333,9 @@ ifcapable attach {
do_test pragma-3.8.1 {
execsql {PRAGMA quick_check}
} {ok}
+ do_test pragma-3.8.2 {
+ execsql {PRAGMA QUICK_CHECK}
+ } {ok}
do_test pragma-3.9 {
execsql {
ATTACH 'testerr.db' AS t2;
@@ -337,7 +344,7 @@ ifcapable attach {
} {{*** in database t2 ***
Page 4 is never used
Page 5 is never used
-Page 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}}
+Page 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}}
do_test pragma-3.10 {
execsql {
PRAGMA integrity_check=1
@@ -351,7 +358,7 @@ Page 4 is never used}}
} {{*** in database t2 ***
Page 4 is never used
Page 5 is never used
-Page 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2}}
+Page 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2}}
do_test pragma-3.12 {
execsql {
PRAGMA integrity_check=4
@@ -359,7 +366,7 @@ Page 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from inde
} {{*** in database t2 ***
Page 4 is never used
Page 5 is never used
-Page 6 is never used} {rowid 1 missing from index i2}}
+Page 6 is never used} {row 1 missing from index i2}}
do_test pragma-3.13 {
execsql {
PRAGMA integrity_check=3
@@ -383,10 +390,10 @@ Page 5 is never used}}
} {{*** in database t2 ***
Page 4 is never used
Page 5 is never used
-Page 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {*** in database t3 ***
+Page 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {*** in database t3 ***
Page 4 is never used
Page 5 is never used
-Page 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}}
+Page 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}}
do_test pragma-3.16 {
execsql {
PRAGMA integrity_check(10)
@@ -394,10 +401,10 @@ Page 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from inde
} {{*** in database t2 ***
Page 4 is never used
Page 5 is never used
-Page 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {*** in database t3 ***
+Page 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {*** in database t3 ***
Page 4 is never used
Page 5 is never used
-Page 6 is never used} {rowid 1 missing from index i2}}
+Page 6 is never used} {row 1 missing from index i2}}
do_test pragma-3.17 {
execsql {
PRAGMA integrity_check=8
@@ -405,7 +412,7 @@ Page 6 is never used} {rowid 1 missing from index i2}}
} {{*** in database t2 ***
Page 4 is never used
Page 5 is never used
-Page 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {*** in database t3 ***
+Page 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {*** in database t3 ***
Page 4 is never used
Page 5 is never used}}
do_test pragma-3.18 {
@@ -415,11 +422,11 @@ Page 5 is never used}}
} {{*** in database t2 ***
Page 4 is never used
Page 5 is never used
-Page 6 is never used} {rowid 1 missing from index i2}}
+Page 6 is never used} {row 1 missing from index i2}}
}
do_test pragma-3.19 {
catch {db close}
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db test.db
db eval {PRAGMA integrity_check}
} {ok}
@@ -527,12 +534,20 @@ do_test pragma-6.2.2 {
b DEFAULT (5+3),
c TEXT,
d INTEGER DEFAULT NULL,
- e TEXT DEFAULT ''
+ e TEXT DEFAULT '',
+ UNIQUE(b,c,d),
+ PRIMARY KEY(e,b,c)
);
PRAGMA table_info(t5);
}
-} {0 a TEXT 0 CURRENT_TIMESTAMP 0 1 b {} 0 5+3 0 2 c TEXT 0 <<NULL>> 0 3 d INTEGER 0 NULL 0 4 e TEXT 0 '' 0}
+} {0 a TEXT 0 CURRENT_TIMESTAMP 0 1 b {} 0 5+3 2 2 c TEXT 0 <<NULL>> 3 3 d INTEGER 0 NULL 0 4 e TEXT 0 '' 1}
db nullvalue {}
+do_test pragma-6.2.3 {
+ execsql {
+ CREATE TABLE t2_3(a,b INTEGER PRIMARY KEY,c);
+ pragma table_info(t2_3)
+ }
+} {0 a {} 0 {} 0 1 b INTEGER 0 {} 1 2 c {} 0 {} 0}
ifcapable {foreignkey} {
do_test pragma-6.3.1 {
execsql {
@@ -741,8 +756,8 @@ do_test pragma-8.1.10 {
} SQLITE_SCHEMA
# Make sure the schema-version can be manipulated in an attached database.
-file delete -force test2.db
-file delete -force test2.db-journal
+forcedelete test2.db
+forcedelete test2.db-journal
ifcapable attach {
do_test pragma-8.1.11 {
execsql {
@@ -921,6 +936,16 @@ proc check_temp_store {} {
return "unknown"
}
+# Application_ID
+#
+do_test pragma-8.3.1 {
+ execsql {
+ PRAGMA application_id;
+ }
+} {0}
+do_test pragma-8.3.2 {
+ execsql {PRAGMA Application_ID(12345); PRAGMA application_id;}
+} {12345}
# Test temp_store and temp_store_directory pragmas
#
@@ -987,7 +1012,7 @@ do_test pragma-9.4 {
} {}
ifcapable wsd {
do_test pragma-9.5 {
- set pwd [string map {' ''} [file nativename [pwd]]]
+ set pwd [string map {' ''} [file nativename [get_pwd]]]
execsql "
PRAGMA temp_store_directory='$pwd';
"
@@ -996,7 +1021,7 @@ ifcapable wsd {
execsql {
PRAGMA temp_store_directory;
}
- } [list [file nativename [pwd]]]
+ } [list [file nativename [get_pwd]]]
do_test pragma-9.7 {
catchsql {
PRAGMA temp_store_directory='/NON/EXISTENT/PATH/FOOBAR';
@@ -1205,7 +1230,7 @@ do_test pragma-13.1 {
ifcapable pager_pragmas {
db close
- file delete -force test.db
+ forcedelete test.db
sqlite3 db test.db
do_test pragma-14.1 {
@@ -1219,6 +1244,9 @@ ifcapable pager_pragmas {
PRAGMA page_count;
}
} {2}
+ do_test pragma-14.2uc {
+ execsql {pragma PAGE_COUNT}
+ } {2}
do_test pragma-14.3 {
execsql {
@@ -1227,6 +1255,9 @@ ifcapable pager_pragmas {
PRAGMA page_count;
}
} {3}
+ do_test pragma-14.3uc {
+ execsql {pragma PAGE_COUNT}
+ } {3}
do_test pragma-14.4 {
set page_size [db one {pragma page_size}]
@@ -1241,7 +1272,7 @@ ifcapable pager_pragmas {
} {2}
do_test pragma-14.6 {
- file delete -force test2.db
+ forcedelete test2.db
sqlite3 db2 test2.db
execsql {
PRAGMA auto_vacuum = 0;
@@ -1256,6 +1287,9 @@ ifcapable pager_pragmas {
PRAGMA aux.page_count;
}
} {5}
+ do_test pragma-14.6uc {
+ execsql {pragma AUX.PAGE_COUNT}
+ } {5}
}
# Test that the value set using the cache_size pragma is not reset when the
@@ -1477,4 +1511,173 @@ foreach {temp_setting val} {
} $val
}
+# The SQLITE_FCNTL_PRAGMA logic, with error handling.
+#
+db close
+testvfs tvfs
+sqlite3 db test.db -vfs tvfs
+do_test pragma-19.1 {
+ catchsql {PRAGMA error}
+} {1 {SQL logic error or missing database}}
+do_test pragma-19.2 {
+ catchsql {PRAGMA error='This is the error message'}
+} {1 {This is the error message}}
+do_test pragma-19.3 {
+ catchsql {PRAGMA error='7 This is the error message'}
+} {1 {This is the error message}}
+do_test pragma-19.4 {
+ catchsql {PRAGMA error=7}
+} {1 {out of memory}}
+do_test pragma-19.5 {
+ file tail [lindex [execsql {PRAGMA filename}] 0]
+} {test.db}
+
+if {$tcl_platform(platform)=="windows"} {
+# Test data_store_directory pragma
+#
+db close
+sqlite3 db test.db
+file mkdir data_dir
+do_test pragma-20.1 {
+ catchsql {PRAGMA data_store_directory}
+} {0 {}}
+do_test pragma-20.2 {
+ set pwd [string map {' ''} [file nativename [get_pwd]]]
+ catchsql "PRAGMA data_store_directory='$pwd';"
+} {0 {}}
+do_test pragma-20.3 {
+ catchsql {PRAGMA data_store_directory}
+} [list 0 [list [file nativename [get_pwd]]]]
+do_test pragma-20.4 {
+ set pwd [string map {' ''} [file nativename \
+ [file join [get_pwd] data_dir]]]
+ catchsql "PRAGMA data_store_directory='$pwd';"
+} {0 {}}
+do_test pragma-20.5 {
+ sqlite3 db2 test2.db
+ catchsql "PRAGMA database_list;" db2
+} [list 0 [list 0 main [file nativename \
+ [file join [get_pwd] data_dir test2.db]]]]
+catch {db2 close}
+do_test pragma-20.6 {
+ sqlite3 db2 [file join [get_pwd] test2.db]
+ catchsql "PRAGMA database_list;" db2
+} [list 0 [list 0 main [file nativename \
+ [file join [get_pwd] test2.db]]]]
+catch {db2 close}
+do_test pragma-20.7 {
+ catchsql "PRAGMA data_store_directory='';"
+} {0 {}}
+do_test pragma-20.8 {
+ catchsql {PRAGMA data_store_directory}
+} {0 {}}
+
+forcedelete data_dir
+} ;# endif windows
+
+do_test 21.1 {
+ # Create a corrupt database in testerr.db. And a non-corrupt at test.db.
+ #
+ db close
+ forcedelete test.db
+ sqlite3 db test.db
+ execsql {
+ PRAGMA page_size = 1024;
+ PRAGMA auto_vacuum = 0;
+ CREATE TABLE t1(a PRIMARY KEY, b);
+ INSERT INTO t1 VALUES(1, 1);
+ }
+ for {set i 0} {$i < 10} {incr i} {
+ execsql { INSERT INTO t1 SELECT a + (1 << $i), b + (1 << $i) FROM t1 }
+ }
+ db close
+ forcecopy test.db testerr.db
+ hexio_write testerr.db 15000 [string repeat 55 100]
+} {100}
+
+set mainerr {*** in database main ***
+Multiple uses for byte 672 of page 15}
+set auxerr {*** in database aux ***
+Multiple uses for byte 672 of page 15}
+
+do_test 22.2 {
+ catch { db close }
+ sqlite3 db testerr.db
+ execsql { PRAGMA integrity_check }
+} [list $mainerr]
+
+do_test 22.3.1 {
+ catch { db close }
+ sqlite3 db test.db
+ execsql {
+ ATTACH 'testerr.db' AS 'aux';
+ PRAGMA integrity_check;
+ }
+} [list $auxerr]
+do_test 22.3.2 {
+ execsql { PRAGMA main.integrity_check; }
+} {ok}
+do_test 22.3.3 {
+ execsql { PRAGMA aux.integrity_check; }
+} [list $auxerr]
+
+do_test 22.4.1 {
+ catch { db close }
+ sqlite3 db testerr.db
+ execsql {
+ ATTACH 'test.db' AS 'aux';
+ PRAGMA integrity_check;
+ }
+} [list $mainerr]
+do_test 22.4.2 {
+ execsql { PRAGMA main.integrity_check; }
+} [list $mainerr]
+do_test 22.4.3 {
+ execsql { PRAGMA aux.integrity_check; }
+} {ok}
+
+db close
+forcedelete test.db test.db-wal test.db-journal
+sqlite3 db test.db
+sqlite3 db2 test.db
+do_test 23.1 {
+ db eval {
+ CREATE TABLE t1(a INTEGER PRIMARY KEY,b,c,d);
+ CREATE INDEX i1 ON t1(b,c);
+ CREATE INDEX i2 ON t1(c,d);
+ CREATE TABLE t2(x INTEGER REFERENCES t1);
+ }
+ db2 eval {SELECT name FROM sqlite_master}
+} {t1 i1 i2 t2}
+do_test 23.2 {
+ db eval {
+ DROP INDEX i2;
+ CREATE INDEX i2 ON t1(c,d,b);
+ }
+ db2 eval {PRAGMA index_info(i2)}
+} {0 2 c 1 3 d 2 1 b}
+do_test 23.3 {
+ db eval {
+ CREATE INDEX i3 ON t1(d,b,c);
+ }
+ db2 eval {PRAGMA index_list(t1)}
+} {0 i3 0 1 i2 0 2 i1 0}
+do_test 23.4 {
+ db eval {
+ ALTER TABLE t1 ADD COLUMN e;
+ }
+ db2 eval {
+ PRAGMA table_info(t1);
+ }
+} {/4 e {} 0 {} 0/}
+do_test 23.5 {
+ db eval {
+ DROP TABLE t2;
+ CREATE TABLE t2(x, y INTEGER REFERENCES t1);
+ }
+ db2 eval {
+ PRAGMA foreign_key_list(t2);
+ }
+} {0 0 t1 y {} {NO ACTION} {NO ACTION} NONE}
+
finish_test
diff --git a/lang/sql/sqlite/test/pragma2.test b/lang/sql/sqlite/test/pragma2.test
index 87c3c5d0..0dbc9777 100644
--- a/lang/sql/sqlite/test/pragma2.test
+++ b/lang/sql/sqlite/test/pragma2.test
@@ -22,6 +22,7 @@ source $testdir/tester.tcl
# pragma2-1.*: Test freelist_count pragma on the main database.
# pragma2-2.*: Test freelist_count pragma on an attached database.
# pragma2-3.*: Test trying to write to the freelist_count is a no-op.
+# pragma2-4.*: Tests for PRAGMA cache_spill
#
ifcapable !pragma||!schema_pragmas {
@@ -33,8 +34,8 @@ ifcapable !pragma||!schema_pragmas {
# that the "all.test" script does.
#
db close
-file delete test.db test.db-journal
-file delete test3.db test3.db-journal
+delete_file test.db test.db-journal
+delete_file test3.db test3.db-journal
sqlite3 db test.db; set DB [sqlite3_connection_pointer db]
db eval {PRAGMA auto_vacuum=0}
@@ -61,8 +62,8 @@ do_test pragma2-1.4 {
}
} {1}
-file delete -force test2.db
-file delete -force test2.db-journal
+forcedelete test2.db
+forcedelete test2.db-journal
ifcapable attach {
do_test pragma2-2.1 {
@@ -116,4 +117,92 @@ ifcapable attach {
} {9 9}
}
+# Default setting of PRAGMA cache_spill is always ON
+#
+# EVIDENCE-OF: R-51036-62828 PRAGMA cache_spill; PRAGMA
+# cache_spill=boolean;
+#
+# EVIDENCE-OF: R-23955-02765 Cache_spill is enabled by default
+#
+db close
+delete_file test.db test.db-journal
+delete_file test2.db test2.db-journal
+sqlite3 db test.db
+do_execsql_test pragma2-4.1 {
+ PRAGMA cache_spill;
+ PRAGMA main.cache_spill;
+ PRAGMA temp.cache_spill;
+} {1 1 1}
+do_execsql_test pragma2-4.2 {
+ PRAGMA cache_spill=OFF;
+ PRAGMA cache_spill;
+ PRAGMA main.cache_spill;
+ PRAGMA temp.cache_spill;
+} {0 0 0}
+do_execsql_test pragma2-4.3 {
+ PRAGMA page_size=1024;
+ PRAGMA cache_size=50;
+ BEGIN;
+ CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, d);
+ INSERT INTO t1 VALUES(1, randomblob(400), 1, randomblob(400));
+ INSERT INTO t1 SELECT a+1, randomblob(400), a+1, randomblob(400) FROM t1;
+ INSERT INTO t1 SELECT a+2, randomblob(400), a+2, randomblob(400) FROM t1;
+ INSERT INTO t1 SELECT a+4, randomblob(400), a+4, randomblob(400) FROM t1;
+ INSERT INTO t1 SELECT a+8, randomblob(400), a+8, randomblob(400) FROM t1;
+ INSERT INTO t1 SELECT a+16, randomblob(400), a+16, randomblob(400) FROM t1;
+ INSERT INTO t1 SELECT a+32, randomblob(400), a+32, randomblob(400) FROM t1;
+ INSERT INTO t1 SELECT a+64, randomblob(400), a+64, randomblob(400) FROM t1;
+ COMMIT;
+ ATTACH 'test2.db' AS aux1;
+ CREATE TABLE aux1.t2(a INTEGER PRIMARY KEY, b, c, d);
+ INSERT INTO t2 SELECT * FROM t1;
+ DETACH aux1;
+ PRAGMA cache_spill=ON;
+} {}
+sqlite3_release_memory
+#
+# EVIDENCE-OF: R-07634-40532 The cache_spill pragma enables or disables
+# the ability of the pager to spill dirty cache pages to the database
+# file in the middle of a transaction.
+#
+do_test pragma2-4.4 {
+ db eval {
+ BEGIN;
+ UPDATE t1 SET c=c+1;
+ PRAGMA lock_status;
+ }
+} {main exclusive temp unknown} ;# EXCLUSIVE lock due to cache spill
+do_test pragma2-4.5 {
+ db eval {
+ COMMIT;
+ PRAGMA cache_spill=OFF;
+ BEGIN;
+ UPDATE t1 SET c=c-1;
+ PRAGMA lock_status;
+ }
+} {main reserved temp unknown} ;# No cache spill, so no exclusive lock
+
+# Verify that newly attached databases inherit the cache_spill=OFF
+# setting.
+#
+do_execsql_test pragma2-4.6 {
+ COMMIT;
+ ATTACH 'test2.db' AS aux1;
+ PRAGMA aux1.cache_size=50;
+ BEGIN;
+ UPDATE t2 SET c=c+1;
+ PRAGMA lock_status;
+} {main unlocked temp unknown aux1 reserved}
+do_execsql_test pragma2-4.7 {
+ COMMIT;
+}
+sqlite3_release_memory
+do_execsql_test pragma2-4.8 {
+ PRAGMA cache_spill=ON; -- Applies to all databases
+ BEGIN;
+ UPDATE t2 SET c=c-1;
+ PRAGMA lock_status;
+} {main unlocked temp unknown aux1 exclusive}
+
+
finish_test
diff --git a/lang/sql/sqlite/test/printf.test b/lang/sql/sqlite/test/printf.test
index 100ce96b..73222720 100644
--- a/lang/sql/sqlite/test/printf.test
+++ b/lang/sql/sqlite/test/printf.test
@@ -3547,7 +3547,7 @@ do_test printf-4.16 {
do_test printf-5.1 {
set x [sqlite3_mprintf_str {%d %d %100000s} 0 0 {Hello}]
string length $x
-} {344}
+} {100004}
do_test printf-5.2 {
sqlite3_mprintf_str {%d %d (%-10.10s) %} -9 -10 {HelloHelloHello}
} {-9 -10 (HelloHello) %}
diff --git a/lang/sql/sqlite/test/printf2.test b/lang/sql/sqlite/test/printf2.test
new file mode 100644
index 00000000..4cb1783b
--- /dev/null
+++ b/lang/sql/sqlite/test/printf2.test
@@ -0,0 +1,99 @@
+# 2013-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 file implements regression tests for SQLite library. The
+# focus of this file is testing the printf() SQL function.
+#
+#
+# EVIDENCE-OF: R-63057-40065 The printf(FORMAT,...) SQL function works
+# like the sqlite3_mprintf() C-language function and the printf()
+# function from the standard C library.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+# EVIDENCE-OF: R-40086-60101 If the FORMAT argument is missing or NULL
+# then the result is NULL.
+#
+do_execsql_test printf2-1.1 {
+ SELECT quote(printf()), quote(printf(NULL,1,2,3));
+} {NULL NULL}
+
+
+do_execsql_test printf2-1.2 {
+ SELECT printf('hello');
+} {hello}
+do_execsql_test printf2-1.3 {
+ SELECT printf('%d,%d,%d',55,-11,3421);
+} {55,-11,3421}
+do_execsql_test printf2-1.4 {
+ SELECT printf('%d,%d,%d',55,'-11',3421);
+} {55,-11,3421}
+do_execsql_test printf2-1.5 {
+ SELECT printf('%d,%d,%d,%d',55,'-11',3421);
+} {55,-11,3421,0}
+do_execsql_test printf2-1.6 {
+ SELECT printf('%.2f',3.141592653);
+} {3.14}
+do_execsql_test printf2-1.7 {
+ SELECT printf('%.*f',2,3.141592653);
+} {3.14}
+do_execsql_test printf2-1.8 {
+ SELECT printf('%*.*f',5,2,3.141592653);
+} {{ 3.14}}
+do_execsql_test printf2-1.9 {
+ SELECT printf('%d',314159.2653);
+} {314159}
+do_execsql_test printf2-1.10 {
+ SELECT printf('%lld',314159.2653);
+} {314159}
+do_execsql_test printf2-1.11 {
+ SELECT printf('%lld%n',314159.2653,'hi');
+} {314159}
+
+# EVIDENCE-OF: R-17002-27534 The %z format is interchangeable with %s.
+#
+do_execsql_test printf2-1.12 {
+ SELECT printf('%.*z',5,'abcdefghijklmnop');
+} {abcde}
+do_execsql_test printf2-1.13 {
+ SELECT printf('%c','abcdefghijklmnop');
+} {a}
+
+# EVIDENCE-OF: R-02347-27622 The %n format is silently ignored and does
+# not consume an argument.
+#
+do_execsql_test printf2-2.1 {
+ CREATE TABLE t1(a,b,c);
+ INSERT INTO t1 VALUES(1,2,3);
+ INSERT INTO t1 VALUES(-1,-2,-3);
+ INSERT INTO t1 VALUES('abc','def','ghi');
+ INSERT INTO t1 VALUES(1.5,2.25,3.125);
+ SELECT printf('(%s)-%n-(%s)',a,b,c) FROM t1 ORDER BY rowid;
+} {(1)--(2) (-1)--(-2) (abc)--(def) (1.5)--(2.25)}
+
+# EVIDENCE-OF: R-56064-04001 The %p format is an alias for %X.
+#
+do_execsql_test printf2-2.2 {
+ SELECT printf('%s=(%p)',a,a) FROM t1 ORDER BY a;
+} {-1=(FFFFFFFFFFFFFFFF) 1=(1) 1.5=(1) abc=(0)}
+
+# EVIDENCE-OF: R-29410-53018 If there are too few arguments in the
+# argument list, missing arguments are assumed to have a NULL value,
+# which is translated into 0 or 0.0 for numeric formats or an empty
+# string for %s.
+#
+do_execsql_test printf2-2.3 {
+ SELECT printf('%s=(%d/%g/%s)',a) FROM t1 ORDER BY a;
+} {-1=(0/0/) 1=(0/0/) 1.5=(0/0/) abc=(0/0/)}
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/progress.test b/lang/sql/sqlite/test/progress.test
index b25a1005..993426aa 100644
--- a/lang/sql/sqlite/test/progress.test
+++ b/lang/sql/sqlite/test/progress.test
@@ -164,10 +164,12 @@ do_test progress-1.7 {
}
set ::res [list]
+ explain {SELECT a, b, c FROM abc}
db eval {SELECT a, b, c FROM abc} {
lappend ::res $a $b $c
- db progress 10 "expr 1"
+ db progress 5 "expr 1"
catch {db eval {SELECT a, b, c FROM abc} { }} msg
+ db progress 5 "expr 0"
lappend ::res $msg
}
diff --git a/lang/sql/sqlite/test/queryonly.test b/lang/sql/sqlite/test/queryonly.test
new file mode 100644
index 00000000..2774e5d4
--- /dev/null
+++ b/lang/sql/sqlite/test/queryonly.test
@@ -0,0 +1,72 @@
+# 2013-07-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 tests the "query_only" pragma.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+do_execsql_test queryonly-1.1 {
+ CREATE TABLE t1(a);
+ INSERT INTO t1 VALUES(123),(456);
+ SELECT a FROM t1 ORDER BY a;
+} {123 456}
+do_execsql_test queryonly-1.2 {
+ PRAGMA query_only;
+} {0}
+do_execsql_test queryonly-1.3 {
+ PRAGMA query_only=ON;
+ PRAGMA query_only;
+} {1}
+do_test queryonly-1.4 {
+ catchsql {INSERT INTO t1 VALUES(789);}
+} {1 {attempt to write a readonly database}}
+do_test queryonly-1.5 {
+ catchsql {DELETE FROM t1;}
+} {1 {attempt to write a readonly database}}
+do_test queryonly-1.6 {
+ catchsql {UPDATE t1 SET a=a+1;}
+} {1 {attempt to write a readonly database}}
+do_test queryonly-1.7 {
+ catchsql {CREATE TABLE t2(b);}
+} {1 {attempt to write a readonly database}}
+do_test queryonly-1.8 {
+ catchsql {CREATE INDEX t1a ON t1(a);}
+} {1 {attempt to write a readonly database}}
+do_test queryonly-1.9 {
+ catchsql {DROP TABLE t1;}
+} {1 {attempt to write a readonly database}}
+do_test queryonly-1.10 {
+ catchsql {ANALYZE;}
+} {1 {attempt to write a readonly database}}
+do_execsql_test queryonly-1.11 {
+ SELECT a FROM t1 ORDER BY a;
+} {123 456}
+
+do_execsql_test queryonly-2.2 {
+ PRAGMA query_only;
+} {1}
+do_execsql_test queryonly-2.3 {
+ PRAGMA query_only=OFF;
+ PRAGMA query_only;
+} {0}
+do_execsql_test queryonly-2.4 {
+ INSERT INTO t1 VALUES(789);
+ SELECT a FROM t1 ORDER BY a;
+} {123 456 789}
+do_execsql_test queryonly-2.5 {
+ UPDATE t1 SET a=a+1;
+ SELECT a FROM t1 ORDER BY a;
+} {124 457 790}
+
+finish_test
diff --git a/lang/sql/sqlite/test/quota-glob.test b/lang/sql/sqlite/test/quota-glob.test
new file mode 100644
index 00000000..28c813c3
--- /dev/null
+++ b/lang/sql/sqlite/test/quota-glob.test
@@ -0,0 +1,87 @@
+# 2011 December 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.
+#
+#***********************************************************************
+#
+# Tests for the glob-style string compare operator embedded in the
+# quota shim.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+catch { unset testnum }
+catch { unset pattern }
+catch { unset text }
+catch { unset ans }
+
+foreach {testnum pattern text ans} {
+ 1 abcdefg abcdefg 1
+ 2 abcdefG abcdefg 0
+ 3 abcdef abcdefg 0
+ 4 abcdefgh abcdefg 0
+ 5 abcdef? abcdefg 1
+ 6 abcdef? abcdef 0
+ 7 abcdef? abcdefgh 0
+ 8 abcdefg abcdef? 0
+ 9 abcdef? abcdef? 1
+ 10 abc/def abc/def 1
+ 11 abc//def abc/def 0
+ 12 */abc/* x/abc/y 1
+ 13 */abc/* /abc/ 1
+ 16 */abc/* x///a/ab/abc 0
+ 17 */abc/* x//a/ab/abc/ 1
+ 16 */abc/* x///a/ab/abc 0
+ 17 */abc/* x//a/ab/abc/ 1
+ 18 **/abc/** x//a/ab/abc/ 1
+ 19 *?/abc/*? x//a/ab/abc/y 1
+ 20 ?*/abc/?* x//a/ab/abc/y 1
+ 21 {abc[cde]efg} abcbefg 0
+ 22 {abc[cde]efg} abccefg 1
+ 23 {abc[cde]efg} abcdefg 1
+ 24 {abc[cde]efg} abceefg 1
+ 25 {abc[cde]efg} abcfefg 0
+ 26 {abc[^cde]efg} abcbefg 1
+ 27 {abc[^cde]efg} abccefg 0
+ 28 {abc[^cde]efg} abcdefg 0
+ 29 {abc[^cde]efg} abceefg 0
+ 30 {abc[^cde]efg} abcfefg 1
+ 31 {abc[c-e]efg} abcbefg 0
+ 32 {abc[c-e]efg} abccefg 1
+ 33 {abc[c-e]efg} abcdefg 1
+ 34 {abc[c-e]efg} abceefg 1
+ 35 {abc[c-e]efg} abcfefg 0
+ 36 {abc[^c-e]efg} abcbefg 1
+ 37 {abc[^c-e]efg} abccefg 0
+ 38 {abc[^c-e]efg} abcdefg 0
+ 39 {abc[^c-e]efg} abceefg 0
+ 40 {abc[^c-e]efg} abcfefg 1
+ 41 {abc[c-e]efg} abc-efg 0
+ 42 {abc[-ce]efg} abc-efg 1
+ 43 {abc[ce-]efg} abc-efg 1
+ 44 {abc[][*?]efg} {abc]efg} 1
+ 45 {abc[][*?]efg} {abc*efg} 1
+ 46 {abc[][*?]efg} {abc?efg} 1
+ 47 {abc[][*?]efg} {abc[efg} 1
+ 48 {abc[^][*?]efg} {abc]efg} 0
+ 49 {abc[^][*?]efg} {abc*efg} 0
+ 50 {abc[^][*?]efg} {abc?efg} 0
+ 51 {abc[^][*?]efg} {abc[efg} 0
+ 52 {abc[^][*?]efg} {abcdefg} 1
+ 53 {*[xyz]efg} {abcxefg} 1
+ 54 {*[xyz]efg} {abcwefg} 0
+} {
+ do_test quota-glob-$testnum.1 {
+ sqlite3_quota_glob $::pattern $::text
+ } $::ans
+ do_test quota-glob-$testnum.2 {
+ sqlite3_quota_glob $::pattern [string map {/ \\} $::text]
+ } $::ans
+}
+finish_test
diff --git a/lang/sql/sqlite/test/quota.test b/lang/sql/sqlite/test/quota.test
index 2cf76280..f9655fb8 100644
--- a/lang/sql/sqlite/test/quota.test
+++ b/lang/sql/sqlite/test/quota.test
@@ -12,8 +12,17 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
+
+# If SQLITE_CURDIR is not defined, omit this file.
+ifcapable !curdir {
+ finish_test
+ return
+}
+
source $testdir/malloc_common.tcl
+unset -nocomplain defaultVfs
+set defaultVfs [file_control_vfsname db]
db close
do_test quota-1.1 { sqlite3_quota_initialize nosuchvfs 1 } {SQLITE_ERROR}
@@ -48,6 +57,7 @@ do_test quota-1.8 { sqlite3_quota_shutdown } {SQLITE_OK}
#
sqlite3_quota_initialize "" 1
+unset -nocomplain quota_request_ok
proc quota_check {filename limitvar size} {
upvar $limitvar limit
@@ -73,6 +83,9 @@ do_test quota-2.1.2 {
}
set ::quota
} {}
+do_test quota-2.1.2.1 {
+ file_control_vfsname db
+} quota/$defaultVfs
do_test quota-2.1.3 { file size test.db } {4096}
do_test quota-2.1.4 {
catchsql { INSERT INTO t1 VALUES(3, randomblob(1100)) }
@@ -123,7 +136,7 @@ proc quota_check {filename limitvar size} {
}
do_test quota-3.1.1 {
- file delete -force test.db
+ forcedelete test.db
sqlite3_quota_initialize "" 1
sqlite3_quota_set *test.db 4096 quota_check
} {SQLITE_OK}
@@ -158,7 +171,7 @@ do_test quota-3.1.6 {
} {SQLITE_OK}
do_test quota-3.2.1 {
- file delete force test.db test2.db
+ delete_file force test.db test2.db
sqlite3_quota_set * 4096 {}
sqlite3 db1a test.db
@@ -202,6 +215,9 @@ do_test quota-3.2.9 {
set ::quota [list]
proc quota_callback {file limitvar size} {
upvar $limitvar limit
+ if {$::tcl_platform(platform)=="windows"} {
+ set file [ lindex [string map {\\ \/} $file] 0 ]
+ }
lappend ::quota $file $size
set limit 0
}
@@ -212,7 +228,7 @@ do_test quota-3.3.1 {
execsql { INSERT INTO t1 VALUES(randomblob(500), randomblob(500)) } db2a
execsql { INSERT INTO t1 VALUES(randomblob(500), randomblob(500)) } db2b
set ::quota
-} [list [file join [pwd] test.db] 5120]
+} [list [file join [get_pwd] test.db] 5120]
do_test quota-3.2.X {
foreach db {db1a db2a db2b db1b} { catch { $db close } }
@@ -220,7 +236,7 @@ do_test quota-3.2.X {
} {SQLITE_OK}
#-------------------------------------------------------------------------
-# Quotas are deleted when unused and when there limit is set to zero
+# Quotas are deleted when unused and when their limit is set to zero
#
# Return a list of all currently defined quotas. Each quota is identified
@@ -232,6 +248,13 @@ proc quota_list {} {
}
return [lsort $allq]
}
+proc quota_size {name} {
+ set allq {}
+ foreach q [sqlite3_quota_dump] {
+ if {[lindex $q 0]==$name} {return [lindex $q 2]}
+ }
+ return 0
+}
do_test quota-4.1.1 {
sqlite3_quota_set *test.db 0 {}
@@ -254,7 +277,7 @@ do_test quota-4.1.5 {
quota_list
} {*test2.db}
do_test quota-4.1.6 {
- file delete -force test2.db test2.db-journal test2.db-wal
+ forcedelete test2.db test2.db-journal test2.db-wal
sqlite3 db test2.db
db eval {CREATE TABLE t2(x); INSERT INTO t2 VALUES('tab-t2');}
quota_list
@@ -326,11 +349,121 @@ do_test quota-4.3.1 {
quota_list
} {}
+unset -nocomplain quotagroup
+if {$tcl_platform(platform)=="windows"} {
+ set quotagroup *\\quota-test-A?.db
+} else {
+ set quotagroup */quota-test-A?.db
+}
+foreach file [glob -nocomplain quota-test-A*] {
+ forcedelete $file
+}
do_test quota-4.4.1 {
+ set ::quota {}
+ sqlite3_quota_set $::quotagroup 10000 quota_callback
+ forcedelete ./quota-test-A1.db ./quota-test-A2.db
+ sqlite3 db ./quota-test-A1.db
+ db eval {
+ CREATE TABLE t1(x);
+ INSERT INTO t1 VALUES(randomblob(5000));
+ }
+ quota_list
+} [list $quotagroup]
+do_test quota-4.4.2 {
+ expr {$::quota==""}
+} {1}
+do_test quota-4.4.3 {
+ db close
+ sqlite3 db ./quota-test-A2.db
+ db eval {
+ CREATE TABLE t1(x);
+ INSERT INTO t1 VALUES(randomblob(5000));
+ }
+ quota_list
+} [list $quotagroup]
+do_test quota-4.4.4 {
+ expr {$::quota!=""}
+} {1}
+do_test quota-4.4.5 {
+ db close
+ sqlite3_quota_set $::quotagroup 0 {}
+ sqlite3_quota_dump
+} {}
+do_test quota-4.4.6 {
+ sqlite3_quota_set $quotagroup 10000 quota_callback
+ sqlite3 db quota-test-A1.db
+ db eval {SELECT count(*) FROM sqlite_master}
+ quota_size $quotagroup
+} [file size quota-test-A1.db]
+do_test quota-4.4.7 {
+ sqlite3_quota_file quota-test-A2.db
+ quota_size $::quotagroup
+} [expr {[file size quota-test-A1.db]+[file size quota-test-A2.db]}]
+
+unset -nocomplain quotagroup
+if {$tcl_platform(platform)=="windows"} {
+ set quotagroup *\\quota-test-B*
+} else {
+ set quotagroup */quota-test-B*
+}
+foreach file [glob -nocomplain quota-test-B*] {
+ forcedelete $file
+}
+do_test quota-4.5.1 {
+ sqlite3_quota_set $::quotagroup 100000 quota_callback
+ quota_size $::quotagroup
+} {0}
+do_test quota-4.5.2 {
+ sqlite3_quota_file quota-test-B1.txt
+ quota_size $::quotagroup
+} {0}
+proc add_to_file {name n} {
+ set out [open $name a]
+ fconfigure $out -translation binary
+ puts -nonewline $out [string repeat x $n]
+ close $out
+}
+do_test quota-4.5.3 {
+ add_to_file quota-test-B1.txt 123
+ sqlite3_quota_file quota-test-B1.txt
+ quota_size $::quotagroup
+} {123}
+do_test quota-4.5.4 {
+ add_to_file quota-test-B2.txt 234
+ sqlite3_quota_file quota-test-B2.txt
+ quota_size $::quotagroup
+} {357}
+do_test quota-4.5.5 {
+ add_to_file quota-test-B1.txt 2000
+ sqlite3_quota_file quota-test-B1.txt
+ quota_size $::quotagroup
+} {2357}
+do_test quota-4.5.6 {
+ forcedelete quota-test-B1.txt
+ sqlite3_quota_file quota-test-B1.txt
+ quota_size $::quotagroup
+} {234}
+do_test quota-4.5.7 {
+ forcedelete quota-test-B2.txt
+ sqlite3_quota_file quota-test-B2.txt
+ quota_size $::quotagroup
+} {0}
+do_test quota-4.5.8 {
+ add_to_file quota-test-B3.txt 1234
+ sqlite3_quota_file quota-test-B3.txt
+ quota_size $::quotagroup
+} {1234}
+do_test quota-4.5.9 {
+ sqlite3_quota_set $quotagroup 0 {}
+ quota_size $::quotagroup
+} {0}
+
+do_test quota-4.9.1 {
+ db close
sqlite3_quota_set A 1000 quota_callback
sqlite3_quota_shutdown
} {SQLITE_OK}
-do_test quota-4.4.2 {
+do_test quota-4.9.2 {
quota_list
} {}
@@ -354,7 +487,7 @@ do_faultsim_test quota-5.2 -prep {
}
catch { db close }
-file delete -force test.db
+forcedelete test.db
do_test quota-5.3.prep {
sqlite3 db test.db
@@ -374,7 +507,7 @@ do_faultsim_test quota-5.3 -prep {
do_test quota-5.4.1 {
catch { db close }
- file delete -force test.db
+ forcedelete test.db
file mkdir test.db
list [catch { sqlite3 db test.db } msg] $msg
} {1 {unable to open database file}}
diff --git a/lang/sql/sqlite/test/quota2.test b/lang/sql/sqlite/test/quota2.test
new file mode 100644
index 00000000..8682bd86
--- /dev/null
+++ b/lang/sql/sqlite/test/quota2.test
@@ -0,0 +1,302 @@
+# 2011 December 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.
+#
+#***********************************************************************
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+# If SQLITE_CURDIR is not defined, omit this file.
+ifcapable !curdir {
+ finish_test
+ return
+}
+
+source $testdir/malloc_common.tcl
+
+db close
+sqlite3_quota_initialize "" 1
+
+foreach dir {quota2a/x1 quota2a/x2 quota2a quota2b quota2c} {
+ forcedelete $dir
+}
+foreach dir {quota2a quota2a/x1 quota2a/x2 quota2b quota2c} {
+ file mkdir $dir
+}
+
+# The standard_path procedure converts a pathname into a standard format
+# that is the same across platforms.
+#
+unset -nocomplain ::quota_pwd ::quota_mapping
+set ::quota_pwd [string map {\\ /} [get_pwd]]
+set ::quota_mapping [list $::quota_pwd PWD]
+proc standard_path {x} {
+ set x [string map {\\ /} $x]
+ return [string map $::quota_mapping $x]
+}
+
+# The quota_check procedure is a callback from the quota handler.
+# It has three arguments which are (1) the full pathname of the file
+# that has gone over quota, (2) the quota limit, (3) the requested
+# new quota size to cover the last write. These three values are
+# appended to the global variable $::quota. The filename is processed
+# to convert every \ character into / and to change the name of the
+# working directory to PWD.
+#
+# The quota is increased to the request if the ::quota_request_ok
+# global variable is true.
+#
+set ::quota {}
+set ::quota_request_ok 0
+
+proc quota_check {filename limitvar size} {
+ upvar $limitvar limit
+ lappend ::quota [standard_path $filename] [set limit] $size
+ if {$::quota_request_ok} {set limit $size}
+}
+
+sqlite3_quota_set */quota2a/* 4000 quota_check
+sqlite3_quota_set */quota2b/* 5000 quota_check
+
+unset -nocomplain bigtext
+for {set i 1} {$i<=1000} {incr i} {
+ if {$i%10==0} {
+ append bigtext [format "%06d\n" $i]
+ } else {
+ append bigtext [format "%06d " $i]
+ }
+}
+
+catch { unset h1 }
+catch { unset x }
+do_test quota2-1.1 {
+ set ::h1 [sqlite3_quota_fopen quota2a/xyz.txt w+b]
+ sqlite3_quota_fwrite $::h1 1 7000 $bigtext
+} {4000}
+do_test quota2-1.2 {
+ set ::quota
+} {PWD/quota2a/xyz.txt 4000 7000}
+do_test quota2-1.2.1 {
+ sqlite3_quota_file_size $::h1
+} {4000}
+do_test quota2-1.2.2 {
+ sqlite3_quota_fflush $::h1 1
+ sqlite3_quota_file_truesize $::h1
+} {4000}
+do_test quota2-1.3 {
+ sqlite3_quota_rewind $::h1
+ set ::x [sqlite3_quota_fread $::h1 1001 7]
+ string length $::x
+} {3003}
+do_test quota2-1.4 {
+ string match $::x [string range $::bigtext 0 3002]
+} {1}
+do_test quota2-1.5 {
+ sqlite3_quota_fseek $::h1 0 SEEK_END
+ sqlite3_quota_ftell $::h1
+} {4000}
+do_test quota2-1.6 {
+ sqlite3_quota_fseek $::h1 -100 SEEK_END
+ sqlite3_quota_ftell $::h1
+} {3900}
+do_test quota2-1.7 {
+ sqlite3_quota_fseek $::h1 -100 SEEK_CUR
+ sqlite3_quota_ftell $::h1
+} {3800}
+do_test quota2-1.8 {
+ sqlite3_quota_fseek $::h1 50 SEEK_CUR
+ sqlite3_quota_ftell $::h1
+} {3850}
+do_test quota2-1.9 {
+ sqlite3_quota_fseek $::h1 50 SEEK_SET
+ sqlite3_quota_ftell $::h1
+} {50}
+do_test quota2-1.10 {
+ sqlite3_quota_rewind $::h1
+ sqlite3_quota_ftell $::h1
+} {0}
+do_test quota2-1.11 {
+ standard_path [sqlite3_quota_dump]
+} {{*/quota2b/* 5000 0} {*/quota2a/* 4000 4000 {PWD/quota2a/xyz.txt 4000 1 0}}}
+do_test quota2-1.12 {
+ sqlite3_quota_ftruncate $::h1 3500
+ sqlite3_quota_file_size $::h1
+} {3500}
+do_test quota2-1.13 {
+ sqlite3_quota_file_truesize $::h1
+} {3500}
+do_test quota2-1.14 {
+ standard_path [sqlite3_quota_dump]
+} {{*/quota2b/* 5000 0} {*/quota2a/* 4000 3500 {PWD/quota2a/xyz.txt 3500 1 0}}}
+do_test quota2-1.15 {
+ sqlite3_quota_fseek $::h1 0 SEEK_END
+ sqlite3_quota_ftell $::h1
+} {3500}
+do_test quota2-1.16 {
+ sqlite3_quota_fwrite $::h1 1 7000 $bigtext
+} {500}
+do_test quota2-1.17 {
+ sqlite3_quota_ftell $::h1
+} {4000}
+do_test quota2-1.18 {
+ sqlite3_quota_file_size $::h1
+} {4000}
+do_test quota2-1.19 {
+ sqlite3_quota_fflush $::h1 1
+ sqlite3_quota_file_truesize $::h1
+} {4000}
+do_test quota2-1.20 {
+ sqlite3_quota_fclose $::h1
+ standard_path [sqlite3_quota_dump]
+} {{*/quota2b/* 5000 0} {*/quota2a/* 4000 4000 {PWD/quota2a/xyz.txt 4000 0 0}}}
+do_test quota2-1.21 {
+ sqlite3_quota_remove quota2a/xyz.txt
+ standard_path [sqlite3_quota_dump]
+} {{*/quota2b/* 5000 0} {*/quota2a/* 4000 0}}
+
+
+
+set quota {}
+do_test quota2-2.1 {
+ set ::h1 [sqlite3_quota_fopen quota2c/xyz.txt w+b]
+ sqlite3_quota_fwrite $::h1 1 7000 $bigtext
+} {7000}
+do_test quota2-2.2 {
+ set ::quota
+} {}
+do_test quota2-2.3.1 {
+ sqlite3_quota_rewind $::h1
+ sqlite3_quota_file_available $::h1
+} {7000}
+do_test quota2-2.3.2 {
+ set ::x [sqlite3_quota_fread $::h1 1001 7]
+ string length $::x
+} {6006}
+do_test quota2-2.3.3 {
+ sqlite3_quota_file_available $::h1
+} {0}
+do_test quota2-2.4 {
+ string match $::x [string range $::bigtext 0 6005]
+} {1}
+do_test quota2-2.5 {
+ sqlite3_quota_fseek $::h1 0 SEEK_END
+ sqlite3_quota_ftell $::h1
+} {7000}
+do_test quota2-2.6 {
+ sqlite3_quota_fseek $::h1 -100 SEEK_END
+ sqlite3_quota_ftell $::h1
+} {6900}
+do_test quota2-2.6.1 {
+ sqlite3_quota_file_available $::h1
+} {100}
+do_test quota2-2.7 {
+ sqlite3_quota_fseek $::h1 -100 SEEK_CUR
+ sqlite3_quota_ftell $::h1
+} {6800}
+do_test quota2-2.7.1 {
+ sqlite3_quota_file_available $::h1
+} {200}
+do_test quota2-2.8 {
+ sqlite3_quota_fseek $::h1 50 SEEK_CUR
+ sqlite3_quota_ftell $::h1
+} {6850}
+do_test quota2-2.8.1 {
+ sqlite3_quota_file_available $::h1
+} {150}
+do_test quota2-2.9 {
+ sqlite3_quota_fseek $::h1 50 SEEK_SET
+ sqlite3_quota_ftell $::h1
+} {50}
+do_test quota2-2.9.1 {
+ sqlite3_quota_file_available $::h1
+} {6950}
+do_test quota2-2.10 {
+ sqlite3_quota_rewind $::h1
+ sqlite3_quota_ftell $::h1
+} {0}
+do_test quota2-2.10.1 {
+ sqlite3_quota_file_available $::h1
+} {7000}
+do_test quota2-2.10.2 {
+ sqlite3_quota_ferror $::h1
+} {0}
+do_test quota2-2.11 {
+ standard_path [sqlite3_quota_dump]
+} {{*/quota2b/* 5000 0} {*/quota2a/* 4000 0}}
+do_test quota2-2.12 {
+ sqlite3_quota_fclose $::h1
+ standard_path [sqlite3_quota_dump]
+} {{*/quota2b/* 5000 0} {*/quota2a/* 4000 0}}
+
+do_test quota2-3.1 {
+ sqlite3_quota_set */quota2b/* 0 quota_check
+ set ::h1 [sqlite3_quota_fopen quota2a/x1/a.txt a]
+ sqlite3_quota_fwrite $::h1 10 10 $bigtext
+} {10}
+do_test quota2-3.2 {
+ standard_path [sqlite3_quota_dump]
+} {{*/quota2a/* 4000 100 {PWD/quota2a/x1/a.txt 100 1 0}}}
+do_test quota2-3.3a {
+ sqlite3_quota_fflush $::h1 0
+ standard_path [sqlite3_quota_dump]
+} {{*/quota2a/* 4000 100 {PWD/quota2a/x1/a.txt 100 1 0}}}
+do_test quota2-3.3b {
+ sqlite3_quota_fflush $::h1 1
+ standard_path [sqlite3_quota_dump]
+} {{*/quota2a/* 4000 100 {PWD/quota2a/x1/a.txt 100 1 0}}}
+do_test quota2-3.3c {
+ sqlite3_quota_fflush $::h1
+ standard_path [sqlite3_quota_dump]
+} {{*/quota2a/* 4000 100 {PWD/quota2a/x1/a.txt 100 1 0}}}
+do_test quota2-3.4 {
+ sqlite3_quota_fclose $::h1
+ standard_path [sqlite3_quota_dump]
+} {{*/quota2a/* 4000 100 {PWD/quota2a/x1/a.txt 100 0 0}}}
+do_test quota2-3.5 {
+ set ::h2 [sqlite3_quota_fopen quota2a/x2/b.txt a]
+ sqlite3_quota_fwrite $::h2 10 20 $bigtext
+ standard_path [sqlite3_quota_dump]
+} {{*/quota2a/* 4000 300 {PWD/quota2a/x2/b.txt 200 1 0} {PWD/quota2a/x1/a.txt 100 0 0}}}
+do_test quota2-3.6 {
+ set ::h3 [sqlite3_quota_fopen quota2a/x1/c.txt a]
+ sqlite3_quota_fwrite $::h3 10 50 $bigtext
+ standard_path [sqlite3_quota_dump]
+} {{*/quota2a/* 4000 800 {PWD/quota2a/x1/c.txt 500 1 0} {PWD/quota2a/x2/b.txt 200 1 0} {PWD/quota2a/x1/a.txt 100 0 0}}}
+do_test quota2-3.7 {
+ file exists quota2a/x1/a.txt
+} {1}
+do_test quota2-3.8 {
+ file exists quota2a/x2/b.txt
+} {1}
+do_test quota2-3.9 {
+ file exists quota2a/x1/c.txt
+} {1}
+do_test quota2-3.10 {
+ sqlite3_quota_remove quota2a/x1
+ standard_path [sqlite3_quota_dump]
+} {{*/quota2a/* 4000 700 {PWD/quota2a/x1/c.txt 500 1 1} {PWD/quota2a/x2/b.txt 200 1 0}}}
+do_test quota2-3.11 {
+ sqlite3_quota_fclose $::h2
+ sqlite3_quota_fclose $::h3
+ standard_path [sqlite3_quota_dump]
+} {{*/quota2a/* 4000 200 {PWD/quota2a/x2/b.txt 200 0 0}}}
+do_test quota2-3.12 {
+ file exists quota2a/x1/a.txt
+} {0}
+do_test quota2-3.13 {
+ file exists quota2a/x2/b.txt
+} {1}
+do_test quota2-3.14 {
+ file exists quota2a/x1/c.txt
+} {0}
+
+catch { sqlite3_quota_shutdown }
+catch { unset quota_request_ok }
+finish_test
diff --git a/lang/sql/sqlite/test/randexpr1.test b/lang/sql/sqlite/test/randexpr1.test
index 10a1d17c..7a98f0be 100644
--- a/lang/sql/sqlite/test/randexpr1.test
+++ b/lang/sql/sqlite/test/randexpr1.test
@@ -22,6 +22,11 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
+ifcapable !compound {
+ finish_test
+ return
+}
+
# Create test data
#
do_test randexpr1-1.1 {
diff --git a/lang/sql/sqlite/test/regexp1.test b/lang/sql/sqlite/test/regexp1.test
new file mode 100644
index 00000000..0e63cd98
--- /dev/null
+++ b/lang/sql/sqlite/test/regexp1.test
@@ -0,0 +1,211 @@
+# 2012 December 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 test for the REGEXP operator in test_regexp.c.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+do_test regexp1-1.1 {
+ load_static_extension db regexp
+ db eval {
+ CREATE TABLE t1(x INTEGER PRIMARY KEY, y TEXT);
+ INSERT INTO t1 VALUES(1, 'For since by man came death,');
+ INSERT INTO t1 VALUES(2, 'by man came also the resurrection of the dead.');
+ INSERT INTO t1 VALUES(3, 'For as in Adam all die,');
+ INSERT INTO t1 VALUES(4, 'even so in Christ shall all be made alive.');
+
+ SELECT x FROM t1 WHERE y REGEXP '^For ' ORDER BY x;
+ }
+} {1 3}
+
+do_execsql_test regexp1-1.2 {
+ SELECT x FROM t1 WHERE y REGEXP 'by|in' ORDER BY x;
+} {1 2 3 4}
+do_execsql_test regexp1-1.3 {
+ SELECT x FROM t1 WHERE y REGEXP 'by|Christ' ORDER BY x;
+} {1 2 4}
+do_execsql_test regexp1-1.4 {
+ SELECT x FROM t1 WHERE y REGEXP 'shal+ al+' ORDER BY x;
+} {4}
+do_execsql_test regexp1-1.5 {
+ SELECT x FROM t1 WHERE y REGEXP 'shall x*y*z*all' ORDER BY x;
+} {4}
+do_execsql_test regexp1-1.6 {
+ SELECT x FROM t1 WHERE y REGEXP 'shallx?y? ?z?all' ORDER BY x;
+} {4}
+do_execsql_test regexp1-1.7 {
+ SELECT x FROM t1 WHERE y REGEXP 'r{2}' ORDER BY x;
+} {2}
+do_execsql_test regexp1-1.8 {
+ SELECT x FROM t1 WHERE y REGEXP 'r{3}' ORDER BY x;
+} {}
+do_execsql_test regexp1-1.9 {
+ SELECT x FROM t1 WHERE y REGEXP 'r{1}' ORDER BY x;
+} {1 2 3 4}
+do_execsql_test regexp1-1.10 {
+ SELECT x FROM t1 WHERE y REGEXP 'ur{2,10}e' ORDER BY x;
+} {2}
+do_execsql_test regexp1-1.11 {
+ SELECT x FROM t1 WHERE y REGEXP '[Aa]dam' ORDER BY x;
+} {3}
+do_execsql_test regexp1-1.12 {
+ SELECT x FROM t1 WHERE y REGEXP '[^Aa]dam' ORDER BY x;
+} {}
+do_execsql_test regexp1-1.13 {
+ SELECT x FROM t1 WHERE y REGEXP '[^b-zB-Z]dam' ORDER BY x;
+} {3}
+do_execsql_test regexp1-1.14 {
+ SELECT x FROM t1 WHERE y REGEXP 'alive' ORDER BY x;
+} {4}
+do_execsql_test regexp1-1.15 {
+ SELECT x FROM t1 WHERE y REGEXP '^alive' ORDER BY x;
+} {}
+do_execsql_test regexp1-1.16 {
+ SELECT x FROM t1 WHERE y REGEXP 'alive$' ORDER BY x;
+} {}
+do_execsql_test regexp1-1.17 {
+ SELECT x FROM t1 WHERE y REGEXP 'alive.$' ORDER BY x;
+} {4}
+do_execsql_test regexp1-1.18 {
+ SELECT x FROM t1 WHERE y REGEXP 'alive\.$' ORDER BY x;
+} {4}
+do_execsql_test regexp1-1.19 {
+ SELECT x FROM t1 WHERE y REGEXP 'ma[nd]' ORDER BY x;
+} {1 2 4}
+do_execsql_test regexp1-1.20 {
+ SELECT x FROM t1 WHERE y REGEXP '\bma[nd]' ORDER BY x;
+} {1 2 4}
+do_execsql_test regexp1-1.21 {
+ SELECT x FROM t1 WHERE y REGEXP 'ma[nd]\b' ORDER BY x;
+} {1 2}
+do_execsql_test regexp1-1.22 {
+ SELECT x FROM t1 WHERE y REGEXP 'ma\w' ORDER BY x;
+} {1 2 4}
+do_execsql_test regexp1-1.23 {
+ SELECT x FROM t1 WHERE y REGEXP 'ma\W' ORDER BY x;
+} {}
+do_execsql_test regexp1-1.24 {
+ SELECT x FROM t1 WHERE y REGEXP '\sma\w' ORDER BY x;
+} {1 2 4}
+do_execsql_test regexp1-1.25 {
+ SELECT x FROM t1 WHERE y REGEXP '\Sma\w' ORDER BY x;
+} {}
+do_execsql_test regexp1-1.26 {
+ SELECT x FROM t1 WHERE y REGEXP 'alive\S$' ORDER BY x;
+} {4}
+do_execsql_test regexp1-1.27 {
+ SELECT x FROM t1 WHERE y REGEXP
+ '\b(unto|us|son|given|his|name|called|' ||
+ 'wonderful|councelor|mighty|god|everlasting|father|' ||
+ 'prince|peace|alive)\b';
+} {4}
+
+do_execsql_test regexp1-2.1 {
+ SELECT 'aaaabbbbcccc' REGEXP 'ab*c',
+ 'aaaacccc' REGEXP 'ab*c';
+} {1 1}
+do_execsql_test regexp1-2.2 {
+ SELECT 'aaaabbbbcccc' REGEXP 'ab+c',
+ 'aaaacccc' REGEXP 'ab+c';
+} {1 0}
+do_execsql_test regexp1-2.3 {
+ SELECT 'aaaabbbbcccc' REGEXP 'ab?c',
+ 'aaaacccc' REGEXP 'ab?c';
+} {0 1}
+do_execsql_test regexp1-2.4 {
+ SELECT 'aaaabbbbbbcccc' REGEXP 'ab{3,5}c',
+ 'aaaabbbbbcccc' REGEXP 'ab{3,5}c',
+ 'aaaabbbbcccc' REGEXP 'ab{3,5}c',
+ 'aaaabbbcccc' REGEXP 'ab{3,5}c',
+ 'aaaabbcccc' REGEXP 'ab{3,5}c',
+ 'aaaabcccc' REGEXP 'ab{3,5}c'
+} {0 1 1 1 0 0}
+do_execsql_test regexp1-2.5 {
+ SELECT 'aaaabbbbcccc' REGEXP 'a(a|b|c)+c',
+ 'aaaabbbbcccc' REGEXP '^a(a|b|c){11}c$',
+ 'aaaabbbbcccc' REGEXP '^a(a|b|c){10}c$',
+ 'aaaabbbbcccc' REGEXP '^a(a|b|c){9}c$'
+} {1 0 1 0}
+do_execsql_test regexp1-2.6 {
+ SELECT 'aaaabbbbcccc' REGEXP '^a(a|bb|c)+c$',
+ 'aaaabbbbcccc' REGEXP '^a(a|bbb|c)+c$',
+ 'aaaabbbbcccc' REGEXP '^a(a|bbbb|c)+c$'
+} {1 0 1}
+do_execsql_test regexp1-2.7 {
+ SELECT 'aaaabbbbcccc' REGEXP '^a([ac]+|bb){3}c$',
+ 'aaaabbbbcccc' REGEXP '^a([ac]+|bb){4}c$',
+ 'aaaabbbbcccc' REGEXP '^a([ac]+|bb){5}c$'
+} {0 1 1}
+
+do_execsql_test regexp1-2.8 {
+ SELECT 'abc*def+ghi.jkl[mno]pqr' REGEXP 'c.d',
+ 'abc*def+ghi.jkl[mno]pqr' REGEXP 'c\*d',
+ 'abc*def+ghi.jkl[mno]pqr' REGEXP 'f\+g',
+ 'abc*def+ghi.jkl[mno]pqr' REGEXP 'i\.j',
+ 'abc*def+ghi.jkl[mno]pqr' REGEXP 'l\[mno\]p'
+} {1 1 1 1 1}
+
+do_test regexp1-2.9 {
+ set v1 "abc\ndef"
+ db eval {SELECT $v1 REGEXP '^abc\ndef$'}
+} {1}
+do_test regexp1-2.10 {
+ set v1 "abc\adef"
+ db eval {SELECT $v1 REGEXP '^abc\adef$'}
+} {1}
+do_test regexp1-2.11 {
+ set v1 "abc\tdef"
+ db eval {SELECT $v1 REGEXP '^abc\tdef$'}
+} {1}
+do_test regexp1-2.12 {
+ set v1 "abc\rdef"
+ db eval {SELECT $v1 REGEXP '^abc\rdef$'}
+} {1}
+do_test regexp1-2.13 {
+ set v1 "abc\fdef"
+ db eval {SELECT $v1 REGEXP '^abc\fdef$'}
+} {1}
+do_test regexp1-2.14 {
+ set v1 "abc\vdef"
+ db eval {SELECT $v1 REGEXP '^abc\vdef$'}
+} {1}
+do_execsql_test regexp1-2.15 {
+ SELECT 'abc\def' REGEXP '^abc\\def',
+ 'abc(def' REGEXP '^abc\(def',
+ 'abc)def' REGEXP '^abc\)def',
+ 'abc*def' REGEXP '^abc\*def',
+ 'abc.def' REGEXP '^abc\.def',
+ 'abc+def' REGEXP '^abc\+def',
+ 'abc?def' REGEXP '^abc\?def',
+ 'abc[def' REGEXP '^abc\[def',
+ 'abc$def' REGEXP '^abc\$',
+ '^def' REGEXP '\^def',
+ 'abc{4}x' REGEXP '^abc\{4\}x$',
+ 'abc|def' REGEXP '^abc\|def$'
+} {1 1 1 1 1 1 1 1 1 1 1 1}
+
+do_execsql_test regexp1-2.20 {
+ SELECT 'abc$¢€xyz' REGEXP '^abc\u0024\u00a2\u20acxyz$',
+ 'abc$¢€xyz' REGEXP '^abc\u0024\u00A2\u20ACxyz$',
+ 'abc$¢€xyz' REGEXP '^abc\x24\xa2\u20acxyz$'
+} {1 1 1}
+do_execsql_test regexp1-2.21 {
+ SELECT 'abc$¢€xyz' REGEXP '^abc[\u0024][\u00a2][\u20ac]xyz$',
+ 'abc$¢€xyz' REGEXP '^abc[\u0024\u00A2\u20AC]{3}xyz$',
+ 'abc$¢€xyz' REGEXP '^abc[\x24][\xa2\u20ac]+xyz$'
+} {1 1 1}
+do_execsql_test regexp1-2.22 {
+ SELECT 'abc$¢€xyz' REGEXP '^abc[^\u0025-X][^ -\u007f][^\u20ab]xyz$'
+} {1}
+
+finish_test
diff --git a/lang/sql/sqlite/test/releasetest.tcl b/lang/sql/sqlite/test/releasetest.tcl
index 84542bb8..b635061c 100644
--- a/lang/sql/sqlite/test/releasetest.tcl
+++ b/lang/sql/sqlite/test/releasetest.tcl
@@ -81,6 +81,22 @@ array set ::Configs {
-DSQLITE_DEFAULT_FILE_FORMAT=4
-DSQLITE_ENABLE_UPDATE_DELETE_LIMIT=1
}
+ "Check-Symbols" {
+ -DSQLITE_MEMDEBUG=1
+ -DSQLITE_ENABLE_FTS3_PARENTHESIS=1
+ -DSQLITE_ENABLE_FTS3=1
+ -DSQLITE_ENABLE_RTREE=1
+ -DSQLITE_ENABLE_MEMSYS5=1
+ -DSQLITE_ENABLE_MEMSYS3=1
+ -DSQLITE_ENABLE_COLUMN_METADATA=1
+ -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT=1
+ -DSQLITE_SECURE_DELETE=1
+ -DSQLITE_SOUNDEX=1
+ -DSQLITE_ENABLE_ATOMIC_WRITE=1
+ -DSQLITE_ENABLE_IOTRACE=1
+ -DSQLITE_ENABLE_MEMORY_MANAGEMENT=1
+ -DSQLITE_ENABLE_OVERSIZE_CELL_CHECK=1
+ }
"Debug-One" {
-O2
-DSQLITE_DEBUG=1
@@ -151,14 +167,24 @@ array set ::Configs {
-DSQLITE_ENABLE_OVERSIZE_CELL_CHECK=1
-DSQLITE_MAX_ATTACHED=62
}
+ "Devkit" {
+ -DSQLITE_DEFAULT_FILE_FORMAT=4
+ -DSQLITE_MAX_ATTACHED=30
+ -DSQLITE_ENABLE_COLUMN_METADATA
+ -DSQLITE_ENABLE_FTS4
+ -DSQLITE_ENABLE_FTS4_PARENTHESIS
+ -DSQLITE_DISABLE_FTS4_DEFERRED
+ -DSQLITE_ENABLE_RTREE
+ }
}
array set ::Platforms {
Linux-x86_64 {
+ "Check-Symbols" checksymbols
+ "Debug-One" test
"Secure-Delete" test
"Unlock-Notify" "QUICKTEST_INCLUDE=notify2.test test"
"Update-Delete-Limit" test
- "Debug-One" test
"Extra-Robustness" test
"Device-Two" test
"Ftrapv" test
@@ -166,6 +192,7 @@ array set ::Platforms {
"Device-One" fulltest
}
Linux-i686 {
+ "Devkit" test
"Unlock-Notify" "QUICKTEST_INCLUDE=notify2.test test"
"Device-One" test
"Device-Two" test
@@ -177,6 +204,7 @@ array set ::Platforms {
}
}
+
# End of configuration section.
#########################################################################
#########################################################################
@@ -217,8 +245,6 @@ proc run_test_suite {name testtarget config} {
if {$::tcl_platform(platform)=="windows"} {
append opts " -DSQLITE_OS_WIN=1"
- } elseif {$::tcl_platform(platform)=="os2"} {
- append opts " -DSQLITE_OS_OS2=1"
} else {
append opts " -DSQLITE_OS_UNIX=1"
}
@@ -321,15 +347,17 @@ proc main {argv} {
# If the configuration included the SQLITE_DEBUG option, then remove
# it and run veryquick.test. If it did not include the SQLITE_DEBUG option
# add it and run veryquick.test.
- set debug_idx [lsearch -glob $config_options -DSQLITE_DEBUG*]
- if {$debug_idx < 0} {
- run_test_suite "${zConfig}_debug" test [
- concat $config_options -DSQLITE_DEBUG=1
- ]
- } else {
- run_test_suite "${zConfig}_ndebug" test [
- lreplace $config_options $debug_idx $debug_idx
- ]
+ if {$target!="checksymbols"} {
+ set debug_idx [lsearch -glob $config_options -DSQLITE_DEBUG*]
+ if {$debug_idx < 0} {
+ run_test_suite "${zConfig}_debug" test [
+ concat $config_options -DSQLITE_DEBUG=1
+ ]
+ } else {
+ run_test_suite "${zConfig}_ndebug" test [
+ lreplace $config_options $debug_idx $debug_idx
+ ]
+ }
}
}
diff --git a/lang/sql/sqlite/test/resolver01.test b/lang/sql/sqlite/test/resolver01.test
new file mode 100644
index 00000000..7d95a213
--- /dev/null
+++ b/lang/sql/sqlite/test/resolver01.test
@@ -0,0 +1,208 @@
+# 2013-04-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 features of the name resolver (the component that
+# figures out what identifiers in the SQL statement refer to) that
+# were fixed by ticket [2500cdb9be]
+#
+# See also tickets [1c69be2daf] and [f617ea3125] from 2013-08-14.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+# "ORDER BY y" binds to the output result-set column named "y"
+# if available. If no output column is named "y", then try to
+# bind against an input column named "y".
+#
+# This is classical SQL92 behavior.
+#
+do_test resolver01-1.1 {
+ catchsql {
+ CREATE TABLE t1(x, y); INSERT INTO t1 VALUES(11,22);
+ CREATE TABLE t2(y, z); INSERT INTO t2 VALUES(33,44);
+ SELECT 1 AS y FROM t1, t2 ORDER BY y;
+ }
+} {0 1}
+do_test resolver01-1.2 {
+ catchsql {
+ SELECT 1 AS yy FROM t1, t2 ORDER BY y;
+ }
+} {1 {ambiguous column name: y}}
+do_test resolver01-1.3 {
+ catchsql {
+ CREATE TABLE t3(x,y); INSERT INTO t3 VALUES(11,44),(33,22);
+ SELECT x AS y FROM t3 ORDER BY y;
+ }
+} {0 {11 33}}
+do_test resolver01-1.4 {
+ catchsql {
+ SELECT x AS yy FROM t3 ORDER BY y;
+ }
+} {0 {33 11}}
+
+# SQLite allows the WHERE clause to reference output columns if there is
+# no other way to resolve the name.
+#
+do_test resolver01-1.5 {
+ catchsql {
+ SELECT x AS yy FROM t3 ORDER BY yy;
+ }
+} {0 {11 33}}
+do_test resolver01-1.6 {
+ catchsql {
+ SELECT x AS yy FROM t3 ORDER BY 1;
+ }
+} {0 {11 33}}
+
+# The "ORDER BY y COLLATE nocase" form works the same as "ORDER BY y".
+# The "y" binds more tightly to output columns than to input columns.
+#
+# This is for compatibility with SQL92 and with historical SQLite behavior.
+# Note that PostgreSQL considers "y COLLATE nocase" to be an expression
+# and thus PostgreSQL treats this case as if it where the 3.x case below.
+#
+do_test resolver01-2.1 {
+ catchsql {
+ SELECT 2 AS y FROM t1, t2 ORDER BY y COLLATE nocase;
+ }
+} {0 2}
+do_test resolver01-2.2 {
+ catchsql {
+ SELECT 2 AS yy FROM t1, t2 ORDER BY y COLLATE nocase;
+ }
+} {1 {ambiguous column name: y}}
+do_test resolver01-2.3 {
+ catchsql {
+ SELECT x AS y FROM t3 ORDER BY y COLLATE nocase;
+ }
+} {0 {11 33}}
+do_test resolver01-2.4 {
+ catchsql {
+ SELECT x AS yy FROM t3 ORDER BY y COLLATE nocase;
+ }
+} {0 {33 11}}
+do_test resolver01-2.5 {
+ catchsql {
+ SELECT x AS yy FROM t3 ORDER BY yy COLLATE nocase;
+ }
+} {0 {11 33}}
+do_test resolver01-2.6 {
+ catchsql {
+ SELECT x AS yy FROM t3 ORDER BY 1 COLLATE nocase;
+ }
+} {0 {11 33}}
+
+# But if the form is "ORDER BY expr" then bind more tightly to the
+# the input column names and only use the output column names if no
+# input column name matches.
+#
+# This is SQL99 behavior, as implemented by PostgreSQL and MS-SQL.
+# Note that Oracle works differently.
+#
+do_test resolver01-3.1 {
+ catchsql {
+ SELECT 3 AS y FROM t1, t2 ORDER BY +y;
+ }
+} {1 {ambiguous column name: y}}
+do_test resolver01-3.2 {
+ catchsql {
+ SELECT 2 AS yy FROM t1, t2 ORDER BY +y;
+ }
+} {1 {ambiguous column name: y}}
+do_test resolver01-3.3 {
+ catchsql {
+ SELECT x AS y FROM t3 ORDER BY +y;
+ }
+} {0 {33 11}}
+do_test resolver01-3.4 {
+ catchsql {
+ SELECT x AS yy FROM t3 ORDER BY +y;
+ }
+} {0 {33 11}}
+do_test resolver01-3.5 {
+ catchsql {
+ SELECT x AS yy FROM t3 ORDER BY +yy
+ }
+} {0 {11 33}}
+
+# This is the test case given in ticket [f617ea3125e9] (with table name
+# changed from "t1" to "t4". The behavior of (1) and (3) match with
+# PostgreSQL, but we intentionally break with PostgreSQL to provide
+# SQL92 behavior for case (2).
+#
+do_execsql_test resolver01-4.1 {
+ CREATE TABLE t4(m CHAR(2));
+ INSERT INTO t4 VALUES('az');
+ INSERT INTO t4 VALUES('by');
+ INSERT INTO t4 VALUES('cx');
+ SELECT '1', substr(m,2) AS m FROM t4 ORDER BY m;
+ SELECT '2', substr(m,2) AS m FROM t4 ORDER BY m COLLATE binary;
+ SELECT '3', substr(m,2) AS m FROM t4 ORDER BY lower(m);
+} {1 x 1 y 1 z 2 x 2 y 2 z 3 z 3 y 3 x}
+
+##########################################################################
+# Test cases for ticket [1c69be2dafc28]: Make sure the GROUP BY binds
+# more tightly to the input tables in all cases.
+#
+# This first case case has been wrong in SQLite for time out of mind.
+# For SQLite version 3.7.17 the answer was two rows, which is wrong.
+#
+do_execsql_test resolver01-5.1 {
+ CREATE TABLE t5(m CHAR(2));
+ INSERT INTO t5 VALUES('ax');
+ INSERT INTO t5 VALUES('bx');
+ INSERT INTO t5 VALUES('cy');
+ SELECT count(*), substr(m,2,1) AS m FROM t5 GROUP BY m ORDER BY 1, 2;
+} {1 x 1 x 1 y}
+
+# This case is unambiguous and has always been correct.
+#
+do_execsql_test resolver01-5.2 {
+ SELECT count(*), substr(m,2,1) AS mx FROM t5 GROUP BY m ORDER BY 1, 2;
+} {1 x 1 x 1 y}
+
+# This case is not allowed in standard SQL, but SQLite allows and does
+# the sensible thing.
+#
+do_execsql_test resolver01-5.3 {
+ SELECT count(*), substr(m,2,1) AS mx FROM t5 GROUP BY mx ORDER BY 1, 2;
+} {1 y 2 x}
+do_execsql_test resolver01-5.4 {
+ SELECT count(*), substr(m,2,1) AS mx FROM t5
+ GROUP BY substr(m,2,1) ORDER BY 1, 2;
+} {1 y 2 x}
+
+# These test case weere provided in the 2013-08-14 email from Rob Golsteijn
+# that originally reported the problem of ticket [1c69be2dafc28].
+#
+do_execsql_test resolver01-6.1 {
+ CREATE TABLE t61(name);
+ SELECT min(name) FROM t61 GROUP BY lower(name);
+} {}
+do_execsql_test resolver01-6.2 {
+ SELECT min(name) AS name FROM t61 GROUP BY lower(name);
+} {}
+do_execsql_test resolver01-6.3 {
+ CREATE TABLE t63(name);
+ INSERT INTO t63 VALUES (NULL);
+ INSERT INTO t63 VALUES ('abc');
+ SELECT count(),
+ NULLIF(name,'abc') AS name
+ FROM t63
+ GROUP BY lower(name);
+} {1 {} 1 {}}
+
+
+
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/rollback.test b/lang/sql/sqlite/test/rollback.test
index e61b61bb..3e399e6b 100644
--- a/lang/sql/sqlite/test/rollback.test
+++ b/lang/sql/sqlite/test/rollback.test
@@ -54,7 +54,7 @@ ifcapable conflict {
catchsql {
INSERT INTO t3 SELECT a FROM t1;
}
- } {1 {column a is not unique}}
+ } {1 {UNIQUE constraint failed: t3.a}}
# Try to continue with the SELECT statement
#
@@ -88,8 +88,8 @@ if {$tcl_platform(platform) == "unix"
BEGIN;
INSERT INTO t3 VALUES('hello world');
}
- #file copy -force test.db testA.db
- #file copy -force test.db-journal testA.db-journal
+ #forcecopy test.db testA.db
+ #forcecopy test.db-journal testA.db-journal
execsql {
COMMIT;
}
diff --git a/lang/sql/sqlite/test/rowid.test b/lang/sql/sqlite/test/rowid.test
index 4a9404de..6d068d79 100644
--- a/lang/sql/sqlite/test/rowid.test
+++ b/lang/sql/sqlite/test/rowid.test
@@ -12,7 +12,9 @@
# focus of this file is testing the magic ROWID column that is
# found on all tables.
#
-# $Id: rowid.test,v 1.21 2009/06/26 15:14:55 drh Exp $
+# EVIDENCE-OF: R-36924-43758 By default, every row in SQLite has a
+# special column, usually called the "rowid", that uniquely identifies
+# that row within the table.
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -657,7 +659,7 @@ do_test rowid-11.4 {
# Test the automatic generation of rowids when the table already contains
# a rowid with the maximum value.
#
-# Once the the maximum rowid is taken, rowids are normally chosen at
+# Once the maximum rowid is taken, rowids are normally chosen at
# random. By by reseting the random number generator, we can cause
# the rowid guessing loop to collide with prior rowids, and test the
# loop out to its limit of 100 iterations. After 100 collisions, the
diff --git a/lang/sql/sqlite/test/run-wordcount.sh b/lang/sql/sqlite/test/run-wordcount.sh
new file mode 100644
index 00000000..1755d581
--- /dev/null
+++ b/lang/sql/sqlite/test/run-wordcount.sh
@@ -0,0 +1,78 @@
+#!/bin/sh
+#
+# This script runs the wordcount program in different ways, comparing
+# the output from each.
+#
+
+# Select the source text to be analyzed.
+#
+if test "x$1" = "x";
+then echo "Usage: $0 FILENAME [ARGS...]"; exit 1;
+fi
+
+# Do test runs
+#
+rm -f wcdb1.db
+./wordcount --timer --summary wcdb1.db $* --insert >wc-out.txt
+mv wc-out.txt wc-baseline.txt
+rm -f wcdb2.db
+./wordcount --timer --summary wcdb2.db $* --insert --without-rowid >wc-out.txt
+ if cmp -s wc-out.txt wc-baseline.txt;
+ then echo hi >/dev/null;
+ else echo ERROR:;
+ diff -u wc-baseline.txt wc-out.txt;
+ fi
+
+rm -f wcdb1.db
+./wordcount --timer --summary wcdb1.db $* --replace >wc-out.txt
+ if cmp -s wc-out.txt wc-baseline.txt;
+ then echo hi >/dev/null;
+ else echo ERROR:;
+ diff -u wc-baseline.txt wc-out.txt;
+ fi
+rm -f wcdb2.db
+./wordcount --timer --summary wcdb2.db $* --replace --without-rowid >wc-out.txt
+ if cmp -s wc-out.txt wc-baseline.txt;
+ then echo hi >/dev/null;
+ else echo ERROR:;
+ diff -u wc-baseline.txt wc-out.txt;
+ fi
+
+rm -f wcdb1.db
+./wordcount --timer --summary wcdb1.db $* --select >wc-out.txt
+ if cmp -s wc-out.txt wc-baseline.txt;
+ then echo hi >/dev/null;
+ else echo ERROR:;
+ diff -u wc-baseline.txt wc-out.txt;
+ fi
+
+rm -f wcdb2.db
+./wordcount --timer --summary wcdb2.db $* --select --without-rowid >wc-out.txt
+ if cmp -s wc-out.txt wc-baseline.txt;
+ then echo hi >/dev/null;
+ else echo ERROR:;
+ diff -u wc-baseline.txt wc-out.txt;
+ fi
+
+./wordcount --timer --summary wcdb1.db $* --query >wc-out.txt
+mv wc-out.txt wc-baseline.txt
+./wordcount --timer --summary wcdb2.db $* --query --without-rowid >wc-out.txt
+ if cmp -s wc-out.txt wc-baseline.txt;
+ then echo hi >/dev/null;
+ else echo ERROR:;
+ diff -u wc-baseline.txt wc-out.txt;
+ fi
+
+./wordcount --timer --summary wcdb1.db $* --delete >wc-out.txt
+mv wc-out.txt wc-baseline.txt
+./wordcount --timer --summary wcdb2.db $* --delete --without-rowid >wc-out.txt
+ if cmp -s wc-out.txt wc-baseline.txt;
+ then echo hi >/dev/null;
+ else echo ERROR:;
+ diff -u wc-baseline.txt wc-out.txt;
+ fi
+
+
+# Clean up temporary files created.
+#
+rm -rf wcdb1.db wcdb2.db wc-out.txt wc-baseline.txt
diff --git a/lang/sql/sqlite/test/savepoint.test b/lang/sql/sqlite/test/savepoint.test
index 042c5558..9f4571ab 100644
--- a/lang/sql/sqlite/test/savepoint.test
+++ b/lang/sql/sqlite/test/savepoint.test
@@ -303,11 +303,19 @@ ifcapable incrblob {
execsql {SAVEPOINT abc}
catchsql {ROLLBACK TO def}
} {1 {no such savepoint: def}}
- do_test savepoint-5.3.2 {
+ do_test savepoint-5.3.2.1 {
execsql {SAVEPOINT def}
set fd [db incrblob -readonly blobs x 1]
+ set rc [catch {seek $fd 0;read $fd} res]
+ lappend rc $res
+ } {0 {hellontyeight character blob}}
+ do_test savepoint-5.3.2.2 {
catchsql {ROLLBACK TO def}
- } {1 {cannot rollback savepoint - SQL statements in progress}}
+ } {0 {}}
+ do_test savepoint-5.3.2.3 {
+ set rc [catch {seek $fd 0; read $fd} res]
+ set rc
+ } {1}
do_test savepoint-5.3.3 {
catchsql {RELEASE def}
} {0 {}}
@@ -371,7 +379,7 @@ wal_check_journal_mode savepoint-5.5
#
ifcapable {autovacuum && pragma} {
db close
- file delete -force test.db
+ forcedelete test.db
sqlite3 db test.db
do_test savepoint-6.1 {
@@ -419,7 +427,7 @@ ifcapable {autovacuum && pragma} {
# surrounding savepoints by growing and shrinking the database file.
#
db close
-file delete -force test.db
+forcedelete test.db
sqlite3 db test.db
do_test savepoint-7.1 {
@@ -490,7 +498,7 @@ wal_check_journal_mode savepoint-7.3.3
do_test savepoint-7.4.1 {
db close
- file delete -force test.db
+ forcedelete test.db
sqlite3 db test.db
execsql { PRAGMA auto_vacuum = incremental }
wal_set_journal_mode
@@ -640,8 +648,8 @@ set templockstate [lindex [db eval {PRAGMA lock_status}] 3]
if {[wal_is_wal_mode]==0} {
do_test savepoint-10.2.1 {
- file delete -force test3.db
- file delete -force test2.db
+ forcedelete test3.db
+ forcedelete test2.db
execsql {
ATTACH 'test2.db' AS aux1;
ATTACH 'test3.db' AS aux2;
@@ -649,10 +657,8 @@ if {[wal_is_wal_mode]==0} {
CREATE TABLE main.t1(x, y);
CREATE TABLE aux1.t2(x, y);
CREATE TABLE aux2.t3(x, y);
- SELECT name FROM sqlite_master
- UNION ALL
- SELECT name FROM aux1.sqlite_master
- UNION ALL
+ SELECT name FROM sqlite_master;
+ SELECT name FROM aux1.sqlite_master;
SELECT name FROM aux2.sqlite_master;
}
} {t1 t2 t3}
@@ -691,7 +697,7 @@ if {[wal_is_wal_mode]==0} {
execsql { PRAGMA lock_status }
} [list main reserved temp $templockstate aux1 reserved aux2 reserved]
do_test savepoint-10.2.9 {
- execsql { SELECT 'a', * FROM t1 UNION ALL SELECT 'b', * FROM t3 }
+ execsql { SELECT 'a', * FROM t1 ; SELECT 'b', * FROM t3 }
} {a 1 2 b 3 4}
do_test savepoint-10.2.9 {
execsql {
@@ -762,7 +768,7 @@ if {[wal_is_wal_mode]==0} {
#
do_test savepoint-11.1 {
db close
- file delete -force test.db
+ forcedelete test.db
sqlite3 db test.db
execsql { PRAGMA auto_vacuum = full; }
wal_set_journal_mode
@@ -852,7 +858,7 @@ do_test savepoint-12.2 {
SAVEPOINT sp2;
INSERT OR ROLLBACK INTO t4 VALUES(1, 'one');
}
-} {1 {column a is not unique}}
+} {1 {UNIQUE constraint failed: t4.a}}
do_test savepoint-12.3 {
sqlite3_get_autocommit db
} {1}
@@ -868,7 +874,7 @@ wal_check_journal_mode savepoint-12.5
if {[wal_is_wal_mode]==0} {
do_test savepoint-13.1 {
db close
- catch {file delete -force test.db}
+ catch {forcedelete test.db}
sqlite3 db test.db
execsql {
BEGIN;
@@ -909,7 +915,7 @@ if {[wal_is_wal_mode]==0} {
}
db close
-file delete test.db
+delete_file test.db
do_multiclient_test tn {
do_test savepoint-14.$tn.1 {
sql1 {
diff --git a/lang/sql/sqlite/test/savepoint6.test b/lang/sql/sqlite/test/savepoint6.test
index 60fde4c2..b1d0d46f 100644
--- a/lang/sql/sqlite/test/savepoint6.test
+++ b/lang/sql/sqlite/test/savepoint6.test
@@ -246,7 +246,7 @@ foreach zSetup [list {
unset -nocomplain ::aEntry
catch { db close }
- file delete -force test.db test.db-wal test.db-journal
+ forcedelete test.db test.db-wal test.db-journal
eval $zSetup
sql $DATABASE_SCHEMA
diff --git a/lang/sql/sqlite/test/savepoint7.test b/lang/sql/sqlite/test/savepoint7.test
new file mode 100644
index 00000000..bc99187d
--- /dev/null
+++ b/lang/sql/sqlite/test/savepoint7.test
@@ -0,0 +1,96 @@
+# 2012 March 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.
+#
+#***********************************************************************
+#
+# Focus on the interaction between RELEASE and ROLLBACK TO with
+# pending query aborts. See ticket [27ca74af3c083f787a1c44b11fbb7c53bdbbcf1e].
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+# The RELEASE of an inner savepoint should not effect pending queries.
+#
+do_test savepoint7-1.1 {
+ db eval {
+ CREATE TABLE t1(a,b,c);
+ CREATE TABLE t2(x,y,z);
+ INSERT INTO t1 VALUES(1,2,3);
+ INSERT INTO t1 VALUES(4,5,6);
+ INSERT INTO t1 VALUES(7,8,9);
+ SAVEPOINT x1;
+ }
+ db eval {SELECT * FROM t1} {
+ db eval {
+ SAVEPOINT x2;
+ INSERT INTO t2 VALUES($a,$b,$c);
+ RELEASE x2;
+ }
+ }
+ db eval {SELECT * FROM t2; RELEASE x1}
+} {1 2 3 4 5 6 7 8 9}
+
+do_test savepoint7-1.2 {
+ db eval {DELETE FROM t2;}
+ db eval {SELECT * FROM t1} {
+ db eval {
+ SAVEPOINT x2;
+ INSERT INTO t2 VALUES($a,$b,$c);
+ RELEASE x2;
+ }
+ }
+ db eval {SELECT * FROM t2}
+} {1 2 3 4 5 6 7 8 9}
+
+do_test savepoint7-1.3 {
+ db eval {DELETE FROM t2; BEGIN;}
+ db eval {SELECT * FROM t1} {
+ db eval {
+ SAVEPOINT x2;
+ INSERT INTO t2 VALUES($a,$b,$c);
+ RELEASE x2;
+ }
+ }
+ db eval {SELECT * FROM t2; ROLLBACK;}
+} {1 2 3 4 5 6 7 8 9}
+
+# However, a ROLLBACK of an inner savepoint will abort all queries, including
+# queries in outer contexts.
+#
+do_test savepoint7-2.1 {
+ db eval {DELETE FROM t2; SAVEPOINT x1;}
+ set rc [catch {
+ db eval {SELECT * FROM t1} {
+ db eval {
+ SAVEPOINT x2;
+ INSERT INTO t2 VALUES($a,$b,$c);
+ ROLLBACK TO x2;
+ }
+ }
+ } msg]
+ db eval {RELEASE x1}
+ list $rc $msg [db eval {SELECT * FROM t2}]
+} {1 {callback requested query abort} {}}
+
+do_test savepoint7-2.2 {
+ db eval {DELETE FROM t2;}
+ set rc [catch {
+ db eval {SELECT * FROM t1} {
+ db eval {
+ SAVEPOINT x2;
+ INSERT INTO t2 VALUES($a,$b,$c);
+ ROLLBACK TO x2;
+ }
+ }
+ } msg]
+ list $rc $msg [db eval {SELECT * FROM t2}]
+} {1 {callback requested query abort} {}}
+
+finish_test
diff --git a/lang/sql/sqlite/test/schema5.test b/lang/sql/sqlite/test/schema5.test
new file mode 100644
index 00000000..29df3f16
--- /dev/null
+++ b/lang/sql/sqlite/test/schema5.test
@@ -0,0 +1,69 @@
+# 2010 September 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 checks corner cases in the CREATE TABLE syntax to make
+# sure that legacy syntax (syntax that is disallowed according to the
+# syntax diagrams) is still accepted, so that older databases that use
+# that syntax can still be read.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+# Table constraints should be separated by commas, but they do not have
+# to be.
+#
+do_test schema5-1.1 {
+ db eval {
+ CREATE TABLE t1(a,b,c, PRIMARY KEY(a) UNIQUE (a) CONSTRAINT one);
+ INSERT INTO t1 VALUES(1,2,3);
+ SELECT * FROM t1;
+ }
+} {1 2 3}
+do_test schema5-1.2 {
+ catchsql {INSERT INTO t1 VALUES(1,3,4);}
+} {1 {UNIQUE constraint failed: t1.a}}
+do_test schema5-1.3 {
+ db eval {
+ DROP TABLE t1;
+ CREATE TABLE t1(a,b,c,
+ CONSTRAINT one PRIMARY KEY(a) CONSTRAINT two CHECK(b<10) UNIQUE(b)
+ CONSTRAINT three
+ );
+ INSERT INTO t1 VALUES(1,2,3);
+ SELECT * FROM t1;
+ }
+} {1 2 3}
+do_test schema5-1.4 {
+ catchsql {INSERT INTO t1 VALUES(10,11,12);}
+} {1 {CHECK constraint failed: two}}
+do_test schema5-1.5 {
+ db eval {
+ DROP TABLE t1;
+ CREATE TABLE t1(a,b,c,
+ UNIQUE(a) CONSTRAINT one,
+ PRIMARY KEY(b,c) CONSTRAINT two
+ );
+ INSERT INTO t1 VALUES(1,2,3);
+ }
+} {}
+do_test schema5-1.6 {
+ catchsql {INSERT INTO t1 VALUES(1,3,4)}
+} {1 {UNIQUE constraint failed: t1.a}}
+do_test schema5-1.7 {
+ catchsql {INSERT INTO t1 VALUES(10,2,3)}
+} {1 {UNIQUE constraint failed: t1.b, t1.c}}
+
+
+
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/securedel.test b/lang/sql/sqlite/test/securedel.test
index c965069e..7111e08e 100644
--- a/lang/sql/sqlite/test/securedel.test
+++ b/lang/sql/sqlite/test/securedel.test
@@ -26,7 +26,7 @@ do_test securedel-1.0 {
db eval {PRAGMA secure_delete;}
} $DEFAULT_SECDEL
-file delete -force test2.db test2.db-journal
+forcedelete test2.db test2.db-journal
do_test securedel-1.1 {
db eval {
ATTACH 'test2.db' AS db2;
@@ -47,7 +47,6 @@ do_test securedel-1.3 {
}
} {0 0}
do_test securedel-1.4 {
-breakpoint
db eval {
PRAGMA secure_delete=ON;
PRAGMA db2.secure_delete;
diff --git a/lang/sql/sqlite/test/securedel2.test b/lang/sql/sqlite/test/securedel2.test
new file mode 100644
index 00000000..9badc560
--- /dev/null
+++ b/lang/sql/sqlite/test/securedel2.test
@@ -0,0 +1,94 @@
+# 2012 August 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.
+#
+#*************************************************************************
+#
+# Tests for the secure_delete pragma.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set ::testprefix securedel2
+
+# Generate 1000 pseudo-random 64-bit blobs.
+#
+for {set i 1} {$i <= 1000} {incr i} {
+ set aBlob($i) [string range [db one {SELECT quote(randomblob(8))}] 2 end-1]
+}
+
+proc detect_blob_prepare {zFile} {
+ set nByte [file size $zFile]
+ set ::detect_blob_data [hexio_read $zFile 0 $nByte]
+}
+
+proc detect_blob {zFile iBlob} {
+ if {$zFile != ""} { detect_blob_prepare $zFile }
+ string match "*$::aBlob($iBlob)*" $::detect_blob_data
+}
+
+do_test 1.1 {
+ execsql { PRAGMA secure_delete = 1 }
+ execsql { PRAGMA auto_vacuum = 0 }
+ execsql { CREATE TABLE t1(x, y) }
+ for {set i 1} {$i <= 1000} {incr i} {
+ set x "X'[string repeat $aBlob($i) 1]'"
+ set y "X'[string repeat $aBlob($i) 500]'"
+ execsql "INSERT INTO t1 VALUES($x, $y)"
+ }
+} {}
+
+do_test 1.2 { detect_blob test.db 1 } {1}
+
+forcecopy test.db test.db.bak
+do_execsql_test 1.3.1 { PRAGMA secure_delete = 0 } {0}
+do_execsql_test 1.3.2 { DELETE FROM t1 WHERE rowid = 1 }
+do_test 1.3.3 { detect_blob test.db 1 } {1}
+
+db close
+forcecopy test.db.bak test.db
+sqlite3 db test.db
+do_execsql_test 1.4.1 { PRAGMA secure_delete = 1 } {1}
+do_execsql_test 1.4.2 { DELETE FROM t1 WHERE rowid = 1 }
+do_test 1.4.3 { detect_blob test.db 1 } {0}
+
+do_execsql_test 1.5.1 { DELETE FROM t1 WHERE rowid>850 } {}
+do_test 1.5.2 {
+ set n 0
+ detect_blob_prepare test.db
+ for {set i 851} {$i <= 1000} {incr i 5} {
+ incr n [detect_blob {} $i]
+ }
+ set n
+} {0}
+
+db close
+sqlite3 db test.db
+do_test 1.6.1 {
+ execsql {
+ PRAGMA cache_size = 200;
+ PRAGMA secure_delete = 1;
+ CREATE TABLE t2(x);
+ SELECT * FROM t1;
+ }
+ for {set i 100} {$i < 5000} {incr i} {
+ execsql { INSERT INTO t2 VALUES(randomblob($i)) }
+ }
+ execsql { DELETE FROM t1 }
+} {}
+
+do_test 1.6.2 {
+ set n 0
+ detect_blob_prepare test.db
+ for {set i 2} {$i <= 850} {incr i 5} {
+ incr n [detect_blob {} $i]
+ }
+ set n
+} {0}
+
+finish_test
diff --git a/lang/sql/sqlite/test/select1.test b/lang/sql/sqlite/test/select1.test
index 73b0e40f..875c87c8 100644
--- a/lang/sql/sqlite/test/select1.test
+++ b/lang/sql/sqlite/test/select1.test
@@ -542,7 +542,7 @@ do_test select1-6.9.7 {
set x [execsql2 {
SELECT * FROM test1 a, (select 5, 6) LIMIT 1
}]
- regsub -all {subquery_[0-9a-fA-F]+_} $x {subquery} x
+ regsub -all {sq_[0-9a-fA-F_]+} $x {subquery} x
set x
} {a.f1 11 a.f2 22 sqlite_subquery.5 5 sqlite_subquery.6 6}
do_test select1-6.9.8 {
@@ -1066,5 +1066,11 @@ if {[db one {PRAGMA locking_mode}]=="normal"} {
execsql { SELECT 2 IN (SELECT a FROM t1) }
} {1}
}
+
+# Crash bug reported on the mailing list on 2012-02-23
+#
+do_test select1-16.1 {
+ catchsql {SELECT 1 FROM (SELECT *)}
+} {1 {no tables specified}}
finish_test
diff --git a/lang/sql/sqlite/test/select4.test b/lang/sql/sqlite/test/select4.test
index dff0b90f..e205b37a 100644
--- a/lang/sql/sqlite/test/select4.test
+++ b/lang/sql/sqlite/test/select4.test
@@ -805,4 +805,23 @@ do_test select4-12.1 {
} ;# ifcapable compound
+
+# Ticket [3557ad65a076c] - Incorrect DISTINCT processing with an
+# indexed query using IN.
+#
+do_test select4-13.1 {
+ sqlite3 db test.db
+ db eval {
+ CREATE TABLE t13(a,b);
+ INSERT INTO t13 VALUES(1,1);
+ INSERT INTO t13 VALUES(2,1);
+ INSERT INTO t13 VALUES(3,1);
+ INSERT INTO t13 VALUES(2,2);
+ INSERT INTO t13 VALUES(3,2);
+ INSERT INTO t13 VALUES(4,2);
+ CREATE INDEX t13ab ON t13(a,b);
+ SELECT DISTINCT b from t13 WHERE a IN (1,2,3);
+ }
+} {1 2}
+
finish_test
diff --git a/lang/sql/sqlite/test/select6.test b/lang/sql/sqlite/test/select6.test
index e0ff165c..64a8519d 100644
--- a/lang/sql/sqlite/test/select6.test
+++ b/lang/sql/sqlite/test/select6.test
@@ -22,6 +22,7 @@ ifcapable !subquery {
finish_test
return
}
+set ::testprefix select6
do_test select6-1.0 {
execsql {
@@ -513,5 +514,48 @@ do_test select6-9.11 {
} {2 12 3 13 4 14}
+#-------------------------------------------------------------------------
+# Test that if a UNION ALL sub-query that would otherwise be eligible for
+# flattening consists of two or more SELECT statements that do not all
+# return the same number of result columns, the error is detected.
+#
+do_execsql_test 10.1 {
+ CREATE TABLE t(i,j,k);
+ CREATE TABLE j(l,m);
+ CREATE TABLE k(o);
+}
+
+set err [list 1 {SELECTs to the left and right of UNION ALL do not have the same number of result columns}]
+
+do_execsql_test 10.2 {
+ SELECT * FROM (SELECT * FROM t), j;
+}
+do_catchsql_test 10.3 {
+ SELECT * FROM t UNION ALL SELECT * FROM j
+} $err
+do_catchsql_test 10.4 {
+ SELECT * FROM (SELECT i FROM t UNION ALL SELECT l, m FROM j)
+} $err
+do_catchsql_test 10.5 {
+ SELECT * FROM (SELECT j FROM t UNION ALL SELECT * FROM j)
+} $err
+do_catchsql_test 10.6 {
+ SELECT * FROM (SELECT * FROM t UNION ALL SELECT * FROM j)
+} $err
+do_catchsql_test 10.7 {
+ SELECT * FROM (
+ SELECT * FROM t UNION ALL
+ SELECT l,m,l FROM j UNION ALL
+ SELECT * FROM k
+ )
+} $err
+do_catchsql_test 10.8 {
+ SELECT * FROM (
+ SELECT * FROM k UNION ALL
+ SELECT * FROM t UNION ALL
+ SELECT l,m,l FROM j
+ )
+} $err
+
finish_test
diff --git a/lang/sql/sqlite/test/select7.test b/lang/sql/sqlite/test/select7.test
index e8fc4400..6816b9fc 100644
--- a/lang/sql/sqlite/test/select7.test
+++ b/lang/sql/sqlite/test/select7.test
@@ -138,21 +138,23 @@ ifcapable {subquery && compound} {
# Verify that an error occurs if you have too many terms on a
# compound select statement.
#
-ifcapable compound {
- if {$SQLITE_MAX_COMPOUND_SELECT>0} {
- set sql {SELECT 0}
- set result 0
- for {set i 1} {$i<$SQLITE_MAX_COMPOUND_SELECT} {incr i} {
- append sql " UNION ALL SELECT $i"
- lappend result $i
+if {[clang_sanitize_address]==0} {
+ ifcapable compound {
+ if {$SQLITE_MAX_COMPOUND_SELECT>0} {
+ set sql {SELECT 0}
+ set result 0
+ for {set i 1} {$i<$SQLITE_MAX_COMPOUND_SELECT} {incr i} {
+ append sql " UNION ALL SELECT $i"
+ lappend result $i
+ }
+ do_test select7-6.1 {
+ catchsql $sql
+ } [list 0 $result]
+ append sql { UNION ALL SELECT 99999999}
+ do_test select7-6.2 {
+ catchsql $sql
+ } {1 {too many terms in compound SELECT}}
}
- do_test select7-6.1 {
- catchsql $sql
- } [list 0 $result]
- append sql { UNION ALL SELECT 99999999}
- do_test select7-6.2 {
- catchsql $sql
- } {1 {too many terms in compound SELECT}}
}
}
diff --git a/lang/sql/sqlite/test/select9.test b/lang/sql/sqlite/test/select9.test
index 085dee0b..4c42236d 100644
--- a/lang/sql/sqlite/test/select9.test
+++ b/lang/sql/sqlite/test/select9.test
@@ -415,5 +415,58 @@ do_test select9-4.X {
}
} {}
+# Testing to make sure that queries involving a view of a compound select
+# are planned efficiently. This detects a problem reported on the mailing
+# list on 2012-04-26. See
+#
+# http://www.mail-archive.com/sqlite-users%40sqlite.org/msg69746.html
+#
+# For additional information.
+#
+do_test select9-5.1 {
+ db eval {
+ CREATE TABLE t51(x, y);
+ CREATE TABLE t52(x, y);
+ CREATE VIEW v5 as
+ SELECT x, y FROM t51
+ UNION ALL
+ SELECT x, y FROM t52;
+ CREATE INDEX t51x ON t51(x);
+ CREATE INDEX t52x ON t52(x);
+ EXPLAIN QUERY PLAN
+ SELECT * FROM v5 WHERE x='12345' ORDER BY y;
+ }
+} {~/SCAN TABLE/} ;# Uses indices with "*"
+do_test select9-5.2 {
+ db eval {
+ EXPLAIN QUERY PLAN
+ SELECT x, y FROM v5 WHERE x='12345' ORDER BY y;
+ }
+} {~/SCAN TABLE/} ;# Uses indices with "x, y"
+do_test select9-5.3 {
+ db eval {
+ EXPLAIN QUERY PLAN
+ SELECT x, y FROM v5 WHERE +x='12345' ORDER BY y;
+ }
+} {/SCAN TABLE/} ;# Full table scan if the "+x" prevents index usage.
+
+# 2013-07-09: Ticket [490a4b7235624298]:
+# "WHERE 0" on the first element of a UNION causes an assertion fault
+#
+do_execsql_test select9-6.1 {
+ CREATE TABLE t61(a);
+ CREATE TABLE t62(b);
+ INSERT INTO t61 VALUES(111);
+ INSERT INTO t62 VALUES(222);
+ SELECT a FROM t61 WHERE 0 UNION SELECT b FROM t62;
+} {222}
+do_execsql_test select9-6.2 {
+ SELECT a FROM t61 WHERE 0 UNION ALL SELECT b FROM t62;
+} {222}
+do_execsql_test select9-6.3 {
+ SELECT a FROM t61 UNION SELECT b FROM t62 WHERE 0;
+} {111}
+
+
finish_test
diff --git a/lang/sql/sqlite/test/selectA.test b/lang/sql/sqlite/test/selectA.test
index 5b863778..5fd2288d 100644
--- a/lang/sql/sqlite/test/selectA.test
+++ b/lang/sql/sqlite/test/selectA.test
@@ -281,13 +281,13 @@ do_test selectA-2.34 {
do_test selectA-2.35 {
execsql {
SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t1
- ORDER BY b COLLATE NOCASE,a,c
+ ORDER BY y COLLATE NOCASE,x,z
}
} {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
do_test selectA-2.36 {
execsql {
SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t1
- ORDER BY b COLLATE NOCASE DESC,a,c
+ ORDER BY y COLLATE NOCASE DESC,x,z
}
} {mad Z z -23 Y y 5200000.0 X x {} U u hare m M abc e e hello d D {} C c 9.9 b B 1 a a}
do_test selectA-2.37 {
@@ -311,7 +311,7 @@ do_test selectA-2.39 {
do_test selectA-2.40 {
execsql {
SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t1
- ORDER BY c COLLATE BINARY DESC,a,b
+ ORDER BY z COLLATE BINARY DESC,x,y
}
} {mad Z z -23 Y y 5200000.0 X x {} U u abc e e {} C c 1 a a hare m M hello d D 9.9 b B}
do_test selectA-2.41 {
@@ -602,7 +602,7 @@ do_test selectA-2.85 {
do_test selectA-2.86 {
execsql {
SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t3
- ORDER BY b COLLATE NOCASE,a,c
+ ORDER BY y COLLATE NOCASE,x,z
}
} {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
do_test selectA-2.87 {
@@ -632,7 +632,7 @@ do_test selectA-2.90 {
do_test selectA-2.91 {
execsql {
SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t3
- ORDER BY c COLLATE BINARY DESC,a,b
+ ORDER BY z COLLATE BINARY DESC,x,y
}
} {mad Z z -23 Y y 5200000.0 X x {} U u abc e e {} C c 1 a a hare m M hello d D 9.9 b B}
do_test selectA-2.92 {
@@ -893,13 +893,13 @@ do_test selectA-3.34 {
do_test selectA-3.35 {
execsql {
SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t1
- ORDER BY b COLLATE NOCASE,a,c
+ ORDER BY y COLLATE NOCASE,x,z
}
} {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
do_test selectA-3.36 {
execsql {
SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t1
- ORDER BY b COLLATE NOCASE DESC,a,c
+ ORDER BY y COLLATE NOCASE DESC,x,z
}
} {mad Z z -23 Y y 5200000.0 X x {} U u hare m M abc e e hello d D {} C c 9.9 b B 1 a a}
do_test selectA-3.37 {
@@ -923,7 +923,7 @@ do_test selectA-3.39 {
do_test selectA-3.40 {
execsql {
SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t1
- ORDER BY c COLLATE BINARY DESC,a,b
+ ORDER BY z COLLATE BINARY DESC,x,y
}
} {mad Z z -23 Y y 5200000.0 X x {} U u abc e e {} C c 1 a a hare m M hello d D 9.9 b B}
do_test selectA-3.41 {
@@ -1214,7 +1214,7 @@ do_test selectA-3.85 {
do_test selectA-3.86 {
execsql {
SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t3
- ORDER BY b COLLATE NOCASE,a,c
+ ORDER BY y COLLATE NOCASE,x,z
}
} {1 a a 9.9 b B {} C c hello d D abc e e hare m M {} U u 5200000.0 X x -23 Y y mad Z z}
do_test selectA-3.87 {
@@ -1244,7 +1244,7 @@ do_test selectA-3.90 {
do_test selectA-3.91 {
execsql {
SELECT x,y,z FROM t2 UNION SELECT a,b,c FROM t3
- ORDER BY c COLLATE BINARY DESC,a,b
+ ORDER BY z COLLATE BINARY DESC,x,y
}
} {mad Z z -23 Y y 5200000.0 X x {} U u abc e e {} C c 1 a a hare m M hello d D 9.9 b B}
do_test selectA-3.92 {
diff --git a/lang/sql/sqlite/test/selectB.test b/lang/sql/sqlite/test/selectB.test
index 3fdf85c0..05ec9c6b 100644
--- a/lang/sql/sqlite/test/selectB.test
+++ b/lang/sql/sqlite/test/selectB.test
@@ -194,19 +194,28 @@ do_test selectB-3.0 {
}
} {}
-for {set ii 3} {$ii <= 4} {incr ii} {
+for {set ii 3} {$ii <= 6} {incr ii} {
- if {$ii == 4} {
- do_test selectB-4.0 {
- execsql {
- CREATE INDEX i1 ON t1(a);
- CREATE INDEX i2 ON t1(b);
- CREATE INDEX i3 ON t1(c);
- CREATE INDEX i4 ON t2(d);
- CREATE INDEX i5 ON t2(e);
- CREATE INDEX i6 ON t2(f);
- }
- } {}
+ switch $ii {
+ 4 {
+ optimization_control db query-flattener off
+ }
+ 5 {
+ optimization_control db query-flattener on
+ do_test selectB-5.0 {
+ execsql {
+ CREATE INDEX i1 ON t1(a);
+ CREATE INDEX i2 ON t1(b);
+ CREATE INDEX i3 ON t1(c);
+ CREATE INDEX i4 ON t2(d);
+ CREATE INDEX i5 ON t2(e);
+ CREATE INDEX i6 ON t2(f);
+ }
+ } {}
+ }
+ 6 {
+ optimization_control db query-flattener off
+ }
}
do_test selectB-$ii.1 {
@@ -355,7 +364,7 @@ for {set ii 3} {$ii <= 4} {incr ii} {
SELECT DISTINCT (a/10) FROM t1 UNION ALL SELECT DISTINCT(d%2) FROM t2
)
}
- } {0 1 0 1}
+ } {0 1 1 0}
do_test selectB-$ii.20 {
execsql {
@@ -371,11 +380,47 @@ for {set ii 3} {$ii <= 4} {incr ii} {
}
} {2 4 6 3 6 9 8 10 12 12 15 18 14 16 18 21 24 27}
- do_test selectB-$ii.21 {
+ do_test selectB-$ii.22 {
execsql {
SELECT * FROM (SELECT 345 UNION ALL SELECT d FROM t2) ORDER BY 1;
}
} {3 12 21 345}
+
+ do_test selectB-$ii.23 {
+ execsql {
+ SELECT x, y FROM (
+ SELECT a AS x, b AS y FROM t1
+ UNION ALL
+ SELECT a*10 + 0.1, f*10 + 0.1 FROM t1 JOIN t2 ON (c=d)
+ UNION ALL
+ SELECT a*100, b*100 FROM t1
+ ) ORDER BY 1;
+ }
+ } {2 4 8 10 14 16 80.1 180.1 200 400 800 1000 1400 1600}
+
+ do_test selectB-$ii.24 {
+ execsql {
+ SELECT x, y FROM (
+ SELECT a AS x, b AS y FROM t1
+ UNION ALL
+ SELECT a*10 + 0.1, f*10 + 0.1 FROM t1 LEFT JOIN t2 ON (c=d)
+ UNION ALL
+ SELECT a*100, b*100 FROM t1
+ ) ORDER BY 1;
+ }
+ } {2 4 8 10 14 16 20.1 {} 80.1 180.1 140.1 {} 200 400 800 1000 1400 1600}
+
+ do_test selectB-$ii.25 {
+ execsql {
+ SELECT x+y FROM (
+ SELECT a AS x, b AS y FROM t1
+ UNION ALL
+ SELECT a*10 + 0.1, f*10 + 0.1 FROM t1 LEFT JOIN t2 ON (c=d)
+ UNION ALL
+ SELECT a*100, b*100 FROM t1
+ ) WHERE y+x NOT NULL ORDER BY 1;
+ }
+ } {6 18 30 260.2 600 1800 3000}
}
finish_test
diff --git a/lang/sql/sqlite/test/selectC.test b/lang/sql/sqlite/test/selectC.test
index fd384053..dedac41f 100644
--- a/lang/sql/sqlite/test/selectC.test
+++ b/lang/sql/sqlite/test/selectC.test
@@ -151,7 +151,7 @@ do_test selectC-1.14.2 {
# The following query used to leak memory. Verify that has been fixed.
#
-ifcapable trigger {
+ifcapable trigger&&compound {
do_test selectC-2.1 {
catchsql {
CREATE TABLE t21a(a,b);
diff --git a/lang/sql/sqlite/test/selectD.test b/lang/sql/sqlite/test/selectD.test
new file mode 100644
index 00000000..89f999eb
--- /dev/null
+++ b/lang/sql/sqlite/test/selectD.test
@@ -0,0 +1,174 @@
+# 2012 December 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 name resolution in SELECT
+# statements that have parenthesized FROM clauses.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+
+for {set i 1} {$i<=2} {incr i} {
+ db close
+ forcedelete test$i.db
+ sqlite3 db test$i.db
+ if {$i==2} {
+ optimization_control db query-flattener off
+ }
+ do_test selectD-$i.0 {
+ db eval {
+ ATTACH ':memory:' AS aux1;
+ CREATE TABLE t1(a,b); INSERT INTO t1 VALUES(111,'x1');
+ CREATE TABLE t2(a,b); INSERT INTO t2 VALUES(222,'x2');
+ CREATE TEMP TABLE t3(a,b); INSERT INTO t3 VALUES(333,'x3');
+ CREATE TABLE main.t4(a,b); INSERT INTO main.t4 VALUES(444,'x4');
+ CREATE TABLE aux1.t4(a,b); INSERT INTO aux1.t4 VALUES(555,'x5');
+ }
+ } {}
+ do_test selectD-$i.1 {
+ db eval {
+ SELECT *
+ FROM (t1), (t2), (t3), (t4)
+ WHERE t4.a=t3.a+111
+ AND t3.a=t2.a+111
+ AND t2.a=t1.a+111;
+ }
+ } {111 x1 222 x2 333 x3 444 x4}
+ do_test selectD-$i.2.1 {
+ db eval {
+ SELECT *
+ FROM t1 JOIN (t2 JOIN (t3 JOIN t4 ON t4.a=t3.a+111)
+ ON t3.a=t2.a+111)
+ ON t2.a=t1.a+111;
+ }
+ } {111 x1 222 x2 333 x3 444 x4}
+ do_test selectD-$i.2.2 {
+ db eval {
+ SELECT t3.a
+ FROM t1 JOIN (t2 JOIN (t3 JOIN t4 ON t4.a=t3.a+111)
+ ON t3.a=t2.a+111)
+ ON t2.a=t1.a+111;
+ }
+ } {333}
+ do_test selectD-$i.2.3 {
+ db eval {
+ SELECT t3.*
+ FROM t1 JOIN (t2 JOIN (t3 JOIN t4 ON t4.a=t3.a+111)
+ ON t3.a=t2.a+111)
+ ON t2.a=t1.a+111;
+ }
+ } {333 x3}
+ do_test selectD-$i.2.3 {
+ db eval {
+ SELECT t3.*, t2.*
+ FROM t1 JOIN (t2 JOIN (t3 JOIN t4 ON t4.a=t3.a+111)
+ ON t3.a=t2.a+111)
+ ON t2.a=t1.a+111;
+ }
+ } {333 x3 222 x2}
+ do_test selectD-$i.2.4 {
+ db eval {
+ SELECT *
+ FROM t1 JOIN (t2 JOIN (main.t4 JOIN aux1.t4 ON aux1.t4.a=main.t4.a+111)
+ ON main.t4.a=t2.a+222)
+ ON t2.a=t1.a+111;
+ }
+ } {111 x1 222 x2 444 x4 555 x5}
+ do_test selectD-$i.2.5 {
+ db eval {
+ SELECT *
+ FROM t1 JOIN (t2 JOIN (main.t4 AS x JOIN aux1.t4 ON aux1.t4.a=x.a+111)
+ ON x.a=t2.a+222)
+ ON t2.a=t1.a+111;
+ }
+ } {111 x1 222 x2 444 x4 555 x5}
+ do_test selectD-$i.2.6 {
+ catchsql {
+ SELECT *
+ FROM t1 JOIN (t2 JOIN (main.t4 JOIN aux.t4 ON aux.t4.a=main.t4.a+111)
+ ON main.t4.a=t2.a+222)
+ ON t2.a=t1.a+111;
+ }
+ } {1 {no such table: aux.t4}}
+ do_test selectD-$i.2.7 {
+ db eval {
+ SELECT x.a, y.b
+ FROM t1 JOIN (t2 JOIN (main.t4 x JOIN aux1.t4 y ON y.a=x.a+111)
+ ON x.a=t2.a+222)
+ ON t2.a=t1.a+111;
+ }
+ } {444 x5}
+ do_test selectD-$i.3 {
+ db eval {
+ UPDATE t2 SET a=111;
+ UPDATE t3 SET a=111;
+ UPDATE t4 SET a=111;
+ SELECT *
+ FROM t1 JOIN (t2 JOIN (t3 JOIN t4 USING(a)) USING (a)) USING (a);
+ }
+ } {111 x1 x2 x3 x4}
+ do_test selectD-$i.4 {
+ db eval {
+ UPDATE t2 SET a=111;
+ UPDATE t3 SET a=111;
+ UPDATE t4 SET a=111;
+ SELECT *
+ FROM t1 LEFT JOIN (t2 LEFT JOIN (t3 LEFT JOIN t4 USING(a))
+ USING (a))
+ USING (a);
+ }
+ } {111 x1 x2 x3 x4}
+ do_test selectD-$i.5 {
+ db eval {
+ UPDATE t3 SET a=222;
+ UPDATE t4 SET a=222;
+ SELECT *
+ FROM (t1 LEFT JOIN t2 USING(a)) JOIN (t3 LEFT JOIN t4 USING(a))
+ ON t1.a=t3.a-111;
+ }
+ } {111 x1 x2 222 x3 x4}
+ do_test selectD-$i.6 {
+ db eval {
+ UPDATE t4 SET a=333;
+ SELECT *
+ FROM (t1 LEFT JOIN t2 USING(a)) JOIN (t3 LEFT JOIN t4 USING(a))
+ ON t1.a=t3.a-111;
+ }
+ } {111 x1 x2 222 x3 {}}
+ do_test selectD-$i.7 {
+ db eval {
+ SELECT t1.*, t2.*, t3.*, t4.b
+ FROM (t1 LEFT JOIN t2 USING(a)) JOIN (t3 LEFT JOIN t4 USING(a))
+ ON t1.a=t3.a-111;
+ }
+ } {111 x1 111 x2 222 x3 {}}
+}
+
+# The following test was added on 2013-04-24 in order to verify that
+# the datatypes and affinities of sub-sub-queries are set prior to computing
+# the datatypes and affinities of the parent sub-queries because the
+# latter computation depends on the former.
+#
+do_execsql_test selectD-4.1 {
+ CREATE TABLE t41(a INTEGER PRIMARY KEY, b INTEGER);
+ CREATE TABLE t42(d INTEGER PRIMARY KEY, e INTEGER);
+ CREATE TABLE t43(f INTEGER PRIMARY KEY, g INTEGER);
+ EXPLAIN QUERY PLAN
+ SELECT *
+ FROM t41
+ LEFT JOIN (SELECT count(*) AS cnt, x1.d
+ FROM (t42 INNER JOIN t43 ON d=g) AS x1
+ WHERE x1.d>5
+ GROUP BY x1.d) AS x2
+ ON t41.b=x2.d;
+} {/.*SEARCH SUBQUERY 1 AS x2 USING AUTOMATIC.*/}
+
+finish_test
diff --git a/lang/sql/sqlite/test/selectE.test b/lang/sql/sqlite/test/selectE.test
new file mode 100644
index 00000000..d7592bbb
--- /dev/null
+++ b/lang/sql/sqlite/test/selectE.test
@@ -0,0 +1,95 @@
+# 2013-05-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 compound SELECT statements
+# that have ORDER BY clauses with collating sequences that differ
+# from the collating sequence used for comparison in the compound.
+#
+# Ticket 6709574d2a8d8b9be3a9cb1afbf4ff2de48ea4e7:
+# drh added on 2013-05-06 15:21:16:
+#
+# In the code shown below (which is intended to be run from the
+# sqlite3.exe command-line tool) the three SELECT statements should all
+# generate the same answer. But the third one does not. It is as if the
+# COLLATE clause on the ORDER BY somehow got pulled into the EXCEPT
+# operator. Note that the ".print" commands are instructions to the
+# sqlite3.exe shell program to output delimiter lines so that you can more
+# easily tell where the output of one query ends and the next query
+# begins.
+#
+# CREATE TABLE t1(a);
+# INSERT INTO t1 VALUES('abc'),('def');
+# CREATE TABLE t2(a);
+# INSERT INTO t2 VALUES('DEF');
+#
+# SELECT a FROM t1 EXCEPT SELECT a FROM t2 ORDER BY a;
+# .print -----
+# SELECT a FROM (SELECT a FROM t1 EXCEPT SELECT a FROM t2)
+# ORDER BY a COLLATE nocase;
+# .print -----
+# SELECT a FROM t1 EXCEPT SELECT a FROM t2 ORDER BY a COLLATE nocase;
+#
+# Bisecting shows that this problem was introduced in SQLite version 3.6.0
+# by check-in [8bbfa97837a74ef] on 2008-06-15.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+do_test selectE-1.0 {
+ db eval {
+ CREATE TABLE t1(a);
+ INSERT INTO t1 VALUES('abc'),('def'),('ghi');
+ CREATE TABLE t2(a);
+ INSERT INTO t2 VALUES('DEF'),('abc');
+ CREATE TABLE t3(a);
+ INSERT INTO t3 VALUES('def'),('jkl');
+
+ SELECT a FROM t1 EXCEPT SELECT a FROM t2
+ ORDER BY a COLLATE nocase;
+ }
+} {def ghi}
+do_test selectE-1.1 {
+ db eval {
+ SELECT a FROM t2 EXCEPT SELECT a FROM t3
+ ORDER BY a COLLATE nocase;
+ }
+} {abc DEF}
+do_test selectE-1.2 {
+ db eval {
+ SELECT a FROM t2 EXCEPT SELECT a FROM t3
+ ORDER BY a COLLATE binary;
+ }
+} {DEF abc}
+do_test selectE-1.3 {
+ db eval {
+ SELECT a FROM t2 EXCEPT SELECT a FROM t3
+ ORDER BY a;
+ }
+} {DEF abc}
+
+do_test selectE-2.1 {
+ db eval {
+ DELETE FROM t2;
+ DELETE FROM t3;
+ INSERT INTO t2 VALUES('ABC'),('def'),('GHI'),('jkl');
+ INSERT INTO t3 SELECT lower(a) FROM t2;
+ SELECT a COLLATE nocase FROM t2 EXCEPT SELECT a FROM t3
+ ORDER BY 1
+ }
+} {}
+do_test selectE-2.2 {
+ db eval {
+ SELECT a COLLATE nocase FROM t2 EXCEPT SELECT a FROM t3
+ ORDER BY 1 COLLATE binary
+ }
+} {}
+
+finish_test
diff --git a/lang/sql/sqlite/test/server1.test b/lang/sql/sqlite/test/server1.test
index 134a9f57..90673ef0 100644
--- a/lang/sql/sqlite/test/server1.test
+++ b/lang/sql/sqlite/test/server1.test
@@ -29,7 +29,7 @@ if {[llength [info command client_step]]==0 || [sqlite3 -has-codec]} {
# The sample server implementation does not work right when memory
# management is enabled.
#
-ifcapable memorymanage {
+ifcapable (memorymanage||mutex_noop) {
finish_test
return
}
diff --git a/lang/sql/sqlite/test/shared.test b/lang/sql/sqlite/test/shared.test
index 35ddf088..4eab4765 100644
--- a/lang/sql/sqlite/test/shared.test
+++ b/lang/sql/sqlite/test/shared.test
@@ -27,7 +27,7 @@ set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
foreach av [list 0 1] {
# Open the database connection and execute the auto-vacuum pragma
-file delete -force test.db
+forcedelete test.db
sqlite3 db test.db
ifcapable autovacuum {
@@ -293,9 +293,9 @@ catch {db3 close}
# db2.main -> ./test2.db
# db2.test -> ./test.db
#
-file delete -force test.db
-file delete -force test2.db
-file delete -force test2.db-journal
+forcedelete test.db
+forcedelete test2.db
+forcedelete test2.db-journal
sqlite3 db test.db
sqlite3 db2 test2.db
do_test shared-$av.4.1.1 {
@@ -426,7 +426,7 @@ catch {db close}
# Tests shared-5.*
#
foreach db [list test.db test1.db test2.db test3.db] {
- file delete -force $db ${db}-journal
+ forcedelete $db ${db}-journal
}
do_test shared-$av.5.1.1 {
sqlite3 db1 test.db
@@ -557,7 +557,7 @@ do_test shared-$av.6.1.4 {
catch {db1 close}
catch {db2 close}
foreach f [list test.db test2.db] {
- file delete -force $f ${f}-journal
+ forcedelete $f ${f}-journal
}
#--------------------------------------------------------------------------
@@ -643,7 +643,7 @@ unset -nocomplain contents
# The following tests try to trick the shared-cache code into assuming
# the wrong encoding for a database.
#
-file delete -force test.db test.db-journal
+forcedelete test.db test.db-journal
ifcapable utf16 {
do_test shared-$av.8.1.1 {
sqlite3 db test.db
@@ -675,7 +675,7 @@ ifcapable utf16 {
}
} {UTF-8}
- file delete -force test2.db test2.db-journal
+ forcedelete test2.db test2.db-journal
do_test shared-$av.8.2.1 {
execsql {
ATTACH 'test2.db' AS aux;
@@ -693,7 +693,7 @@ ifcapable utf16 {
catch {db close}
catch {db2 close}
- file delete -force test.db test2.db
+ forcedelete test.db test2.db
do_test shared-$av.8.3.2 {
sqlite3 db test.db
@@ -732,7 +732,7 @@ if 0 {
catch {db close}
catch {db2 close}
-file delete -force test.db test2.db
+forcedelete test.db test2.db
#---------------------------------------------------------------------------
# The following tests - shared-9.* - test interactions between TEMP triggers
@@ -772,7 +772,7 @@ do_test shared-$av.9.3 {
#
do_test shared-$av.10.1 {
# Create a small sample database with two connections to it (db and db2).
- file delete -force test.db
+ forcedelete test.db
sqlite3 db test.db
sqlite3 db2 test.db
execsql {
@@ -853,7 +853,7 @@ do_test shared-$av.10.11 {
} {}
do_test shared-$av.11.1 {
- file delete -force test.db
+ forcedelete test.db
sqlite3 db test.db
sqlite3 db2 test.db
execsql {
@@ -904,9 +904,11 @@ do_test shared-$av.11.8 {
set res
} {1 4 {} 7}
if {[llength [info command sqlite3_shared_cache_report]]==1} {
- do_test shared-$av.11.9 {
- string tolower [sqlite3_shared_cache_report]
- } [string tolower [list [file nativename [file normalize test.db]] 2]]
+ ifcapable curdir {
+ do_test shared-$av.11.9 {
+ string tolower [sqlite3_shared_cache_report]
+ } [string tolower [list [file nativename [file normalize test.db]] 2]]
+ }
}
do_test shared-$av.11.11 {
@@ -916,7 +918,7 @@ do_test shared-$av.11.11 {
# This tests that if it is impossible to free any pages, SQLite will
# exceed the limit set by PRAGMA cache_size.
-file delete -force test.db test.db-journal
+forcedelete test.db test.db-journal
sqlite3 db test.db
ifcapable pager_pragmas {
do_test shared-$av.12.1 {
@@ -963,7 +965,7 @@ do_test shared-$av.12.X {
# database handle. This covers an extra line or two.
#
do_test shared-$av.13.1 {
- file delete -force test2.db test3.db test4.db test5.db
+ forcedelete test2.db test3.db test4.db test5.db
sqlite3 db :memory:
execsql {
ATTACH 'test2.db' AS aux2;
@@ -1026,7 +1028,7 @@ do_test shared-$av.14.3 {
# assert() statements in the C code.
#
do_test shared-$av-15.1 {
- file delete -force test.db
+ forcedelete test.db
sqlite3 db test.db -fullmutex 1
sqlite3 db2 test.db -fullmutex 1
execsql {
@@ -1056,7 +1058,127 @@ do_test shared-$av-15.2 {
db close
db2 close
-}
+# Shared cache on a :memory: database. This only works for URI filenames.
+#
+do_test shared-$av-16.1 {
+ sqlite3 db1 file::memory: -uri 1
+ sqlite3 db2 file::memory: -uri 1
+ db1 eval {
+ CREATE TABLE t1(x); INSERT INTO t1 VALUES(1),(2),(3);
+ }
+ db2 eval {
+ SELECT x FROM t1 ORDER BY x;
+ }
+} {1 2 3}
+do_test shared-$av-16.2 {
+ db2 eval {
+ INSERT INTO t1 VALUES(99);
+ DELETE FROM t1 WHERE x=2;
+ }
+ db1 eval {
+ SELECT x FROM t1 ORDER BY x;
+ }
+} {1 3 99}
+
+# Verify that there is no cache sharing ordinary (non-URI) filenames are
+# used.
+#
+do_test shared-$av-16.3 {
+ db1 close
+ db2 close
+ sqlite3 db1 :memory:
+ sqlite3 db2 :memory:
+ db1 eval {
+ CREATE TABLE t1(x); INSERT INTO t1 VALUES(4),(5),(6);
+ }
+ catchsql {
+ SELECT * FROM t1;
+ } db2
+} {1 {no such table: t1}}
+
+# Shared cache on named memory databases.
+#
+do_test shared-$av-16.4 {
+ db1 close
+ db2 close
+ forcedelete test.db test.db-wal test.db-journal
+ sqlite3 db1 file:test.db?mode=memory -uri 1
+ sqlite3 db2 file:test.db?mode=memory -uri 1
+ db1 eval {
+ CREATE TABLE t1(x); INSERT INTO t1 VALUES(1),(2),(3);
+ }
+ db2 eval {
+ SELECT x FROM t1 ORDER BY x;
+ }
+} {1 2 3}
+do_test shared-$av-16.5 {
+ db2 eval {
+ INSERT INTO t1 VALUES(99);
+ DELETE FROM t1 WHERE x=2;
+ }
+ db1 eval {
+ SELECT x FROM t1 ORDER BY x;
+ }
+} {1 3 99}
+do_test shared-$av-16.6 {
+ file exists test.db
+} {0} ;# Verify that the database is in-memory
+
+# Shared cache on named memory databases with different names.
+#
+do_test shared-$av-16.7 {
+ db1 close
+ db2 close
+ forcedelete test1.db test2.db
+ sqlite3 db1 file:test1.db?mode=memory -uri 1
+ sqlite3 db2 file:test2.db?mode=memory -uri 1
+ db1 eval {
+ CREATE TABLE t1(x); INSERT INTO t1 VALUES(1),(2),(3);
+ }
+ catchsql {
+ SELECT x FROM t1 ORDER BY x;
+ } db2
+} {1 {no such table: t1}}
+do_test shared-$av-16.8 {
+ file exists test1.db
+} {0} ;# Verify that the database is in-memory
+
+# Shared cache on named memory databases attached to readonly connections.
+#
+do_test shared-$av-16.8.1 {
+ db1 close
+ db2 close
+
+ sqlite3 db test1.db
+ db eval {
+ CREATE TABLE yy(a, b);
+ INSERT INTO yy VALUES(77, 88);
+ }
+ db close
+
+ sqlite3 db1 test1.db -uri 1 -readonly 1
+ sqlite3 db2 test2.db -uri 1
+
+ db1 eval {
+ ATTACH 'file:mem?mode=memory&cache=shared' AS shared;
+ CREATE TABLE shared.xx(a, b);
+ INSERT INTO xx VALUES(55, 66);
+ }
+ db2 eval {
+ ATTACH 'file:mem?mode=memory&cache=shared' AS shared;
+ SELECT * FROM xx;
+ }
+} {55 66}
+
+do_test shared-$av-16.8.2 { db1 eval { SELECT * FROM yy } } {77 88}
+do_test shared-$av-16.8.3 {
+ list [catch {db1 eval { INSERT INTO yy VALUES(1, 2) }} msg] $msg
+} {1 {attempt to write a readonly database}}
+
+db1 close
+db2 close
+
+} ;# end of autovacuum on/off loop
sqlite3_enable_shared_cache $::enable_shared_cache
finish_test
diff --git a/lang/sql/sqlite/test/shared2.test b/lang/sql/sqlite/test/shared2.test
index d2a0d1b0..5bde8cfa 100644
--- a/lang/sql/sqlite/test/shared2.test
+++ b/lang/sql/sqlite/test/shared2.test
@@ -79,48 +79,6 @@ do_test shared2-1.3 {
list $a $count
} {32 64}
-#---------------------------------------------------------------------------
-# These tests, shared2.2.*, test the outcome when data is added to or
-# removed from a table due to a rollback while a read-uncommitted
-# cursor is scanning it.
-#
-do_test shared2-2.1 {
- execsql {
- INSERT INTO numbers VALUES(1, 'Medium length text field');
- INSERT INTO numbers VALUES(2, 'Medium length text field');
- INSERT INTO numbers VALUES(3, 'Medium length text field');
- INSERT INTO numbers VALUES(4, 'Medium length text field');
- BEGIN;
- DELETE FROM numbers WHERE (a%2)=0;
- } db1
- set res [list]
- db2 eval {
- SELECT a FROM numbers ORDER BY a;
- } {
- lappend res $a
- if {$a==3} {
- execsql {ROLLBACK} db1
- }
- }
- set res
-} {1 3 4}
-do_test shared2-2.2 {
- execsql {
- BEGIN;
- INSERT INTO numbers VALUES(5, 'Medium length text field');
- INSERT INTO numbers VALUES(6, 'Medium length text field');
- } db1
- set res [list]
- db2 eval {
- SELECT a FROM numbers ORDER BY a;
- } {
- lappend res $a
- if {$a==5} {
- execsql {ROLLBACK} db1
- }
- }
- set res
-} {1 2 3 4 5}
db1 close
db2 close
@@ -129,7 +87,7 @@ do_test shared2-3.2 {
sqlite3_enable_shared_cache 1
} {1}
-file delete -force test.db
+forcedelete test.db
sqlite3 db test.db
do_test shared2-4.1 {
diff --git a/lang/sql/sqlite/test/shared3.test b/lang/sql/sqlite/test/shared3.test
index 0a365524..f84eb4fa 100644
--- a/lang/sql/sqlite/test/shared3.test
+++ b/lang/sql/sqlite/test/shared3.test
@@ -13,6 +13,7 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
+set testprefix shared3
db close
ifcapable !shared_cache {
@@ -24,7 +25,7 @@ set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
# Ticket #1824
#
do_test shared3-1.1 {
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db1 test.db
db1 eval {
PRAGMA encoding=UTF16;
@@ -103,5 +104,39 @@ db1 close
db2 close
#db3 close
+#-------------------------------------------------------------------------
+# At one point this was causing a faulty assert to fail.
+#
+forcedelete test.db
+sqlite3 db test.db
+sqlite3 db2 test.db
+do_execsql_test 3.1 {
+ PRAGMA auto_vacuum = 2;
+ CREATE TABLE t1(x, y);
+ INSERT INTO t1 VALUES(randomblob(500), randomblob(500));
+ INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1;
+ INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1;
+ INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1;
+ INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1;
+ INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1;
+ INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1;
+ INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1;
+}
+do_test 3.2 {
+ execsql { SELECT count(*) FROM sqlite_master } db2
+} {1}
+do_execsql_test 3.3 {
+ BEGIN;
+ DELETE FROM t1 WHERE 1;
+ PRAGMA incremental_vacuum;
+} {}
+do_test 3.4 {
+ execsql { SELECT count(*) FROM sqlite_master } db2
+} {1}
+do_test 3.5 {
+ execsql { COMMIT }
+} {}
+
sqlite3_enable_shared_cache $::enable_shared_cache
finish_test
+
diff --git a/lang/sql/sqlite/test/shared4.test b/lang/sql/sqlite/test/shared4.test
index f9f01738..83925b06 100644
--- a/lang/sql/sqlite/test/shared4.test
+++ b/lang/sql/sqlite/test/shared4.test
@@ -30,10 +30,10 @@ set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
# Prepare multiple databases in shared cache mode.
#
do_test shared4-1.1 {
- file delete -force test1.db test1.db-journal
- file delete -force test2.db test2.db-journal
- file delete -force test3.db test3.db-journal
- file delete -force test4.db test4.db-journal
+ forcedelete test1.db test1.db-journal
+ forcedelete test2.db test2.db-journal
+ forcedelete test3.db test3.db-journal
+ forcedelete test4.db test4.db-journal
sqlite3 db1 test1.db
sqlite3 db2 test2.db
sqlite3 db3 test3.db
diff --git a/lang/sql/sqlite/test/shared6.test b/lang/sql/sqlite/test/shared6.test
index 6f3f66e1..585819fa 100644
--- a/lang/sql/sqlite/test/shared6.test
+++ b/lang/sql/sqlite/test/shared6.test
@@ -235,7 +235,7 @@ do_test shared6-3.X {
} {}
do_test shared6-4.1 {
- #file delete -force test.db test.db-journal
+ #forcedelete test.db test.db-journal
sqlite3 db1 test.db
sqlite3 db2 test.db
diff --git a/lang/sql/sqlite/test/shared7.test b/lang/sql/sqlite/test/shared7.test
index d003f0ae..9f4880f5 100644
--- a/lang/sql/sqlite/test/shared7.test
+++ b/lang/sql/sqlite/test/shared7.test
@@ -23,6 +23,9 @@ do_test shared7-1.1 {
sqlite3_enable_shared_cache
} {1}
+# EVIDENCE-OF: R-05098-06501 In shared cache mode, attempting to attach
+# the same database file more than once results in an error.
+#
do_test shared7-1.2 {
db close
sqlite3 db test.db
@@ -35,7 +38,7 @@ do_test shared7-1.2 {
} {1 {database is already attached}}
do_test shared7-1.3 {
- file delete -force test2.db test2.db-journal
+ forcedelete test2.db test2.db-journal
db eval {
ATTACH 'test2.db' AS test2;
CREATE TABLE test2.t2(y);
diff --git a/lang/sql/sqlite/test/shared8.test b/lang/sql/sqlite/test/shared8.test
new file mode 100644
index 00000000..73f0d476
--- /dev/null
+++ b/lang/sql/sqlite/test/shared8.test
@@ -0,0 +1,112 @@
+# 2012 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.
+#
+#***********************************************************************
+#
+# The tests in this file are intended to show that closing one database
+# connection to a shared-cache while there exist other connections (a)
+# does not cause the schema to be reloaded and (b) does not cause any
+# other problems.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+ifcapable !shared_cache { finish_test ; return }
+set testprefix shared8
+
+db close
+set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
+do_test 0.0 { sqlite3_enable_shared_cache } {1}
+
+proc roman {n} {
+ array set R {1 i 2 ii 3 iii 4 iv 5 v 6 vi 7 vii 8 viii 9 ix 10 x}
+ set R($n)
+}
+
+#-------------------------------------------------------------------------
+# The following tests work as follows:
+#
+# 1.0: Open connection [db1] and populate the database.
+#
+# 1.1: Using "PRAGMA writable_schema", destroy the database schema on
+# disk. The schema is still in memory, so it is possible to keep
+# using it, but any attempt to reload it from disk will fail.
+#
+# 1.3-4: Open connection db2. Check that it can see the db schema. Then
+# close db1 and check that db2 still works. This shows that closing
+# db1 did not reset the in-memory schema.
+#
+# 1.5-7: Similar to 1.3-4.
+#
+# 1.8: Close all database connections (deleting the in-memory schema).
+# Then open a new connection and check that it cannot read the db.
+#
+do_test 1.0 {
+ sqlite3 db1 test.db
+ db1 func roman roman
+ execsql {
+ CREATE TABLE t1(a, b);
+ INSERT INTO t1 VALUES(1, 1);
+ INSERT INTO t1 VALUES(2, 2);
+ INSERT INTO t1 VALUES(3, 3);
+ INSERT INTO t1 VALUES(4, 4);
+ CREATE VIEW v1 AS SELECT a, roman(b) FROM t1;
+ SELECT * FROM v1;
+ } db1
+} {1 i 2 ii 3 iii 4 iv}
+
+do_test 1.1 {
+ execsql {
+ PRAGMA writable_schema = 1;
+ DELETE FROM sqlite_master WHERE 1;
+ PRAGMA writable_schema = 0;
+ SELECT * FROM sqlite_master;
+ } db1
+} {}
+
+do_test 1.2 {
+ execsql { SELECT * FROM v1 } db1
+} {1 i 2 ii 3 iii 4 iv}
+
+do_test 1.3 {
+ sqlite3 db2 test.db
+ db2 func roman roman
+ execsql { SELECT * FROM v1 } db2
+} {1 i 2 ii 3 iii 4 iv}
+
+do_test 1.4 {
+ db1 close
+ execsql { SELECT * FROM v1 } db2
+} {1 i 2 ii 3 iii 4 iv}
+
+do_test 1.5 {
+ sqlite3 db3 test.db
+ db3 func roman roman
+ execsql { SELECT * FROM v1 } db3
+} {1 i 2 ii 3 iii 4 iv}
+
+do_test 1.6 {
+ execsql { SELECT * FROM v1 } db2
+} {1 i 2 ii 3 iii 4 iv}
+
+do_test 1.7 {
+ db2 close
+ execsql { SELECT * FROM v1 } db3
+} {1 i 2 ii 3 iii 4 iv}
+
+do_test 1.8 {
+ db3 close
+ sqlite3 db4 test.db
+ catchsql { SELECT * FROM v1 } db4
+} {1 {no such table: v1}}
+
+
+foreach db {db1 db2 db3 db4} { catch { $db close } }
+sqlite3_enable_shared_cache $::enable_shared_cache
+finish_test
diff --git a/lang/sql/sqlite/test/shared9.test b/lang/sql/sqlite/test/shared9.test
new file mode 100644
index 00000000..1982a593
--- /dev/null
+++ b/lang/sql/sqlite/test/shared9.test
@@ -0,0 +1,230 @@
+# 2012 October 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 tests in this file are intended to show if two connections attach
+# to the same shared cache using different database names, views and
+# virtual tables may still be accessed.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+source $testdir/lock_common.tcl
+set testprefix shared9
+
+ifcapable !view||!trigger {
+ finish_test
+ return
+}
+
+db close
+set enable_shared_cache [sqlite3_enable_shared_cache 1]
+
+sqlite3 db1 test.db
+sqlite3 db2 test.db
+forcedelete test.db2
+
+do_test 1.1 {
+ db1 eval {
+ ATTACH 'test.db2' AS 'fred';
+ CREATE TABLE fred.t1(a, b, c);
+ CREATE VIEW fred.v1 AS SELECT * FROM t1;
+
+ CREATE TABLE fred.t2(a, b);
+ CREATE TABLE fred.t3(a, b);
+ CREATE TRIGGER fred.trig AFTER INSERT ON t2 BEGIN
+ DELETE FROM t3;
+ INSERT INTO t3 SELECT * FROM t2;
+ END;
+ INSERT INTO t2 VALUES(1, 2);
+ SELECT * FROM t3;
+ }
+} {1 2}
+
+do_test 1.2 { db2 eval "ATTACH 'test.db2' AS 'jones'" } {}
+do_test 1.3 { db2 eval "SELECT * FROM v1" } {}
+do_test 1.4 { db2 eval "INSERT INTO t2 VALUES(3, 4)" } {}
+
+ifcapable fts3 {
+ do_test 1.5 {
+ db1 eval {
+ CREATE VIRTUAL TABLE fred.t4 USING fts4;
+ INSERT INTO t4 VALUES('hello world');
+ }
+ } {}
+
+ do_test 1.6 {
+ db2 eval {
+ INSERT INTO t4 VALUES('shared cache');
+ SELECT * FROM t4 WHERE t4 MATCH 'hello';
+ }
+ } {{hello world}}
+
+ do_test 1.7 {
+ db1 eval {
+ SELECT * FROM t4 WHERE t4 MATCH 'c*';
+ }
+ } {{shared cache}}
+}
+
+db1 close
+db2 close
+
+#-------------------------------------------------------------------------
+# The following tests attempt to find a similar problem with collation
+# sequence names - pointers to database handle specific allocations leaking
+# into schema objects and being used after the original handle has been
+# closed.
+#
+forcedelete test.db test.db2
+sqlite3 db1 test.db
+sqlite3 db2 test.db
+foreach x {collate1 collate2 collate3} {
+ proc $x {a b} { string compare $a $b }
+ db1 collate $x $x
+ db2 collate $x $x
+}
+do_test 2.1 {
+ db1 eval {
+ CREATE TABLE t1(a, b, c COLLATE collate1);
+ CREATE INDEX i1 ON t1(a COLLATE collate2, c, b);
+ }
+} {}
+do_test 2.2 {
+ db1 close
+ db2 eval "INSERT INTO t1 VALUES('abc', 'def', 'ghi')"
+} {}
+db2 close
+
+#-------------------------------------------------------------------------
+# At one point, the following would cause a collation sequence belonging
+# to connection [db1] to be invoked by a call to [db2 eval]. Which is a
+# problem if [db1] has already been closed.
+#
+forcedelete test.db test.db2
+sqlite3 db1 test.db
+sqlite3 db2 test.db
+
+proc mycollate_db1 {a b} {set ::invoked_mycollate_db1 1 ; string compare $a $b}
+proc mycollate_db2 {a b} {string compare $a $b}
+
+db1 collate mycollate mycollate_db1
+db2 collate mycollate mycollate_db2
+
+do_test 2.3 {
+ set ::invoked_mycollate_db1 0
+ db1 eval {
+ CREATE TABLE t1(a COLLATE mycollate, CHECK (a IN ('one', 'two', 'three')));
+ INSERT INTO t1 VALUES('one');
+ }
+ db1 close
+ set ::invoked_mycollate_db1
+} {1}
+do_test 2.4 {
+ set ::invoked_mycollate_db1 0
+ db2 eval {
+ INSERT INTO t1 VALUES('two');
+ }
+ db2 close
+ set ::invoked_mycollate_db1
+} {0}
+
+forcedelete test.db test.db2
+sqlite3 db1 test.db
+sqlite3 db2 test.db
+db1 collate mycollate mycollate_db1
+db2 collate mycollate mycollate_db2
+
+do_test 2.13 {
+ set ::invoked_mycollate_db1 0
+ db1 eval {
+ CREATE TABLE t1(a, CHECK (a COLLATE mycollate IN ('one', 'two', 'three')));
+ INSERT INTO t1 VALUES('one');
+ }
+ db1 close
+ set ::invoked_mycollate_db1
+} {1}
+do_test 2.14 {
+ set ::invoked_mycollate_db1 0
+ db2 eval {
+ INSERT INTO t1 VALUES('two');
+ }
+ db2 close
+ set ::invoked_mycollate_db1
+} {0}
+
+#-------------------------------------------------------------------------
+# This test verifies that a bug causing a busy-handler belonging to one
+# shared-cache connection to be executed as a result of an sqlite3_step()
+# on another has been fixed.
+#
+forcedelete test.db test.db2
+sqlite3 db1 test.db
+sqlite3 db2 test.db
+
+proc busyhandler {handle args} {
+ set ::busyhandler_invoked_for $handle
+ return 1
+}
+db1 busy [list busyhandler db1]
+db2 busy [list busyhandler db2]
+
+do_test 3.1 {
+ db1 eval {
+ BEGIN;
+ CREATE TABLE t1(a, b);
+ CREATE TABLE t2(a, b);
+ INSERT INTO t1 VALUES(1, 2);
+ INSERT INTO t2 VALUES(1, 2);
+ }
+ # Keep this next COMMIT as a separate statement. This ensures that COMMIT
+ # has already been compiled and loaded into the tcl interface statement
+ # cache when it is attempted below.
+ db1 eval COMMIT
+ db1 eval {
+ BEGIN;
+ INSERT INTO t1 VALUES(3, 4);
+ }
+} {}
+
+do_test 3.2 {
+ set ::tf [launch_testfixture]
+ testfixture $::tf {
+ sqlite3 db test.db
+ db eval {
+ BEGIN;
+ SELECT * FROM t1;
+ }
+ }
+} {1 2}
+
+do_test 3.3 {
+ db2 eval { SELECT * FROM t2 }
+} {1 2}
+
+do_test 3.4 {
+ list [catch { db1 eval COMMIT } msg] $msg
+} {1 {database is locked}}
+
+# At one point the following would fail, showing that the busy-handler
+# belonging to [db2] was invoked instead.
+do_test 3.5 {
+ set ::busyhandler_invoked_for
+} {db1}
+do_test 3.6 {
+ close $::tf
+ db1 eval COMMIT
+} {}
+
+db1 close
+db2 close
+
+sqlite3_enable_shared_cache $::enable_shared_cache
+finish_test
diff --git a/lang/sql/sqlite/test/sharedA.test b/lang/sql/sqlite/test/sharedA.test
new file mode 100644
index 00000000..146fb26b
--- /dev/null
+++ b/lang/sql/sqlite/test/sharedA.test
@@ -0,0 +1,188 @@
+# 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
+if {[run_thread_tests]==0} { finish_test ; return }
+db close
+set ::testprefix sharedA
+
+set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
+
+#-------------------------------------------------------------------------
+#
+do_test 0.1 {
+ sqlite3 db1 test.db
+ sqlite3 db2 test.db
+
+ db1 eval {
+ CREATE TABLE t1(x);
+ INSERT INTO t1 VALUES(randomblob(100));
+ INSERT INTO t1 SELECT randomblob(100) FROM t1;
+ INSERT INTO t1 SELECT randomblob(100) FROM t1;
+ INSERT INTO t1 SELECT randomblob(100) FROM t1;
+ INSERT INTO t1 SELECT randomblob(100) FROM t1;
+ INSERT INTO t1 SELECT randomblob(100) FROM t1;
+ INSERT INTO t1 SELECT randomblob(100) FROM t1;
+ CREATE INDEX i1 ON t1(x);
+ }
+
+ db1 eval {
+ BEGIN;
+ DROP INDEX i1;
+ }
+
+ db2 close
+
+ db1 eval {
+ INSERT INTO t1 SELECT randomblob(100) FROM t1;
+ ROLLBACK;
+ PRAGMA integrity_check;
+ }
+} {ok}
+
+db1 close
+forcedelete test.db
+
+
+#-------------------------------------------------------------------------
+#
+do_test 1.1 {
+ sqlite3 db1 test.db
+ sqlite3 db2 test.db
+ db2 eval {
+ CREATE TABLE t1(x);
+ INSERT INTO t1 VALUES(123);
+ }
+ db1 eval {
+ SELECT * FROM t1;
+ CREATE INDEX i1 ON t1(x);
+ }
+} {123}
+
+do_test 1.2 {
+ db2 eval { SELECT * FROM t1 ORDER BY x; }
+
+ db1 eval {
+ BEGIN; DROP INDEX i1;
+ }
+ db1 close
+
+ db2 eval { SELECT * FROM t1 ORDER BY x; }
+} {123}
+
+do_test 1.3 {
+ db2 close
+} {}
+
+#-------------------------------------------------------------------------
+#
+# sqlite3RollbackAll() loops through all attached b-trees and rolls
+# back each one separately. Then if the SQLITE_InternChanges flag is
+# set, it resets the schema. Both of the above steps must be done
+# while holding a mutex, otherwise another thread might slip in and
+# try to use the new schema with the old data.
+#
+# The following sequence of tests attempt to verify that the actions
+# taken by sqlite3RollbackAll() are thread-atomic (that they cannot be
+# interrupted by a separate thread.)
+#
+# Note that a TCL interpreter can only be used within the thread in which
+# it was originally created (because it uses thread-local-storage).
+# The tvfs callbacks must therefore only run on the main thread.
+# There is some trickery in the read_callback procedure to ensure that
+# this is the case.
+#
+testvfs tvfs
+
+# Set up two databases and two database connections.
+#
+# db1: main(test.db), two(test2.db)
+# db2: main(test.db)
+#
+# The cache for test.db is shared between db1 and db2.
+#
+do_test 2.1 {
+ forcedelete test.db test.db2
+ sqlite3 db1 test.db -vfs tvfs
+ db1 eval { ATTACH 'test.db2' AS two }
+
+ db1 eval {
+ CREATE TABLE t1(x);
+ INSERT INTO t1 VALUES(1);
+ INSERT INTO t1 VALUES(2);
+ INSERT INTO t1 VALUES(3);
+ CREATE TABLE two.t2(x);
+ INSERT INTO t2 SELECT * FROM t1;
+ }
+
+ sqlite3 db2 test.db -vfs tvfs
+ db2 eval { SELECT * FROM t1 }
+} {1 2 3}
+
+# Create a prepared statement on db2 that will attempt a schema change
+# in test.db. Meanwhile, start a transaction on db1 that changes
+# the schema of test.db and that creates a rollback journal on test2.db
+#
+do_test 2.2 {
+ set ::STMT [sqlite3_prepare db2 "CREATE INDEX i1 ON t1(x)" -1 tail]
+ db1 eval {
+ BEGIN;
+ CREATE INDEX i1 ON t1(x);
+ INSERT INTO t2 VALUES('value!');
+ }
+} {}
+
+# Set up a callback that will cause db2 to try to execute its
+# schema change when db1 accesses the journal file of test2.db.
+#
+# This callback will be invoked after the content of test.db has
+# be rolled back but before the schema has been reset. If the
+# sqlite3RollbackAll() operation is not thread-atomic, then the
+# db2 statement in the callback will see old content with the newer
+# schema, which is wrong.
+#
+tvfs filter xRead
+tvfs script read_callback
+unset -nocomplain ::some_time_laster
+unset -nocomplain ::thread_result
+proc read_callback {call file args} {
+ if {[string match *test.db2-journal $file]} {
+ tvfs filter {} ;# Ensure that tvfs callbacks to do run on the
+ # child thread
+ sqlthread spawn ::thread_result [subst -nocommands {
+ sqlite3_step $::STMT
+ set rc [sqlite3_finalize $::STMT]
+ }]
+ after 1000 { set ::some_time_later 1 }
+ vwait ::some_time_later
+ }
+}
+do_test 2.3 { db1 eval ROLLBACK } {}
+
+# Verify that the db2 statement invoked by the callback detected the
+# schema change.
+#
+if {[info exists ::thread_result]==0} { vwait ::thread_result }
+do_test 2.4 {
+ list $::thread_result [sqlite3_errmsg db2]
+} {SQLITE_SCHEMA {database schema has changed}}
+
+db1 close
+db2 close
+tvfs delete
+
+sqlite3_enable_shared_cache $::enable_shared_cache
+finish_test
diff --git a/lang/sql/sqlite/test/shared_err.test b/lang/sql/sqlite/test/shared_err.test
index f501fc70..17add94b 100644
--- a/lang/sql/sqlite/test/shared_err.test
+++ b/lang/sql/sqlite/test/shared_err.test
@@ -401,6 +401,8 @@ do_malloc_test shared_err-8 -tclprep {
execsql {INSERT INTO t1 VALUES($a, $b)} db2
}
execsql {COMMIT} db2
+ execsql BEGIN
+ execsql ROLLBACK
set ::DB2 [sqlite3_connection_pointer db2]
set ::STMT [sqlite3_prepare $::DB2 "SELECT a FROM t1 ORDER BY a" -1 DUMMY]
sqlite3_step $::STMT ;# Cursor points at 0000000000
@@ -409,8 +411,7 @@ do_malloc_test shared_err-8 -tclprep {
execsql {
BEGIN;
INSERT INTO t1 VALUES(6, NULL);
- ROLLBACK;
- }
+ ROLLBACK}
} -cleanup {
# UPDATE: As of [5668], if the rollback fails SQLITE_CORRUPT is returned.
# So these tests have been updated to expect SQLITE_CORRUPT and its
diff --git a/lang/sql/sqlite/test/sharedlock.test b/lang/sql/sqlite/test/sharedlock.test
index 1e78eeaf..caa48f5b 100644
--- a/lang/sql/sqlite/test/sharedlock.test
+++ b/lang/sql/sqlite/test/sharedlock.test
@@ -13,6 +13,7 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
+set testprefix sharedlock
db close
ifcapable !shared_cache {
@@ -47,9 +48,35 @@ do_test sharedlock-1.2 {
set res
} {1 one 2 two 3 three}
+
+#-------------------------------------------------------------------------
+# Test that a write-lock is taken on a table when its entire contents
+# are deleted using the OP_Clear optimization.
+#
+foreach {tn delete_sql} {
+ 1 { DELETE FROM t2 WHERE 1 }
+ 2 { DELETE FROM t2 }
+} {
+ do_execsql_test 2.1 {
+ DROP TABLE IF EXISTS t2;
+ CREATE TABLE t2(x, y);
+ INSERT INTO t2 VALUES(1, 2);
+ INSERT INTO t2 VALUES(3, 4);
+ }
+
+ do_test 2.2 { execsql { SELECT * FROM t2 } db2 } {1 2 3 4}
+
+ do_execsql_test 2.3 " BEGIN; $delete_sql; "
+
+ do_test 2.4 {
+ catchsql { SELECT * FROM t2 } db2
+ } {1 {database table is locked: t2}}
+
+ do_execsql_test 2.5 COMMIT
+}
+
+
db close
db2 close
-
sqlite3_enable_shared_cache $::enable_shared_cache
finish_test
-
diff --git a/lang/sql/sqlite/test/shell1.test b/lang/sql/sqlite/test/shell1.test
new file mode 100644
index 00000000..2e936a0b
--- /dev/null
+++ b/lang/sql/sqlite/test/shell1.test
@@ -0,0 +1,812 @@
+# 2009 Nov 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.
+#
+#***********************************************************************
+#
+# The focus of this file is testing the CLI shell tool.
+#
+#
+
+# Test plan:
+#
+# shell1-1.*: Basic command line option handling.
+# shell1-2.*: Basic "dot" command token parsing.
+# shell1-3.*: Basic test that "dot" command can be called.
+#
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+if {$tcl_platform(platform)=="windows"} {
+ set CLI "sqlite3.exe"
+} else {
+ set CLI "./sqlite3"
+}
+if {![file executable $CLI]} {
+ finish_test
+ return
+}
+db close
+forcedelete test.db test.db-journal test.db-wal
+sqlite3 db test.db
+
+#----------------------------------------------------------------------------
+# Test cases shell1-1.*: Basic command line option handling.
+#
+
+# invalid option
+do_test shell1-1.1.1 {
+ set res [catchcmd "-bad test.db" ""]
+ set rc [lindex $res 0]
+ list $rc \
+ [regexp {Error: unknown option: -bad} $res]
+} {1 1}
+# error on extra options
+do_test shell1-1.1.2 {
+ set res [catchcmd "-bad test.db \"select 3\" \"select 4\"" ""]
+ set rc [lindex $res 0]
+ list $rc \
+ [regexp {Error: too many options: "select 4"} $res]
+} {1 1}
+# error on extra options
+do_test shell1-1.1.3 {
+ set res [catchcmd "-bad FOO test.db BAD" ".quit"]
+ set rc [lindex $res 0]
+ list $rc \
+ [regexp {Error: too many options: "BAD"} $res]
+} {1 1}
+
+# -help
+do_test shell1-1.2.1 {
+ set res [catchcmd "-help test.db" ""]
+ set rc [lindex $res 0]
+ list $rc \
+ [regexp {Usage} $res] \
+ [regexp {\-init} $res] \
+ [regexp {\-version} $res]
+} {1 1 1 1}
+
+# -init filename read/process named file
+do_test shell1-1.3.1 {
+ catchcmd "-init FOO test.db" ""
+} {0 {}}
+do_test shell1-1.3.2 {
+ set res [catchcmd "-init FOO test.db .quit BAD" ""]
+ set rc [lindex $res 0]
+ list $rc \
+ [regexp {Error: too many options: "BAD"} $res]
+} {1 1}
+
+# -echo print commands before execution
+do_test shell1-1.4.1 {
+ catchcmd "-echo test.db" ""
+} {0 {}}
+
+# -[no]header turn headers on or off
+do_test shell1-1.5.1 {
+ catchcmd "-header test.db" ""
+} {0 {}}
+do_test shell1-1.5.2 {
+ catchcmd "-noheader test.db" ""
+} {0 {}}
+
+# -bail stop after hitting an error
+do_test shell1-1.6.1 {
+ catchcmd "-bail test.db" ""
+} {0 {}}
+
+# -interactive force interactive I/O
+do_test shell1-1.7.1 {
+ set res [catchcmd "-interactive test.db" ".quit"]
+ set rc [lindex $res 0]
+ list $rc \
+ [regexp {SQLite version} $res] \
+ [regexp {Enter SQL statements} $res]
+} {0 1 1}
+
+# -batch force batch I/O
+do_test shell1-1.8.1 {
+ catchcmd "-batch test.db" ""
+} {0 {}}
+
+# -column set output mode to 'column'
+do_test shell1-1.9.1 {
+ catchcmd "-column test.db" ""
+} {0 {}}
+
+# -csv set output mode to 'csv'
+do_test shell1-1.10.1 {
+ catchcmd "-csv test.db" ""
+} {0 {}}
+
+# -html set output mode to HTML
+do_test shell1-1.11.1 {
+ catchcmd "-html test.db" ""
+} {0 {}}
+
+# -line set output mode to 'line'
+do_test shell1-1.12.1 {
+ catchcmd "-line test.db" ""
+} {0 {}}
+
+# -list set output mode to 'list'
+do_test shell1-1.13.1 {
+ catchcmd "-list test.db" ""
+} {0 {}}
+
+# -separator 'x' set output field separator (|)
+do_test shell1-1.14.1 {
+ catchcmd "-separator 'x' test.db" ""
+} {0 {}}
+do_test shell1-1.14.2 {
+ catchcmd "-separator x test.db" ""
+} {0 {}}
+do_test shell1-1.14.3 {
+ set res [catchcmd "-separator" ""]
+ set rc [lindex $res 0]
+ list $rc \
+ [regexp {Error: missing argument to -separator} $res]
+} {1 1}
+
+# -stats print memory stats before each finalize
+do_test shell1-1.14b.1 {
+ catchcmd "-stats test.db" ""
+} {0 {}}
+
+# -nullvalue 'text' set text string for NULL values
+do_test shell1-1.15.1 {
+ catchcmd "-nullvalue 'x' test.db" ""
+} {0 {}}
+do_test shell1-1.15.2 {
+ catchcmd "-nullvalue x test.db" ""
+} {0 {}}
+do_test shell1-1.15.3 {
+ set res [catchcmd "-nullvalue" ""]
+ set rc [lindex $res 0]
+ list $rc \
+ [regexp {Error: missing argument to -nullvalue} $res]
+} {1 1}
+
+# -version show SQLite version
+do_test shell1-1.16.1 {
+ set x [catchcmd "-version test.db" ""]
+} {/3.[0-9.]+ 20\d\d-[01]\d-\d\d \d\d:\d\d:\d\d [0-9a-f]+/}
+
+#----------------------------------------------------------------------------
+# Test cases shell1-2.*: Basic "dot" command token parsing.
+#
+
+# check first token handling
+do_test shell1-2.1.1 {
+ catchcmd "test.db" ".foo"
+} {1 {Error: unknown command or invalid arguments: "foo". Enter ".help" for help}}
+do_test shell1-2.1.2 {
+ catchcmd "test.db" ".\"foo OFF\""
+} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}}
+do_test shell1-2.1.3 {
+ catchcmd "test.db" ".\'foo OFF\'"
+} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}}
+
+# unbalanced quotes
+do_test shell1-2.2.1 {
+ catchcmd "test.db" ".\"foo OFF"
+} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}}
+do_test shell1-2.2.2 {
+ catchcmd "test.db" ".\'foo OFF"
+} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}}
+do_test shell1-2.2.3 {
+ catchcmd "test.db" ".explain \"OFF"
+} {0 {}}
+do_test shell1-2.2.4 {
+ catchcmd "test.db" ".explain \'OFF"
+} {0 {}}
+do_test shell1-2.2.5 {
+ catchcmd "test.db" ".mode \"insert FOO"
+} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
+do_test shell1-2.2.6 {
+ catchcmd "test.db" ".mode \'insert FOO"
+} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
+
+# check multiple tokens, and quoted tokens
+do_test shell1-2.3.1 {
+ catchcmd "test.db" ".explain 1"
+} {0 {}}
+do_test shell1-2.3.2 {
+ catchcmd "test.db" ".explain on"
+} {0 {}}
+do_test shell1-2.3.3 {
+ catchcmd "test.db" ".explain \"1 2 3\""
+} {1 {ERROR: Not a boolean value: "1 2 3". Assuming "no".}}
+do_test shell1-2.3.4 {
+ catchcmd "test.db" ".explain \"OFF\""
+} {0 {}}
+do_test shell1-2.3.5 {
+ catchcmd "test.db" ".\'explain\' \'OFF\'"
+} {0 {}}
+do_test shell1-2.3.6 {
+ catchcmd "test.db" ".explain \'OFF\'"
+} {0 {}}
+do_test shell1-2.3.7 {
+ catchcmd "test.db" ".\'explain\' \'OFF\'"
+} {0 {}}
+
+# check quoted args are unquoted
+do_test shell1-2.4.1 {
+ catchcmd "test.db" ".mode FOO"
+} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
+do_test shell1-2.4.2 {
+ catchcmd "test.db" ".mode csv"
+} {0 {}}
+do_test shell1-2.4.2 {
+ catchcmd "test.db" ".mode \"csv\""
+} {0 {}}
+
+
+#----------------------------------------------------------------------------
+# Test cases shell1-3.*: Basic test that "dot" command can be called.
+#
+
+# .backup ?DB? FILE Backup DB (default "main") to FILE
+do_test shell1-3.1.1 {
+ catchcmd "test.db" ".backup"
+} {1 {missing FILENAME argument on .backup}}
+do_test shell1-3.1.2 {
+ catchcmd "test.db" ".backup FOO"
+} {0 {}}
+do_test shell1-3.1.3 {
+ catchcmd "test.db" ".backup FOO BAR"
+} {1 {Error: unknown database FOO}}
+do_test shell1-3.1.4 {
+ # too many arguments
+ catchcmd "test.db" ".backup FOO BAR BAD"
+} {1 {too many arguments to .backup}}
+
+# .bail ON|OFF Stop after hitting an error. Default OFF
+do_test shell1-3.2.1 {
+ catchcmd "test.db" ".bail"
+} {1 {Error: unknown command or invalid arguments: "bail". Enter ".help" for help}}
+do_test shell1-3.2.2 {
+ catchcmd "test.db" ".bail ON"
+} {0 {}}
+do_test shell1-3.2.3 {
+ catchcmd "test.db" ".bail OFF"
+} {0 {}}
+do_test shell1-3.2.4 {
+ # too many arguments
+ catchcmd "test.db" ".bail OFF BAD"
+} {1 {Error: unknown command or invalid arguments: "bail". Enter ".help" for help}}
+
+# .databases List names and files of attached databases
+do_test shell1-3.3.1 {
+ catchcmd "-csv test.db" ".databases"
+} "/0 +.*main +[string map {/ .} [string range [get_pwd] 0 10]].*/"
+do_test shell1-3.3.2 {
+ # too many arguments
+ catchcmd "test.db" ".databases BAD"
+} {1 {Error: unknown command or invalid arguments: "databases". Enter ".help" for help}}
+
+# .dump ?TABLE? ... Dump the database in an SQL text format
+# If TABLE specified, only dump tables matching
+# LIKE pattern TABLE.
+do_test shell1-3.4.1 {
+ set res [catchcmd "test.db" ".dump"]
+ list [regexp {BEGIN TRANSACTION;} $res] \
+ [regexp {COMMIT;} $res]
+} {1 1}
+do_test shell1-3.4.2 {
+ set res [catchcmd "test.db" ".dump FOO"]
+ list [regexp {BEGIN TRANSACTION;} $res] \
+ [regexp {COMMIT;} $res]
+} {1 1}
+do_test shell1-3.4.3 {
+ # too many arguments
+ catchcmd "test.db" ".dump FOO BAD"
+} {1 {Error: unknown command or invalid arguments: "dump". Enter ".help" for help}}
+
+# .echo ON|OFF Turn command echo on or off
+do_test shell1-3.5.1 {
+ catchcmd "test.db" ".echo"
+} {1 {Error: unknown command or invalid arguments: "echo". Enter ".help" for help}}
+do_test shell1-3.5.2 {
+ catchcmd "test.db" ".echo ON"
+} {0 {}}
+do_test shell1-3.5.3 {
+ catchcmd "test.db" ".echo OFF"
+} {0 {}}
+do_test shell1-3.5.4 {
+ # too many arguments
+ catchcmd "test.db" ".echo OFF BAD"
+} {1 {Error: unknown command or invalid arguments: "echo". Enter ".help" for help}}
+
+# .exit Exit this program
+do_test shell1-3.6.1 {
+ catchcmd "test.db" ".exit"
+} {0 {}}
+
+# .explain ON|OFF Turn output mode suitable for EXPLAIN on or off.
+do_test shell1-3.7.1 {
+ catchcmd "test.db" ".explain"
+ # explain is the exception to the booleans. without an option, it turns it on.
+} {0 {}}
+do_test shell1-3.7.2 {
+ catchcmd "test.db" ".explain ON"
+} {0 {}}
+do_test shell1-3.7.3 {
+ catchcmd "test.db" ".explain OFF"
+} {0 {}}
+do_test shell1-3.7.4 {
+ # too many arguments
+ catchcmd "test.db" ".explain OFF BAD"
+} {1 {Error: unknown command or invalid arguments: "explain". Enter ".help" for help}}
+
+
+# .header(s) ON|OFF Turn display of headers on or off
+do_test shell1-3.9.1 {
+ catchcmd "test.db" ".header"
+} {1 {Error: unknown command or invalid arguments: "header". Enter ".help" for help}}
+do_test shell1-3.9.2 {
+ catchcmd "test.db" ".header ON"
+} {0 {}}
+do_test shell1-3.9.3 {
+ catchcmd "test.db" ".header OFF"
+} {0 {}}
+do_test shell1-3.9.4 {
+ # too many arguments
+ catchcmd "test.db" ".header OFF BAD"
+} {1 {Error: unknown command or invalid arguments: "header". Enter ".help" for help}}
+
+do_test shell1-3.9.5 {
+ catchcmd "test.db" ".headers"
+} {1 {Error: unknown command or invalid arguments: "headers". Enter ".help" for help}}
+do_test shell1-3.9.6 {
+ catchcmd "test.db" ".headers ON"
+} {0 {}}
+do_test shell1-3.9.7 {
+ catchcmd "test.db" ".headers OFF"
+} {0 {}}
+do_test shell1-3.9.8 {
+ # too many arguments
+ catchcmd "test.db" ".headers OFF BAD"
+} {1 {Error: unknown command or invalid arguments: "headers". Enter ".help" for help}}
+
+# .help Show this message
+do_test shell1-3.10.1 {
+ set res [catchcmd "test.db" ".help"]
+ # look for a few of the possible help commands
+ list [regexp {.help} $res] \
+ [regexp {.quit} $res] \
+ [regexp {.show} $res]
+} {1 1 1}
+do_test shell1-3.10.2 {
+ # we allow .help to take extra args (it is help after all)
+ set res [catchcmd "test.db" ".help BAD"]
+ # look for a few of the possible help commands
+ list [regexp {.help} $res] \
+ [regexp {.quit} $res] \
+ [regexp {.show} $res]
+} {1 1 1}
+
+# .import FILE TABLE Import data from FILE into TABLE
+do_test shell1-3.11.1 {
+ catchcmd "test.db" ".import"
+} {1 {Error: unknown command or invalid arguments: "import". Enter ".help" for help}}
+do_test shell1-3.11.2 {
+ catchcmd "test.db" ".import FOO"
+} {1 {Error: unknown command or invalid arguments: "import". Enter ".help" for help}}
+#do_test shell1-3.11.2 {
+# catchcmd "test.db" ".import FOO BAR"
+#} {1 {Error: no such table: BAR}}
+do_test shell1-3.11.3 {
+ # too many arguments
+ catchcmd "test.db" ".import FOO BAR BAD"
+} {1 {Error: unknown command or invalid arguments: "import". Enter ".help" for help}}
+
+# .indices ?TABLE? Show names of all indices
+# If TABLE specified, only show indices for tables
+# matching LIKE pattern TABLE.
+do_test shell1-3.12.1 {
+ catchcmd "test.db" ".indices"
+} {0 {}}
+do_test shell1-3.12.2 {
+ catchcmd "test.db" ".indices FOO"
+} {0 {}}
+do_test shell1-3.12.3 {
+ # too many arguments
+ catchcmd "test.db" ".indices FOO BAD"
+} {1 {Error: unknown command or invalid arguments: "indices". Enter ".help" for help}}
+
+# .mode MODE ?TABLE? Set output mode where MODE is one of:
+# csv Comma-separated values
+# column Left-aligned columns. (See .width)
+# html HTML <table> code
+# insert SQL insert statements for TABLE
+# line One value per line
+# list Values delimited by .separator string
+# tabs Tab-separated values
+# tcl TCL list elements
+do_test shell1-3.13.1 {
+ catchcmd "test.db" ".mode"
+} {1 {Error: unknown command or invalid arguments: "mode". Enter ".help" for help}}
+do_test shell1-3.13.2 {
+ catchcmd "test.db" ".mode FOO"
+} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
+do_test shell1-3.13.3 {
+ catchcmd "test.db" ".mode csv"
+} {0 {}}
+do_test shell1-3.13.4 {
+ catchcmd "test.db" ".mode column"
+} {0 {}}
+do_test shell1-3.13.5 {
+ catchcmd "test.db" ".mode html"
+} {0 {}}
+do_test shell1-3.13.6 {
+ catchcmd "test.db" ".mode insert"
+} {0 {}}
+do_test shell1-3.13.7 {
+ catchcmd "test.db" ".mode line"
+} {0 {}}
+do_test shell1-3.13.8 {
+ catchcmd "test.db" ".mode list"
+} {0 {}}
+do_test shell1-3.13.9 {
+ catchcmd "test.db" ".mode tabs"
+} {0 {}}
+do_test shell1-3.13.10 {
+ catchcmd "test.db" ".mode tcl"
+} {0 {}}
+do_test shell1-3.13.11 {
+ # too many arguments
+ catchcmd "test.db" ".mode tcl BAD"
+} {1 {Error: invalid arguments: "BAD". Enter ".help" for help}}
+
+# don't allow partial mode type matches
+do_test shell1-3.13.12 {
+ catchcmd "test.db" ".mode l"
+} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
+do_test shell1-3.13.13 {
+ catchcmd "test.db" ".mode li"
+} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
+do_test shell1-3.13.14 {
+ catchcmd "test.db" ".mode lin"
+} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
+
+# .nullvalue STRING Print STRING in place of NULL values
+do_test shell1-3.14.1 {
+ catchcmd "test.db" ".nullvalue"
+} {1 {Error: unknown command or invalid arguments: "nullvalue". Enter ".help" for help}}
+do_test shell1-3.14.2 {
+ catchcmd "test.db" ".nullvalue FOO"
+} {0 {}}
+do_test shell1-3.14.3 {
+ # too many arguments
+ catchcmd "test.db" ".nullvalue FOO BAD"
+} {1 {Error: unknown command or invalid arguments: "nullvalue". Enter ".help" for help}}
+
+# .output FILENAME Send output to FILENAME
+do_test shell1-3.15.1 {
+ catchcmd "test.db" ".output"
+} {1 {Error: unknown command or invalid arguments: "output". Enter ".help" for help}}
+do_test shell1-3.15.2 {
+ catchcmd "test.db" ".output FOO"
+} {0 {}}
+do_test shell1-3.15.3 {
+ # too many arguments
+ catchcmd "test.db" ".output FOO BAD"
+} {1 {Error: unknown command or invalid arguments: "output". Enter ".help" for help}}
+
+# .output stdout Send output to the screen
+do_test shell1-3.16.1 {
+ catchcmd "test.db" ".output stdout"
+} {0 {}}
+do_test shell1-3.16.2 {
+ # too many arguments
+ catchcmd "test.db" ".output stdout BAD"
+} {1 {Error: unknown command or invalid arguments: "output". Enter ".help" for help}}
+
+# .prompt MAIN CONTINUE Replace the standard prompts
+do_test shell1-3.17.1 {
+ catchcmd "test.db" ".prompt"
+} {1 {Error: unknown command or invalid arguments: "prompt". Enter ".help" for help}}
+do_test shell1-3.17.2 {
+ catchcmd "test.db" ".prompt FOO"
+} {0 {}}
+do_test shell1-3.17.3 {
+ catchcmd "test.db" ".prompt FOO BAR"
+} {0 {}}
+do_test shell1-3.17.4 {
+ # too many arguments
+ catchcmd "test.db" ".prompt FOO BAR BAD"
+} {1 {Error: unknown command or invalid arguments: "prompt". Enter ".help" for help}}
+
+# .quit Exit this program
+do_test shell1-3.18.1 {
+ catchcmd "test.db" ".quit"
+} {0 {}}
+do_test shell1-3.18.2 {
+ # too many arguments
+ catchcmd "test.db" ".quit BAD"
+} {1 {Error: unknown command or invalid arguments: "quit". Enter ".help" for help}}
+
+# .read FILENAME Execute SQL in FILENAME
+do_test shell1-3.19.1 {
+ catchcmd "test.db" ".read"
+} {1 {Error: unknown command or invalid arguments: "read". Enter ".help" for help}}
+do_test shell1-3.19.2 {
+ forcedelete FOO
+ catchcmd "test.db" ".read FOO"
+} {1 {Error: cannot open "FOO"}}
+do_test shell1-3.19.3 {
+ # too many arguments
+ catchcmd "test.db" ".read FOO BAD"
+} {1 {Error: unknown command or invalid arguments: "read". Enter ".help" for help}}
+
+# .restore ?DB? FILE Restore content of DB (default "main") from FILE
+do_test shell1-3.20.1 {
+ catchcmd "test.db" ".restore"
+} {1 {Error: unknown command or invalid arguments: "restore". Enter ".help" for help}}
+do_test shell1-3.20.2 {
+ catchcmd "test.db" ".restore FOO"
+} {0 {}}
+do_test shell1-3.20.3 {
+ catchcmd "test.db" ".restore FOO BAR"
+} {1 {Error: unknown database FOO}}
+do_test shell1-3.20.4 {
+ # too many arguments
+ catchcmd "test.db" ".restore FOO BAR BAD"
+} {1 {Error: unknown command or invalid arguments: "restore". Enter ".help" for help}}
+
+# .schema ?TABLE? Show the CREATE statements
+# If TABLE specified, only show tables matching
+# LIKE pattern TABLE.
+do_test shell1-3.21.1 {
+ catchcmd "test.db" ".schema"
+} {0 {}}
+do_test shell1-3.21.2 {
+ catchcmd "test.db" ".schema FOO"
+} {0 {}}
+do_test shell1-3.21.3 {
+ # too many arguments
+ catchcmd "test.db" ".schema FOO BAD"
+} {1 {Error: unknown command or invalid arguments: "schema". Enter ".help" for help}}
+
+do_test shell1-3.21.4 {
+ catchcmd "test.db" {
+ CREATE TABLE t1(x);
+ CREATE VIEW v2 AS SELECT x+1 AS y FROM t1;
+ CREATE VIEW v1 AS SELECT y+1 FROM v2;
+ }
+ catchcmd "test.db" ".schema"
+} {0 {CREATE TABLE t1(x);
+CREATE VIEW v2 AS SELECT x+1 AS y FROM t1;
+CREATE VIEW v1 AS SELECT y+1 FROM v2;}}
+db eval {DROP VIEW v1; DROP VIEW v2; DROP TABLE t1;}
+
+# .separator STRING Change separator used by output mode and .import
+do_test shell1-3.22.1 {
+ catchcmd "test.db" ".separator"
+} {1 {Error: unknown command or invalid arguments: "separator". Enter ".help" for help}}
+do_test shell1-3.22.2 {
+ catchcmd "test.db" ".separator FOO"
+} {0 {}}
+do_test shell1-3.22.3 {
+ # too many arguments
+ catchcmd "test.db" ".separator FOO BAD"
+} {1 {Error: unknown command or invalid arguments: "separator". Enter ".help" for help}}
+
+# .show Show the current values for various settings
+do_test shell1-3.23.1 {
+ set res [catchcmd "test.db" ".show"]
+ list [regexp {echo:} $res] \
+ [regexp {explain:} $res] \
+ [regexp {headers:} $res] \
+ [regexp {mode:} $res] \
+ [regexp {nullvalue:} $res] \
+ [regexp {output:} $res] \
+ [regexp {separator:} $res] \
+ [regexp {stats:} $res] \
+ [regexp {width:} $res]
+} {1 1 1 1 1 1 1 1 1}
+do_test shell1-3.23.2 {
+ # too many arguments
+ catchcmd "test.db" ".show BAD"
+} {1 {Error: unknown command or invalid arguments: "show". Enter ".help" for help}}
+
+# .stats ON|OFF Turn stats on or off
+do_test shell1-3.23b.1 {
+ catchcmd "test.db" ".stats"
+} {1 {Error: unknown command or invalid arguments: "stats". Enter ".help" for help}}
+do_test shell1-3.23b.2 {
+ catchcmd "test.db" ".stats ON"
+} {0 {}}
+do_test shell1-3.23b.3 {
+ catchcmd "test.db" ".stats OFF"
+} {0 {}}
+do_test shell1-3.23b.4 {
+ # too many arguments
+ catchcmd "test.db" ".stats OFF BAD"
+} {1 {Error: unknown command or invalid arguments: "stats". Enter ".help" for help}}
+
+# .tables ?TABLE? List names of tables
+# If TABLE specified, only list tables matching
+# LIKE pattern TABLE.
+do_test shell1-3.24.1 {
+ catchcmd "test.db" ".tables"
+} {0 {}}
+do_test shell1-3.24.2 {
+ catchcmd "test.db" ".tables FOO"
+} {0 {}}
+do_test shell1-3.24.3 {
+ # too many arguments
+ catchcmd "test.db" ".tables FOO BAD"
+} {1 {Error: unknown command or invalid arguments: "tables". Enter ".help" for help}}
+
+# .timeout MS Try opening locked tables for MS milliseconds
+do_test shell1-3.25.1 {
+ catchcmd "test.db" ".timeout"
+} {1 {Error: unknown command or invalid arguments: "timeout". Enter ".help" for help}}
+do_test shell1-3.25.2 {
+ catchcmd "test.db" ".timeout zzz"
+ # this should be treated the same as a '0' timeout
+} {0 {}}
+do_test shell1-3.25.3 {
+ catchcmd "test.db" ".timeout 1"
+} {0 {}}
+do_test shell1-3.25.4 {
+ # too many arguments
+ catchcmd "test.db" ".timeout 1 BAD"
+} {1 {Error: unknown command or invalid arguments: "timeout". Enter ".help" for help}}
+
+# .width NUM NUM ... Set column widths for "column" mode
+do_test shell1-3.26.1 {
+ catchcmd "test.db" ".width"
+} {1 {Error: unknown command or invalid arguments: "width". Enter ".help" for help}}
+do_test shell1-3.26.2 {
+ catchcmd "test.db" ".width xxx"
+ # this should be treated the same as a '0' width for col 1
+} {0 {}}
+do_test shell1-3.26.3 {
+ catchcmd "test.db" ".width xxx yyy"
+ # this should be treated the same as a '0' width for col 1 and 2
+} {0 {}}
+do_test shell1-3.26.4 {
+ catchcmd "test.db" ".width 1 1"
+ # this should be treated the same as a '1' width for col 1 and 2
+} {0 {}}
+do_test shell1-3.26.5 {
+ catchcmd "test.db" ".mode column\n.width 10 -10\nSELECT 'abcdefg', 123456;"
+ # this should be treated the same as a '1' width for col 1 and 2
+} {0 {abcdefg 123456}}
+do_test shell1-3.26.6 {
+ catchcmd "test.db" ".mode column\n.width -10 10\nSELECT 'abcdefg', 123456;"
+ # this should be treated the same as a '1' width for col 1 and 2
+} {0 { abcdefg 123456 }}
+
+
+# .timer ON|OFF Turn the CPU timer measurement on or off
+do_test shell1-3.27.1 {
+ catchcmd "test.db" ".timer"
+} {1 {Error: unknown command or invalid arguments: "timer". Enter ".help" for help}}
+do_test shell1-3.27.2 {
+ catchcmd "test.db" ".timer ON"
+} {0 {}}
+do_test shell1-3.27.3 {
+ catchcmd "test.db" ".timer OFF"
+} {0 {}}
+do_test shell1-3.27.4 {
+ # too many arguments
+ catchcmd "test.db" ".timer OFF BAD"
+} {1 {Error: unknown command or invalid arguments: "timer". Enter ".help" for help}}
+
+do_test shell1-3-28.1 {
+ catchcmd test.db \
+ ".log stdout\nSELECT coalesce(sqlite_log(123,'hello'),'456');"
+} "0 {(123) hello\n456}"
+
+do_test shell1-3-29.1 {
+ catchcmd "test.db" ".print this is a test"
+} {0 {this is a test}}
+
+# dot-command argument quoting
+do_test shell1-3-30.1 {
+ catchcmd {test.db} {.print "this\"is'a\055test" 'this\"is\\a\055test'}
+} {0 {this"is'a-test this\"is\\a\055test}}
+do_test shell1-3-31.1 {
+ catchcmd {test.db} {.print "this\nis\ta\\test" 'this\nis\ta\\test'}
+} [list 0 "this\nis\ta\\test this\\nis\\ta\\\\test"]
+
+
+# Test the output of the ".dump" command
+#
+do_test shell1-4.1 {
+ db close
+ forcedelete test.db
+ sqlite3 db test.db
+ db eval {
+ PRAGMA encoding=UTF16;
+ CREATE TABLE t1(x);
+ INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f');
+ }
+ catchcmd test.db {.dump}
+} {0 {PRAGMA foreign_keys=OFF;
+BEGIN TRANSACTION;
+CREATE TABLE t1(x);
+INSERT INTO "t1" VALUES(NULL);
+INSERT INTO "t1" VALUES('');
+INSERT INTO "t1" VALUES(1);
+INSERT INTO "t1" VALUES(2.25);
+INSERT INTO "t1" VALUES('hello');
+INSERT INTO "t1" VALUES(X'807F');
+COMMIT;}}
+
+# Test the output of ".mode insert"
+#
+do_test shell1-4.2 {
+ catchcmd test.db ".mode insert t1\nselect * from t1;"
+} {0 {INSERT INTO t1 VALUES(NULL);
+INSERT INTO t1 VALUES('');
+INSERT INTO t1 VALUES(1);
+INSERT INTO t1 VALUES(2.25);
+INSERT INTO t1 VALUES('hello');
+INSERT INTO t1 VALUES(X'807f');}}
+
+# Test the output of ".mode tcl"
+#
+do_test shell1-4.3 {
+ db close
+ forcedelete test.db
+ sqlite3 db test.db
+ db eval {
+ PRAGMA encoding=UTF8;
+ CREATE TABLE t1(x);
+ INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f');
+ }
+ catchcmd test.db ".mode tcl\nselect * from t1;"
+} {0 {""
+""
+"1"
+"2.25"
+"hello"
+"\200\177"}}
+
+# Test the output of ".mode tcl" with multiple columns
+#
+do_test shell1-4.4 {
+ db eval {
+ CREATE TABLE t2(x,y);
+ INSERT INTO t2 VALUES(null, ''), (1, 2.25), ('hello', x'807f');
+ }
+ catchcmd test.db ".mode tcl\nselect * from t2;"
+} {0 {"" ""
+"1" "2.25"
+"hello" "\200\177"}}
+
+# Test the output of ".mode tcl" with ".nullvalue"
+#
+do_test shell1-4.5 {
+ catchcmd test.db ".mode tcl\n.nullvalue NULL\nselect * from t2;"
+} {0 {"NULL" ""
+"1" "2.25"
+"hello" "\200\177"}}
+
+# Test the output of ".mode tcl" with Tcl reserved characters
+#
+do_test shell1-4.6 {
+ db eval {
+ CREATE TABLE tcl1(x);
+ INSERT INTO tcl1 VALUES('"'), ('['), (']'), ('\{'), ('\}'), (';'), ('$');
+ }
+ foreach {x y} [catchcmd test.db ".mode tcl\nselect * from tcl1;"] break
+ list $x $y [llength $y]
+} {0 {"\""
+"["
+"]"
+"\\{"
+"\\}"
+";"
+"$"} 7}
+
+finish_test
diff --git a/lang/sql/sqlite/test/shell2.test b/lang/sql/sqlite/test/shell2.test
new file mode 100644
index 00000000..def574c7
--- /dev/null
+++ b/lang/sql/sqlite/test/shell2.test
@@ -0,0 +1,199 @@
+# 2009 Nov 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.
+#
+#***********************************************************************
+#
+# The focus of this file is testing the CLI shell tool.
+#
+# $Id: shell2.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $
+#
+
+# Test plan:
+#
+# shell2-1.*: Misc. test of various tickets and reported errors.
+#
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+if {$tcl_platform(platform)=="windows"} {
+ set CLI "sqlite3.exe"
+} else {
+ set CLI "./sqlite3"
+}
+if {![file executable $CLI]} {
+ finish_test
+ return
+}
+db close
+forcedelete test.db test.db-journal test.db-wal
+sqlite3 db test.db
+
+
+#----------------------------------------------------------------------------
+# shell2-1.*: Misc. test of various tickets and reported errors.
+#
+
+# Batch mode not creating databases.
+# Reported on mailing list by Ken Zalewski.
+# Ticket [aeff892c57].
+do_test shell2-1.1.1 {
+ forcedelete foo.db
+ set rc [ catchcmd "-batch foo.db" "CREATE TABLE t1(a);" ]
+ set fexist [file exist foo.db]
+ list $rc $fexist
+} {{0 {}} 1}
+
+# Shell silently ignores extra parameters.
+# Ticket [f5cb008a65].
+do_test shell2-1.2.1 {
+ set rc [catch { eval exec $CLI \":memory:\" \"select 3\" \"select 4\" } msg]
+ list $rc \
+ [regexp {Error: too many options: "select 4"} $msg]
+} {1 1}
+
+# Test a problem reported on the mailing list. The shell was at one point
+# returning the generic SQLITE_ERROR message ("SQL error or missing database")
+# instead of the "too many levels..." message in the test below.
+#
+do_test shell2-1.3 {
+ catchcmd "-batch test.db" {
+ PRAGMA recursive_triggers = ON;
+ CREATE TABLE t5(a PRIMARY KEY, b, c);
+ INSERT INTO t5 VALUES(1, 2, 3);
+ CREATE TRIGGER au_tble AFTER UPDATE ON t5 BEGIN
+ UPDATE OR IGNORE t5 SET a = new.a, c = 10;
+ END;
+
+ UPDATE OR REPLACE t5 SET a = 4 WHERE a = 1;
+ }
+} {1 {Error: near line 9: too many levels of trigger recursion}}
+
+
+
+# Shell not echoing all commands with echo on.
+# Ticket [eb620916be].
+
+# Test with echo off
+# NB. whitespace is important
+do_test shell2-1.4.1 {
+ forcedelete foo.db
+ catchcmd "foo.db" {CREATE TABLE foo(a);
+INSERT INTO foo(a) VALUES(1);
+SELECT * FROM foo;}
+} {0 1}
+
+# Test with echo on using command line option
+# NB. whitespace is important
+do_test shell2-1.4.2 {
+ forcedelete foo.db
+ catchcmd "-echo foo.db" {CREATE TABLE foo(a);
+INSERT INTO foo(a) VALUES(1);
+SELECT * FROM foo;}
+} {0 {CREATE TABLE foo(a);
+INSERT INTO foo(a) VALUES(1);
+SELECT * FROM foo;
+1}}
+
+# Test with echo on using dot command
+# NB. whitespace is important
+do_test shell2-1.4.3 {
+ forcedelete foo.db
+ catchcmd "foo.db" {.echo ON
+CREATE TABLE foo(a);
+INSERT INTO foo(a) VALUES(1);
+SELECT * FROM foo;}
+} {0 {CREATE TABLE foo(a);
+INSERT INTO foo(a) VALUES(1);
+SELECT * FROM foo;
+1}}
+
+# Test with echo on using dot command and
+# turning off mid- processing.
+# NB. whitespace is important
+do_test shell2-1.4.4 {
+ forcedelete foo.db
+ catchcmd "foo.db" {.echo ON
+CREATE TABLE foo(a);
+.echo OFF
+INSERT INTO foo(a) VALUES(1);
+SELECT * FROM foo;}
+} {0 {CREATE TABLE foo(a);
+.echo OFF
+1}}
+
+# Test with echo on using dot command and
+# multiple commands per line.
+# NB. whitespace is important
+do_test shell2-1.4.5 {
+ forcedelete foo.db
+ catchcmd "foo.db" {.echo ON
+CREATE TABLE foo1(a);
+INSERT INTO foo1(a) VALUES(1);
+CREATE TABLE foo2(b);
+INSERT INTO foo2(b) VALUES(1);
+SELECT * FROM foo1; SELECT * FROM foo2;
+INSERT INTO foo1(a) VALUES(2); INSERT INTO foo2(b) VALUES(2);
+SELECT * FROM foo1; SELECT * FROM foo2;
+}
+} {0 {CREATE TABLE foo1(a);
+INSERT INTO foo1(a) VALUES(1);
+CREATE TABLE foo2(b);
+INSERT INTO foo2(b) VALUES(1);
+SELECT * FROM foo1;
+1
+SELECT * FROM foo2;
+1
+INSERT INTO foo1(a) VALUES(2);
+INSERT INTO foo2(b) VALUES(2);
+SELECT * FROM foo1;
+1
+2
+SELECT * FROM foo2;
+1
+2
+}}
+
+# Test with echo on and headers on using dot command and
+# multiple commands per line.
+# NB. whitespace is important
+do_test shell2-1.4.6 {
+ forcedelete foo.db
+ catchcmd "foo.db" {.echo ON
+.headers ON
+CREATE TABLE foo1(a);
+INSERT INTO foo1(a) VALUES(1);
+CREATE TABLE foo2(b);
+INSERT INTO foo2(b) VALUES(1);
+SELECT * FROM foo1; SELECT * FROM foo2;
+INSERT INTO foo1(a) VALUES(2); INSERT INTO foo2(b) VALUES(2);
+SELECT * FROM foo1; SELECT * FROM foo2;
+}
+} {0 {.headers ON
+CREATE TABLE foo1(a);
+INSERT INTO foo1(a) VALUES(1);
+CREATE TABLE foo2(b);
+INSERT INTO foo2(b) VALUES(1);
+SELECT * FROM foo1;
+a
+1
+SELECT * FROM foo2;
+b
+1
+INSERT INTO foo1(a) VALUES(2);
+INSERT INTO foo2(b) VALUES(2);
+SELECT * FROM foo1;
+a
+1
+2
+SELECT * FROM foo2;
+b
+1
+2
+}}
+
+finish_test
diff --git a/lang/sql/sqlite/test/shell3.test b/lang/sql/sqlite/test/shell3.test
new file mode 100644
index 00000000..ce1fd4ec
--- /dev/null
+++ b/lang/sql/sqlite/test/shell3.test
@@ -0,0 +1,97 @@
+# 2009 Dec 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.
+#
+#***********************************************************************
+#
+# The focus of this file is testing the CLI shell tool.
+#
+# $Id: shell2.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $
+#
+
+# Test plan:
+#
+# shell3-1.*: Basic tests for running SQL statments from command line.
+# shell3-2.*: Basic tests for running SQL file from command line.
+#
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+if {$tcl_platform(platform)=="windows"} {
+ set CLI "sqlite3.exe"
+} else {
+ set CLI "./sqlite3"
+}
+if {![file executable $CLI]} {
+ finish_test
+ return
+}
+db close
+forcedelete test.db test.db-journal test.db-wal
+sqlite3 db test.db
+
+#----------------------------------------------------------------------------
+# shell3-1.*: Basic tests for running SQL statments from command line.
+#
+
+# Run SQL statement from command line
+do_test shell3-1.1 {
+ forcedelete foo.db
+ set rc [ catchcmd "foo.db \"CREATE TABLE t1(a);\"" ]
+ set fexist [file exist foo.db]
+ list $rc $fexist
+} {{0 {}} 1}
+do_test shell3-1.2 {
+ catchcmd "foo.db" ".tables"
+} {0 t1}
+do_test shell3-1.3 {
+ catchcmd "foo.db \"DROP TABLE t1;\""
+} {0 {}}
+do_test shell3-1.4 {
+ catchcmd "foo.db" ".tables"
+} {0 {}}
+do_test shell3-1.5 {
+ catchcmd "foo.db \"CREATE TABLE t1(a); DROP TABLE t1;\""
+} {0 {}}
+do_test shell3-1.6 {
+ catchcmd "foo.db" ".tables"
+} {0 {}}
+do_test shell3-1.7 {
+ catchcmd "foo.db \"CREATE TABLE\""
+} {1 {Error: near "TABLE": syntax error}}
+
+#----------------------------------------------------------------------------
+# shell3-2.*: Basic tests for running SQL file from command line.
+#
+
+# Run SQL file from command line
+do_test shell3-2.1 {
+ forcedelete foo.db
+ set rc [ catchcmd "foo.db" "CREATE TABLE t1(a);" ]
+ set fexist [file exist foo.db]
+ list $rc $fexist
+} {{0 {}} 1}
+do_test shell3-2.2 {
+ catchcmd "foo.db" ".tables"
+} {0 t1}
+do_test shell3-2.3 {
+ catchcmd "foo.db" "DROP TABLE t1;"
+} {0 {}}
+do_test shell3-2.4 {
+ catchcmd "foo.db" ".tables"
+} {0 {}}
+do_test shell3-2.5 {
+ catchcmd "foo.db" "CREATE TABLE t1(a); DROP TABLE t1;"
+} {0 {}}
+do_test shell3-2.6 {
+ catchcmd "foo.db" ".tables"
+} {0 {}}
+do_test shell3-2.7 {
+ catchcmd "foo.db" "CREATE TABLE"
+} {1 {Error: incomplete SQL: CREATE TABLE}}
+
+finish_test
diff --git a/lang/sql/sqlite/test/shell4.test b/lang/sql/sqlite/test/shell4.test
new file mode 100644
index 00000000..5af44c8f
--- /dev/null
+++ b/lang/sql/sqlite/test/shell4.test
@@ -0,0 +1,116 @@
+# 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.
+#
+#***********************************************************************
+#
+# The focus of this file is testing the CLI shell tool.
+# These tests are specific to the .stats command.
+#
+# $Id: shell4.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $
+#
+
+# Test plan:
+#
+# shell4-1.*: Basic tests specific to the "stats" command.
+#
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+if {$tcl_platform(platform)=="windows"} {
+ set CLI "sqlite3.exe"
+} else {
+ set CLI "./sqlite3"
+}
+if {![file executable $CLI]} {
+ finish_test
+ return
+}
+db close
+forcedelete test.db test.db-journal test.db-wal
+sqlite3 db test.db
+
+#----------------------------------------------------------------------------
+# Test cases shell4-1.*: Tests specific to the "stats" command.
+#
+
+# should default to off
+do_test shell4-1.1.1 {
+ set res [catchcmd "test.db" ".show"]
+ list [regexp {stats: off} $res]
+} {1}
+
+do_test shell4-1.1.2 {
+ set res [catchcmd "test.db" ".show"]
+ list [regexp {stats: on} $res]
+} {0}
+
+# -stats should turn it on
+do_test shell4-1.2.1 {
+ set res [catchcmd "-stats test.db" ".show"]
+ list [regexp {stats: on} $res]
+} {1}
+
+do_test shell4-1.2.2 {
+ set res [catchcmd "-stats test.db" ".show"]
+ list [regexp {stats: off} $res]
+} {0}
+
+# .stats ON|OFF Turn stats on or off
+do_test shell4-1.3.1 {
+ catchcmd "test.db" ".stats"
+} {1 {Error: unknown command or invalid arguments: "stats". Enter ".help" for help}}
+do_test shell4-1.3.2 {
+ catchcmd "test.db" ".stats ON"
+} {0 {}}
+do_test shell4-1.3.3 {
+ catchcmd "test.db" ".stats OFF"
+} {0 {}}
+do_test shell4-1.3.4 {
+ # too many arguments
+ catchcmd "test.db" ".stats OFF BAD"
+} {1 {Error: unknown command or invalid arguments: "stats". Enter ".help" for help}}
+
+# NB. whitespace is important
+do_test shell4-1.4.1 {
+ set res [catchcmd "test.db" {.show}]
+ list [regexp {stats: off} $res]
+} {1}
+
+do_test shell4-1.4.2 {
+ set res [catchcmd "test.db" {.stats ON
+.show
+}]
+ list [regexp {stats: on} $res]
+} {1}
+
+do_test shell4-1.4.3 {
+ set res [catchcmd "test.db" {.stats OFF
+.show
+}]
+ list [regexp {stats: off} $res]
+} {1}
+
+# make sure stats not present when off
+do_test shell4-1.5.1 {
+ set res [catchcmd "test.db" {SELECT 1;}]
+ list [regexp {Memory Used} $res] \
+ [regexp {Heap Usage} $res] \
+ [regexp {Autoindex Inserts} $res]
+} {0 0 0}
+
+# make sure stats are present when on
+do_test shell4-1.5.2 {
+ set res [catchcmd "test.db" {.stats ON
+SELECT 1;
+}]
+ list [regexp {Memory Used} $res] \
+ [regexp {Heap Usage} $res] \
+ [regexp {Autoindex Inserts} $res]
+} {1 1 1}
+
+finish_test
diff --git a/lang/sql/sqlite/test/shell5.test b/lang/sql/sqlite/test/shell5.test
new file mode 100644
index 00000000..ce05a303
--- /dev/null
+++ b/lang/sql/sqlite/test/shell5.test
@@ -0,0 +1,290 @@
+# 2010 August 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 this file is testing the CLI shell tool.
+# These tests are specific to the .import command.
+#
+# $Id: shell5.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $
+#
+
+# Test plan:
+#
+# shell5-1.*: Basic tests specific to the ".import" command.
+#
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+if {$tcl_platform(platform)=="windows"} {
+ set CLI "sqlite3.exe"
+} else {
+ set CLI "./sqlite3"
+}
+if {![file executable $CLI]} {
+ finish_test
+ return
+}
+db close
+forcedelete test.db test.db-journal test.db-wal
+
+#----------------------------------------------------------------------------
+# Test cases shell5-1.*: Basic handling of the .import and .separator commands.
+#
+
+# .import FILE TABLE Import data from FILE into TABLE
+do_test shell5-1.1.1 {
+ catchcmd "test.db" ".import"
+} {1 {Error: unknown command or invalid arguments: "import". Enter ".help" for help}}
+do_test shell5-1.1.2 {
+ catchcmd "test.db" ".import FOO"
+} {1 {Error: unknown command or invalid arguments: "import". Enter ".help" for help}}
+#do_test shell5-1.1.2 {
+# catchcmd "test.db" ".import FOO BAR"
+#} {1 {Error: no such table: BAR}}
+do_test shell5-1.1.3 {
+ # too many arguments
+ catchcmd "test.db" ".import FOO BAR BAD"
+} {1 {Error: unknown command or invalid arguments: "import". Enter ".help" for help}}
+
+# .separator STRING Change separator used by output mode and .import
+do_test shell1-1.2.1 {
+ catchcmd "test.db" ".separator"
+} {1 {Error: unknown command or invalid arguments: "separator". Enter ".help" for help}}
+do_test shell1-1.2.2 {
+ catchcmd "test.db" ".separator FOO"
+} {0 {}}
+do_test shell1-1.2.3 {
+ # too many arguments
+ catchcmd "test.db" ".separator FOO BAD"
+} {1 {Error: unknown command or invalid arguments: "separator". Enter ".help" for help}}
+
+# separator should default to "|"
+do_test shell5-1.3.1 {
+ set res [catchcmd "test.db" ".show"]
+ list [regexp {separator: \"\|\"} $res]
+} {1}
+
+# set separator to different value.
+# check that .show reports new value
+do_test shell5-1.3.2 {
+ set res [catchcmd "test.db" {.separator ,
+.show}]
+ list [regexp {separator: \",\"} $res]
+} {1}
+
+# import file doesn't exist
+do_test shell5-1.4.1 {
+ forcedelete FOO
+ set res [catchcmd "test.db" {CREATE TABLE t1(a, b);
+.import FOO t1}]
+} {1 {Error: cannot open "FOO"}}
+
+# empty import file
+do_test shell5-1.4.2 {
+ forcedelete shell5.csv
+ set in [open shell5.csv w]
+ close $in
+ set res [catchcmd "test.db" {.import shell5.csv t1
+SELECT COUNT(*) FROM t1;}]
+} {0 0}
+
+# import file with 1 row, 1 column (expecting 2 cols)
+do_test shell5-1.4.3 {
+ set in [open shell5.csv w]
+ puts $in "1"
+ close $in
+ set res [catchcmd "test.db" {.import shell5.csv t1}]
+} {1 {shell5.csv:1: expected 2 columns but found 1 - filling the rest with NULL}}
+
+# import file with 1 row, 3 columns (expecting 2 cols)
+do_test shell5-1.4.4 {
+ set in [open shell5.csv w]
+ puts $in "1|2|3"
+ close $in
+ set res [catchcmd "test.db" {.import shell5.csv t1}]
+} {1 {shell5.csv:1: expected 2 columns but found 3 - extras ignored}}
+
+# import file with 1 row, 2 columns
+do_test shell5-1.4.5 {
+ set in [open shell5.csv w]
+ puts $in "1|2"
+ close $in
+ set res [catchcmd "test.db" {DELETE FROM t1;
+.import shell5.csv t1
+SELECT COUNT(*) FROM t1;}]
+} {0 1}
+
+# import file with 2 rows, 2 columns
+# note we end up with 3 rows because of the 1 row
+# imported above.
+do_test shell5-1.4.6 {
+ set in [open shell5.csv w]
+ puts $in "2|3"
+ puts $in "3|4"
+ close $in
+ set res [catchcmd "test.db" {.import shell5.csv t1
+SELECT COUNT(*) FROM t1;}]
+} {0 3}
+
+# import file with 1 row, 2 columns, using a comma
+do_test shell5-1.4.7 {
+ set in [open shell5.csv w]
+ puts $in "4,5"
+ close $in
+ set res [catchcmd "test.db" {.separator ,
+.import shell5.csv t1
+SELECT COUNT(*) FROM t1;}]
+} {0 4}
+
+# import file with 1 row, 2 columns, text data
+do_test shell5-1.4.8.1 {
+ set in [open shell5.csv w]
+ puts $in "5|Now is the time for all good men to come to the aid of their country."
+ close $in
+ set res [catchcmd "test.db" {.import shell5.csv t1
+SELECT COUNT(*) FROM t1;}]
+} {0 5}
+
+do_test shell5-1.4.8.2 {
+ catchcmd "test.db" {SELECT b FROM t1 WHERE a='5';}
+} {0 {Now is the time for all good men to come to the aid of their country.}}
+
+# import file with 1 row, 2 columns, quoted text data
+# note that currently sqlite doesn't support quoted fields, and
+# imports the entire field, quotes and all.
+do_test shell5-1.4.9.1 {
+ set in [open shell5.csv w]
+ puts $in "6|'Now is the time for all good men to come to the aid of their country.'"
+ close $in
+ set res [catchcmd "test.db" {.import shell5.csv t1
+SELECT COUNT(*) FROM t1;}]
+} {0 6}
+
+do_test shell5-1.4.9.2 {
+ catchcmd "test.db" {SELECT b FROM t1 WHERE a='6';}
+} {0 {'Now is the time for all good men to come to the aid of their country.'}}
+
+# import file with 1 row, 2 columns, quoted text data
+do_test shell5-1.4.10.1 {
+ set in [open shell5.csv w]
+ puts $in "7|\"Now is the time for all good men to come to the aid of their country.\""
+ close $in
+ set res [catchcmd "test.db" {.import shell5.csv t1
+SELECT COUNT(*) FROM t1;}]
+} {0 7}
+
+do_test shell5-1.4.10.2 {
+ catchcmd "test.db" {SELECT b FROM t1 WHERE a='7';}
+} {0 {Now is the time for all good men to come to the aid of their country.}}
+
+# check importing very long field
+do_test shell5-1.5.1 {
+ set str [string repeat X 999]
+ set in [open shell5.csv w]
+ puts $in "8|$str"
+ close $in
+ set res [catchcmd "test.db" {.import shell5.csv t1
+SELECT length(b) FROM t1 WHERE a='8';}]
+} {0 999}
+
+# try importing into a table with a large number of columns.
+# This is limited by SQLITE_MAX_VARIABLE_NUMBER, which defaults to 999.
+set cols 999
+do_test shell5-1.6.1 {
+ set data {}
+ for {set i 1} {$i<$cols} {incr i} {
+ append data "c$i|"
+ }
+ append data "c$cols\n";
+ for {set i 1} {$i<$cols} {incr i} {
+ append data "$i|"
+ }
+ append data "$cols"
+ set in [open shell5.csv w]
+ puts $in $data
+ close $in
+ set res [catchcmd "test.db" {.import shell5.csv t2
+SELECT COUNT(*) FROM t2;}]
+} {0 1}
+
+# try importing a large number of rows
+set rows 9999
+do_test shell5-1.7.1 {
+ set in [open shell5.csv w]
+ puts $in a
+ for {set i 1} {$i<=$rows} {incr i} {
+ puts $in $i
+ }
+ close $in
+ set res [catchcmd "test.db" {.mode csv
+.import shell5.csv t3
+SELECT COUNT(*) FROM t3;}]
+} [list 0 $rows]
+
+# Inport from a pipe. (Unix only, as it requires "awk")
+if {$tcl_platform(platform)=="unix"} {
+ do_test shell5-1.8 {
+ forcedelete test.db
+ catchcmd test.db {.mode csv
+.import "|awk 'END{print \"x,y\";for(i=1;i<=5;i++){print i \",this is \" i}}'" t1
+SELECT * FROM t1;}
+ } {0 {1,"this is 1"
+2,"this is 2"
+3,"this is 3"
+4,"this is 4"
+5,"this is 5"}}
+}
+
+# Import columns containing quoted strings
+do_test shell5-1.9 {
+ set out [open shell5.csv w]
+ fconfigure $out -translation lf
+ puts $out {1,"",11}
+ puts $out {2,"x",22}
+ puts $out {3,"""",33}
+ puts $out {4,"hello",44}
+ puts $out "5,55,\"\"\r"
+ puts $out {6,66,"x"}
+ puts $out {7,77,""""}
+ puts $out {8,88,"hello"}
+ puts $out {"",9,99}
+ puts $out {"x",10,110}
+ puts $out {"""",11,121}
+ puts $out {"hello",12,132}
+ close $out
+ forcedelete test.db
+ catchcmd test.db {.mode csv
+ CREATE TABLE t1(a,b,c);
+.import shell5.csv t1
+ }
+ sqlite3 db test.db
+ db eval {SELECT *, '|' FROM t1 ORDER BY rowid}
+} {1 {} 11 | 2 x 22 | 3 {"} 33 | 4 hello 44 | 5 55 {} | 6 66 x | 7 77 {"} | 8 88 hello | {} 9 99 | x 10 110 | {"} 11 121 | hello 12 132 |}
+db close
+
+# Import columns containing quoted strings
+do_test shell5-1.10 {
+ set out [open shell5.csv w]
+ fconfigure $out -translation lf
+ puts $out {column1,column2,column3,column4}
+ puts $out "field1,field2,\"x3 \"\"\r\ndata\"\" 3\",field4"
+ puts $out "x1,x2,\"x3 \"\"\ndata\"\" 3\",x4"
+ close $out
+ forcedelete test.db
+ catchcmd test.db {.mode csv
+ CREATE TABLE t1(a,b,c,d);
+.import shell5.csv t1
+ }
+ sqlite3 db test.db
+ db eval {SELECT hex(c) FROM t1 ORDER BY rowid}
+} {636F6C756D6E33 783320220D0A64617461222033 783320220A64617461222033}
+
+db close
+
+finish_test
diff --git a/lang/sql/sqlite/test/shrink.test b/lang/sql/sqlite/test/shrink.test
new file mode 100644
index 00000000..e03ebeeb
--- /dev/null
+++ b/lang/sql/sqlite/test/shrink.test
@@ -0,0 +1,43 @@
+# 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_release_memory and
+# the PRAGMA shrink_memory statement.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+unset -nocomplain baseline
+do_test shrink-1.1 {
+ db eval {
+ PRAGMA cache_size = 2000;
+ CREATE TABLE t1(x,y);
+ INSERT INTO t1 VALUES(randomblob(1000000),1);
+ }
+ set ::baseline sqlite3_memory_used
+ sqlite3_db_release_memory db
+ expr {$::baseline > [sqlite3_memory_used]+500000}
+} {1}
+do_test shrink-1.2 {
+ set baseline [sqlite3_memory_used]
+ db eval {
+ UPDATE t1 SET y=y+1;
+ }
+ expr {$::baseline+500000 < [sqlite3_memory_used]}
+} {1}
+do_test shrink-1.3 {
+ set baseline [sqlite3_memory_used]
+ db eval {PRAGMA shrink_memory}
+ expr {$::baseline > [sqlite3_memory_used]+500000}
+} {1}
+
+finish_test
diff --git a/lang/sql/sqlite/test/skipscan1.test b/lang/sql/sqlite/test/skipscan1.test
new file mode 100644
index 00000000..b9eaf272
--- /dev/null
+++ b/lang/sql/sqlite/test/skipscan1.test
@@ -0,0 +1,212 @@
+# 2013-11-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 of the "skip-scan" query strategy.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+do_execsql_test skipscan1-1.1 {
+ CREATE TABLE t1(a TEXT, b INT, c INT, d INT);
+ CREATE INDEX t1abc ON t1(a,b,c);
+ INSERT INTO t1 VALUES('abc',123,4,5);
+ INSERT INTO t1 VALUES('abc',234,5,6);
+ INSERT INTO t1 VALUES('abc',234,6,7);
+ INSERT INTO t1 VALUES('abc',345,7,8);
+ INSERT INTO t1 VALUES('def',567,8,9);
+ INSERT INTO t1 VALUES('def',345,9,10);
+ INSERT INTO t1 VALUES('bcd',100,6,11);
+
+ /* Fake the sqlite_stat1 table so that the query planner believes
+ ** the table contains thousands of rows and that the first few
+ ** columns are not selective. */
+ ANALYZE;
+ DELETE FROM sqlite_stat1;
+ INSERT INTO sqlite_stat1 VALUES('t1','t1abc','10000 5000 2000 10');
+ ANALYZE sqlite_master;
+} {}
+
+# Simple queries that leave the first one or two columns of the
+# index unconstrainted.
+#
+do_execsql_test skipscan1-1.2 {
+ SELECT a,b,c,d,'|' FROM t1 WHERE b=345 ORDER BY a;
+} {abc 345 7 8 | def 345 9 10 |}
+do_execsql_test skipscan1-1.2eqp {
+ EXPLAIN QUERY PLAN
+ SELECT a,b,c,d,'|' FROM t1 WHERE b=345 ORDER BY a;
+} {/* USING INDEX t1abc (ANY(a) AND b=?)*/}
+do_execsql_test skipscan1-1.2sort {
+ EXPLAIN QUERY PLAN
+ SELECT a,b,c,d,'|' FROM t1 WHERE b=345 ORDER BY a;
+} {~/*ORDER BY*/}
+
+do_execsql_test skipscan1-1.3 {
+ SELECT a,b,c,d,'|' FROM t1 WHERE b=345 ORDER BY a DESC;
+} {def 345 9 10 | abc 345 7 8 |}
+do_execsql_test skipscan1-1.3eqp {
+ EXPLAIN QUERY PLAN
+ SELECT a,b,c,d,'|' FROM t1 WHERE b=345 ORDER BY a;
+} {/* USING INDEX t1abc (ANY(a) AND b=?)*/}
+do_execsql_test skipscan1-1.3sort {
+ EXPLAIN QUERY PLAN
+ SELECT a,b,c,d,'|' FROM t1 WHERE b=345 ORDER BY a;
+} {~/*ORDER BY*/}
+
+do_execsql_test skipscan1-1.4 {
+ SELECT a,b,c,d,'|' FROM t1 WHERE c=6 ORDER BY a, b, c;
+} {abc 234 6 7 | bcd 100 6 11 |}
+do_execsql_test skipscan1-1.4eqp {
+ EXPLAIN QUERY PLAN
+ SELECT a,b,c,d,'|' FROM t1 WHERE c=6 ORDER BY a, b, c;
+} {/* USING INDEX t1abc (ANY(a) AND ANY(b) AND c=?)*/}
+do_execsql_test skipscan1-1.4sort {
+ EXPLAIN QUERY PLAN
+ SELECT a,b,c,d,'|' FROM t1 WHERE c=6 ORDER BY a, b, c;
+} {~/*ORDER BY*/}
+
+do_execsql_test skipscan1-1.5 {
+ SELECT a,b,c,d,'|' FROM t1 WHERE c IN (6,7) ORDER BY a, b, c;
+} {abc 234 6 7 | abc 345 7 8 | bcd 100 6 11 |}
+do_execsql_test skipscan1-1.5eqp {
+ EXPLAIN QUERY PLAN
+ SELECT a,b,c,d,'|' FROM t1 WHERE c IN (6,7) ORDER BY a, b, c;
+} {/* USING INDEX t1abc (ANY(a) AND ANY(b) AND c=?)*/}
+do_execsql_test skipscan1-1.5sort {
+ EXPLAIN QUERY PLAN
+ SELECT a,b,c,d,'|' FROM t1 WHERE c IN (6,7) ORDER BY a, b, c;
+} {~/*ORDER BY*/}
+
+do_execsql_test skipscan1-1.6 {
+ SELECT a,b,c,d,'|' FROM t1 WHERE c BETWEEN 6 AND 7 ORDER BY a, b, c;
+} {abc 234 6 7 | abc 345 7 8 | bcd 100 6 11 |}
+do_execsql_test skipscan1-1.6eqp {
+ EXPLAIN QUERY PLAN
+ SELECT a,b,c,d,'|' FROM t1 WHERE c BETWEEN 6 AND 7 ORDER BY a, b, c;
+} {/* USING INDEX t1abc (ANY(a) AND ANY(b) AND c>? AND c<?)*/}
+do_execsql_test skipscan1-1.6sort {
+ EXPLAIN QUERY PLAN
+ SELECT a,b,c,d,'|' FROM t1 WHERE c BETWEEN 6 AND 7 ORDER BY a, b, c;
+} {~/*ORDER BY*/}
+
+do_execsql_test skipscan1-1.7 {
+ SELECT a,b,c,d,'|' FROM t1 WHERE b IN (234, 345) AND c BETWEEN 6 AND 7
+ ORDER BY a, b;
+} {abc 234 6 7 | abc 345 7 8 |}
+do_execsql_test skipscan1-1.7eqp {
+ EXPLAIN QUERY PLAN
+ SELECT a,b,c,d,'|' FROM t1 WHERE b IN (234, 345) AND c BETWEEN 6 AND 7
+ ORDER BY a, b;
+} {/* USING INDEX t1abc (ANY(a) AND b=? AND c>? AND c<?)*/}
+do_execsql_test skipscan1-1.7sort {
+ EXPLAIN QUERY PLAN
+ SELECT a,b,c,d,'|' FROM t1 WHERE b IN (234, 345) AND c BETWEEN 6 AND 7
+ ORDER BY a, b;
+} {~/*ORDER BY*/}
+
+
+# Joins
+#
+do_execsql_test skipscan1-1.51 {
+ CREATE TABLE t1j(x TEXT, y INTEGER);
+ INSERT INTO t1j VALUES('one',1),('six',6),('ninty-nine',99);
+ INSERT INTO sqlite_stat1 VALUES('t1j',null,'3');
+ ANALYZE sqlite_master;
+ SELECT x, a, b, c, d, '|' FROM t1j, t1 WHERE c=y ORDER BY +a;
+} {six abc 234 6 7 | six bcd 100 6 11 |}
+do_execsql_test skipscan1-1.51eqp {
+ EXPLAIN QUERY PLAN
+ SELECT x, a, b, c, d, '|' FROM t1j, t1 WHERE c=y ORDER BY +a;
+} {/* INDEX t1abc (ANY(a) AND ANY(b) AND c=?)*/}
+
+do_execsql_test skipscan1-1.52 {
+ SELECT x, a, b, c, d, '|' FROM t1j LEFT JOIN t1 ON c=y ORDER BY +y, +a;
+} {one {} {} {} {} | six abc 234 6 7 | six bcd 100 6 11 | ninty-nine {} {} {} {} |}
+do_execsql_test skipscan1-1.52eqp {
+ EXPLAIN QUERY PLAN
+ SELECT x, a, b, c, d, '|' FROM t1j LEFT JOIN t1 ON c=y ORDER BY +y, +a;
+} {/* INDEX t1abc (ANY(a) AND ANY(b) AND c=?)*/}
+
+do_execsql_test skipscan1-2.1 {
+ CREATE TABLE t2(a TEXT, b INT, c INT, d INT,
+ PRIMARY KEY(a,b,c));
+ INSERT INTO t2 SELECT * FROM t1;
+
+ /* Fake the sqlite_stat1 table so that the query planner believes
+ ** the table contains thousands of rows and that the first few
+ ** columns are not selective. */
+ ANALYZE;
+ UPDATE sqlite_stat1 SET stat='10000 5000 2000 10' WHERE idx NOT NULL;
+ ANALYZE sqlite_master;
+} {}
+
+do_execsql_test skipscan1-2.2 {
+ SELECT a,b,c,d,'|' FROM t2 WHERE b=345 ORDER BY a;
+} {abc 345 7 8 | def 345 9 10 |}
+do_execsql_test skipscan1-2.2eqp {
+ EXPLAIN QUERY PLAN
+ SELECT a,b,c,d,'|' FROM t2 WHERE b=345 ORDER BY a;
+} {/* USING INDEX sqlite_autoindex_t2_1 (ANY(a) AND b=?)*/}
+do_execsql_test skipscan1-2.2sort {
+ EXPLAIN QUERY PLAN
+ SELECT a,b,c,d,'|' FROM t2 WHERE b=345 ORDER BY a;
+} {~/*ORDER BY*/}
+
+
+do_execsql_test skipscan1-3.1 {
+ CREATE TABLE t3(a TEXT, b INT, c INT, d INT,
+ PRIMARY KEY(a,b,c)) WITHOUT ROWID;
+ INSERT INTO t3 SELECT * FROM t1;
+
+ /* Fake the sqlite_stat1 table so that the query planner believes
+ ** the table contains thousands of rows and that the first few
+ ** columns are not selective. */
+ ANALYZE;
+ UPDATE sqlite_stat1 SET stat='10000 5000 2000 10' WHERE idx NOT NULL;
+ ANALYZE sqlite_master;
+} {}
+
+do_execsql_test skipscan1-3.2 {
+ SELECT a,b,c,d,'|' FROM t3 WHERE b=345 ORDER BY a;
+} {abc 345 7 8 | def 345 9 10 |}
+do_execsql_test skipscan1-3.2eqp {
+ EXPLAIN QUERY PLAN
+ SELECT a,b,c,d,'|' FROM t3 WHERE b=345 ORDER BY a;
+} {/* INDEX sqlite_autoindex_t3_1 (ANY(a) AND b=?)*/}
+do_execsql_test skipscan1-3.2sort {
+ EXPLAIN QUERY PLAN
+ SELECT a,b,c,d,'|' FROM t3 WHERE b=345 ORDER BY a;
+} {~/*ORDER BY*/}
+
+# Ticket 520070ec7fbaac: Array overrun in the skip-scan optimization
+# 2013-12-22
+#
+do_execsql_test skipscan1-4.1 {
+ CREATE TABLE t4(a,b,c,d,e,f,g,h,i);
+ CREATE INDEX t4all ON t4(a,b,c,d,e,f,g,h);
+ INSERT INTO t4 VALUES(1,2,3,4,5,6,7,8,9);
+ ANALYZE;
+ DELETE FROM sqlite_stat1;
+ INSERT INTO sqlite_stat1
+ VALUES('t4','t4all','655360 163840 40960 10240 2560 640 160 40 10');
+ ANALYZE sqlite_master;
+ SELECT i FROM t4 WHERE a=1;
+ SELECT i FROM t4 WHERE b=2;
+ SELECT i FROM t4 WHERE c=3;
+ SELECT i FROM t4 WHERE d=4;
+ SELECT i FROM t4 WHERE e=5;
+ SELECT i FROM t4 WHERE f=6;
+ SELECT i FROM t4 WHERE g=7;
+ SELECT i FROM t4 WHERE h=8;
+} {9 9 9 9 9 9 9 9}
+
+finish_test
diff --git a/lang/sql/sqlite/test/skipscan2.test b/lang/sql/sqlite/test/skipscan2.test
new file mode 100644
index 00000000..e39b16ed
--- /dev/null
+++ b/lang/sql/sqlite/test/skipscan2.test
@@ -0,0 +1,190 @@
+# 2013-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 implements tests of the "skip-scan" query strategy.
+#
+# The test cases in this file are derived from the description of
+# the skip-scan query strategy in the "optoverview.html" document.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+do_execsql_test skipscan2-1.1 {
+ CREATE TABLE people(
+ name TEXT PRIMARY KEY,
+ role TEXT NOT NULL,
+ height INT NOT NULL, -- in cm
+ CHECK( role IN ('student','teacher') )
+ );
+ CREATE INDEX people_idx1 ON people(role, height);
+} {}
+do_execsql_test skipscan2-1.2 {
+ INSERT INTO people VALUES('Alice','student',156);
+ INSERT INTO people VALUES('Bob','student',161);
+ INSERT INTO people VALUES('Cindy','student',155);
+ INSERT INTO people VALUES('David','student',181);
+ INSERT INTO people VALUES('Emily','teacher',158);
+ INSERT INTO people VALUES('Fred','student',163);
+ INSERT INTO people VALUES('Ginny','student',169);
+ INSERT INTO people VALUES('Harold','student',172);
+ INSERT INTO people VALUES('Imma','student',179);
+ INSERT INTO people VALUES('Jack','student',181);
+ INSERT INTO people VALUES('Karen','student',163);
+ INSERT INTO people VALUES('Logan','student',177);
+ INSERT INTO people VALUES('Megan','teacher',159);
+ INSERT INTO people VALUES('Nathan','student',163);
+ INSERT INTO people VALUES('Olivia','student',161);
+ INSERT INTO people VALUES('Patrick','teacher',180);
+ INSERT INTO people VALUES('Quiana','student',182);
+ INSERT INTO people VALUES('Robert','student',159);
+ INSERT INTO people VALUES('Sally','student',166);
+ INSERT INTO people VALUES('Tom','student',171);
+ INSERT INTO people VALUES('Ursula','student',170);
+ INSERT INTO people VALUES('Vance','student',179);
+ INSERT INTO people VALUES('Willma','student',175);
+ INSERT INTO people VALUES('Xavier','teacher',185);
+ INSERT INTO people VALUES('Yvonne','student',149);
+ INSERT INTO people VALUES('Zach','student',170);
+}
+
+# Without ANALYZE, a skip-scan is not used
+#
+do_execsql_test skipscan2-1.3 {
+ SELECT name FROM people WHERE height>=180 ORDER BY +name;
+} {David Jack Patrick Quiana Xavier}
+do_execsql_test skipscan2-1.3eqp {
+ EXPLAIN QUERY PLAN
+ SELECT name FROM people WHERE height>=180 ORDER BY +name;
+} {~/*INDEX people_idx1 */}
+
+# Now do an ANALYZE. A skip-scan can be used after ANALYZE.
+#
+do_execsql_test skipscan2-1.4 {
+ ANALYZE;
+ -- We do not have enough people above to actually force the use
+ -- of a skip-scan. So make a manual adjustment to the stat1 table
+ -- to make it seem like there are many more.
+ UPDATE sqlite_stat1 SET stat='10000 5000 20' WHERE idx='people_idx1';
+ ANALYZE sqlite_master;
+}
+db cache flush
+do_execsql_test skipscan2-1.5 {
+ SELECT name FROM people WHERE height>=180 ORDER BY +name;
+} {David Jack Patrick Quiana Xavier}
+do_execsql_test skipscan2-1.5eqp {
+ EXPLAIN QUERY PLAN
+ SELECT name FROM people WHERE height>=180 ORDER BY +name;
+} {/*INDEX people_idx1 */}
+
+# Same answer with other formulations of the same query
+#
+do_execsql_test skipscan2-1.6 {
+ SELECT name FROM people
+ WHERE role IN (SELECT DISTINCT role FROM people)
+ AND height>=180 ORDER BY +name;
+} {David Jack Patrick Quiana Xavier}
+do_execsql_test skipscan2-1.7 {
+ SELECT name FROM people WHERE role='teacher' AND height>=180
+ UNION ALL
+ SELECT name FROM people WHERE role='student' AND height>=180
+ ORDER BY 1;
+} {David Jack Patrick Quiana Xavier}
+
+# Add 8 more people, bringing the total to 34. Then the number of
+# duplicates in the left-column of the index will be 17 and
+# skip-scan should not be used after an (unfudged) ANALYZE.
+#
+do_execsql_test skipscan2-1.8 {
+ INSERT INTO people VALUES('Angie','student',166);
+ INSERT INTO people VALUES('Brad','student',176);
+ INSERT INTO people VALUES('Claire','student',168);
+ INSERT INTO people VALUES('Donald','student',162);
+ INSERT INTO people VALUES('Elaine','student',177);
+ INSERT INTO people VALUES('Frazier','student',159);
+ INSERT INTO people VALUES('Grace','student',179);
+ INSERT INTO people VALUES('Horace','student',166);
+ ANALYZE;
+ SELECT stat FROM sqlite_stat1 WHERE idx='people_idx1';
+} {{34 17 2}}
+db cache flush
+do_execsql_test skipscan2-1.9 {
+ SELECT name FROM people WHERE height>=180 ORDER BY +name;
+} {David Jack Patrick Quiana Xavier}
+do_execsql_test skipscan2-1.9eqp {
+ EXPLAIN QUERY PLAN
+ SELECT name FROM people WHERE height>=180 ORDER BY +name;
+} {~/*INDEX people_idx1 */}
+
+# Add 2 more people, bringing the total to 36. Then the number of
+# duplicates in the left-column of the index will be 18 and
+# skip-scan will be used after an (unfudged) ANALYZE.
+#
+do_execsql_test skipscan2-1.10 {
+ INSERT INTO people VALUES('Ingrad','student',155);
+ INSERT INTO people VALUES('Jacob','student',179);
+ ANALYZE;
+ SELECT stat FROM sqlite_stat1 WHERE idx='people_idx1';
+} {{36 18 2}}
+db cache flush
+do_execsql_test skipscan2-1.11 {
+ SELECT name FROM people WHERE height>=180 ORDER BY +name;
+} {David Jack Patrick Quiana Xavier}
+do_execsql_test skipscan2-1.11eqp {
+ EXPLAIN QUERY PLAN
+ SELECT name FROM people WHERE height>=180 ORDER BY +name;
+} {/*INDEX people_idx1 */}
+
+
+# Repeat using a WITHOUT ROWID table.
+#
+do_execsql_test skipscan2-2.1 {
+ CREATE TABLE peoplew(
+ name TEXT PRIMARY KEY,
+ role TEXT NOT NULL,
+ height INT NOT NULL, -- in cm
+ CHECK( role IN ('student','teacher') )
+ ) WITHOUT ROWID;
+ CREATE INDEX peoplew_idx1 ON peoplew(role, height);
+ INSERT INTO peoplew(name,role,height)
+ SELECT name, role, height FROM people;
+ ALTER TABLE people RENAME TO old_people;
+ SELECT name FROM peoplew WHERE height>=180 ORDER BY +name;
+} {David Jack Patrick Quiana Xavier}
+do_execsql_test skipscan2-2.2 {
+ SELECT name FROM peoplew
+ WHERE role IN (SELECT DISTINCT role FROM peoplew)
+ AND height>=180 ORDER BY +name;
+} {David Jack Patrick Quiana Xavier}
+do_execsql_test skipscan2-2.2 {
+ SELECT name FROM peoplew WHERE role='teacher' AND height>=180
+ UNION ALL
+ SELECT name FROM peoplew WHERE role='student' AND height>=180
+ ORDER BY 1;
+} {David Jack Patrick Quiana Xavier}
+
+# Now do an ANALYZE. A skip-scan can be used after ANALYZE.
+#
+do_execsql_test skipscan2-2.4 {
+ ANALYZE;
+}
+db cache flush
+do_execsql_test skipscan2-2.5 {
+ SELECT name FROM peoplew WHERE height>=180 ORDER BY +name;
+} {David Jack Patrick Quiana Xavier}
+do_execsql_test skipscan2-2.5eqp {
+ EXPLAIN QUERY PLAN
+ SELECT name FROM peoplew WHERE height>=180 ORDER BY +name;
+} {/*INDEX peoplew_idx1 */}
+
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/softheap1.test b/lang/sql/sqlite/test/softheap1.test
index 68555536..522e455e 100644
--- a/lang/sql/sqlite/test/softheap1.test
+++ b/lang/sql/sqlite/test/softheap1.test
@@ -24,10 +24,27 @@ ifcapable !integrityck {
return
}
-sqlite3_soft_heap_limit -1
-sqlite3_soft_heap_limit 0
-sqlite3_soft_heap_limit 5000
+do_test softheap1-1.0 {
+ execsql {PRAGMA soft_heap_limit}
+} [sqlite3_soft_heap_limit -1]
do_test softheap1-1.1 {
+ execsql {PRAGMA soft_heap_limit=123456; PRAGMA soft_heap_limit;}
+} {123456 123456}
+do_test softheap1-1.2 {
+ sqlite3_soft_heap_limit -1
+} {123456}
+do_test softheap1-1.3 {
+ execsql {PRAGMA soft_heap_limit(-1); PRAGMA soft_heap_limit;}
+} {123456 123456}
+do_test softheap1-1.4 {
+ execsql {PRAGMA soft_heap_limit(0); PRAGMA soft_heap_limit;}
+} {0 0}
+
+sqlite3_soft_heap_limit 5000
+do_test softheap1-2.0 {
+ execsql {PRAGMA soft_heap_limit}
+} {5000}
+do_test softheap1-2.1 {
execsql {
PRAGMA auto_vacuum=1;
CREATE TABLE t1(x);
diff --git a/lang/sql/sqlite/test/speed1p.test b/lang/sql/sqlite/test/speed1p.test
index 915f1653..6bf7b10e 100644
--- a/lang/sql/sqlite/test/speed1p.test
+++ b/lang/sql/sqlite/test/speed1p.test
@@ -24,6 +24,8 @@ set testdir [file dirname $argv0]
source $testdir/tester.tcl
speed_trial_init speed1
+sqlite3_memdebug_vfs_oom_test 0
+
# Set a uniform random seed
expr srand(0)
@@ -78,7 +80,6 @@ do_test speed1p-1.0 {
}
} {i2a i2b t1 t2}
-
# 50000 INSERTs on an unindexed table
#
set list {}
diff --git a/lang/sql/sqlite/test/speed3.test b/lang/sql/sqlite/test/speed3.test
index a99a6245..1beaeb74 100644
--- a/lang/sql/sqlite/test/speed3.test
+++ b/lang/sql/sqlite/test/speed3.test
@@ -116,7 +116,7 @@ proc reset_db {} {
}
}
-file delete -force test2.db test2.db-journal
+forcedelete test2.db test2.db-journal
reset_db
# Set up a database in auto-vacuum mode and create a database schema.
diff --git a/lang/sql/sqlite/test/speedtest1.c b/lang/sql/sqlite/test/speedtest1.c
new file mode 100644
index 00000000..38f891e4
--- /dev/null
+++ b/lang/sql/sqlite/test/speedtest1.c
@@ -0,0 +1,1011 @@
+/*
+** A program for performance testing.
+**
+** The available command-line options are described below:
+*/
+static const char zHelp[] =
+ "Usage: %s [--options] DATABASE\n"
+ "Options:\n"
+ " --autovacuum Enable AUTOVACUUM mode\n"
+ " --cachesize N Set the cache size to N\n"
+ " --exclusive Enable locking_mode=EXCLUSIVE\n"
+ " --explain Like --sqlonly but with added EXPLAIN keywords\n"
+ " --heap SZ MIN Memory allocator uses SZ bytes & min allocation MIN\n"
+ " --incrvacuum Enable incremenatal vacuum mode\n"
+ " --journalmode M Set the journal_mode to MODE\n"
+ " --key KEY Set the encryption key to KEY\n"
+ " --lookaside N SZ Configure lookaside for N slots of SZ bytes each\n"
+ " --nosync Set PRAGMA synchronous=OFF\n"
+ " --notnull Add NOT NULL constraints to table columns\n"
+ " --pagesize N Set the page size to N\n"
+ " --pcache N SZ Configure N pages of pagecache each of size SZ bytes\n"
+ " --primarykey Use PRIMARY KEY instead of UNIQUE where appropriate\n"
+ " --reprepare Reprepare each statement upon every invocation\n"
+ " --scratch N SZ Configure scratch memory for N slots of SZ bytes each\n"
+ " --sqlonly No-op. Only show the SQL that would have been run.\n"
+ " --size N Relative test size. Default=100\n"
+ " --stats Show statistics at the end\n"
+ " --testset T Run test-set T\n"
+ " --trace Turn on SQL tracing\n"
+ " --utf16be Set text encoding to UTF-16BE\n"
+ " --utf16le Set text encoding to UTF-16LE\n"
+ " --without-rowid Use WITHOUT ROWID where appropriate\n"
+;
+
+
+#include "sqlite3.h"
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <ctype.h>
+
+/* All global state is held in this structure */
+static struct Global {
+ sqlite3 *db; /* The open database connection */
+ sqlite3_stmt *pStmt; /* Current SQL statement */
+ sqlite3_int64 iStart; /* Start-time for the current test */
+ sqlite3_int64 iTotal; /* Total time */
+ int bWithoutRowid; /* True for --without-rowid */
+ int bReprepare; /* True to reprepare the SQL on each rerun */
+ int bSqlOnly; /* True to print the SQL once only */
+ int bExplain; /* Print SQL with EXPLAIN prefix */
+ int szTest; /* Scale factor for test iterations */
+ const char *zWR; /* Might be WITHOUT ROWID */
+ const char *zNN; /* Might be NOT NULL */
+ const char *zPK; /* Might be UNIQUE or PRIMARY KEY */
+ unsigned int x, y; /* Pseudo-random number generator state */
+ int nResult; /* Size of the current result */
+ char zResult[3000]; /* Text of the current result */
+} g;
+
+
+/* Print an error message and exit */
+static void fatal_error(const char *zMsg, ...){
+ va_list ap;
+ va_start(ap, zMsg);
+ vfprintf(stderr, zMsg, ap);
+ va_end(ap);
+ exit(1);
+}
+
+/*
+** 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;
+}
+
+/* Provide an alternative to sqlite3_stricmp() in older versions of
+** SQLite */
+#if SQLITE_VERSION_NUMBER<3007011
+# define sqlite3_stricmp strcmp
+#endif
+
+/*
+** 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; i<sizeof(aMult)/sizeof(aMult[0]); i++){
+ if( sqlite3_stricmp(aMult[i].zSuffix, zArg)==0 ){
+ v *= aMult[i].iMult;
+ break;
+ }
+ }
+ if( v>0x7fffffff ) fatal_error("parameter too large - max 2147483648");
+ return (int)(isNeg? -v : v);
+}
+
+/* Return the current wall-clock time, in milliseconds */
+sqlite3_int64 speedtest1_timestamp(void){
+ static sqlite3_vfs *clockVfs = 0;
+ sqlite3_int64 t;
+ if( clockVfs==0 ) clockVfs = sqlite3_vfs_find(0);
+#if SQLITE_VERSION_NUMBER>=3007000
+ if( clockVfs->iVersion>=2 && clockVfs->xCurrentTimeInt64!=0 ){
+ clockVfs->xCurrentTimeInt64(clockVfs, &t);
+ }else
+#endif
+ {
+ double r;
+ clockVfs->xCurrentTime(clockVfs, &r);
+ t = (sqlite3_int64)(r*86400000.0);
+ }
+ return t;
+}
+
+/* Return a pseudo-random unsigned integer */
+unsigned int speedtest1_random(void){
+ g.x = (g.x>>1) ^ ((1+~(g.x&1)) & 0xd0000001);
+ g.y = g.y*1103515245 + 12345;
+ return g.x ^ g.y;
+}
+
+/* Map the value in within the range of 1...limit into another
+** number in a way that is chatic and invertable.
+*/
+unsigned swizzle(unsigned in, unsigned limit){
+ unsigned out = 0;
+ while( limit ){
+ out = (out<<1) | (in&1);
+ in >>= 1;
+ limit >>= 1;
+ }
+ return out;
+}
+
+/* Round up a number so that it is a power of two minus one
+*/
+unsigned roundup_allones(unsigned limit){
+ unsigned m = 1;
+ while( m<limit ) m = (m<<1)+1;
+ return m;
+}
+
+/* The speedtest1_numbername procedure below converts its argment (an integer)
+** into a string which is the English-language name for that number.
+** The returned string should be freed with sqlite3_free().
+**
+** Example:
+**
+** speedtest1_numbername(123) -> "one hundred twenty three"
+*/
+int speedtest1_numbername(unsigned int n, char *zOut, int nOut){
+ static const char *ones[] = { "zero", "one", "two", "three", "four", "five",
+ "six", "seven", "eight", "nine", "ten", "eleven", "twelve",
+ "thirteen", "fourteen", "fifteen", "sixteen", "seventeen",
+ "eighteen", "nineteen" };
+ static const char *tens[] = { "", "ten", "twenty", "thirty", "forty",
+ "fifty", "sixty", "seventy", "eighty", "ninety" };
+ int i = 0;
+
+ if( n>=1000000000 ){
+ i += speedtest1_numbername(n/1000000000, zOut+i, nOut-i);
+ sqlite3_snprintf(nOut-i, zOut+i, " billion");
+ i += (int)strlen(zOut+i);
+ n = n % 1000000000;
+ }
+ if( n>=1000000 ){
+ if( i && i<nOut-1 ) zOut[i++] = ' ';
+ i += speedtest1_numbername(n/1000000, zOut+i, nOut-i);
+ sqlite3_snprintf(nOut-i, zOut+i, " million");
+ i += (int)strlen(zOut+i);
+ n = n % 1000000;
+ }
+ if( n>=1000 ){
+ if( i && i<nOut-1 ) zOut[i++] = ' ';
+ i += speedtest1_numbername(n/1000, zOut+i, nOut-i);
+ sqlite3_snprintf(nOut-i, zOut+i, " thousand");
+ i += (int)strlen(zOut+i);
+ n = n % 1000;
+ }
+ if( n>=100 ){
+ if( i && i<nOut-1 ) zOut[i++] = ' ';
+ sqlite3_snprintf(nOut-i, zOut+i, "%s hundred", ones[n/100]);
+ i += (int)strlen(zOut+i);
+ n = n % 100;
+ }
+ if( n>=20 ){
+ if( i && i<nOut-1 ) zOut[i++] = ' ';
+ sqlite3_snprintf(nOut-i, zOut+i, "%s", tens[n/10]);
+ i += (int)strlen(zOut+i);
+ n = n % 10;
+ }
+ if( n>0 ){
+ if( i && i<nOut-1 ) zOut[i++] = ' ';
+ sqlite3_snprintf(nOut-i, zOut+i, "%s", ones[n]);
+ i += (int)strlen(zOut+i);
+ }
+ if( i==0 ){
+ sqlite3_snprintf(nOut-i, zOut+i, "zero");
+ i += (int)strlen(zOut+i);
+ }
+ return i;
+}
+
+
+/* Start a new test case */
+#define NAMEWIDTH 60
+static const char zDots[] =
+ ".......................................................................";
+void speedtest1_begin_test(int iTestNum, const char *zTestName, ...){
+ int n = (int)strlen(zTestName);
+ char *zName;
+ va_list ap;
+ va_start(ap, zTestName);
+ zName = sqlite3_vmprintf(zTestName, ap);
+ va_end(ap);
+ n = (int)strlen(zName);
+ if( n>NAMEWIDTH ){
+ zName[NAMEWIDTH] = 0;
+ n = NAMEWIDTH;
+ }
+ if( g.bSqlOnly ){
+ printf("/* %4d - %s%.*s */\n", iTestNum, zName, NAMEWIDTH-n, zDots);
+ }else{
+ printf("%4d - %s%.*s ", iTestNum, zName, NAMEWIDTH-n, zDots);
+ fflush(stdout);
+ }
+ sqlite3_free(zName);
+ g.nResult = 0;
+ g.iStart = speedtest1_timestamp();
+ g.x = 0xad131d0b;
+ g.y = 0x44f9eac8;
+}
+
+/* Complete a test case */
+void speedtest1_end_test(void){
+ sqlite3_int64 iElapseTime = speedtest1_timestamp() - g.iStart;
+ if( !g.bSqlOnly ){
+ g.iTotal += iElapseTime;
+ printf("%4d.%03ds\n", (int)(iElapseTime/1000), (int)(iElapseTime%1000));
+ }
+ if( g.pStmt ){
+ sqlite3_finalize(g.pStmt);
+ g.pStmt = 0;
+ }
+}
+
+/* Report end of testing */
+void speedtest1_final(void){
+ if( !g.bSqlOnly ){
+ printf(" TOTAL%.*s %4d.%03ds\n", NAMEWIDTH-5, zDots,
+ (int)(g.iTotal/1000), (int)(g.iTotal%1000));
+ }
+}
+
+/* Print an SQL statement to standard output */
+static void printSql(const char *zSql){
+ int n = (int)strlen(zSql);
+ while( n>0 && (zSql[n-1]==';' || isspace(zSql[n-1])) ){ n--; }
+ if( g.bExplain ) printf("EXPLAIN ");
+ printf("%.*s;\n", n, zSql);
+ if( g.bExplain
+#if SQLITE_VERSION_NUMBER>=3007010
+ && ( sqlite3_strglob("CREATE *", zSql)==0
+ || sqlite3_strglob("DROP *", zSql)==0
+ || sqlite3_strglob("ALTER *", zSql)==0
+ )
+#endif
+ ){
+ printf("%.*s;\n", n, zSql);
+ }
+}
+
+/* Run SQL */
+void speedtest1_exec(const char *zFormat, ...){
+ va_list ap;
+ char *zSql;
+ va_start(ap, zFormat);
+ zSql = sqlite3_vmprintf(zFormat, ap);
+ va_end(ap);
+ if( g.bSqlOnly ){
+ printSql(zSql);
+ }else{
+ char *zErrMsg = 0;
+ int rc = sqlite3_exec(g.db, zSql, 0, 0, &zErrMsg);
+ if( zErrMsg ) fatal_error("SQL error: %s\n%s\n", zErrMsg, zSql);
+ if( rc!=SQLITE_OK ) fatal_error("exec error: %s\n", sqlite3_errmsg(g.db));
+ }
+ sqlite3_free(zSql);
+}
+
+/* Prepare an SQL statement */
+void speedtest1_prepare(const char *zFormat, ...){
+ va_list ap;
+ char *zSql;
+ va_start(ap, zFormat);
+ zSql = sqlite3_vmprintf(zFormat, ap);
+ va_end(ap);
+ if( g.bSqlOnly ){
+ printSql(zSql);
+ }else{
+ int rc;
+ if( g.pStmt ) sqlite3_finalize(g.pStmt);
+ rc = sqlite3_prepare_v2(g.db, zSql, -1, &g.pStmt, 0);
+ if( rc ){
+ fatal_error("SQL error: %s\n", sqlite3_errmsg(g.db));
+ }
+ }
+ sqlite3_free(zSql);
+}
+
+/* Run an SQL statement previously prepared */
+void speedtest1_run(void){
+ int i, n, len;
+ if( g.bSqlOnly ) return;
+ assert( g.pStmt );
+ g.nResult = 0;
+ while( sqlite3_step(g.pStmt)==SQLITE_ROW ){
+ n = sqlite3_column_count(g.pStmt);
+ for(i=0; i<n; i++){
+ const char *z = (const char*)sqlite3_column_text(g.pStmt, i);
+ if( z==0 ) z = "nil";
+ len = (int)strlen(z);
+ if( g.nResult+len<sizeof(g.zResult)-2 ){
+ if( g.nResult>0 ) g.zResult[g.nResult++] = ' ';
+ memcpy(g.zResult + g.nResult, z, len+1);
+ g.nResult += len;
+ }
+ }
+ }
+ if( g.bReprepare ){
+ sqlite3_stmt *pNew;
+ sqlite3_prepare_v2(g.db, sqlite3_sql(g.pStmt), -1, &pNew, 0);
+ sqlite3_finalize(g.pStmt);
+ g.pStmt = pNew;
+ }else{
+ sqlite3_reset(g.pStmt);
+ }
+}
+
+/* The sqlite3_trace() callback function */
+static void traceCallback(void *NotUsed, const char *zSql){
+ int n = (int)strlen(zSql);
+ while( n>0 && (zSql[n-1]==';' || isspace(zSql[n-1])) ) n--;
+ fprintf(stderr,"%.*s;\n", n, zSql);
+}
+
+/* Substitute random() function that gives the same random
+** sequence on each run, for repeatability. */
+static void randomFunc(
+ sqlite3_context *context,
+ int NotUsed,
+ sqlite3_value **NotUsed2
+){
+ sqlite3_result_int64(context, (sqlite3_int64)speedtest1_random());
+}
+
+/* Estimate the square root of an integer */
+static int est_square_root(int x){
+ int y0 = x/2;
+ int y1;
+ int n;
+ for(n=0; y0>0 && n<10; n++){
+ y1 = (y0 + x/y0)/2;
+ if( y1==y0 ) break;
+ y0 = y1;
+ }
+ return y0;
+}
+
+/*
+** The main and default testset
+*/
+void testset_main(void){
+ int i; /* Loop counter */
+ int n; /* iteration count */
+ int sz; /* Size of the tables */
+ int maxb; /* Maximum swizzled value */
+ unsigned x1, x2; /* Parameters */
+ int len; /* Length of the zNum[] string */
+ char zNum[2000]; /* A number name */
+
+ sz = n = g.szTest*500;
+ maxb = roundup_allones(sz);
+ speedtest1_begin_test(100, "%d INSERTs into table with no index", n);
+ speedtest1_exec("BEGIN");
+ speedtest1_exec("CREATE TABLE t1(a INTEGER %s, b INTEGER %s, c TEXT %s);",
+ g.zNN, g.zNN, g.zNN);
+ speedtest1_prepare("INSERT INTO t1 VALUES(?1,?2,?3); -- %d times", n);
+ for(i=1; i<=n; i++){
+ x1 = swizzle(i,maxb);
+ speedtest1_numbername(x1, zNum, sizeof(zNum));
+ sqlite3_bind_int64(g.pStmt, 1, (sqlite3_int64)x1);
+ sqlite3_bind_int(g.pStmt, 2, i);
+ sqlite3_bind_text(g.pStmt, 3, zNum, -1, SQLITE_STATIC);
+ speedtest1_run();
+ }
+ speedtest1_exec("COMMIT");
+ speedtest1_end_test();
+
+
+ n = sz;
+ speedtest1_begin_test(110, "%d ordered INSERTS with one index/PK", n);
+ speedtest1_exec("BEGIN");
+ speedtest1_exec("CREATE TABLE t2(a INTEGER %s %s, b INTEGER %s, c TEXT %s) %s",
+ g.zNN, g.zPK, g.zNN, g.zNN, g.zWR);
+ speedtest1_prepare("INSERT INTO t2 VALUES(?1,?2,?3); -- %d times", n);
+ for(i=1; i<=n; i++){
+ x1 = swizzle(i,maxb);
+ speedtest1_numbername(x1, zNum, sizeof(zNum));
+ sqlite3_bind_int(g.pStmt, 1, i);
+ sqlite3_bind_int64(g.pStmt, 2, (sqlite3_int64)x1);
+ sqlite3_bind_text(g.pStmt, 3, zNum, -1, SQLITE_STATIC);
+ speedtest1_run();
+ }
+ speedtest1_exec("COMMIT");
+ speedtest1_end_test();
+
+
+ n = sz;
+ speedtest1_begin_test(120, "%d unordered INSERTS with one index/PK", n);
+ speedtest1_exec("BEGIN");
+ speedtest1_exec("CREATE TABLE t3(a INTEGER %s %s, b INTEGER %s, c TEXT %s) %s",
+ g.zNN, g.zPK, g.zNN, g.zNN, g.zWR);
+ speedtest1_prepare("INSERT INTO t3 VALUES(?1,?2,?3); -- %d times", n);
+ for(i=1; i<=n; i++){
+ x1 = swizzle(i,maxb);
+ speedtest1_numbername(x1, zNum, sizeof(zNum));
+ sqlite3_bind_int(g.pStmt, 2, i);
+ sqlite3_bind_int64(g.pStmt, 1, (sqlite3_int64)x1);
+ sqlite3_bind_text(g.pStmt, 3, zNum, -1, SQLITE_STATIC);
+ speedtest1_run();
+ }
+ speedtest1_exec("COMMIT");
+ speedtest1_end_test();
+
+
+ n = g.szTest/2;
+ speedtest1_begin_test(130, "%d SELECTS, numeric BETWEEN, unindexed", n);
+ speedtest1_exec("BEGIN");
+ speedtest1_prepare(
+ "SELECT count(*), avg(b), sum(length(c)) FROM t1\n"
+ " WHERE b BETWEEN ?1 AND ?2; -- %d times", n
+ );
+ for(i=1; i<=n; i++){
+ x1 = speedtest1_random()%maxb;
+ x2 = speedtest1_random()%10 + sz/5000 + x1;
+ sqlite3_bind_int(g.pStmt, 1, x1);
+ sqlite3_bind_int(g.pStmt, 2, x2);
+ speedtest1_run();
+ }
+ speedtest1_exec("COMMIT");
+ speedtest1_end_test();
+
+
+ n = g.szTest/5;
+ speedtest1_begin_test(140, "%d SELECTS, LIKE, unindexed", n);
+ speedtest1_exec("BEGIN");
+ speedtest1_prepare(
+ "SELECT count(*), avg(b), sum(length(c)) FROM t1\n"
+ " WHERE c LIKE ?1; -- %d times", n
+ );
+ for(i=1; i<=n; i++){
+ x1 = speedtest1_random()%maxb;
+ zNum[0] = '%';
+ len = speedtest1_numbername(i, zNum+1, sizeof(zNum)-2);
+ zNum[len] = '%';
+ zNum[len+1] = 0;
+ sqlite3_bind_text(g.pStmt, 1, zNum, len, SQLITE_STATIC);
+ speedtest1_run();
+ }
+ speedtest1_exec("COMMIT");
+ speedtest1_end_test();
+
+
+ speedtest1_begin_test(150, "CREATE INDEX five times");
+ speedtest1_exec("BEGIN;");
+ speedtest1_exec("CREATE UNIQUE INDEX t1b ON t1(b);");
+ speedtest1_exec("CREATE INDEX t1c ON t1(c);");
+ speedtest1_exec("CREATE UNIQUE INDEX t2b ON t2(b);");
+ speedtest1_exec("CREATE INDEX t2c ON t2(c DESC);");
+ speedtest1_exec("CREATE INDEX t3bc ON t3(b,c);");
+ speedtest1_exec("COMMIT;");
+ speedtest1_end_test();
+
+
+ n = sz/5;
+ speedtest1_begin_test(160, "%d SELECTS, numeric BETWEEN, indexed", n);
+ speedtest1_exec("BEGIN");
+ speedtest1_prepare(
+ "SELECT count(*), avg(b), sum(length(c)) FROM t1\n"
+ " WHERE b BETWEEN ?1 AND ?2; -- %d times", n
+ );
+ for(i=1; i<=n; i++){
+ x1 = speedtest1_random()%maxb;
+ x2 = speedtest1_random()%10 + sz/5000 + x1;
+ sqlite3_bind_int(g.pStmt, 1, x1);
+ sqlite3_bind_int(g.pStmt, 2, x2);
+ speedtest1_run();
+ }
+ speedtest1_exec("COMMIT");
+ speedtest1_end_test();
+
+
+ n = sz/5;
+ speedtest1_begin_test(161, "%d SELECTS, numeric BETWEEN, PK", n);
+ speedtest1_exec("BEGIN");
+ speedtest1_prepare(
+ "SELECT count(*), avg(b), sum(length(c)) FROM t2\n"
+ " WHERE a BETWEEN ?1 AND ?2; -- %d times", n
+ );
+ for(i=1; i<=n; i++){
+ x1 = speedtest1_random()%maxb;
+ x2 = speedtest1_random()%10 + sz/5000 + x1;
+ sqlite3_bind_int(g.pStmt, 1, x1);
+ sqlite3_bind_int(g.pStmt, 2, x2);
+ speedtest1_run();
+ }
+ speedtest1_exec("COMMIT");
+ speedtest1_end_test();
+
+
+ n = sz/5;
+ speedtest1_begin_test(170, "%d SELECTS, text BETWEEN, indexed", n);
+ speedtest1_exec("BEGIN");
+ speedtest1_prepare(
+ "SELECT count(*), avg(b), sum(length(c)) FROM t1\n"
+ " WHERE c BETWEEN ?1 AND (?1||'~'); -- %d times", n
+ );
+ for(i=1; i<=n; i++){
+ x1 = swizzle(i, maxb);
+ len = speedtest1_numbername(x1, zNum, sizeof(zNum)-1);
+ sqlite3_bind_text(g.pStmt, 1, zNum, len, SQLITE_STATIC);
+ speedtest1_run();
+ }
+ speedtest1_exec("COMMIT");
+ speedtest1_end_test();
+
+ n = sz;
+ speedtest1_begin_test(180, "%d INSERTS with three indexes", n);
+ speedtest1_exec("BEGIN");
+ speedtest1_exec(
+ "CREATE TABLE t4(\n"
+ " a INTEGER %s %s,\n"
+ " b INTEGER %s,\n"
+ " c TEXT %s\n"
+ ") %s",
+ g.zNN, g.zPK, g.zNN, g.zNN, g.zWR);
+ speedtest1_exec("CREATE INDEX t4b ON t4(b)");
+ speedtest1_exec("CREATE INDEX t4c ON t4(c)");
+ speedtest1_exec("INSERT INTO t4 SELECT * FROM t1");
+ speedtest1_exec("COMMIT");
+ speedtest1_end_test();
+
+ n = sz;
+ speedtest1_begin_test(190, "DELETE and REFILL one table", n);
+ speedtest1_exec("DELETE FROM t2;");
+ speedtest1_exec("INSERT INTO t2 SELECT * FROM t1;");
+ speedtest1_end_test();
+
+
+ speedtest1_begin_test(200, "VACUUM");
+ speedtest1_exec("VACUUM");
+ speedtest1_end_test();
+
+
+ speedtest1_begin_test(210, "ALTER TABLE ADD COLUMN, and query");
+ speedtest1_exec("ALTER TABLE t2 ADD COLUMN d DEFAULT 123");
+ speedtest1_exec("SELECT sum(d) FROM t2");
+ speedtest1_end_test();
+
+
+ n = sz/5;
+ speedtest1_begin_test(230, "%d UPDATES, numeric BETWEEN, indexed", n);
+ speedtest1_exec("BEGIN");
+ speedtest1_prepare(
+ "UPDATE t2 SET d=b*2 WHERE b BETWEEN ?1 AND ?2; -- %d times", n
+ );
+ for(i=1; i<=n; i++){
+ x1 = speedtest1_random()%maxb;
+ x2 = speedtest1_random()%10 + sz/5000 + x1;
+ sqlite3_bind_int(g.pStmt, 1, x1);
+ sqlite3_bind_int(g.pStmt, 2, x2);
+ speedtest1_run();
+ }
+ speedtest1_exec("COMMIT");
+ speedtest1_end_test();
+
+
+ n = sz;
+ speedtest1_begin_test(240, "%d UPDATES of individual rows", n);
+ speedtest1_exec("BEGIN");
+ speedtest1_prepare(
+ "UPDATE t2 SET d=b*3 WHERE a=?1; -- %d times", n
+ );
+ for(i=1; i<=n; i++){
+ x1 = speedtest1_random()%sz + 1;
+ sqlite3_bind_int(g.pStmt, 1, x1);
+ speedtest1_run();
+ }
+ speedtest1_exec("COMMIT");
+ speedtest1_end_test();
+
+ speedtest1_begin_test(250, "One big UPDATE of the whole %d-row table", sz);
+ speedtest1_exec("UPDATE t2 SET d=b*4");
+ speedtest1_end_test();
+
+
+ speedtest1_begin_test(260, "Query added column after filling");
+ speedtest1_exec("SELECT sum(d) FROM t2");
+ speedtest1_end_test();
+
+
+
+ n = sz/5;
+ speedtest1_begin_test(270, "%d DELETEs, numeric BETWEEN, indexed", n);
+ speedtest1_exec("BEGIN");
+ speedtest1_prepare(
+ "DELETE FROM t2 WHERE b BETWEEN ?1 AND ?2; -- %d times", n
+ );
+ for(i=1; i<=n; i++){
+ x1 = speedtest1_random()%maxb + 1;
+ x2 = speedtest1_random()%10 + sz/5000 + x1;
+ sqlite3_bind_int(g.pStmt, 1, x1);
+ sqlite3_bind_int(g.pStmt, 2, x2);
+ speedtest1_run();
+ }
+ speedtest1_exec("COMMIT");
+ speedtest1_end_test();
+
+
+ n = sz;
+ speedtest1_begin_test(280, "%d DELETEs of individual rows", n);
+ speedtest1_exec("BEGIN");
+ speedtest1_prepare(
+ "DELETE FROM t3 WHERE a=?1; -- %d times", n
+ );
+ for(i=1; i<=n; i++){
+ x1 = speedtest1_random()%sz + 1;
+ sqlite3_bind_int(g.pStmt, 1, x1);
+ speedtest1_run();
+ }
+ speedtest1_exec("COMMIT");
+ speedtest1_end_test();
+
+
+ speedtest1_begin_test(290, "Refill two %d-row tables using REPLACE", sz);
+ speedtest1_exec("REPLACE INTO t2(a,b,c) SELECT a,b,c FROM t1");
+ speedtest1_exec("REPLACE INTO t3(a,b,c) SELECT a,b,c FROM t1");
+ speedtest1_end_test();
+
+ speedtest1_begin_test(300, "Refill a %d-row table using (b&1)==(a&1)", sz);
+ speedtest1_exec("DELETE FROM t2;");
+ speedtest1_exec("INSERT INTO t2(a,b,c)\n"
+ " SELECT a,b,c FROM t1 WHERE (b&1)==(a&1);");
+ speedtest1_exec("INSERT INTO t2(a,b,c)\n"
+ " SELECT a,b,c FROM t1 WHERE (b&1)<>(a&1);");
+ speedtest1_end_test();
+
+
+ n = sz/5;
+ speedtest1_begin_test(310, "%d four-ways joins", n);
+ speedtest1_exec("BEGIN");
+ speedtest1_prepare(
+ "SELECT t1.c FROM t1, t2, t3, t4\n"
+ " WHERE t4.a BETWEEN ?1 AND ?2\n"
+ " AND t3.a=t4.b\n"
+ " AND t2.a=t3.b\n"
+ " AND t1.c=t2.c"
+ );
+ for(i=1; i<=n; i++){
+ x1 = speedtest1_random()%sz + 1;
+ x2 = speedtest1_random()%10 + x1 + 4;
+ sqlite3_bind_int(g.pStmt, 1, x1);
+ sqlite3_bind_int(g.pStmt, 2, x2);
+ speedtest1_run();
+ }
+ speedtest1_exec("COMMIT");
+ speedtest1_end_test();
+
+ speedtest1_begin_test(320, "subquery in result set", n);
+ speedtest1_prepare(
+ "SELECT sum(a), max(c),\n"
+ " avg((SELECT a FROM t2 WHERE 5+t2.b=t1.b) AND rowid<?1), max(c)\n"
+ " FROM t1 WHERE rowid<?1;"
+ );
+ sqlite3_bind_int(g.pStmt, 1, est_square_root(g.szTest)*50);
+ speedtest1_run();
+ speedtest1_end_test();
+
+ speedtest1_begin_test(980, "PRAGMA integrity_check");
+ speedtest1_exec("PRAGMA integrity_check");
+ speedtest1_end_test();
+
+
+ speedtest1_begin_test(990, "ANALYZE");
+ speedtest1_exec("ANALYZE");
+ speedtest1_end_test();
+}
+
+/*
+** A testset used for debugging speedtest1 itself.
+*/
+void testset_debug1(void){
+ unsigned i, n;
+ unsigned x1, x2;
+ char zNum[2000]; /* A number name */
+
+ n = g.szTest;
+ for(i=1; i<=n; i++){
+ x1 = swizzle(i, n);
+ x2 = swizzle(x1, n);
+ speedtest1_numbername(x1, zNum, sizeof(zNum));
+ printf("%5d %5d %5d %s\n", i, x1, x2, zNum);
+ }
+}
+
+int main(int argc, char **argv){
+ int doAutovac = 0; /* True for --autovacuum */
+ int cacheSize = 0; /* Desired cache size. 0 means default */
+ int doExclusive = 0; /* True for --exclusive */
+ int nHeap = 0, mnHeap = 0; /* Heap size from --heap */
+ int doIncrvac = 0; /* True for --incrvacuum */
+ const char *zJMode = 0; /* Journal mode */
+ const char *zKey = 0; /* Encryption key */
+ int nLook = 0, szLook = 0; /* --lookaside configuration */
+ int noSync = 0; /* True for --nosync */
+ int pageSize = 0; /* Desired page size. 0 means default */
+ int nPCache = 0, szPCache = 0;/* --pcache configuration */
+ int nScratch = 0, szScratch=0;/* --scratch configuration */
+ int showStats = 0; /* True for --stats */
+ const char *zTSet = "main"; /* Which --testset torun */
+ int doTrace = 0; /* True for --trace */
+ const char *zEncoding = 0; /* --utf16be or --utf16le */
+ const char *zDbName = 0; /* Name of the test database */
+
+ void *pHeap = 0; /* Allocated heap space */
+ void *pLook = 0; /* Allocated lookaside space */
+ void *pPCache = 0; /* Allocated storage for pcache */
+ void *pScratch = 0; /* Allocated storage for scratch */
+ int iCur, iHi; /* Stats values, current and "highwater" */
+ int i; /* Loop counter */
+ int rc; /* API return code */
+
+ /* Process command-line arguments */
+ g.zWR = "";
+ g.zNN = "";
+ g.zPK = "UNIQUE";
+ g.szTest = 100;
+ for(i=1; i<argc; i++){
+ const char *z = argv[i];
+ if( z[0]=='-' ){
+ do{ z++; }while( z[0]=='-' );
+ if( strcmp(z,"autovacuum")==0 ){
+ doAutovac = 1;
+ }else if( strcmp(z,"cachesize")==0 ){
+ if( i>=argc-1 ) fatal_error("missing argument on %s\n", argv[i]);
+ i++;
+ cacheSize = integerValue(argv[i]);
+ }else if( strcmp(z,"exclusive")==0 ){
+ doExclusive = 1;
+ }else if( strcmp(z,"explain")==0 ){
+ g.bSqlOnly = 1;
+ g.bExplain = 1;
+ }else if( strcmp(z,"heap")==0 ){
+ if( i>=argc-2 ) fatal_error("missing arguments on %s\n", argv[i]);
+ nHeap = integerValue(argv[i+1]);
+ mnHeap = integerValue(argv[i+2]);
+ i += 2;
+ }else if( strcmp(z,"incrvacuum")==0 ){
+ doIncrvac = 1;
+ }else if( strcmp(z,"journal")==0 ){
+ if( i>=argc-1 ) fatal_error("missing argument on %s\n", argv[i]);
+ zJMode = argv[++i];
+ }else if( strcmp(z,"key")==0 ){
+ if( i>=argc-1 ) fatal_error("missing argument on %s\n", argv[i]);
+ zKey = argv[++i];
+ }else if( strcmp(z,"lookaside")==0 ){
+ if( i>=argc-2 ) fatal_error("missing arguments on %s\n", argv[i]);
+ nLook = integerValue(argv[i+1]);
+ szLook = integerValue(argv[i+2]);
+ i += 2;
+ }else if( strcmp(z,"nosync")==0 ){
+ noSync = 1;
+ }else if( strcmp(z,"notnull")==0 ){
+ g.zNN = "NOT NULL";
+ }else if( strcmp(z,"pagesize")==0 ){
+ if( i>=argc-1 ) fatal_error("missing argument on %s\n", argv[i]);
+ pageSize = integerValue(argv[++i]);
+ }else if( strcmp(z,"pcache")==0 ){
+ if( i>=argc-2 ) fatal_error("missing arguments on %s\n", argv[i]);
+ nPCache = integerValue(argv[i+1]);
+ szPCache = integerValue(argv[i+2]);
+ i += 2;
+ }else if( strcmp(z,"primarykey")==0 ){
+ g.zPK = "PRIMARY KEY";
+ }else if( strcmp(z,"reprepare")==0 ){
+ g.bReprepare = 1;
+ }else if( strcmp(z,"scratch")==0 ){
+ if( i>=argc-2 ) fatal_error("missing arguments on %s\n", argv[i]);
+ nScratch = integerValue(argv[i+1]);
+ szScratch = integerValue(argv[i+2]);
+ i += 2;
+ }else if( strcmp(z,"sqlonly")==0 ){
+ g.bSqlOnly = 1;
+ }else if( strcmp(z,"size")==0 ){
+ if( i>=argc-1 ) fatal_error("missing argument on %s\n", argv[i]);
+ g.szTest = integerValue(argv[++i]);
+ }else if( strcmp(z,"stats")==0 ){
+ showStats = 1;
+ }else if( strcmp(z,"testset")==0 ){
+ if( i>=argc-1 ) fatal_error("missing argument on %s\n", argv[i]);
+ zTSet = argv[++i];
+ }else if( strcmp(z,"trace")==0 ){
+ doTrace = 1;
+ }else if( strcmp(z,"utf16le")==0 ){
+ zEncoding = "utf16le";
+ }else if( strcmp(z,"utf16be")==0 ){
+ zEncoding = "utf16be";
+ }else if( strcmp(z,"without-rowid")==0 ){
+ g.zWR = "WITHOUT ROWID";
+ g.zPK = "PRIMARY KEY";
+ }else if( strcmp(z, "help")==0 || strcmp(z,"?")==0 ){
+ printf(zHelp, argv[0]);
+ exit(0);
+ }else{
+ fatal_error("unknown option: %s\nUse \"%s -?\" for help\n",
+ argv[i], argv[0]);
+ }
+ }else if( zDbName==0 ){
+ zDbName = argv[i];
+ }else{
+ fatal_error("surplus argument: %s\nUse \"%s -?\" for help\n",
+ argv[i], argv[0]);
+ }
+ }
+#if 0
+ if( zDbName==0 ){
+ fatal_error(zHelp, argv[0]);
+ }
+#endif
+ if( nHeap>0 ){
+ pHeap = malloc( nHeap );
+ if( pHeap==0 ) fatal_error("cannot allocate %d-byte heap\n", nHeap);
+ rc = sqlite3_config(SQLITE_CONFIG_HEAP, pHeap, nHeap, mnHeap);
+ if( rc ) fatal_error("heap configuration failed: %d\n", rc);
+ }
+ if( nPCache>0 && szPCache>0 ){
+ pPCache = malloc( nPCache*(sqlite3_int64)szPCache );
+ if( pPCache==0 ) fatal_error("cannot allocate %lld-byte pcache\n",
+ nPCache*(sqlite3_int64)szPCache);
+ rc = sqlite3_config(SQLITE_CONFIG_PAGECACHE, pPCache, szPCache, nPCache);
+ if( rc ) fatal_error("pcache configuration failed: %d\n", rc);
+ }
+ if( nScratch>0 && szScratch>0 ){
+ pScratch = malloc( nScratch*(sqlite3_int64)szScratch );
+ if( pScratch==0 ) fatal_error("cannot allocate %lld-byte scratch\n",
+ nScratch*(sqlite3_int64)szScratch);
+ rc = sqlite3_config(SQLITE_CONFIG_SCRATCH, pScratch, szScratch, nScratch);
+ if( rc ) fatal_error("scratch configuration failed: %d\n", rc);
+ }
+ if( nLook>0 ){
+ sqlite3_config(SQLITE_CONFIG_LOOKASIDE, 0, 0);
+ }
+
+ /* Open the database and the input file */
+ if( sqlite3_open(zDbName, &g.db) ){
+ fatal_error("Cannot open database file: %s\n", zDbName);
+ }
+ if( nLook>0 && szLook>0 ){
+ pLook = malloc( nLook*szLook );
+ rc = sqlite3_db_config(g.db, SQLITE_DBCONFIG_LOOKASIDE, pLook, szLook,nLook);
+ if( rc ) fatal_error("lookaside configuration failed: %d\n", rc);
+ }
+
+ /* Set database connection options */
+ sqlite3_create_function(g.db, "random", 0, SQLITE_UTF8, 0, randomFunc, 0, 0);
+ if( doTrace ) sqlite3_trace(g.db, traceCallback, 0);
+ if( zKey ){
+ speedtest1_exec("PRAGMA key('%s')", zKey);
+ }
+ if( zEncoding ){
+ speedtest1_exec("PRAGMA encoding=%s", zEncoding);
+ }
+ if( doAutovac ){
+ speedtest1_exec("PRAGMA auto_vacuum=FULL");
+ }else if( doIncrvac ){
+ speedtest1_exec("PRAGMA auto_vacuum=INCREMENTAL");
+ }
+ if( pageSize ){
+ speedtest1_exec("PRAGMA page_size=%d", pageSize);
+ }
+ if( cacheSize ){
+ speedtest1_exec("PRAGMA cache_size=%d", cacheSize);
+ }
+ if( noSync ) speedtest1_exec("PRAGMA synchronous=OFF");
+ if( doExclusive ){
+ speedtest1_exec("PRAGMA locking_mode=EXCLUSIVE");
+ }
+ if( zJMode ){
+ speedtest1_exec("PRAGMA journal_mode=%s", zJMode);
+ }
+
+ if( g.bExplain ) printf(".explain\n.echo on\n");
+ if( strcmp(zTSet,"main")==0 ){
+ testset_main();
+ }else if( strcmp(zTSet,"debug1")==0 ){
+ testset_debug1();
+ }else{
+ fatal_error("unknown testset: \"%s\"\n", zTSet);
+ }
+ speedtest1_final();
+
+ /* Database connection statistics printed after both prepared statements
+ ** have been finalized */
+#if SQLITE_VERSION_NUMBER>=3007009
+ if( showStats ){
+ sqlite3_db_status(g.db, SQLITE_DBSTATUS_LOOKASIDE_USED, &iCur, &iHi, 0);
+ printf("-- Lookaside Slots Used: %d (max %d)\n", iCur,iHi);
+ sqlite3_db_status(g.db, SQLITE_DBSTATUS_LOOKASIDE_HIT, &iCur, &iHi, 0);
+ printf("-- Successful lookasides: %d\n", iHi);
+ sqlite3_db_status(g.db, SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE, &iCur,&iHi,0);
+ printf("-- Lookaside size faults: %d\n", iHi);
+ sqlite3_db_status(g.db, SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL, &iCur,&iHi,0);
+ printf("-- Lookaside OOM faults: %d\n", iHi);
+ sqlite3_db_status(g.db, SQLITE_DBSTATUS_CACHE_USED, &iCur, &iHi, 0);
+ printf("-- Pager Heap Usage: %d bytes\n", iCur);
+ sqlite3_db_status(g.db, SQLITE_DBSTATUS_CACHE_HIT, &iCur, &iHi, 1);
+ printf("-- Page cache hits: %d\n", iCur);
+ sqlite3_db_status(g.db, SQLITE_DBSTATUS_CACHE_MISS, &iCur, &iHi, 1);
+ printf("-- Page cache misses: %d\n", iCur);
+#if SQLITE_VERSION_NUMBER>=3007012
+ sqlite3_db_status(g.db, SQLITE_DBSTATUS_CACHE_WRITE, &iCur, &iHi, 1);
+ printf("-- Page cache writes: %d\n", iCur);
+#endif
+ sqlite3_db_status(g.db, SQLITE_DBSTATUS_SCHEMA_USED, &iCur, &iHi, 0);
+ printf("-- Schema Heap Usage: %d bytes\n", iCur);
+ sqlite3_db_status(g.db, SQLITE_DBSTATUS_STMT_USED, &iCur, &iHi, 0);
+ printf("-- Statement Heap Usage: %d bytes\n", iCur);
+ }
+#endif
+
+ sqlite3_close(g.db);
+
+ /* Global memory usage statistics printed after the database connection
+ ** has closed. Memory usage should be zero at this point. */
+ if( showStats ){
+ sqlite3_status(SQLITE_STATUS_MEMORY_USED, &iCur, &iHi, 0);
+ printf("-- Memory Used (bytes): %d (max %d)\n", iCur,iHi);
+#if SQLITE_VERSION_NUMBER>=3007000
+ sqlite3_status(SQLITE_STATUS_MALLOC_COUNT, &iCur, &iHi, 0);
+ printf("-- Outstanding Allocations: %d (max %d)\n", iCur,iHi);
+#endif
+ sqlite3_status(SQLITE_STATUS_PAGECACHE_OVERFLOW, &iCur, &iHi, 0);
+ printf("-- Pcache Overflow Bytes: %d (max %d)\n", iCur,iHi);
+ sqlite3_status(SQLITE_STATUS_SCRATCH_OVERFLOW, &iCur, &iHi, 0);
+ printf("-- Scratch Overflow Bytes: %d (max %d)\n", iCur,iHi);
+ sqlite3_status(SQLITE_STATUS_MALLOC_SIZE, &iCur, &iHi, 0);
+ printf("-- Largest Allocation: %d bytes\n",iHi);
+ sqlite3_status(SQLITE_STATUS_PAGECACHE_SIZE, &iCur, &iHi, 0);
+ printf("-- Largest Pcache Allocation: %d bytes\n",iHi);
+ sqlite3_status(SQLITE_STATUS_SCRATCH_SIZE, &iCur, &iHi, 0);
+ printf("-- Largest Scratch Allocation: %d bytes\n", iHi);
+ }
+
+ /* Release memory */
+ free( pLook );
+ free( pPCache );
+ free( pScratch );
+ free( pHeap );
+ return 0;
+}
diff --git a/lang/sql/sqlite/test/spellfix.test b/lang/sql/sqlite/test/spellfix.test
new file mode 100644
index 00000000..21383c2d
--- /dev/null
+++ b/lang/sql/sqlite/test/spellfix.test
@@ -0,0 +1,273 @@
+# 2012 July 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 spellfix
+
+ifcapable !vtab { finish_test ; return }
+
+load_static_extension db spellfix nextchar
+
+set vocab {
+rabbi rabbit rabbits rabble rabid rabies raccoon raccoons race raced racer
+racers races racetrack racial racially racing rack racked racket racketeer
+racketeering racketeers rackets racking racks radar radars radial radially
+radian radiance radiant radiantly radiate radiated radiates radiating radiation
+radiations radiator radiators radical radically radicals radices radii radio
+radioactive radioastronomy radioed radiography radioing radiology radios radish
+radishes radium radius radix radon raft rafter rafters rafts rag rage raged
+rages ragged raggedly raggedness raging rags ragweed raid raided raider raiders
+raiding raids rail railed railer railers railing railroad railroaded railroader
+railroaders railroading railroads rails railway railways raiment rain rainbow
+raincoat raincoats raindrop raindrops rained rainfall rainier rainiest raining
+rains rainstorm rainy raise raised raiser raisers raises raisin raising rake
+raked rakes raking rallied rallies rally rallying ram ramble rambler rambles
+rambling ramblings ramification ramifications ramp rampage rampant rampart
+ramps ramrod rams ran ranch ranched rancher ranchers ranches ranching rancid
+random randomization randomize randomized randomizes randomly randomness randy
+rang range ranged rangeland ranger rangers ranges ranging rangy rank ranked
+ranker rankers rankest ranking rankings rankle rankly rankness ranks ransack
+ransacked ransacking ransacks ransom ransomer ransoming ransoms rant ranted
+ranter ranters ranting rants rap rapacious rape raped raper rapes rapid
+rapidity rapidly rapids rapier raping rapport rapprochement raps rapt raptly
+rapture raptures rapturous rare rarely rareness rarer rarest rarity rascal
+rascally rascals rash rasher rashly rashness rasp raspberry rasped rasping
+rasps raster rat rate rated rater raters rates rather ratification ratified
+ratifies ratify ratifying rating ratings ratio ration rational rationale
+rationales rationalities rationality rationalization rationalizations
+rationalize rationalized rationalizes rationalizing rationally rationals
+rationing rations ratios rats rattle rattled rattler rattlers rattles
+rattlesnake rattlesnakes rattling raucous ravage ravaged ravager ravagers
+ravages ravaging rave raved raven ravening ravenous ravenously ravens raves
+ravine ravines raving ravings raw rawer rawest rawly rawness ray rays raze
+razor razors re reabbreviate reabbreviated reabbreviates reabbreviating reach
+reachability reachable reachably reached reacher reaches reaching reacquired
+react reacted reacting reaction reactionaries reactionary reactions reactivate
+reactivated reactivates reactivating reactivation reactive reactively
+reactivity reactor reactors reacts read readability readable reader readers
+readied readier readies readiest readily readiness reading readings readjusted
+readout readouts reads ready readying real realest realign realigned realigning
+realigns realism realist realistic realistically realists realities reality
+}
+
+do_test 1.1 {
+ execsql { CREATE VIRTUAL TABLE t1 USING spellfix1 }
+ foreach word $vocab {
+ execsql { INSERT INTO t1(word) VALUES($word) }
+ }
+} {}
+
+foreach {tn word res} {
+ 1 raxpi* {rasping 5 rasped 5 ragweed 5 raspberry 6 rasp 4}
+ 2 ril* {rail 4 railed 4 railer 4 railers 4 railing 4}
+ 3 rilis* {realism 6 realist 6 realistic 6 realistically 6 realists 6}
+ 4 reail* {real 3 realest 3 realign 3 realigned 3 realigning 3}
+ 5 ras* {rascal 3 rascally 3 rascals 3 rash 3 rasher 3}
+ 6 realistss* {realists 8 realigns 8 realistic 9 realistically 9 realest 7}
+ 7 realistss {realists 8 realist 7 realigns 8 realistic 9 realest 7}
+ 8 rllation* {realities 9 reality 7 rallied 7 railed 4}
+ 9 renstom* {rainstorm 8 ransom 6 ransomer 6 ransoming 6 ransoms 6}
+} {
+ do_execsql_test 1.2.$tn {
+ SELECT word, matchlen FROM t1 WHERE word MATCH $word
+ ORDER BY score, word LIMIT 5
+ } $res
+}
+
+# Tests of the next_char function.
+#
+do_test 1.10 {
+ db eval {
+ CREATE TABLE vocab(w TEXT PRIMARY KEY);
+ INSERT INTO vocab SELECT word FROM t1;
+ }
+} {}
+do_execsql_test 1.11 {
+ SELECT next_char('re','vocab','w');
+} {a}
+do_execsql_test 1.11sub {
+ SELECT next_char('re','(SELECT w AS x FROM vocab)','x');
+} {a}
+do_execsql_test 1.12 {
+ SELECT next_char('r','vocab','w');
+} {ae}
+do_execsql_test 1.13 {
+ SELECT next_char('','vocab','w');
+} {r}
+do_test 1.14 {
+ catchsql {SELECT next_char('','xyzzy','a')}
+} {1 {no such table: xyzzy}}
+
+do_execsql_test 1.20 {
+ CREATE TABLE vocab2(w TEXT);
+ CREATE INDEX vocab2w ON vocab2(w COLLATE nocase);
+ INSERT INTO vocab2 VALUES('abc'), ('ABD'), ('aBe'), ('AbF');
+ SELECT next_char('ab', 'vocab2', 'w', null, 'nocase');
+} {cDeF}
+do_execsql_test 1.21 {
+ SELECT next_char('ab','vocab2','w',null,null);
+} {c}
+do_execsql_test 1.22 {
+ SELECT next_char('AB','vocab2','w',null,'NOCASE');
+} {cDeF}
+do_execsql_test 1.23 {
+ SELECT next_char('ab','vocab2','w',null,'binary');
+} {c}
+
+do_execsql_test 2.1 {
+ CREATE VIRTUAL TABLE t2 USING spellfix1;
+ INSERT INTO t2 (word, soundslike) VALUES('school', 'skuul');
+ INSERT INTO t2 (word, soundslike) VALUES('psalm', 'sarm');
+ SELECT word, matchlen FROM t2 WHERE word MATCH 'sar*' LIMIT 5;
+} {psalm 4}
+
+do_execsql_test 2.2 {
+ SELECT word, matchlen FROM t2 WHERE word MATCH 'skol*' LIMIT 5;
+} {school 6}
+
+set vocab {
+kangaroo kanji kappa karate keel keeled keeling keels keen keener keenest
+keenly keenness keep keeper keepers keeping keeps ken kennel kennels kept
+kerchief kerchiefs kern kernel kernels kerosene ketchup kettle
+kettles key keyboard keyboards keyed keyhole keying keynote keypad keypads keys
+keystroke keystrokes keyword keywords kick kicked kicker kickers kicking
+kickoff kicks kid kidded kiddie kidding kidnap kidnapper kidnappers kidnapping
+kidnappings kidnaps kidney kidneys kids kill killed killer killers killing
+killingly killings killjoy kills kilobit kilobits kiloblock kilobyte kilobytes
+kilogram kilograms kilohertz kilohm kilojoule kilometer kilometers kiloton
+kilovolt kilowatt kiloword kimono kin kind kinder kindergarten kindest
+kindhearted kindle kindled kindles kindling kindly kindness kindred kinds
+kinetic king kingdom kingdoms kingly kingpin kings kink kinky kinship kinsman
+kiosk kiss kissed kisser kissers kisses kissing kit kitchen kitchenette
+kitchens kite kited kites kiting kits kitten kittenish kittens kitty klaxon
+kludge kludges klystron knack knapsack knapsacks knave knaves knead kneads knee
+kneecap kneed kneeing kneel kneeled kneeling kneels knees knell knells knelt
+knew knife knifed knifes knifing knight knighted knighthood knighting knightly
+knights knit knits knives knob knobs knock knockdown knocked knocker knockers
+knocking knockout knocks knoll knolls knot knots knotted knotting know knowable
+knower knowhow knowing knowingly knowledge knowledgeable known knows knuckle
+knuckled knuckles koala kosher kudo
+}
+
+do_execsql_test 3.1 {
+ CREATE TABLE costs(iLang, cFrom, cTo, iCost);
+ INSERT INTO costs VALUES(0, 'a', 'e', 1);
+ INSERT INTO costs VALUES(0, 'e', 'i', 1);
+ INSERT INTO costs VALUES(0, 'i', 'o', 1);
+ INSERT INTO costs VALUES(0, 'o', 'u', 1);
+ INSERT INTO costs VALUES(0, 'u', 'a', 1);
+ CREATE VIRTUAL TABLE t3 USING spellfix1(edit_cost_table=costs);
+}
+
+do_test 3.2 {
+ foreach w $vocab {
+ execsql { INSERT INTO t3(word) VALUES($w) }
+ }
+} {}
+
+foreach {tn word res} {
+ 1 kos* {kosher 3 kiosk 4 kudo 2 kiss 3 kissed 3}
+ 2 kellj* {killjoy 5 kill 4 killed 4 killer 4 killers 4}
+ 3 kellj {kill 4 kills 5 killjoy 7 keel 4 killed 6}
+} {
+ do_execsql_test 3.2.$tn {
+ SELECT word, matchlen FROM t3 WHERE word MATCH $word
+ ORDER BY score, word LIMIT 5
+ } $res
+}
+
+do_execsql_test 4.0 {
+ INSERT INTO t3(command) VALUES('edit_cost_table=NULL');
+}
+foreach {tn word res} {
+ 1 kosher {kosher 0 kisser 51 kissers 76 kissed 126 kisses 126}
+ 2 kellj {keels 60 killjoy 68 kills 80 keel 120 kill 125}
+ 3 kashar {kosher 80 kisser 91 kissers 116 kissed 166 kisses 166}
+} {
+ do_execsql_test 4.1.$tn {
+ SELECT word, distance FROM t3 WHERE word MATCH $word
+ ORDER BY score, word LIMIT 5
+ } $res
+}
+do_execsql_test 5.0 {
+ CREATE TABLE costs2(iLang, cFrom, cTo, iCost);
+ INSERT INTO costs2 VALUES(0, 'a', 'o', 1);
+ INSERT INTO costs2 VALUES(0, 'e', 'o', 4);
+ INSERT INTO costs2 VALUES(0, 'i', 'o', 8);
+ INSERT INTO costs2 VALUES(0, 'u', 'o', 16);
+ INSERT INTO t3(command) VALUES('edit_cost_table="costs2"');
+}
+
+foreach {tn word res} {
+ 1 kasher {kosher 1}
+ 2 kesher {kosher 4}
+ 3 kisher {kosher 8}
+ 4 kosher {kosher 0}
+ 5 kusher {kosher 16}
+} {
+ do_execsql_test 5.1.$tn {
+ SELECT word, distance FROM t3 WHERE word MATCH $word
+ ORDER BY score, word LIMIT 1
+ } $res
+}
+
+#-------------------------------------------------------------------------
+# Try some queries by rowid.
+#
+do_execsql_test 6.1.1 {
+ SELECT word FROM t3 WHERE rowid = 10;
+} {keener}
+do_execsql_test 6.1.2 {
+ SELECT word, distance FROM t3 WHERE rowid = 10;
+} {keener {}}
+do_execsql_test 6.1.3 {
+ SELECT word, distance FROM t3 WHERE rowid = 10 AND word MATCH 'kiiner';
+} {keener 300}
+
+ifcapable trace {
+ proc trace_callback {sql} {
+ if {[string range $sql 0 2] == "-- "} {
+ lappend ::trace [string range $sql 3 end]
+ }
+ }
+
+ proc do_tracesql_test {tn sql {res {}}} {
+ set ::trace [list]
+ uplevel [list do_test $tn [subst -nocommands {
+ set vals [execsql {$sql}]
+ concat [set vals] [set ::trace]
+ }] [list {*}$res]]
+ }
+
+ db trace trace_callback
+ do_tracesql_test 6.2.1 {
+ SELECT word FROM t3 WHERE rowid = 10;
+ } {keener
+ {SELECT word, rank, NULL, langid, id FROM "main"."t3_vocab" WHERE rowid=?}
+ }
+ do_tracesql_test 6.2.2 {
+ SELECT word, distance FROM t3 WHERE rowid = 10;
+ } {keener {}
+ {SELECT word, rank, NULL, langid, id FROM "main"."t3_vocab" WHERE rowid=?}
+ }
+ do_tracesql_test 6.2.3 {
+ SELECT word, distance FROM t3 WHERE rowid = 10 AND word MATCH 'kiiner';
+ } {keener 300
+ {SELECT id, word, rank, k1 FROM "main"."t3_vocab" WHERE langid=0 AND k2>=?1 AND k2<?2}
+ }
+}
+
+
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/sqllimits1.test b/lang/sql/sqlite/test/sqllimits1.test
index bf4a2626..2cbad3ff 100644
--- a/lang/sql/sqlite/test/sqllimits1.test
+++ b/lang/sql/sqlite/test/sqllimits1.test
@@ -319,18 +319,22 @@ do_test sqllimits1-5.14.4 {
catch {sqlite3_bind_text $::STMT 1 $::str1 -1} res
set res
} {SQLITE_TOOBIG}
-do_test sqllimits1-5.14.5 {
- catch {sqlite3_bind_text16 $::STMT 1 $::str1 -1} res
- set res
-} {SQLITE_TOOBIG}
+ifcapable utf16 {
+ do_test sqllimits1-5.14.5 {
+ catch {sqlite3_bind_text16 $::STMT 1 $::str1 -1} res
+ set res
+ } {SQLITE_TOOBIG}
+}
do_test sqllimits1-5.14.6 {
catch {sqlite3_bind_text $::STMT 1 $::str1 $np1} res
set res
} {SQLITE_TOOBIG}
-do_test sqllimits1-5.14.7 {
- catch {sqlite3_bind_text16 $::STMT 1 $::str1 $np1} res
- set res
-} {SQLITE_TOOBIG}
+ifcapable utf16 {
+ do_test sqllimits1-5.14.7 {
+ catch {sqlite3_bind_text16 $::STMT 1 $::str1 $np1} res
+ set res
+ } {SQLITE_TOOBIG}
+}
do_test sqllimits1-5.14.8 {
set n [expr {$np1-1}]
catch {sqlite3_bind_text $::STMT 1 $::str1 $n} res
@@ -755,7 +759,7 @@ ifcapable attach {
do_test sqllimits1-12.1 {
set max $::SQLITE_MAX_ATTACHED
for {set i 0} {$i < ($max)} {incr i} {
- file delete -force test${i}.db test${i}.db-journal
+ forcedelete test${i}.db test${i}.db-journal
}
for {set i 0} {$i < ($max)} {incr i} {
execsql "ATTACH 'test${i}.db' AS aux${i}"
diff --git a/lang/sql/sqlite/test/stat.test b/lang/sql/sqlite/test/stat.test
index e1aeaa9e..f0447e45 100644
--- a/lang/sql/sqlite/test/stat.test
+++ b/lang/sql/sqlite/test/stat.test
@@ -15,7 +15,7 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
-ifcapable !vtab {
+ifcapable !vtab||!compound {
finish_test
return
}
@@ -36,7 +36,8 @@ ifcapable wal {
do_execsql_test stat-0.1 {
PRAGMA journal_mode = WAL;
PRAGMA journal_mode = delete;
- SELECT * FROM stat;
+ SELECT name, path, pageno, pagetype, ncell, payload, unused, mx_payload
+ FROM stat;
} {wal delete sqlite_master / 1 leaf 0 0 916 0}
}
@@ -50,17 +51,20 @@ do_test stat-1.0 {
} {}
do_test stat-1.1 {
execsql {
- SELECT * FROM stat WHERE name = 't1';
+ SELECT name, path, pageno, pagetype, ncell, payload, unused, mx_payload
+ FROM stat WHERE name = 't1';
}
} {t1 / 2 leaf 2 10 998 5}
do_test stat-1.2 {
execsql {
- SELECT * FROM stat WHERE name = 'i1';
+ SELECT name, path, pageno, pagetype, ncell, payload, unused, mx_payload
+ FROM stat WHERE name = 'i1';
}
} {i1 / 3 leaf 2 10 1000 5}
do_test stat-1.3 {
execsql {
- SELECT * FROM stat WHERE name = 'sqlite_master';
+ SELECT name, path, pageno, pagetype, ncell, payload, unused, mx_payload
+ FROM stat WHERE name = 'sqlite_master';
}
} {sqlite_master / 1 leaf 2 77 831 40}
do_test stat-1.4 {
@@ -72,12 +76,18 @@ do_test stat-1.4 {
do_execsql_test stat-2.1 {
CREATE TABLE t3(a PRIMARY KEY, b);
INSERT INTO t3(rowid, a, b) VALUES(2, a_string(111), a_string(222));
- INSERT INTO t3 SELECT a_string(110+rowid), a_string(221+rowid) FROM t3;
- INSERT INTO t3 SELECT a_string(110+rowid), a_string(221+rowid) FROM t3;
- INSERT INTO t3 SELECT a_string(110+rowid), a_string(221+rowid) FROM t3;
- INSERT INTO t3 SELECT a_string(110+rowid), a_string(221+rowid) FROM t3;
- INSERT INTO t3 SELECT a_string(110+rowid), a_string(221+rowid) FROM t3;
- SELECT * FROM stat WHERE name != 'sqlite_master';
+ INSERT INTO t3 SELECT a_string(110+rowid), a_string(221+rowid) FROM t3
+ ORDER BY rowid;
+ INSERT INTO t3 SELECT a_string(110+rowid), a_string(221+rowid) FROM t3
+ ORDER BY rowid;
+ INSERT INTO t3 SELECT a_string(110+rowid), a_string(221+rowid) FROM t3
+ ORDER BY rowid;
+ INSERT INTO t3 SELECT a_string(110+rowid), a_string(221+rowid) FROM t3
+ ORDER BY rowid;
+ INSERT INTO t3 SELECT a_string(110+rowid), a_string(221+rowid) FROM t3
+ ORDER BY rowid;
+ SELECT name, path, pageno, pagetype, ncell, payload, unused, mx_payload
+ FROM stat WHERE name != 'sqlite_master';
} [list \
sqlite_autoindex_t3_1 / 3 internal 3 368 623 125 \
sqlite_autoindex_t3_1 /000/ 8 leaf 8 946 46 123 \
@@ -102,54 +112,66 @@ do_execsql_test stat-2.1 {
t3 /00e/ 22 leaf 2 730 276 366 \
t3 /00f/ 23 leaf 2 738 268 370 \
]
-do_execsql_test stat-2.2 { DROP TABLE t3 } {}
+
+# With every index entry overflowing, make sure no pages are missed
+# (other than the locking page which is 64 in this test build.)
+#
+do_execsql_test stat-2.2 {
+ UPDATE t3 SET a=a||hex(randomblob(700));
+ VACUUM;
+ SELECT pageno FROM stat EXCEPT SELECT pageno-1 FROM stat;
+} {64 136}
+
+do_execsql_test stat-2.3 { DROP TABLE t3; VACUUM; } {}
do_execsql_test stat-3.1 {
CREATE TABLE t4(x);
CREATE INDEX i4 ON t4(x);
INSERT INTO t4(rowid, x) VALUES(2, a_string(7777));
- SELECT * FROM stat WHERE name != 'sqlite_master';
+ SELECT name, path, pageno, pagetype, ncell, payload, unused, mx_payload
+ FROM stat WHERE name != 'sqlite_master';
} [list \
i4 / 3 leaf 1 103 905 7782 \
- i4 /000+000000 9 overflow 0 1020 0 0 \
- i4 /000+000001 10 overflow 0 1020 0 0 \
- i4 /000+000002 11 overflow 0 1020 0 0 \
- i4 /000+000003 12 overflow 0 1020 0 0 \
- i4 /000+000004 13 overflow 0 1020 0 0 \
- i4 /000+000005 14 overflow 0 1020 0 0 \
- i4 /000+000006 15 overflow 0 1020 0 0 \
- i4 /000+000007 16 overflow 0 539 481 0 \
+ i4 /000+000000 4 overflow 0 1020 0 0 \
+ i4 /000+000001 5 overflow 0 1020 0 0 \
+ i4 /000+000002 6 overflow 0 1020 0 0 \
+ i4 /000+000003 7 overflow 0 1020 0 0 \
+ i4 /000+000004 8 overflow 0 1020 0 0 \
+ i4 /000+000005 9 overflow 0 1020 0 0 \
+ i4 /000+000006 10 overflow 0 1020 0 0 \
+ i4 /000+000007 11 overflow 0 539 481 0 \
t4 / 2 leaf 1 640 367 7780 \
- t4 /000+000000 22 overflow 0 1020 0 0 \
- t4 /000+000001 23 overflow 0 1020 0 0 \
- t4 /000+000002 21 overflow 0 1020 0 0 \
- t4 /000+000003 20 overflow 0 1020 0 0 \
- t4 /000+000004 19 overflow 0 1020 0 0 \
- t4 /000+000005 18 overflow 0 1020 0 0 \
- t4 /000+000006 17 overflow 0 1020 0 0 \
+ t4 /000+000000 12 overflow 0 1020 0 0 \
+ t4 /000+000001 13 overflow 0 1020 0 0 \
+ t4 /000+000002 14 overflow 0 1020 0 0 \
+ t4 /000+000003 15 overflow 0 1020 0 0 \
+ t4 /000+000004 16 overflow 0 1020 0 0 \
+ t4 /000+000005 17 overflow 0 1020 0 0 \
+ t4 /000+000006 18 overflow 0 1020 0 0 \
]
do_execsql_test stat-4.1 {
CREATE TABLE t5(x);
CREATE INDEX i5 ON t5(x);
- SELECT * FROM stat WHERE name = 't5' OR name = 'i5';
+ SELECT name, path, pageno, pagetype, ncell, payload, unused, mx_payload
+ FROM stat WHERE name = 't5' OR name = 'i5';
} [list \
- i5 / 5 leaf 0 0 1016 0 \
- t5 / 4 leaf 0 0 1016 0 \
+ i5 / 20 leaf 0 0 1016 0 \
+ t5 / 19 leaf 0 0 1016 0 \
]
db close
-file delete -force test.db
+forcedelete test.db
sqlite3 db test.db
register_dbstat_vtab db
-breakpoint
do_execsql_test stat-5.1 {
PRAGMA auto_vacuum = OFF;
CREATE VIRTUAL TABLE temp.stat USING dbstat;
CREATE TABLE t1(x);
INSERT INTO t1 VALUES(zeroblob(1513));
INSERT INTO t1 VALUES(zeroblob(1514));
- SELECT * FROM stat WHERE name = 't1';
+ SELECT name, path, pageno, pagetype, ncell, payload, unused, mx_payload
+ FROM stat WHERE name = 't1';
} [list \
t1 / 2 leaf 2 993 5 1517 \
t1 /000+000000 3 overflow 0 1020 0 0 \
diff --git a/lang/sql/sqlite/test/subquery.test b/lang/sql/sqlite/test/subquery.test
index 169cedac..93c3f28d 100644
--- a/lang/sql/sqlite/test/subquery.test
+++ b/lang/sql/sqlite/test/subquery.test
@@ -241,8 +241,11 @@ do_test subquery-2.5.3.1 {
} {10.0}
do_test subquery-2.5.3.2 {
# Verify that the t4i index was not used in the previous query
- set ::sqlite_query_plan
-} {t4 {}}
+ execsql {
+ EXPLAIN QUERY PLAN
+ SELECT * FROM t4 WHERE x IN (SELECT a FROM t3);
+ }
+} {~/t4i/}
do_test subquery-2.5.4 {
execsql {
DROP TABLE t3;
@@ -331,12 +334,97 @@ do_test subquery-3.3.5 {
}
} {1 1 2 1}
+# The following tests check for aggregate subqueries in an aggregate
+# query.
+#
+do_test subquery-3.4.1 {
+ execsql {
+ CREATE TABLE t34(x,y);
+ INSERT INTO t34 VALUES(106,4), (107,3), (106,5), (107,5);
+ SELECT a.x, avg(a.y)
+ FROM t34 AS a
+ GROUP BY a.x
+ HAVING NOT EXISTS( SELECT b.x, avg(b.y)
+ FROM t34 AS b
+ GROUP BY b.x
+ HAVING avg(a.y) > avg(b.y));
+ }
+} {107 4.0}
+do_test subquery-3.4.2 {
+ execsql {
+ SELECT a.x, avg(a.y) AS avg1
+ FROM t34 AS a
+ GROUP BY a.x
+ HAVING NOT EXISTS( SELECT b.x, avg(b.y) AS avg2
+ FROM t34 AS b
+ GROUP BY b.x
+ HAVING avg1 > avg2);
+ }
+} {107 4.0}
+do_test subquery-3.4.3 {
+ execsql {
+ SELECT
+ a.x,
+ avg(a.y),
+ NOT EXISTS ( SELECT b.x, avg(b.y)
+ FROM t34 AS b
+ GROUP BY b.x
+ HAVING avg(a.y) > avg(b.y)),
+ EXISTS ( SELECT c.x, avg(c.y)
+ FROM t34 AS c
+ GROUP BY c.x
+ HAVING avg(a.y) > avg(c.y))
+ FROM t34 AS a
+ GROUP BY a.x
+ ORDER BY a.x;
+ }
+} {106 4.5 0 1 107 4.0 1 0}
+
+do_test subquery-3.5.1 {
+ execsql {
+ CREATE TABLE t35a(x); INSERT INTO t35a VALUES(1),(2),(3);
+ CREATE TABLE t35b(y); INSERT INTO t35b VALUES(98), (99);
+ SELECT max((SELECT avg(y) FROM t35b)) FROM t35a;
+ }
+} {98.5}
+do_test subquery-3.5.2 {
+ execsql {
+ SELECT max((SELECT count(y) FROM t35b)) FROM t35a;
+ }
+} {2}
+do_test subquery-3.5.3 {
+ execsql {
+ SELECT max((SELECT count() FROM t35b)) FROM t35a;
+ }
+} {2}
+do_test subquery-3.5.4 {
+ catchsql {
+ SELECT max((SELECT count(x) FROM t35b)) FROM t35a;
+ }
+} {1 {misuse of aggregate: count()}}
+do_test subquery-3.5.5 {
+ catchsql {
+ SELECT max((SELECT count(x) FROM t35b)) FROM t35a;
+ }
+} {1 {misuse of aggregate: count()}}
+do_test subquery-3.5.6 {
+ catchsql {
+ SELECT max((SELECT a FROM (SELECT count(x) AS a FROM t35b))) FROM t35a;
+ }
+} {1 {misuse of aggregate: count()}}
+do_test subquery-3.5.7 {
+ execsql {
+ SELECT max((SELECT a FROM (SELECT count(y) AS a FROM t35b))) FROM t35a;
+ }
+} {2}
+
+
#------------------------------------------------------------------
# These tests - subquery-4.* - use the TCL statement cache to try
# and expose bugs to do with re-using statements that have been
# passed to sqlite3_reset().
#
-# One problem was that VDBE memory cells were not being initialised
+# One problem was that VDBE memory cells were not being initialized
# to NULL on the second and subsequent executions.
#
do_test subquery-4.1.1 {
diff --git a/lang/sql/sqlite/test/subquery2.test b/lang/sql/sqlite/test/subquery2.test
new file mode 100644
index 00000000..4406efcc
--- /dev/null
+++ b/lang/sql/sqlite/test/subquery2.test
@@ -0,0 +1,107 @@
+# 2011 September 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 correlated subqueries
+#
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set ::testprefix subquery2
+
+ifcapable !subquery {
+ finish_test
+ return
+}
+
+do_test subquery2-1.1 {
+ execsql {
+ BEGIN;
+ CREATE TABLE t1(a,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);
+ CREATE TABLE t2(c,d);
+ INSERT INTO t2 VALUES(1,1);
+ INSERT INTO t2 VALUES(3,9);
+ INSERT INTO t2 VALUES(5,25);
+ INSERT INTO t2 VALUES(7,49);
+ CREATE TABLE t3(e,f);
+ INSERT INTO t3 VALUES(1,1);
+ INSERT INTO t3 VALUES(3,27);
+ INSERT INTO t3 VALUES(5,125);
+ INSERT INTO t3 VALUES(7,343);
+ COMMIT;
+ }
+ execsql {
+ SELECT a FROM t1
+ WHERE b IN (SELECT x+1 FROM (SELECT DISTINCT f/(a*a) AS x FROM t3));
+ }
+} {1 3 5 7}
+do_test subquery2-1.2 {
+ execsql {
+ CREATE INDEX t1b ON t1(b);
+ SELECT a FROM t1
+ WHERE b IN (SELECT x+1 FROM (SELECT DISTINCT f/(a*a) AS x FROM t3));
+ }
+} {1 3 5 7}
+
+do_test subquery2-1.11 {
+ execsql {
+ SELECT a FROM t1
+ WHERE +b=(SELECT x+1 FROM (SELECT DISTINCT f/(a*a) AS x FROM t3));
+ }
+} {1}
+do_test subquery2-1.12 {
+ execsql {
+ SELECT a FROM t1
+ WHERE b=(SELECT x+1 FROM (SELECT DISTINCT f/(a*a) AS x FROM t3));
+ }
+} {1}
+
+do_test subquery2-1.21 {
+ execsql {
+ SELECT a FROM t1
+ WHERE +b=(SELECT x+1 FROM
+ (SELECT DISTINCT f/d AS x FROM t2 JOIN t3 ON d*a=f))
+ }
+} {1 3 5 7}
+do_test subquery2-1.22 {
+ execsql {
+ SELECT a FROM t1
+ WHERE b=(SELECT x+1 FROM
+ (SELECT DISTINCT f/d AS x FROM t2 JOIN t3 ON d*a=f))
+ }
+} {1 3 5 7}
+
+#-------------------------------------------------------------------------
+# Test that ticket d6b36be38a has been fixed.
+do_execsql_test 2.1 {
+ CREATE TABLE t4(a, b);
+ CREATE TABLE t5(a, b);
+ INSERT INTO t5 VALUES(3, 5);
+
+ INSERT INTO t4 VALUES(1, 1);
+ INSERT INTO t4 VALUES(2, 3);
+ INSERT INTO t4 VALUES(3, 6);
+ INSERT INTO t4 VALUES(4, 10);
+ INSERT INTO t4 VALUES(5, 15);
+}
+
+do_execsql_test 2.2 {
+ SELECT *
+ FROM (SELECT * FROM t4 ORDER BY a LIMIT -1 OFFSET 1)
+ LIMIT (SELECT a FROM t5)
+} {2 3 3 6 4 10}
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/superlock.test b/lang/sql/sqlite/test/superlock.test
index b12863f7..8199d521 100644
--- a/lang/sql/sqlite/test/superlock.test
+++ b/lang/sql/sqlite/test/superlock.test
@@ -48,6 +48,11 @@ do_execsql_test 1.1 {
PRAGMA journal_mode = DELETE;
} {delete}
+ifcapable !wal {
+ finish_test
+ return
+}
+
do_test 1.2 { sqlite3demo_superlock unlock test.db } {unlock}
do_catchsql_test 1.3 { SELECT * FROM t1 } {1 {database is locked}}
do_test 1.4 { unlock } {}
@@ -71,7 +76,10 @@ do_catchsql_test 3.4 { INSERT INTO t1 VALUES(5, 6)} {1 {database is locked}}
do_catchsql_test 3.5 { PRAGMA wal_checkpoint } {0 {1 -1 -1}}
do_test 3.6 { unlock } {}
-do_execsql_test 4.1 { PRAGMA wal_checkpoint } {0 2 2}
+# At this point the WAL file consists of a single frame only - written
+# by test case 3.1. If the ZERO_DAMAGE flag were not set, it would consist
+# of two frames - the frame written by 3.1 and a padding frame.
+do_execsql_test 4.1 { PRAGMA wal_checkpoint } {0 1 1}
do_test 4.2 { sqlite3demo_superlock unlock test.db } {unlock}
do_catchsql_test 4.3 { SELECT * FROM t1 } {1 {database is locked}}
diff --git a/lang/sql/sqlite/test/sync.test b/lang/sql/sqlite/test/sync.test
index 98aa7731..14252b5c 100644
--- a/lang/sql/sqlite/test/sync.test
+++ b/lang/sql/sqlite/test/sync.test
@@ -19,32 +19,38 @@ set testdir [file dirname $argv0]
source $testdir/tester.tcl
#
-# These tests are only applicable on unix when pager pragma are
+# These tests are only applicable when pager pragma are
# enabled. Also, since every test uses an ATTACHed database, they
# are only run when ATTACH is enabled.
#
-if {$::tcl_platform(platform)!="unix"} {
- finish_test
- return
-}
ifcapable !pager_pragmas||!attach {
finish_test
return
}
+set sqlite_sync_count 0
+proc cond_incr_sync_count {adj} {
+ global sqlite_sync_count
+ if {$::tcl_platform(platform) == "windows"} {
+ incr sqlite_sync_count $adj
+ } {
+ ifcapable !dirsync {
+ incr sqlite_sync_count $adj
+ }
+ }
+}
+
do_test sync-1.1 {
set sqlite_sync_count 0
- file delete -force test2.db
- file delete -force test2.db-journal
+ forcedelete test2.db
+ forcedelete test2.db-journal
execsql {
PRAGMA fullfsync=OFF;
CREATE TABLE t1(a,b);
ATTACH DATABASE 'test2.db' AS db2;
CREATE TABLE db2.t2(x,y);
}
- ifcapable !dirsync {
- incr sqlite_sync_count 2
- }
+ cond_incr_sync_count 2
set sqlite_sync_count
} 8
ifcapable pager_pragmas {
@@ -58,9 +64,7 @@ ifcapable pager_pragmas {
INSERT INTO t2 VALUES(3,4);
COMMIT;
}
- ifcapable !dirsync {
- incr sqlite_sync_count 3
- }
+ cond_incr_sync_count 3
set sqlite_sync_count
} 8
}
@@ -74,9 +78,7 @@ do_test sync-1.3 {
INSERT INTO t2 VALUES(5,6);
COMMIT;
}
- ifcapable !dirsync {
- incr sqlite_sync_count 3
- }
+ cond_incr_sync_count 3
set sqlite_sync_count
} 10
ifcapable pager_pragmas {
diff --git a/lang/sql/sqlite/test/syscall.test b/lang/sql/sqlite/test/syscall.test
index 4442612a..5bf12258 100644
--- a/lang/sql/sqlite/test/syscall.test
+++ b/lang/sql/sqlite/test/syscall.test
@@ -59,7 +59,8 @@ do_test 2.1.2 { test_syscall exists nosuchcall } 0
foreach s {
open close access getcwd stat fstat ftruncate
fcntl read pread write pwrite fchmod fallocate
- pread64 pwrite64
+ pread64 pwrite64 unlink openDirectory mkdir rmdir
+ statvfs fchown umask mmap munmap mremap
} {
if {[test_syscall exists $s]} {lappend syscall_list $s}
}
diff --git a/lang/sql/sqlite/test/sysfault.test b/lang/sql/sqlite/test/sysfault.test
index 07d525ca..92fb534d 100644
--- a/lang/sql/sqlite/test/sysfault.test
+++ b/lang/sql/sqlite/test/sysfault.test
@@ -243,5 +243,35 @@ do_faultsim_test 3 -faults vfsfault-* -prep {
faultsim_test_result {0 20000}
}
-finish_test
+#-------------------------------------------------------------------------
+# Test errors in mmap().
+#
+proc vfsfault_install {} {
+ test_syscall reset
+ test_syscall install {mmap}
+}
+
+faultsim_delete_and_reopen
+execsql {
+ CREATE TABLE t1(a, b);
+ INSERT INTO t1 VALUES(1, 2);
+}
+faultsim_save_and_close
+
+do_faultsim_test 4 -faults vfsfault-* -prep {
+ faultsim_restore_and_reopen
+ file_control_chunksize_test db main 8192
+ execsql {
+ PRAGMA mmap_size = 1000000;
+ }
+} -body {
+ test_syscall errno mmap EACCES
+
+ execsql {
+ SELECT * FROM t1;
+ }
+} -test {
+ faultsim_test_result {0 {1 2}} {1 {disk I/O error}}
+}
+finish_test
diff --git a/lang/sql/sqlite/test/table.test b/lang/sql/sqlite/test/table.test
index 5fa91166..ed9efc02 100644
--- a/lang/sql/sqlite/test/table.test
+++ b/lang/sql/sqlite/test/table.test
@@ -260,6 +260,19 @@ do_test table-5.2 {
catchsql {DROP TABLE IF EXISTS sqlite_master}
} {1 {table sqlite_master may not be dropped}}
+# Dropping sqlite_statN tables is OK.
+#
+do_test table-5.2.1 {
+ db eval {
+ ANALYZE;
+ DROP TABLE IF EXISTS sqlite_stat1;
+ DROP TABLE IF EXISTS sqlite_stat2;
+ DROP TABLE IF EXISTS sqlite_stat3;
+ DROP TABLE IF EXISTS sqlite_stat4;
+ SELECT name FROM sqlite_master WHERE name GLOB 'sqlite_stat*';
+ }
+} {}
+
# Make sure an EXPLAIN does not really create a new table
#
do_test table-5.3 {
@@ -451,7 +464,7 @@ do_test table-10.1 {
CREATE TABLE t6(a REFERENCES t4(a) NOT NULL);
INSERT INTO t6 VALUES(NULL);
}
-} {1 {t6.a may not be NULL}}
+} {1 {NOT NULL constraint failed: t6.a}}
do_test table-10.2 {
catchsql {
DROP TABLE t6;
@@ -667,8 +680,8 @@ ifcapable attach {
# Now attach a database and ensure that a table can be created in the
# attached database whilst in a callback from a query on the main database.
do_test table-14.3 {
- file delete -force test2.db
- file delete -force test2.db-journal
+ forcedelete test2.db
+ forcedelete test2.db-journal
execsql {
ATTACH 'test2.db' as aux;
}
diff --git a/lang/sql/sqlite/test/tableopts.test b/lang/sql/sqlite/test/tableopts.test
new file mode 100644
index 00000000..0b2457ec
--- /dev/null
+++ b/lang/sql/sqlite/test/tableopts.test
@@ -0,0 +1,76 @@
+# 2013-10-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.
+#
+#***********************************************************************
+#
+# Test the operation of table-options in the WITH clause of the
+# CREATE TABLE statement.
+#
+
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+do_test tableopt-1.1 {
+ catchsql {
+ CREATE TABLE t1(a,b) WITHOUT rowid;
+ }
+} {1 {PRIMARY KEY missing on table t1}}
+do_test tableopt-1.1b {
+ catchsql {
+ CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT,b) WITHOUT rowid;
+ }
+} {1 {AUTOINCREMENT not allowed on WITHOUT ROWID tables}}
+do_test tableopt-1.2 {
+ catchsql {
+ CREATE TABLE t1(a,b) WITHOUT unknown2;
+ }
+} {1 {unknown table option: unknown2}}
+
+do_execsql_test tableopt-2.1 {
+ CREATE TABLE t1(a, b, c, PRIMARY KEY(a,b)) WITHOUT rowid;
+ INSERT INTO t1 VALUES(1,2,3),(2,3,4);
+ SELECT c FROM t1 WHERE a IN (1,2) ORDER BY b;
+} {3 4}
+do_test tableopt-2.1.1 {
+ catchsql {
+ SELECT rowid, * FROM t1;
+ }
+} {1 {no such column: rowid}}
+do_test tableopt-2.1.2 {
+ catchsql {
+ SELECT _rowid_, * FROM t1;
+ }
+} {1 {no such column: _rowid_}}
+do_test tableopt-2.1.3 {
+ catchsql {
+ SELECT oid, * FROM t1;
+ }
+} {1 {no such column: oid}}
+do_execsql_test tableopt-2.2 {
+ VACUUM;
+ SELECT c FROM t1 WHERE a IN (1,2) ORDER BY b;
+} {3 4}
+do_test tableopt-2.3 {
+ sqlite3 db2 test.db
+ db2 eval {SELECT c FROM t1 WHERE a IN (1,2) ORDER BY b;}
+} {3 4}
+db2 close
+
+# Make sure the "without" keyword is still usable as a table or
+# column name.
+#
+do_execsql_test tableopt-3.1 {
+ CREATE TABLE without(x INTEGER PRIMARY KEY, without TEXT);
+ INSERT INTO without VALUES(1, 'xyzzy'), (2, 'fizzle');
+ SELECT * FROM without WHERE without='xyzzy';
+} {1 xyzzy}
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/tclsqlite.test b/lang/sql/sqlite/test/tclsqlite.test
index 8db04ebf..3d9cd46a 100644
--- a/lang/sql/sqlite/test/tclsqlite.test
+++ b/lang/sql/sqlite/test/tclsqlite.test
@@ -25,7 +25,7 @@ source $testdir/tester.tcl
if {[sqlite3 -has-codec]} {
set r "sqlite_orig HANDLE FILENAME ?-key CODEC-KEY?"
} else {
- set r "sqlite_orig HANDLE FILENAME ?-vfs VFSNAME? ?-readonly BOOLEAN? ?-create BOOLEAN? ?-nomutex BOOLEAN? ?-fullmutex BOOLEAN?"
+ set r "sqlite_orig HANDLE FILENAME ?-vfs VFSNAME? ?-readonly BOOLEAN? ?-create BOOLEAN? ?-nomutex BOOLEAN? ?-fullmutex BOOLEAN? ?-uri BOOLEAN?"
}
do_test tcl-1.1 {
set v [catch {sqlite3 bogus} msg]
@@ -143,11 +143,11 @@ do_test tcl-1.21 {
set v [catch {db total_changes xyz} msg]
lappend v $msg
} {1 {wrong # args: should be "db total_changes "}}
-do_test tcl-1.20 {
+do_test tcl-1.22 {
set v [catch {db copy} msg]
lappend v $msg
} {1 {wrong # args: should be "db copy CONFLICT-ALGORITHM TABLE FILENAME ?SEPARATOR? ?NULLINDICATOR?"}}
-do_test tcl-1.21 {
+do_test tcl-1.23 {
set v [catch {sqlite3 db2 test.db -vfs nosuchvfs} msg]
lappend v $msg
} {1 {no such vfs: nosuchvfs}}
@@ -319,14 +319,23 @@ do_test tcl-8.1 {
execsql {INSERT INTO t1 VALUES(30,NULL)}
db eval {SELECT * FROM t1 WHERE b IS NULL}
} {30 NaN}
+proc concatFunc args {return [join $args {}]}
do_test tcl-8.2 {
+ db function concat concatFunc
+ db eval {SELECT concat('a', b, 'z') FROM t1 WHERE b is NULL}
+} {aNaNz}
+do_test tcl-8.3 {
db nullvalue NULL
db nullvalue
} {NULL}
-do_test tcl-8.3 {
+do_test tcl-8.4 {
db nullvalue {}
db eval {SELECT * FROM t1 WHERE b IS NULL}
} {30 {}}
+do_test tcl-8.5 {
+ db function concat concatFunc
+ db eval {SELECT concat('a', b, 'z') FROM t1 WHERE b is NULL}
+} {az}
# Test the return type of user-defined functions
#
@@ -617,5 +626,16 @@ ifcapable tclvar {
} {31323334 blob}
}
+db func xCall xCall
+proc xCall {} { return "value" }
+do_execsql_test tcl-14.1 {
+ CREATE TABLE t6(x);
+ INSERT INTO t6 VALUES(1);
+}
+do_test tcl-14.2 {
+ db one {SELECT x FROM t6 WHERE xCall()!='value'}
+} {}
+
+
finish_test
diff --git a/lang/sql/sqlite/test/temptable.test b/lang/sql/sqlite/test/temptable.test
index ad85f7e9..6a1e2b98 100644
--- a/lang/sql/sqlite/test/temptable.test
+++ b/lang/sql/sqlite/test/temptable.test
@@ -150,7 +150,7 @@ do_test temptable-3.4 {
# Check for correct name collision processing. A name collision can
# occur when process A creates a temporary table T then process B
# creates a permanent table also named T. The temp table in process A
-# hides the existance of the permanent table.
+# hides the existence of the permanent table.
#
do_test temptable-4.1 {
execsql {
@@ -292,6 +292,7 @@ do_test temptable-5.1 {
execsql {
CREATE TEMP TABLE mask(a,b,c)
} db2
+ if {[permutation]=="prepare"} { db2 cache flush }
execsql {
CREATE INDEX mask ON t2(x);
SELECT * FROM t2;
@@ -403,7 +404,7 @@ do_test temptable-6.8 {
}
} {1 {no such table: t9}}
-file delete -force test2.db test2.db-journal
+forcedelete test2.db test2.db-journal
ifcapable attach {
do_test temptable-7.1 {
catchsql {
@@ -414,14 +415,14 @@ ifcapable attach {
}
# Need to do the following for tcl 8.5 on mac. On that configuration, the
-# -readonly flag is taken so seriously that a subsequent [file delete -force]
+# -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}
do_test temptable-8.0 {
db close
- catch {file delete -force test.db}
+ catch {forcedelete test.db}
sqlite3 db test.db
} {}
do_test temptable-8.1 {
diff --git a/lang/sql/sqlite/test/temptrigger.test b/lang/sql/sqlite/test/temptrigger.test
index ececc4a8..551c6204 100644
--- a/lang/sql/sqlite/test/temptrigger.test
+++ b/lang/sql/sqlite/test/temptrigger.test
@@ -13,6 +13,7 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
+set testprefix temptrigger
ifcapable {!trigger || !shared_cache} { finish_test ; return }
@@ -157,8 +158,8 @@ sqlite3_enable_shared_cache $::enable_shared_cache
# temptrigger-3.4: Check that the temp trigger can be dropped without error.
#
do_test temptrigger-3.1 {
- catch { file delete -force test2.db test2.db-journal }
- catch { file delete -force test.db test.db-journal }
+ catch { forcedelete test2.db test2.db-journal }
+ catch { forcedelete test.db test.db-journal }
sqlite3 db test.db
sqlite3 db2 test2.db
execsql { CREATE TABLE t2(a, b) } db2
@@ -201,4 +202,78 @@ do_test temptrigger-3.4 {
catch { db close }
catch { db2 close }
+
+#-------------------------------------------------------------------------
+# Test that creating a temp table after a temp trigger on the same name
+# has been created is an error.
+#
+reset_db
+do_execsql_test 4.0 {
+ CREATE TABLE t1(x);
+ CREATE TEMP TRIGGER tr1 BEFORE INSERT ON t1 BEGIN
+ SELECT 1,2,3;
+ END;
+}
+
+do_execsql_test 4.1 {
+ CREATE TEMP TABLE t1(x);
+}
+
+#-------------------------------------------------------------------------
+# Test that no harm is done if the table a temp trigger is attached to is
+# deleted by an external connection.
+#
+reset_db
+do_execsql_test 5.0 {
+ CREATE TABLE t1(x);
+ CREATE TEMP TRIGGER tr1 BEFORE INSERT ON t1 BEGIN SELECT 1,2,3; END;
+}
+
+do_test 5.1 {
+ sqlite3 db2 test.db
+ execsql { DROP TABLE t1 } db2
+} {}
+
+do_execsql_test 5.2 {
+ SELECT * FROM sqlite_master;
+ SELECT * FROM sqlite_temp_master;
+} {
+ trigger tr1 t1 0
+ {CREATE TRIGGER tr1 BEFORE INSERT ON t1 BEGIN SELECT 1,2,3; END}
+}
+db2 close
+
+#-------------------------------------------------------------------------
+# Check that if a second connection creates a table in an attached database
+# with the same name as a table in the main database that has a temp
+# trigger attached to it nothing goes awry.
+#
+reset_db
+forcedelete test.db2
+
+do_execsql_test 6.0 {
+ CREATE TABLE t1(x);
+ CREATE TEMP TRIGGER tr1 BEFORE INSERT ON t1 BEGIN
+ SELECT raise(ABORT, 'error');
+ END;
+ ATTACH 'test.db2' AS aux;
+}
+
+do_test 6.1 {
+ sqlite3 db2 test.db2
+ execsql { CREATE TABLE t1(a, b, c); } db2
+} {}
+
+do_execsql_test 6.2 {
+ SELECT type,name,tbl_name,sql FROM aux.sqlite_master;
+ INSERT INTO aux.t1 VALUES(1,2,3);
+} {
+ table t1 t1 {CREATE TABLE t1(a, b, c)}
+}
+
+do_catchsql_test 6.3 {
+ INSERT INTO main.t1 VALUES(1);
+} {1 error}
+db2 close
+
finish_test
diff --git a/lang/sql/sqlite/test/tester.tcl b/lang/sql/sqlite/test/tester.tcl
index 941e12e7..f40a064a 100644
--- a/lang/sql/sqlite/test/tester.tcl
+++ b/lang/sql/sqlite/test/tester.tcl
@@ -14,18 +14,24 @@
# $Id: tester.tcl,v 1.143 2009/04/09 01:23:49 drh Exp $
#-------------------------------------------------------------------------
-# The commands provided by the code in this file to help with creating
+# The commands provided by the code in this file to help with creating
# test cases are as follows:
#
# Commands to manipulate the db and the file-system at a high level:
#
+# is_relative_file
+# test_pwd
+# get_pwd
# copy_file FROM TO
-# drop_all_table ?DB?
+# delete_file FILENAME
+# drop_all_tables ?DB?
+# forcecopy FROM TO
# forcedelete FILENAME
#
# Test the capability of the SQLite version built into the interpreter to
# determine if a specific test can be run:
#
+# capable EXPR
# ifcapable EXPR
#
# Calulate checksums based on database contents:
@@ -36,6 +42,7 @@
#
# Commands to execute/explain SQL statements:
#
+# memdbsql SQL
# stepsql DB SQL
# execsql2 SQL
# explain_no_trace SQL
@@ -48,14 +55,16 @@
# do_ioerr_test TESTNAME ARGS...
# crashsql ARGS...
# integrity_check TESTNAME ?DB?
+# verify_ex_errcode TESTNAME EXPECTED ?DB?
# do_test TESTNAME SCRIPT EXPECTED
# do_execsql_test TESTNAME SQL EXPECTED
# do_catchsql_test TESTNAME SQL EXPECTED
+# do_timed_execsql_test TESTNAME SQL EXPECTED
#
# Commands providing a lower level interface to the global test counters:
#
# set_test_counter COUNTER ?VALUE?
-# omit_test TESTNAME REASON
+# omit_test TESTNAME REASON ?APPEND?
# fail_test TESTNAME
# incr_ntest
#
@@ -73,7 +82,7 @@
# presql
#
-# Set the precision of FP arithmatic used by the interpreter. And
+# Set the precision of FP arithmatic used by the interpreter. And
# configure SQLite to take database file locks on the page that begins
# 64KB into the database file instead of the one 1GB in. This means
# the code that handles that special case can be tested without creating
@@ -83,7 +92,7 @@ set tcl_precision 15
sqlite3_test_control_pending_byte 0x0010000
-# If the pager codec is available, create a wrapper for the [sqlite3]
+# If the pager codec is available, create a wrapper for the [sqlite3]
# command that appends "-key {xyzzy}" to the command line. i.e. this:
#
# sqlite3 db test.db
@@ -115,14 +124,235 @@ if {[info command sqlite_orig]==""} {
}
set res
} else {
- # This command is not opening a new database connection. Pass the
- # arguments through to the C implemenation as the are.
+ # This command is not opening a new database connection. Pass the
+ # arguments through to the C implementation as the are.
#
uplevel 1 sqlite_orig $args
}
}
}
+proc getFileRetries {} {
+ if {![info exists ::G(file-retries)]} {
+ #
+ # NOTE: Return the default number of retries for [file] operations. A
+ # value of zero or less here means "disabled".
+ #
+ return [expr {$::tcl_platform(platform) eq "windows" ? 10 : 0}]
+ }
+ return $::G(file-retries)
+}
+
+proc getFileRetryDelay {} {
+ if {![info exists ::G(file-retry-delay)]} {
+ #
+ # NOTE: Return the default number of milliseconds to wait when retrying
+ # failed [file] operations. A value of zero or less means "do not
+ # wait".
+ #
+ return 100; # TODO: Good default?
+ }
+ return $::G(file-retry-delay)
+}
+
+# Return the string representing the name of the current directory. On
+# Windows, the result is "normalized" to whatever our parent command shell
+# is using to prevent case-mismatch issues.
+#
+proc get_pwd {} {
+ if {$::tcl_platform(platform) eq "windows"} {
+ #
+ # NOTE: Cannot use [file normalize] here because it would alter the
+ # case of the result to what Tcl considers canonical, which would
+ # defeat the purpose of this procedure.
+ #
+ return [string map [list \\ /] \
+ [string trim [exec -- $::env(ComSpec) /c echo %CD%]]]
+ } else {
+ return [pwd]
+ }
+}
+
+# Copy file $from into $to. This is used because some versions of
+# TCL for windows (notably the 8.4.1 binary package shipped with the
+# current mingw release) have a broken "file copy" command.
+#
+proc copy_file {from to} {
+ do_copy_file false $from $to
+}
+
+proc forcecopy {from to} {
+ do_copy_file true $from $to
+}
+
+proc do_copy_file {force from to} {
+ set nRetry [getFileRetries] ;# Maximum number of retries.
+ set nDelay [getFileRetryDelay] ;# Delay in ms before retrying.
+
+ # On windows, sometimes even a [file copy -force] can fail. The cause is
+ # usually "tag-alongs" - programs like anti-virus software, automatic backup
+ # tools and various explorer extensions that keep a file open a little longer
+ # than we expect, causing the delete to fail.
+ #
+ # The solution is to wait a short amount of time before retrying the copy.
+ #
+ if {$nRetry > 0} {
+ for {set i 0} {$i<$nRetry} {incr i} {
+ set rc [catch {
+ if {$force} {
+ file copy -force $from $to
+ } else {
+ file copy $from $to
+ }
+ } msg]
+ if {$rc==0} break
+ if {$nDelay > 0} { after $nDelay }
+ }
+ if {$rc} { error $msg }
+ } else {
+ if {$force} {
+ file copy -force $from $to
+ } else {
+ file copy $from $to
+ }
+ }
+}
+
+# Check if a file name is relative
+#
+proc is_relative_file { file } {
+ return [expr {[file pathtype $file] != "absolute"}]
+}
+
+# If the VFS supports using the current directory, returns [pwd];
+# otherwise, it returns only the provided suffix string (which is
+# empty by default).
+#
+proc test_pwd { args } {
+ if {[llength $args] > 0} {
+ set suffix1 [lindex $args 0]
+ if {[llength $args] > 1} {
+ set suffix2 [lindex $args 1]
+ } else {
+ set suffix2 $suffix1
+ }
+ } else {
+ set suffix1 ""; set suffix2 ""
+ }
+ ifcapable curdir {
+ return "[get_pwd]$suffix1"
+ } else {
+ return $suffix2
+ }
+}
+
+# Delete a file or directory
+#
+proc delete_file {args} {
+ do_delete_file false {*}$args
+}
+
+proc forcedelete {args} {
+ do_delete_file true {*}$args
+}
+
+proc do_delete_file {force args} {
+ set nRetry [getFileRetries] ;# Maximum number of retries.
+ set nDelay [getFileRetryDelay] ;# Delay in ms before retrying.
+
+ foreach filename $args {
+ # On windows, sometimes even a [file delete -force] can fail just after
+ # a file is closed. The cause is usually "tag-alongs" - programs like
+ # anti-virus software, automatic backup tools and various explorer
+ # extensions that keep a file open a little longer than we expect, causing
+ # the delete to fail.
+ #
+ # The solution is to wait a short amount of time before retrying the
+ # delete.
+ #
+ if {$nRetry > 0} {
+ for {set i 0} {$i<$nRetry} {incr i} {
+ set rc [catch {
+ if {$force} {
+ file delete -force $filename
+ } else {
+ file delete $filename
+ }
+ } msg]
+ if {$rc==0} break
+ if {$nDelay > 0} { after $nDelay }
+ }
+ if {$rc} { error $msg }
+ } else {
+ if {$force} {
+ file delete -force $filename
+ } else {
+ file delete $filename
+ }
+ }
+ }
+}
+
+if {$::tcl_platform(platform) eq "windows"} {
+ proc do_remove_win32_dir {args} {
+ set nRetry [getFileRetries] ;# Maximum number of retries.
+ set nDelay [getFileRetryDelay] ;# Delay in ms before retrying.
+
+ foreach dirName $args {
+ # On windows, sometimes even a [remove_win32_dir] can fail just after
+ # a directory is emptied. The cause is usually "tag-alongs" - programs
+ # like anti-virus software, automatic backup tools and various explorer
+ # extensions that keep a file open a little longer than we expect,
+ # causing the delete to fail.
+ #
+ # The solution is to wait a short amount of time before retrying the
+ # removal.
+ #
+ if {$nRetry > 0} {
+ for {set i 0} {$i < $nRetry} {incr i} {
+ set rc [catch {
+ remove_win32_dir $dirName
+ } msg]
+ if {$rc == 0} break
+ if {$nDelay > 0} { after $nDelay }
+ }
+ if {$rc} { error $msg }
+ } else {
+ remove_win32_dir $dirName
+ }
+ }
+ }
+
+ proc do_delete_win32_file {args} {
+ set nRetry [getFileRetries] ;# Maximum number of retries.
+ set nDelay [getFileRetryDelay] ;# Delay in ms before retrying.
+
+ foreach fileName $args {
+ # On windows, sometimes even a [delete_win32_file] can fail just after
+ # a file is closed. The cause is usually "tag-alongs" - programs like
+ # anti-virus software, automatic backup tools and various explorer
+ # extensions that keep a file open a little longer than we expect,
+ # causing the delete to fail.
+ #
+ # The solution is to wait a short amount of time before retrying the
+ # delete.
+ #
+ if {$nRetry > 0} {
+ for {set i 0} {$i < $nRetry} {incr i} {
+ set rc [catch {
+ delete_win32_file $fileName
+ } msg]
+ if {$rc == 0} break
+ if {$nDelay > 0} { after $nDelay }
+ }
+ if {$rc} { error $msg }
+ } else {
+ delete_win32_file $fileName
+ }
+ }
+ }
+}
+
proc execpresql {handle args} {
trace remove execution $handle enter [list execpresql $handle]
if {[info exists ::G(perm:presql)]} {
@@ -144,8 +374,8 @@ proc do_not_use_codec {} {
#
if {[info exists cmdlinearg]==0} {
- # Parse any options specified in the $argv array. This script accepts the
- # following options:
+ # Parse any options specified in the $argv array. This script accepts the
+ # following options:
#
# --pause
# --soft-heap-limit=NN
@@ -154,7 +384,10 @@ if {[info exists cmdlinearg]==0} {
# --backtrace=N
# --binarylog=N
# --soak=N
+ # --file-retries=N
+ # --file-retry-delay=N
# --start=[$permutation:]$testfile
+ # --match=$pattern
#
set cmdlinearg(soft-heap-limit) 0
set cmdlinearg(maxerror) 1000
@@ -162,13 +395,16 @@ if {[info exists cmdlinearg]==0} {
set cmdlinearg(backtrace) 10
set cmdlinearg(binarylog) 0
set cmdlinearg(soak) 0
- set cmdlinearg(start) ""
+ set cmdlinearg(file-retries) 0
+ set cmdlinearg(file-retry-delay) 0
+ set cmdlinearg(start) ""
+ set cmdlinearg(match) ""
set leftover [list]
foreach a $argv {
switch -regexp -- $a {
{^-+pause$} {
- # Wait for user input before continuing. This is to give the user an
+ # Wait for user input before continuing. This is to give the user an
# opportunity to connect profiling tools to the process.
puts -nonewline "Press RETURN to begin..."
flush stdout
@@ -197,6 +433,14 @@ if {[info exists cmdlinearg]==0} {
foreach {dummy cmdlinearg(soak)} [split $a =] break
set ::G(issoak) $cmdlinearg(soak)
}
+ {^-+file-retries=.+$} {
+ foreach {dummy cmdlinearg(file-retries)} [split $a =] break
+ set ::G(file-retries) $cmdlinearg(file-retries)
+ }
+ {^-+file-retry-delay=.+$} {
+ foreach {dummy cmdlinearg(file-retry-delay)} [split $a =] break
+ set ::G(file-retry-delay) $cmdlinearg(file-retry-delay)
+ }
{^-+start=.+$} {
foreach {dummy cmdlinearg(start)} [split $a =] break
@@ -207,6 +451,12 @@ if {[info exists cmdlinearg]==0} {
}
if {$::G(start:file) == ""} {unset ::G(start:file)}
}
+ {^-+match=.+$} {
+ foreach {dummy cmdlinearg(match)} [split $a =] break
+
+ set ::G(match) $cmdlinearg(match)
+ if {$::G(match) == ""} {unset ::G(match)}
+ }
default {
lappend leftover $a
}
@@ -217,8 +467,8 @@ if {[info exists cmdlinearg]==0} {
# Install the malloc layer used to inject OOM errors. And the 'automatic'
# extensions. This only needs to be done once for the process.
#
- sqlite3_shutdown
- install_malloc_faultsim 1
+ sqlite3_shutdown
+ install_malloc_faultsim 1
sqlite3_initialize
autoinstall_test_functions
@@ -246,10 +496,13 @@ sqlite3_soft_heap_limit $cmdlinearg(soft-heap-limit)
#
proc reset_db {} {
catch {db close}
- file delete -force test.db
- file delete -force test.db-journal
- file delete -force test.db-wal
+ forcedelete test.db
+ forcedelete test.db-journal
+ forcedelete test.db-wal
sqlite3 db ./test.db
+ if {[ array names ::env BDB_BLOB_SETTING ] != "" } {
+ db eval "pragma large_record_opt=$::env(BDB_BLOB_SETTING)"
+ }
set ::DB [sqlite3_connection_pointer db]
if {[info exists ::SETUP_SQL]} {
db eval $::SETUP_SQL
@@ -274,6 +527,7 @@ if {0==[info exists ::SLAVE]} {
set TC(count) 0
set TC(fail_list) [list]
set TC(omit_list) [list]
+ set TC(warn_list) [list]
proc set_test_counter {counter args} {
if {[llength $args]} {
@@ -290,9 +544,11 @@ source $testdir/../../../../test/sql/bdb_excl.test
# Record the fact that a sequence of tests were omitted.
#
-proc omit_test {name reason} {
+proc omit_test {name reason {append 1}} {
set omitList [set_test_counter omit_list]
- lappend omitList [list $name $reason]
+ if {$append} {
+ lappend omitList [list $name $reason]
+ }
set_test_counter omit_list $omitList
}
@@ -311,6 +567,18 @@ proc fail_test {name} {
}
}
+# Remember a warning message to be displayed at the conclusion of all testing
+#
+proc warning {msg {append 1}} {
+ puts "Warning: $msg"
+ set warnList [set_test_counter warn_list]
+ if {$append} {
+ lappend warnList $msg
+ }
+ set_test_counter warn_list $warnList
+}
+
+
# Increment the number of tests run
#
proc incr_ntest {} {
@@ -318,10 +586,9 @@ proc incr_ntest {} {
}
-# Invoke the do_test procedure to run a single test
+# Invoke the do_test procedure to run a single test
#
proc do_test {name cmd expected} {
-
global argv cmdlinearg IGNORE_CASES EXCLUDE_CASES
fix_testname name
@@ -335,7 +602,8 @@ proc do_test {name cmd expected} {
return
}
}
-# if {[llength $argv]==0} {
+
+# if {[llength $argv]==0} {
# set go 1
# } else {
# set go 0
@@ -354,45 +622,130 @@ proc do_test {name cmd expected} {
incr_ntest
puts -nonewline $name...
flush stdout
- if {[catch {uplevel #0 "$cmd;\n"} result]} {
- puts "\nError: $result"
- fail_test $name
- } elseif {[string compare $result $expected]} {
- set ignore 0
- foreach pattern $IGNORE_CASES {
- if {[string match $pattern $name]} {
- set ignore 1
- break
- }
- }
- if {$ignore} {
- puts " Ignored"
- } else {
- puts "\nExpected: \[$expected\]\n Got: \[$result\]"
+
+ if {![info exists ::G(match)] || [string match $::G(match) $name]} {
+ if {[catch {uplevel #0 "$cmd;\n"} result]} {
+ puts "\nError: $result"
fail_test $name
+ } else {
+ if {[regexp {^~?/.*/$} $expected]} {
+ # "expected" is of the form "/PATTERN/" then the result if correct if
+ # regular expression PATTERN matches the result. "~/PATTERN/" means
+ # the regular expression must not match.
+ if {[string index $expected 0]=="~"} {
+ set re [string range $expected 2 end-1]
+ if {[string index $re 0]=="*"} {
+ # If the regular expression begins with * then treat it as a glob instead
+ set ok [string match $re $result]
+ } else {
+ set re [string map {# {[-0-9.]+}} $re]
+ set ok [regexp $re $result]
+ }
+ set ok [expr {!$ok}]
+ } else {
+ set re [string range $expected 1 end-1]
+ if {[string index $re 0]=="*"} {
+ # If the regular expression begins with * then treat it as a glob instead
+ set ok [string match $re $result]
+ } else {
+ set re [string map {# {[-0-9.]+}} $re]
+ set ok [regexp $re $result]
+ }
+ }
+ } elseif {[regexp {^~?\*.*\*$} $expected]} {
+ # "expected" is of the form "*GLOB*" then the result if correct if
+ # glob pattern GLOB matches the result. "~/GLOB/" means
+ # the glob must not match.
+ if {[string index $expected 0]=="~"} {
+ set e [string range $expected 1 end]
+ set ok [expr {![string match $e $result]}]
+ } else {
+ set ok [string match $expected $result]
+ }
+ } else {
+ set ok [expr {[string compare $result $expected]==0}]
+ }
+ if {!$ok} {
+ set ignore 0
+ foreach pattern $IGNORE_CASES {
+ if {[string match $pattern $name]} {
+ set ignore 1
+ break
+ }
+ }
+ if {$ignore} {
+ puts " Ignored"
+ } else {
+ puts "\nExpected: \[$expected\]\n Got: \[$result\]"
+ fail_test $name
+ }
+ } else {
+ puts " Ok"
+ }
}
} else {
- puts " Ok"
+ puts " Omitted"
+ omit_test $name "pattern mismatch" 0
}
flush stdout
}
+proc catchcmd {db {cmd ""}} {
+ global CLI
+ set out [open cmds.txt w]
+ puts $out $cmd
+ close $out
+ set line "exec $CLI $db < cmds.txt"
+ set rc [catch { eval $line } msg]
+ list $rc $msg
+}
+
+proc filepath_normalize {p} {
+ # test cases should be written to assume "unix"-like file paths
+ if {$::tcl_platform(platform)!="unix"} {
+ # lreverse*2 as a hack to remove any unneeded {} after the string map
+ lreverse [lreverse [string map {\\ /} [regsub -nocase -all {[a-z]:[/\\]+} $p {/}]]]
+ } {
+ set p
+ }
+}
+proc do_filepath_test {name cmd expected} {
+ uplevel [list do_test $name [
+ subst -nocommands { filepath_normalize [ $cmd ] }
+ ] [filepath_normalize $expected]]
+}
+
+proc realnum_normalize {r} {
+ # different TCL versions display floating point values differently.
+ string map {1.#INF inf Inf inf .0e e} [regsub -all {(e[+-])0+} $r {\1}]
+}
+proc do_realnum_test {name cmd expected} {
+ uplevel [list do_test $name [
+ subst -nocommands { realnum_normalize [ $cmd ] }
+ ] [realnum_normalize $expected]]
+}
+
proc fix_testname {varname} {
upvar $varname testname
- if {[info exists ::testprefix]
+ if {[info exists ::testprefix]
&& [string is digit [string range $testname 0 0]]
} {
set testname "${::testprefix}-$testname"
}
}
-
+
proc do_execsql_test {testname sql {result {}}} {
fix_testname testname
- uplevel do_test $testname [list "execsql {$sql}"] [list [list {*}$result]]
+ uplevel do_test [list $testname] [list "execsql {$sql}"] [list [list {*}$result]]
}
proc do_catchsql_test {testname sql result} {
fix_testname testname
- uplevel do_test $testname [list "catchsql {$sql}"] [list $result]
+ uplevel do_test [list $testname] [list "catchsql {$sql}"] [list $result]
+}
+proc do_timed_execsql_test {testname sql {result {}}} {
+ fix_testname testname
+ uplevel do_test [list $testname] [list "execsql_timed {$sql}"]\
+ [list [list {*}$result]]
}
proc do_eqp_test {name sql res} {
uplevel do_execsql_test $name [list "EXPLAIN QUERY PLAN $sql"] [list $res]
@@ -471,7 +824,7 @@ proc delete_all_data {} {
}
}
-# Run an SQL script.
+# Run an SQL script.
# Return the number of microseconds per statement.
#
proc speed_trial {name numstmt units sql} {
@@ -557,9 +910,31 @@ proc finalize_testing {} {
set nTest [incr_ntest]
set nErr [set_test_counter errors]
- puts "$nErr errors out of $nTest tests"
- if {$nErr>0} {
- puts "Failures on these tests: [set_test_counter fail_list]"
+ set nKnown 0
+ if {[file readable known-problems.txt]} {
+ set fd [open known-problems.txt]
+ set content [read $fd]
+ close $fd
+ foreach x $content {set known_error($x) 1}
+ foreach x [set_test_counter fail_list] {
+ if {[info exists known_error($x)]} {incr nKnown}
+ }
+ }
+ if {$nKnown>0} {
+ puts "[expr {$nErr-$nKnown}] new errors and $nKnown known errors\
+ out of $nTest tests"
+ } else {
+ puts "$nErr errors out of $nTest tests"
+ }
+ if {$nErr>$nKnown} {
+ puts -nonewline "Failures on these tests:"
+ foreach x [set_test_counter fail_list] {
+ if {![info exists known_error($x)]} {puts -nonewline " $x"}
+ }
+ puts ""
+ }
+ foreach warning [set_test_counter warn_list] {
+ puts "Warning: $warning"
}
run_thread_tests 1
if {[llength $omitList]>0} {
@@ -620,10 +995,10 @@ proc finalize_testing {} {
}
}
foreach f [glob -nocomplain test.db-*-journal] {
- file delete -force $f
+ forcedelete $f
}
foreach f [glob -nocomplain test.db-mj*] {
- file delete -force $f
+ forcedelete $f
}
exit [expr {$nErr>0}]
}
@@ -668,6 +1043,14 @@ proc execsql {sql {db db}} {
# puts "SQL = $sql"
uplevel [list $db eval $sql]
}
+proc execsql_timed {sql {db db}} {
+ set tm [time {
+ set x [uplevel [list $db eval $sql]]
+ } 1]
+ set tm [lindex $tm 0]
+ puts -nonewline " ([expr {$tm*0.001}]ms) "
+ set x
+}
# Execute SQL and catch exceptions.
#
@@ -691,6 +1074,80 @@ proc explain {sql {db db}} {
}
}
+proc explain_i {sql {db db}} {
+ puts ""
+ puts "addr opcode p1 p2 p3 p4 p5 #"
+ puts "---- ------------ ------ ------ ------ ---------------- -- -"
+
+
+ # Set up colors for the different opcodes. Scheme is as follows:
+ #
+ # Red: Opcodes that write to a b-tree.
+ # Blue: Opcodes that reposition or seek a cursor.
+ # Green: The ResultRow opcode.
+ #
+ set R "\033\[31;1m" ;# Red fg
+ set G "\033\[32;1m" ;# Green fg
+ set B "\033\[34;1m" ;# Red fg
+ set D "\033\[39;0m" ;# Default fg
+ foreach opcode {
+ Seek SeekGe SeekGt SeekLe SeekLt NotFound Last Rewind
+ NoConflict Next Prev VNext VPrev VFilter
+ } {
+ set color($opcode) $B
+ }
+ foreach opcode {ResultRow} {
+ set color($opcode) $G
+ }
+ foreach opcode {IdxInsert Insert Delete IdxDelete} {
+ set color($opcode) $R
+ }
+
+ set bSeenGoto 0
+ $db eval "explain $sql" {} {
+ set x($addr) 0
+ set op($addr) $opcode
+
+ if {$opcode == "Goto" && ($bSeenGoto==0 || ($p2 > $addr+10))} {
+ set linebreak($p2) 1
+ set bSeenGoto 1
+ }
+
+ if {$opcode=="Next" || $opcode=="Prev"
+ || $opcode=="VNext" || $opcode=="VPrev"
+ } {
+ for {set i $p2} {$i<$addr} {incr i} {
+ incr x($i) 2
+ }
+ }
+
+ if {$opcode == "Goto" && $p2<$addr && $op($p2)=="Yield"} {
+ for {set i [expr $p2+1]} {$i<$addr} {incr i} {
+ incr x($i) 2
+ }
+ }
+
+ if {$opcode == "Halt" && $comment == "End of coroutine"} {
+ set linebreak([expr $addr+1]) 1
+ }
+ }
+
+ $db eval "explain $sql" {} {
+ if {[info exists linebreak($addr)]} {
+ puts ""
+ }
+ set I [string repeat " " $x($addr)]
+
+ set col ""
+ catch { set col $color($opcode) }
+
+ puts [format {%-4d %s%s%-12.12s%s %-6d %-6d %-6d % -17s %s %s} \
+ $addr $I $col $opcode $D $p1 $p2 $p3 $p4 $p5 $comment
+ ]
+ }
+ puts "---- ------------ ------ ------ ------ ---------------- -- -"
+}
+
# Show the VDBE program for an SQL statement but omit the Trace
# opcode at the beginning. This procedure can be used to prove
# that different SQL statements generate exactly the same VDBE code.
@@ -713,6 +1170,15 @@ proc execsql2 {sql} {
return $result
}
+# Use a temporary in-memory database to execute SQL statements
+#
+proc memdbsql {sql} {
+ sqlite3 memdb :memory:
+ set result [memdb eval $sql]
+ memdb close
+ return $result
+}
+
# Use the non-callback API to execute multiple SQL statements
#
proc stepsql {dbptr sql} {
@@ -738,30 +1204,6 @@ proc stepsql {dbptr sql} {
return $r
}
-# Delete a file or directory
-#
-proc forcedelete {args} {
- foreach filename $args {
- # On windows, sometimes even a [file delete -force] can fail just after
- # a file is closed. The cause is usually "tag-alongs" - programs like
- # anti-virus software, automatic backup tools and various explorer
- # extensions that keep a file open a little longer than we expect, causing
- # the delete to fail.
- #
- # The solution is to wait a short amount of time before retrying the
- # delete.
- #
- set nRetry 50 ;# Maximum number of retries.
- set nDelay 100 ;# Delay in ms before retrying.
- for {set i 0} {$i<$nRetry} {incr i} {
- set rc [catch {file delete -force $filename} msg]
- if {$rc==0} break
- after $nDelay
- }
- if {$rc} { error $msg }
- }
-}
-
# Do an integrity check of the entire database
#
proc integrity_check {name {db db}} {
@@ -770,6 +1212,23 @@ proc integrity_check {name {db db}} {
}
}
+# Check the extended error code
+#
+proc verify_ex_errcode {name expected {db db}} {
+ do_test $name [list sqlite3_extended_errcode $db] $expected
+}
+
+
+# Return true if the SQL statement passed as the second argument uses a
+# statement transaction.
+#
+proc sql_uses_stmt {db sql} {
+ set stmt [sqlite3_prepare $db $sql -1 dummy]
+ set uses [uses_stmt_journal $stmt]
+ sqlite3_finalize $stmt
+ return $uses
+}
+
proc fix_ifcapable_expr {expr} {
set ret ""
set state 0
@@ -815,7 +1274,7 @@ proc ifcapable {expr code {else ""} {elsecode ""}} {
# boolean, indicating whether or not the process actually crashed or
# reported some other error. The second element in the returned list is the
# error message. This is "child process exited abnormally" if the crash
-# occured.
+# occurred.
#
# crashsql -delay CRASHDELAY -file CRASHFILE ?-blocksize BLOCKSIZE? $sql
#
@@ -824,17 +1283,19 @@ proc crashsql {args} {
set blocksize ""
set crashdelay 1
set prngseed 0
+ set opendb { sqlite3 db test.db -vfs crash }
set tclbody {}
set crashfile ""
set dc ""
set sql [lindex $args end]
-
+
for {set ii 0} {$ii < [llength $args]-1} {incr ii 2} {
set z [lindex $args $ii]
set n [string length $z]
set z2 [lindex $args [expr $ii+1]]
if {$n>1 && [string first $z -delay]==0} {set crashdelay $z2} \
+ elseif {$n>1 && [string first $z -opendb]==0} {set opendb $z2} \
elseif {$n>1 && [string first $z -seed]==0} {set prngseed $z2} \
elseif {$n>1 && [string first $z -file]==0} {set crashfile $z2} \
elseif {$n>1 && [string first $z -tclbody]==0} {set tclbody $z2} \
@@ -847,16 +1308,16 @@ proc crashsql {args} {
error "Compulsory option -file missing"
}
- # $crashfile gets compared to the native filename in
+ # $crashfile gets compared to the native filename in
# cfSync(), which can be different then what TCL uses by
# default, so here we force it to the "nativename" format.
- set cfile [string map {\\ \\\\} [file nativename [file join [pwd] $crashfile]]]
+ set cfile [string map {\\ \\\\} [file nativename [file join [get_pwd] $crashfile]]]
set f [open crash.tcl w]
puts $f "sqlite3_crash_enable 1"
puts $f "sqlite3_crashparams $blocksize $dc $crashdelay $cfile"
puts $f "sqlite3_test_control_pending_byte $::sqlite_pending_byte"
- puts $f "sqlite3 db test.db -vfs crash"
+ puts $f $opendb
# This block sets the cache size of the main database to 10
# pages. This is done in case the build is configured to omit
@@ -864,6 +1325,7 @@ proc crashsql {args} {
puts $f {db eval {SELECT * FROM sqlite_master;}}
puts $f {set bt [btree_from_db db]}
puts $f {btree_set_cache_size $bt 10}
+
if {$prngseed} {
set seed [expr {$prngseed%10007+1}]
# puts seed=$seed
@@ -882,7 +1344,7 @@ proc crashsql {args} {
set r [catch {
exec [info nameofexec] crash.tcl >@stdout
} msg]
-
+
# Windows/ActiveState TCL returns a slightly different
# error message. We map that to the expected message
# so that we don't have to change all of the test
@@ -892,14 +1354,14 @@ proc crashsql {args} {
set msg "child process exited abnormally"
}
}
-
+
lappend r $msg
}
# Usage: do_ioerr_test <test number> <options...>
#
# This proc is used to implement test cases that check that IO errors
-# are correctly handled. The first argument, <test number>, is an integer
+# are correctly handled. The first argument, <test number>, is an integer
# used to name the tests executed by this proc. Options are as follows:
#
# -tclprep TCL script to run to prepare test.
@@ -936,7 +1398,7 @@ proc do_ioerr_test {testname args} {
set ::TN $n
incr ::ioerropts(-count) -1
if {$::ioerropts(-count)<0} break
-
+
# Skip this IO error if it was specified with the "-exclude" option.
if {[info exists ::ioerropts(-exclude)]} {
if {[lsearch $::ioerropts(-exclude) $n]!=-1} continue
@@ -945,16 +1407,16 @@ proc do_ioerr_test {testname args} {
restore_prng_state
}
- # Delete the files test.db and test2.db, then execute the TCL and
+ # Delete the files test.db and test2.db, then execute the TCL and
# SQL (in that order) to prepare for the test case.
do_test $testname.$n.1 {
set ::sqlite_io_error_pending 0
catch {db close}
catch {db2 close}
- catch {file delete -force test.db}
- catch {file delete -force test.db-journal}
- catch {file delete -force test2.db}
- catch {file delete -force test2.db-journal}
+ catch {forcedelete test.db}
+ catch {forcedelete test.db-journal}
+ catch {forcedelete test2.db}
+ catch {forcedelete test2.db-journal}
set ::DB [sqlite3 db test.db; sqlite3_connection_pointer db]
sqlite3_extended_result_codes $::DB $::ioerropts(-erc)
if {[info exists ::ioerropts(-tclprep)]} {
@@ -1042,12 +1504,12 @@ proc do_ioerr_test {testname args} {
set ::sqlite_io_error_hit 0
set ::sqlite_io_error_pending 0
- # Check that no page references were leaked. There should be
- # a single reference if there is still an active transaction,
+ # Check that no page references were leaked. There should be
+ # a single reference if there is still an active transaction,
# or zero otherwise.
#
# UPDATE: If the IO error occurs after a 'BEGIN' but before any
- # locks are established on database files (i.e. if the error
+ # locks are established on database files (i.e. if the error
# occurs while attempting to detect a hot-journal file), then
# there may 0 page references and an active transaction according
# to [sqlite3_get_autocommit].
@@ -1063,7 +1525,7 @@ proc do_ioerr_test {testname args} {
} {1}
}
- # If there is an open database handle and no open transaction,
+ # If there is an open database handle and no open transaction,
# and the pager is not running in exclusive-locking mode,
# check that the pager is in "unlocked" state. Theoretically,
# if a call to xUnlock() failed due to an IO error the underlying
@@ -1085,7 +1547,7 @@ proc do_ioerr_test {testname args} {
}
}
- # If an IO error occured, then the checksum of the database should
+ # If an IO error occurred, then the checksum of the database should
# be the same as before the script that caused the IO error was run.
#
if {$::go && $::sqlite_io_error_hardhit && $::ioerropts(-cksum)} {
@@ -1160,7 +1622,7 @@ proc allcksum {{db db}} {
}
# Generate a checksum based on the contents of a single database with
-# a database connection. The name of the database is $dbname.
+# a database connection. The name of the database is $dbname.
# Examples of $dbname are "temp" or "main".
#
proc dbcksum {db dbname} {
@@ -1228,24 +1690,6 @@ proc memdebug_log_sql {{filename mallocs.sql}} {
close $fd
}
-# Copy file $from into $to. This is used because some versions of
-# TCL for windows (notably the 8.4.1 binary package shipped with the
-# current mingw release) have a broken "file copy" command.
-#
-proc copy_file {from to} {
- if {$::tcl_platform(platform)=="unix"} {
- file copy -force $from $to
- } else {
- set f [open $from]
- fconfigure $f -translation binary
- set t [open $to w]
- fconfigure $t -translation binary
- puts -nonewline $t [read $f [file size $from]]
- close $t
- close $f
- }
-}
-
# Drop all tables in database [db]
proc drop_all_tables {{db db}} {
ifcapable trigger&&foreignkey {
@@ -1272,8 +1716,8 @@ proc drop_all_tables {{db db}} {
#-------------------------------------------------------------------------
# If a test script is executed with global variable $::G(perm:name) set to
-# "wal", then the tests are run in WAL mode. Otherwise, they should be run
-# in rollback mode. The following Tcl procs are used to make this less
+# "wal", then the tests are run in WAL mode. Otherwise, they should be run
+# in rollback mode. The following Tcl procs are used to make this less
# intrusive:
#
# wal_set_journal_mode ?DB?
@@ -1288,9 +1732,9 @@ proc drop_all_tables {{db db}} {
# Otherwise (if not running a WAL permutation) this is a no-op.
#
# wal_is_wal_mode
-#
+#
# Returns true if this test should be run in WAL mode. False otherwise.
-#
+#
proc wal_is_wal_mode {} {
expr {[permutation] eq "wal"}
}
@@ -1304,6 +1748,7 @@ proc wal_check_journal_mode {testname {db db}} {
$db eval { SELECT * FROM sqlite_master }
do_test $testname [list $db eval "PRAGMA main.journal_mode"] {wal}
}
+ forcedelete test.db-journal/__db.register
}
proc permutation {} {
@@ -1391,10 +1836,10 @@ proc slave_test_file {zFile} {
}
set ::sqlite_open_file_count 0
- # Test that the global "shared-cache" setting was not altered by
+ # Test that the global "shared-cache" setting was not altered by
# the test script.
#
- ifcapable shared_cache {
+ ifcapable shared_cache {
set res [expr {[sqlite3_enable_shared_cache] == $scs}]
do_test ${tail}-sharedcachesetting [list set {} $res] 1
}
@@ -1427,7 +1872,7 @@ proc db_save {} {
foreach f [glob -nocomplain sv_test.db*] { forcedelete $f }
foreach f [glob -nocomplain test.db*] {
set f2 "sv_$f"
- file copy -force $f $f2
+ forcecopy $f $f2
}
}
proc db_save_and_close {} {
@@ -1439,9 +1884,9 @@ proc db_restore {} {
foreach f [glob -nocomplain test.db*] { forcedelete $f }
foreach f2 [glob -nocomplain sv_test.db*] {
set f [string range $f2 3 end]
- file copy -force $f2 $f
+ forcecopy $f2 $f
}
- file delete test.db-journal/__db.register
+ forcedelete test.db-journal/__db.register
}
proc db_restore_and_reopen {{dbfile test.db}} {
catch { db close }
@@ -1458,5 +1903,14 @@ proc db_delete_and_reopen {{file test.db}} {
# to non-zero, then set the global variable $AUTOVACUUM to 1.
set AUTOVACUUM $sqlite_options(default_autovacuum)
+# Make sure the FTS enhanced query syntax is disabled.
+set sqlite_fts3_enable_parentheses 0
+
+# During testing, assume that all database files are well-formed. The
+# few test cases that deliberately corrupt database files should rescind
+# this setting by invoking "database_can_be_corrupt"
+#
+database_never_corrupt
+
source $testdir/thread_common.tcl
source $testdir/malloc_common.tcl
diff --git a/lang/sql/sqlite/test/thread001.test b/lang/sql/sqlite/test/thread001.test
index d94a613a..a796c57b 100644
--- a/lang/sql/sqlite/test/thread001.test
+++ b/lang/sql/sqlite/test/thread001.test
@@ -42,7 +42,7 @@ foreach {tn same_db shared_cache} [list \
sqlite3_enable_shared_cache $shared_cache
sqlite3_enable_shared_cache $shared_cache
} $shared_cache
- sqlite3 db test.db -fullmutex 1
+ sqlite3 db test.db -fullmutex 1 -key xyzzy
set dbconfig ""
if {$same_db} {
@@ -77,11 +77,7 @@ foreach {tn same_db shared_cache} [list \
#sqlthread parent {puts STARTING..}
set needToClose 0
if {![info exists ::DB]} {
- set key ""
- if {[sqlite -has-codec]} {
- set key "xyzzy"
- }
- set ::DB [sqlthread open test.db $key]
+ set ::DB [sqlthread open test.db xyzzy]
#sqlthread parent "puts \"OPEN $::DB\""
set needToClose 1
}
@@ -91,7 +87,7 @@ foreach {tn same_db shared_cache} [list \
do_test t1 {
execsql {
SELECT
- (SELECT md5sum(a, b) FROM ab WHERE a < (SELECT max(a) FROM ab)) ==
+ (SELECT md5sum(a, b) FROM ab WHERE +a < (SELECT max(a) FROM ab)) ==
(SELECT b FROM ab WHERE a = (SELECT max(a) FROM ab))
}
} {1}
@@ -135,7 +131,7 @@ foreach {tn same_db shared_cache} [list \
do_test thread001.$tn.6 {
execsql {
SELECT
- (SELECT md5sum(a, b) FROM ab WHERE a < (SELECT max(a) FROM ab)) ==
+ (SELECT md5sum(a, b) FROM ab WHERE +a < (SELECT max(a) FROM ab)) ==
(SELECT b FROM ab WHERE a = (SELECT max(a) FROM ab))
}
} {1}
diff --git a/lang/sql/sqlite/test/thread002.test b/lang/sql/sqlite/test/thread002.test
index b1e5f636..b39c9ae7 100644
--- a/lang/sql/sqlite/test/thread002.test
+++ b/lang/sql/sqlite/test/thread002.test
@@ -16,9 +16,11 @@
set testdir [file dirname $argv0]
+set do_not_use_codec 1
source $testdir/tester.tcl
if {[run_thread_tests]==0} { finish_test ; return }
+
db close
set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
@@ -27,7 +29,7 @@ set ::NTHREAD 10
do_test thread002.1 {
# Create 3 databases with identical schemas:
for {set ii 0} {$ii < 3} {incr ii} {
- file delete -force test${ii}.db
+ forcedelete test${ii}.db
sqlite3 db test${ii}.db
execsql {
CREATE TABLE t1(k, v);
diff --git a/lang/sql/sqlite/test/thread003.test b/lang/sql/sqlite/test/thread003.test
index 6a89e33e..8c7440c8 100644
--- a/lang/sql/sqlite/test/thread003.test
+++ b/lang/sql/sqlite/test/thread003.test
@@ -40,7 +40,7 @@ do_test thread003.1.2 {
} {1}
do_test thread003.1.3 {
db close
- file delete -force test2.db
+ forcedelete test2.db
sqlite3 db test2.db
} {}
do_test thread003.1.4 {
@@ -80,11 +80,7 @@ do_test thread003.2 {
foreach zFile {test.db test2.db} {
set SCRIPT [format {
set iEnd [expr {[clock_seconds] + %d}]
- set key ""
- if {[sqlite -has-codec]} {
- set key "xyzzy"
- }
- set ::DB [sqlthread open %s $key]
+ set ::DB [sqlthread open %s xyzzy]
# Set the cache size to 15 pages per cache. 30 available globally.
execsql { PRAGMA cache_size = 15 }
@@ -121,11 +117,7 @@ do_test thread003.3 {
set SCRIPT [format {
set iStart [clock_seconds]
set iEnd [expr {[clock_seconds] + %d}]
- set key ""
- if {[sqlite -has-codec]} {
- set key "xyzzy"
- }
- set ::DB [sqlthread open %s $key]
+ set ::DB [sqlthread open %s xyzzy]
# Set the cache size to 15 pages per cache. 30 available globally.
execsql { PRAGMA cache_size = 15 }
@@ -164,11 +156,7 @@ unset -nocomplain finished(2)
do_test thread003.4 {
thread_spawn finished(1) $thread_procs [format {
set iEnd [expr {[clock_seconds] + %d}]
- set key ""
- if {[sqlite -has-codec]} {
- set key "xyzzy"
- }
- set ::DB [sqlthread open test.db $key]
+ set ::DB [sqlthread open test.db xyzzy]
# Set the cache size to 15 pages per cache. 30 available globally.
execsql { PRAGMA cache_size = 15 }
diff --git a/lang/sql/sqlite/test/thread005.test b/lang/sql/sqlite/test/thread005.test
index 9253287d..89cbfe76 100644
--- a/lang/sql/sqlite/test/thread005.test
+++ b/lang/sql/sqlite/test/thread005.test
@@ -121,7 +121,7 @@ for {set ii 2} {$ii < 500} {incr ii} {
# switch or something...
#
-file delete -force test.db test2.db
+forcedelete test.db test2.db
unset -nocomplain finished
do_test thread005-2.1 {
diff --git a/lang/sql/sqlite/test/tkt-02a8e81d44.test b/lang/sql/sqlite/test/tkt-02a8e81d44.test
index 4a48fb02..7ca98664 100644
--- a/lang/sql/sqlite/test/tkt-02a8e81d44.test
+++ b/lang/sql/sqlite/test/tkt-02a8e81d44.test
@@ -17,6 +17,11 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
+ifcapable !compound {
+ finish_test
+ return
+}
+
do_test tkt-02a838-1.1 {
execsql {
CREATE TABLE t1(a);
diff --git a/lang/sql/sqlite/test/tkt-2a5629202f.test b/lang/sql/sqlite/test/tkt-2a5629202f.test
new file mode 100644
index 00000000..8f09c310
--- /dev/null
+++ b/lang/sql/sqlite/test/tkt-2a5629202f.test
@@ -0,0 +1,76 @@
+# 2012 April 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.
+#
+#***********************************************************************
+# The tests in this file were used while developing the SQLite 4 code.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix tkt-2a5629202f
+
+# 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 data [execsql $sql]
+ if {[db status sort]} {set x sort} {set x nosort}
+ lappend data $x
+ return $data
+}
+
+do_execsql_test 1.1 {
+ CREATE TABLE t8(b TEXT, c TEXT);
+ INSERT INTO t8 VALUES('a', 'one');
+ INSERT INTO t8 VALUES('b', 'two');
+ INSERT INTO t8 VALUES(NULL, 'three');
+ INSERT INTO t8 VALUES(NULL, 'four');
+}
+
+do_execsql_test 1.2 {
+ SELECT coalesce(b, 'null') || '/' || c FROM t8 x ORDER BY x.b, x.c
+} {null/four null/three a/one b/two}
+
+do_execsql_test 1.3 {
+ CREATE UNIQUE INDEX i1 ON t8(b);
+ SELECT coalesce(b, 'null') || '/' || c FROM t8 x ORDER BY x.b, x.c
+} {null/four null/three a/one b/two}
+
+do_execsql_test 1.4 {
+ DROP INDEX i1;
+ CREATE UNIQUE INDEX i1 ON t8(b, c);
+ SELECT coalesce(b, 'null') || '/' || c FROM t8 x ORDER BY x.b, x.c
+} {null/four null/three a/one b/two}
+
+#-------------------------------------------------------------------------
+#
+
+do_execsql_test 2.1 {
+ CREATE TABLE t2(a, b NOT NULL, c);
+ CREATE UNIQUE INDEX t2ab ON t2(a, b);
+ CREATE UNIQUE INDEX t2ba ON t2(b, a);
+}
+
+do_test 2.2 {
+ cksort { SELECT * FROM t2 WHERE a = 10 ORDER BY a, b, c }
+} {nosort}
+
+do_test 2.3 {
+ cksort { SELECT * FROM t2 WHERE b = 10 ORDER BY a, b, c }
+} {sort}
+
+do_test 2.4 {
+ cksort { SELECT * FROM t2 WHERE a IS NULL ORDER BY a, b, c }
+} {sort}
+
+finish_test
diff --git a/lang/sql/sqlite/test/tkt-2d1a5c67d.test b/lang/sql/sqlite/test/tkt-2d1a5c67d.test
new file mode 100644
index 00000000..3fef187e
--- /dev/null
+++ b/lang/sql/sqlite/test/tkt-2d1a5c67d.test
@@ -0,0 +1,127 @@
+# 2011 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.
+#
+#***********************************************************************
+# This file implements regression tests for SQLite library. Specifically,
+# it tests that ticket [2d1a5c67dfc2363e44f29d9bbd57f7331851390a] has
+# been resolved.
+#
+#
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix tkt-2d1a5c67d
+
+ifcapable {!wal || !vtab} {finish_test; return}
+
+for {set ii 1} {$ii<=10} {incr ii} {
+ do_test tkt-2d1a5c67d.1.$ii {
+ db close
+ forcedelete test.db test.db-wal
+ sqlite3 db test.db
+ db eval "PRAGMA cache_size=$::ii"
+ db eval {
+ PRAGMA journal_mode=WAL;
+ CREATE TABLE t1(a,b);
+ CREATE INDEX t1b ON t1(b);
+ CREATE TABLE t2(x,y UNIQUE);
+ INSERT INTO t2 VALUES(3,4);
+ BEGIN;
+ INSERT INTO t1(a,b) VALUES(1,2);
+ SELECT 'A', * FROM t2 WHERE y=4;
+ SELECT 'B', * FROM t1;
+ COMMIT;
+ SELECT 'C', * FROM t1;
+ }
+ } {wal A 3 4 B 1 2 C 1 2}
+}
+
+db close
+forcedelete test.db test.db-wal
+sqlite3 db test.db
+load_static_extension db wholenumber
+db eval {
+ PRAGMA journal_mode=WAL;
+ CREATE TABLE t1(a,b);
+ CREATE INDEX t1b ON t1(b);
+ CREATE TABLE t2(x,y);
+ CREATE VIRTUAL TABLE nums USING wholenumber;
+ INSERT INTO t2 SELECT value, randomblob(1000) FROM nums
+ WHERE value BETWEEN 1 AND 1000;
+}
+
+for {set ii 1} {$ii<=10} {incr ii} {
+ do_test tkt-2d1a5c67d.2.$ii {
+ db eval "PRAGMA cache_size=$::ii"
+ db eval {
+ DELETE FROM t1;
+ BEGIN;
+ INSERT INTO t1(a,b) VALUES(1,2);
+ SELECT sum(length(y)) FROM t2;
+ COMMIT;
+ SELECT * FROM t1;
+ }
+ } {1000000 1 2}
+}
+
+db close
+sqlite3 db test.db
+
+
+do_execsql_test 3.1 {
+ PRAGMA cache_size = 10;
+ CREATE TABLE t3(a INTEGER PRIMARY KEY, b);
+ CREATE TABLE t4(a);
+}
+
+do_execsql_test 3.2 {
+ INSERT INTO t3 VALUES(NULL, randomblob(500));
+ INSERT INTO t3 SELECT NULL, b||b FROM t3; -- 2
+ INSERT INTO t3 SELECT NULL, b||b FROM t3; -- 4
+ INSERT INTO t3 SELECT NULL, b||b FROM t3; -- 8
+ INSERT INTO t3 SELECT NULL, b||b FROM t3; -- 16
+ INSERT INTO t3 SELECT NULL, b||b FROM t3; -- 32
+ INSERT INTO t3 SELECT NULL, b||b FROM t3; -- 64
+ INSERT INTO t3 SELECT NULL, b||b FROM t3; -- 128
+}
+
+do_execsql_test 3.3 {
+ BEGIN;
+ INSERT INTO t4 VALUES('xyz');
+}
+
+do_test 3.4 {
+ set blobs [list]
+ for {set i 1} {$i<100} {incr i} {
+ set b [db incrblob -readonly t3 b $i]
+ read $b
+ lappend blobs $b
+ }
+
+ execsql COMMIT
+ execsql { SELECT * FROM t4 WHERE a = 'xyz' }
+} {xyz}
+
+do_test 3.5 {
+ foreach b $blobs { close $b }
+ execsql { SELECT * FROM t4 WHERE a = 'xyz' }
+} {xyz}
+
+# Check that recovery works on the WAL file.
+#
+forcedelete test.db2-wal test.db2
+do_test 3.6 {
+ copy_file test.db-wal test.db2-wal
+ copy_file test.db test.db2
+ sqlite3 db2 test.db2
+ execsql { SELECT * FROM t4 WHERE a = 'xyz' } db2
+} {xyz}
+
+finish_test
diff --git a/lang/sql/sqlite/test/tkt-31338dca7e.test b/lang/sql/sqlite/test/tkt-31338dca7e.test
index 3f66816d..41dd9d3b 100644
--- a/lang/sql/sqlite/test/tkt-31338dca7e.test
+++ b/lang/sql/sqlite/test/tkt-31338dca7e.test
@@ -74,4 +74,105 @@ do_test tkt-31338-2.2 {
} {111 222 222 333 888 333 444 444 555 888 333 444 444 555 999}
+# Ticket [2c2de252666662f5459904fc33a9f2956cbff23c]
+#
+do_test tkt-31338-3.1 {
+ foreach x [db eval {SELECT name FROM sqlite_master WHERE type='table'}] {
+ db eval "DROP TABLE $x"
+ }
+ db eval {
+ CREATE TABLE t1(a,b,c,d);
+ CREATE TABLE t2(e,f);
+ INSERT INTO t1 VALUES(1,2,3,4);
+ INSERT INTO t2 VALUES(10,-8);
+ CREATE INDEX t1a ON t1(a);
+ CREATE INDEX t1b ON t1(b);
+ CREATE TABLE t3(g);
+ INSERT INTO t3 VALUES(4);
+ CREATE TABLE t4(h);
+ INSERT INTO t4 VALUES(5);
+
+ SELECT * FROM t3 LEFT JOIN t1 ON d=g LEFT JOIN t4 ON c=h
+ WHERE (a=1 AND h=4)
+ OR (b IN (
+ SELECT x FROM (SELECT e+f AS x, e FROM t2 ORDER BY 1 LIMIT 2)
+ GROUP BY e
+ ));
+ }
+} {4 1 2 3 4 {}}
+do_test tkt-31338-3.2 {
+ db eval {
+ SELECT * FROM t3 LEFT JOIN t1 ON d=g LEFT JOIN t4 ON c=h
+ WHERE (a=1 AND h=4)
+ OR (b=2 AND b NOT IN (
+ SELECT x+1 FROM (SELECT e+f AS x, e FROM t2 ORDER BY 1 LIMIT 2)
+ GROUP BY e
+ ));
+ }
+} {4 1 2 3 4 {}}
+do_test tkt-31338-3.3 {
+ db eval {
+ SELECT * FROM t3 LEFT JOIN t1 ON d=g LEFT JOIN t4 ON c=h
+ WHERE (+a=1 AND h=4)
+ OR (b IN (
+ SELECT x FROM (SELECT e+f AS x, e FROM t2 ORDER BY 1 LIMIT 2)
+ GROUP BY e
+ ));
+ }
+} {4 1 2 3 4 {}}
+do_test tkt-31338-3.4 {
+ db eval {
+ SELECT * FROM t3 LEFT JOIN t1 ON d=g LEFT JOIN t4 ON c=h
+ WHERE (a=1 AND h=4)
+ OR (+b IN (
+ SELECT x FROM (SELECT e+f AS x, e FROM t2 ORDER BY 1 LIMIT 2)
+ GROUP BY e
+ ));
+ }
+} {4 1 2 3 4 {}}
+
+do_test tkt-31338-3.5 {
+ db eval {
+ CREATE TABLE t5(a,b,c,d,e,f);
+ CREATE TABLE t6(g,h);
+ CREATE TRIGGER t6r AFTER INSERT ON t6 BEGIN
+ INSERT INTO t5
+ SELECT * FROM t3 LEFT JOIN t1 ON d=g LEFT JOIN t4 ON c=h
+ WHERE (a=1 AND h=4)
+ OR (b IN (
+ SELECT x FROM (SELECT e+f AS x, e FROM t2 ORDER BY 1 LIMIT 2)
+ GROUP BY e
+ ));
+ END;
+ INSERT INTO t6 VALUES(88,99);
+ SELECT * FROM t5;
+ }
+} {4 1 2 3 4 {}}
+
+do_test tkt-31338-3.6 {
+ db eval {
+ INSERT INTO t1 VALUES(2,4,3,4);
+ INSERT INTO t1 VALUES(99,101,3,4);
+ INSERT INTO t1 VALUES(98,97,3,4);
+ SELECT * FROM t3 LEFT JOIN t1 ON d=g LEFT JOIN t4 ON c=h
+ WHERE (a=1 AND h=4)
+ OR (b IN (
+ SELECT x+a FROM (SELECT e+f AS x, e FROM t2 ORDER BY 1 LIMIT 2)
+ GROUP BY e
+ ));
+ }
+} {4 2 4 3 4 {} 4 99 101 3 4 {}}
+
+do_test tkt-31338-3.7 {
+ db eval {
+ SELECT * FROM t3 LEFT JOIN t1 ON d=g LEFT JOIN t4 ON c=h
+ WHERE (a=1 AND h=4)
+ OR (b IN (
+ SELECT x FROM (SELECT e+f+a AS x, e FROM t2 ORDER BY 1 LIMIT 2)
+ GROUP BY e
+ ));
+ }
+} {4 2 4 3 4 {} 4 99 101 3 4 {}}
+
+
finish_test
diff --git a/lang/sql/sqlite/test/tkt-385a5b56b9.test b/lang/sql/sqlite/test/tkt-385a5b56b9.test
new file mode 100644
index 00000000..1338435e
--- /dev/null
+++ b/lang/sql/sqlite/test/tkt-385a5b56b9.test
@@ -0,0 +1,53 @@
+# 2012 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.
+#
+#***********************************************************************
+# The tests in this file were used while developing the SQLite 4 code.
+#
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix tkt-385a5b56b9
+
+do_execsql_test 1.0 {
+ CREATE TABLE t1(x, y);
+ INSERT INTO t1 VALUES(1, NULL);
+ INSERT INTO t1 VALUES(2, NULL);
+ INSERT INTO t1 VALUES(1, NULL);
+}
+
+do_execsql_test 1.1 { SELECT DISTINCT x, y FROM t1 } {1 {} 2 {}}
+do_execsql_test 1.2 { CREATE UNIQUE INDEX i1 ON t1(x, y) }
+do_execsql_test 1.3 { SELECT DISTINCT x, y FROM t1 } {1 {} 2 {}}
+
+
+#-------------------------------------------------------------------------
+
+do_execsql_test 2.0 {
+ CREATE TABLE t2(x, y NOT NULL);
+ CREATE UNIQUE INDEX t2x ON t2(x);
+ CREATE UNIQUE INDEX t2y ON t2(y);
+}
+
+do_eqp_test 2.1 { SELECT DISTINCT x FROM t2 } {
+ 0 0 0 {SCAN TABLE t2 USING COVERING INDEX t2x}
+}
+
+do_eqp_test 2.2 { SELECT DISTINCT y FROM t2 } {
+ 0 0 0 {SCAN TABLE t2 USING COVERING INDEX t2y}
+}
+
+do_eqp_test 2.3 { SELECT DISTINCT x, y FROM t2 WHERE y=10 } {
+ 0 0 0 {SEARCH TABLE t2 USING INDEX t2y (y=?)}
+}
+
+do_eqp_test 2.4 { SELECT DISTINCT x, y FROM t2 WHERE x=10 } {
+ 0 0 0 {SEARCH TABLE t2 USING INDEX t2x (x=?)}
+}
+
+finish_test
diff --git a/lang/sql/sqlite/test/tkt-38cb5df375.test b/lang/sql/sqlite/test/tkt-38cb5df375.test
index 47b0b551..e5e02671 100644
--- a/lang/sql/sqlite/test/tkt-38cb5df375.test
+++ b/lang/sql/sqlite/test/tkt-38cb5df375.test
@@ -16,6 +16,11 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
+ifcapable !compound {
+ finish_test
+ return
+}
+
do_test tkt-38cb5df375.0 {
execsql {
CREATE TABLE t1(a);
diff --git a/lang/sql/sqlite/test/tkt-3a77c9714e.test b/lang/sql/sqlite/test/tkt-3a77c9714e.test
new file mode 100644
index 00000000..b7d366f3
--- /dev/null
+++ b/lang/sql/sqlite/test/tkt-3a77c9714e.test
@@ -0,0 +1,72 @@
+# 2011 December 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 to verify that ticket [3a77c9714e] has been
+# fixed.
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+ifcapable !compound {
+ finish_test
+ return
+}
+
+set testprefix "tkt-3a77c9714e"
+
+do_execsql_test 1.1 {
+ CREATE TABLE t1(t1_id INTEGER PRIMARY KEY, t1_title TEXT);
+ CREATE TABLE t2(t2_id INTEGER PRIMARY KEY, t2_title TEXT);
+ CREATE TABLE t3(t3_id INTEGER PRIMARY KEY, t3_title TEXT);
+
+ INSERT INTO t1 (t1_id, t1_title) VALUES (888, 'ABCDEF');
+ INSERT INTO t2 (t2_id, t2_title) VALUES (999, 'ABCDEF');
+ INSERT INTO t3 (t3_id, t3_title) VALUES (999, 'ABCDEF');
+}
+
+do_execsql_test 1.2 {
+ SELECT t1_title, t2_title
+ FROM t1 LEFT JOIN t2
+ WHERE
+ t2_id = (SELECT t3_id FROM
+ ( SELECT t3_id FROM t3 WHERE t3_title=t1_title LIMIT 500 )
+ )
+} {ABCDEF ABCDEF}
+
+do_execsql_test 2.1 {
+ CREATE TABLE [Beginnings] (
+ [Id] INTEGER PRIMARY KEY AUTOINCREMENT,[Title] TEXT, [EndingId] INTEGER
+ );
+ CREATE TABLE [Endings] (Id INT,Title TEXT,EndingId INT);
+ INSERT INTO Beginnings (Id, Title, EndingId) VALUES (1, 'FACTOR', 18);
+ INSERT INTO Beginnings (Id, Title, EndingId) VALUES (2, 'SWIMM', 18);
+ INSERT INTO Endings (Id, Title, EndingId) VALUES (1, 'ING', 18);
+}
+
+do_execsql_test 2.2 {
+ SELECT
+ SrcWord, Beginnings.Title
+ FROM
+ (SELECT 'FACTORING' AS SrcWord UNION SELECT 'SWIMMING' AS SrcWord )
+ LEFT JOIN
+ Beginnings
+ WHERE Beginnings.Id= (
+ SELECT BeginningId FROM (
+ SELECT SrcWord, B.Id as BeginningId, B.Title || E.Title As Connected
+ FROM Beginnings B LEFT JOIN Endings E ON B.EndingId=E.EndingId
+ WHERE Connected=SrcWord LIMIT 1
+ )
+ )
+} {FACTORING FACTOR SWIMMING SWIMM}
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/tkt-3fe897352e.test b/lang/sql/sqlite/test/tkt-3fe897352e.test
index deafe48e..bc2b2033 100644
--- a/lang/sql/sqlite/test/tkt-3fe897352e.test
+++ b/lang/sql/sqlite/test/tkt-3fe897352e.test
@@ -16,9 +16,9 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
-
-# The following tests use hex_to_utf16be() and hex_to_utf16le() which
-# which are only available if SQLite is built with UTF16 support.
+
+# The following tests use hex_to_utf16be() and hex_to_utf16le() which
+# which are only available if SQLite is built with UTF16 support.
ifcapable {!utf16} {
finish_test
return
diff --git a/lang/sql/sqlite/test/tkt-4a03edc4c8.test b/lang/sql/sqlite/test/tkt-4a03edc4c8.test
index 649f27d2..1908bcdf 100644
--- a/lang/sql/sqlite/test/tkt-4a03edc4c8.test
+++ b/lang/sql/sqlite/test/tkt-4a03edc4c8.test
@@ -31,7 +31,7 @@ do_test tkt-4a03ed-1.1 {
INSERT INTO t1 VALUES(1, 2);
COMMIT;
}
-} {1 {column b is not unique}}
+} {1 {UNIQUE constraint failed: t1.b}}
do_test tkt-4a03ed-1.2 {
db eval {
PRAGMA integrity_check;
diff --git a/lang/sql/sqlite/test/tkt-4c86b126f2.test b/lang/sql/sqlite/test/tkt-4c86b126f2.test
new file mode 100644
index 00000000..3c5177ed
--- /dev/null
+++ b/lang/sql/sqlite/test/tkt-4c86b126f2.test
@@ -0,0 +1,49 @@
+# 2014-02-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. Specifically,
+# it tests that ticket [4c86b126f22ad548fee0125337bdc9366912d9ac].
+#
+# When SQLite is compiled using SQLITE_ENABLE_STAT3 or SQLITE_ENABLE_STAT4,
+# it gets the wrong answer...
+#
+# The problem was introduced in SQLite 3.8.1.
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+do_execsql_test tkt-4c86b126f2-1.1 {
+ CREATE TABLE nodes(
+ local_relpath TEXT PRIMARY KEY,
+ moved_to TEXT
+ );
+ INSERT INTO nodes VALUES('A',NULL);
+ INSERT INTO nodes VALUES('A/B',NULL);
+ INSERT INTO nodes VALUES('',NULL);
+ INSERT INTO nodes VALUES('A/B/C-move',NULL);
+ INSERT INTO nodes VALUES('A/B/C','A/B/C-move');
+ INSERT INTO nodes VALUES('A/B-move',NULL);
+ INSERT INTO nodes VALUES('A/B-move/C-move',NULL);
+ INSERT INTO nodes VALUES('A/B-move/C','x');
+ SELECT local_relpath, moved_to
+ FROM nodes
+ WHERE (local_relpath = 'A/B' OR
+ ((local_relpath > 'A/B/') AND (local_relpath < 'A/B0')))
+ AND moved_to IS NOT NULL;
+} {A/B/C A/B/C-move}
+
+do_execsql_test tkt-4c86b126f2-2.1 {
+ CREATE TABLE t1(x TEXT UNIQUE, y TEXT UNIQUE, z);
+ INSERT INTO t1 VALUES('ghi','jkl','y');
+ SELECT * FROM t1 WHERE (x='ghi' OR y='jkl') AND z IS NOT NULL;
+} {ghi jkl y}
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/tkt-4dd95f6943.test b/lang/sql/sqlite/test/tkt-4dd95f6943.test
new file mode 100644
index 00000000..353031e7
--- /dev/null
+++ b/lang/sql/sqlite/test/tkt-4dd95f6943.test
@@ -0,0 +1,151 @@
+# 2013 March 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.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set ::testprefix tkt-4dd95f6943
+
+do_execsql_test 1.0 {
+ CREATE TABLE t1(x);
+ INSERT INTO t1 VALUES (3), (4), (2), (1), (5), (6);
+}
+
+foreach {tn1 idx} {
+ 1 { CREATE INDEX i1 ON t1(x ASC) }
+ 2 { CREATE INDEX i1 ON t1(x DESC) }
+} {
+ do_execsql_test 1.$tn1.1 { DROP INDEX IF EXISTS i1; }
+ do_execsql_test 1.$tn1.2 $idx
+
+ do_execsql_test 1.$tn1.3 {
+ SELECT x FROM t1 WHERE x IN(2, 4, 5) ORDER BY x ASC;
+ } {2 4 5}
+
+ do_execsql_test 1.$tn1.4 {
+ SELECT x FROM t1 WHERE x IN(2, 4, 5) ORDER BY x DESC;
+ } {5 4 2}
+}
+
+
+do_execsql_test 2.0 {
+ CREATE TABLE t2(x, y);
+ INSERT INTO t2 VALUES (5, 3), (5, 4), (5, 2), (5, 1), (5, 5), (5, 6);
+ INSERT INTO t2 VALUES (1, 3), (1, 4), (1, 2), (1, 1), (1, 5), (1, 6);
+ INSERT INTO t2 VALUES (3, 3), (3, 4), (3, 2), (3, 1), (3, 5), (3, 6);
+ INSERT INTO t2 VALUES (2, 3), (2, 4), (2, 2), (2, 1), (2, 5), (2, 6);
+ INSERT INTO t2 VALUES (4, 3), (4, 4), (4, 2), (4, 1), (4, 5), (4, 6);
+ INSERT INTO t2 VALUES (6, 3), (6, 4), (6, 2), (6, 1), (6, 5), (6, 6);
+
+ CREATE TABLE t3(a, b);
+ INSERT INTO t3 VALUES (2, 2), (4, 4), (5, 5);
+ CREATE UNIQUE INDEX t3i1 ON t3(a ASC);
+ CREATE UNIQUE INDEX t3i2 ON t3(b DESC);
+}
+
+foreach {tn1 idx} {
+ 1 { CREATE INDEX i1 ON t2(x ASC, y ASC) }
+ 2 { CREATE INDEX i1 ON t2(x ASC, y DESC) }
+ 3 { CREATE INDEX i1 ON t2(x DESC, y ASC) }
+ 4 { CREATE INDEX i1 ON t2(x DESC, y DESC) }
+
+ 5 { CREATE INDEX i1 ON t2(y ASC, x ASC) }
+ 6 { CREATE INDEX i1 ON t2(y ASC, x DESC) }
+ 7 { CREATE INDEX i1 ON t2(y DESC, x ASC) }
+ 8 { CREATE INDEX i1 ON t2(y DESC, x DESC) }
+} {
+ do_execsql_test 2.$tn1.1 { DROP INDEX IF EXISTS i1; }
+ do_execsql_test 2.$tn1.2 $idx
+
+ foreach {tn2 inexpr} {
+ 3 "(2, 4, 5)"
+ 4 "(SELECT a FROM t3)"
+ 5 "(SELECT b FROM t3)"
+ } {
+ do_execsql_test 2.$tn1.$tn2.1 "
+ SELECT x, y FROM t2 WHERE x = 1 AND y IN $inexpr ORDER BY x ASC, y ASC;
+ " {1 2 1 4 1 5}
+
+ do_execsql_test 2.$tn1.$tn2.2 "
+ SELECT x, y FROM t2 WHERE x = 2 AND y IN $inexpr ORDER BY x ASC, y DESC;
+ " {2 5 2 4 2 2}
+
+ do_execsql_test 2.$tn1.$tn2.3 "
+ SELECT x, y FROM t2 WHERE x = 3 AND y IN $inexpr ORDER BY x DESC, y ASC;
+ " {3 2 3 4 3 5}
+
+ do_execsql_test 2.$tn1.$tn2.4 "
+ SELECT x, y FROM t2 WHERE x = 4 AND y IN $inexpr ORDER BY x DESC, y DESC;
+ " {4 5 4 4 4 2}
+
+ do_execsql_test 2.$tn1.$tn2.5 "
+ SELECT a, x, y FROM t2, t3 WHERE a = 4 AND x = 1 AND y IN $inexpr
+ ORDER BY a, x ASC, y ASC;
+ " {4 1 2 4 1 4 4 1 5}
+ do_execsql_test 2.$tn1.$tn2.6 "
+ SELECT a, x, y FROM t2, t3 WHERE a = 2 AND x = 1 AND y IN $inexpr
+ ORDER BY x ASC, y ASC;
+ " {2 1 2 2 1 4 2 1 5}
+
+ do_execsql_test 2.$tn1.$tn2.7 "
+ SELECT a, x, y FROM t2, t3 WHERE a = 4 AND x = 1 AND y IN $inexpr
+ ORDER BY a, x ASC, y DESC;
+ " {4 1 5 4 1 4 4 1 2}
+ do_execsql_test 2.$tn1.8 "
+ SELECT a, x, y FROM t2, t3 WHERE a = 2 AND x = 1 AND y IN $inexpr
+ ORDER BY x ASC, y DESC;
+ " {2 1 5 2 1 4 2 1 2}
+
+ do_execsql_test 2.$tn1.$tn2.9 "
+ SELECT a, x, y FROM t2, t3 WHERE a = 4 AND x = 1 AND y IN $inexpr
+ ORDER BY a, x DESC, y ASC;
+ " {4 1 2 4 1 4 4 1 5}
+ do_execsql_test 2.$tn1.10 "
+ SELECT a, x, y FROM t2, t3 WHERE a = 2 AND x = 1 AND y IN $inexpr
+ ORDER BY x DESC, y ASC;
+ " {2 1 2 2 1 4 2 1 5}
+
+ do_execsql_test 2.$tn1.$tn2.11 "
+ SELECT a, x, y FROM t2, t3 WHERE a = 4 AND x = 1 AND y IN $inexpr
+ ORDER BY a, x DESC, y DESC;
+ " {4 1 5 4 1 4 4 1 2}
+ do_execsql_test 2.$tn1.$tn2.12 "
+ SELECT a, x, y FROM t2, t3 WHERE a = 2 AND x = 1 AND y IN $inexpr
+ ORDER BY x DESC, y DESC;
+ " {2 1 5 2 1 4 2 1 2}
+ }
+}
+
+do_execsql_test 3.0 {
+ CREATE TABLE t7(x);
+ INSERT INTO t7 VALUES (1), (2), (3);
+ CREATE INDEX i7 ON t7(x);
+
+ CREATE TABLE t8(y);
+ INSERT INTO t8 VALUES (1), (2), (3);
+}
+
+foreach {tn idxdir sortdir sortdata} {
+ 1 ASC ASC {1 2 3}
+ 2 ASC DESC {3 2 1}
+ 3 DESC ASC {1 2 3}
+ 4 ASC DESC {3 2 1}
+} {
+
+ do_execsql_test 3.$tn "
+ DROP INDEX IF EXISTS i8;
+ CREATE UNIQUE INDEX i8 ON t8(y $idxdir);
+ SELECT x FROM t7 WHERE x IN (SELECT y FROM t8) ORDER BY x $sortdir;
+ " $sortdata
+}
+
+finish_test
diff --git a/lang/sql/sqlite/test/tkt-54844eea3f.test b/lang/sql/sqlite/test/tkt-54844eea3f.test
new file mode 100644
index 00000000..7b04f693
--- /dev/null
+++ b/lang/sql/sqlite/test/tkt-54844eea3f.test
@@ -0,0 +1,67 @@
+# 2011 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 implements regression tests for SQLite library. The
+# focus of this file is testing that bug [54844eea3f] has been fixed.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+set ::testprefix tkt-54844eea3f
+
+do_test 1.0 {
+ execsql {
+ CREATE TABLE t1(a INTEGER PRIMARY KEY);
+ INSERT INTO t1 VALUES(1);
+ INSERT INTO t1 VALUES(4);
+
+ CREATE TABLE t2(b INTEGER PRIMARY KEY);
+ INSERT INTO t2 VALUES(1);
+ INSERT INTO t2 VALUES(2);
+ INSERT INTO t2 SELECT b+2 FROM t2;
+ INSERT INTO t2 SELECT b+4 FROM t2;
+ INSERT INTO t2 SELECT b+8 FROM t2;
+ INSERT INTO t2 SELECT b+16 FROM t2;
+
+ CREATE TABLE t3(c INTEGER PRIMARY KEY);
+ INSERT INTO t3 VALUES(1);
+ INSERT INTO t3 VALUES(2);
+ INSERT INTO t3 VALUES(3);
+ }
+} {}
+
+do_test 1.1 {
+ execsql {
+ SELECT 'test-2', t3.c, (
+ SELECT count(*)
+ FROM t1 JOIN (SELECT DISTINCT t3.c AS p FROM t2) AS x ON t1.a=x.p
+ )
+ FROM t3;
+ }
+} {test-2 1 1 test-2 2 0 test-2 3 0}
+
+do_test 1.2 {
+ execsql {
+ CREATE TABLE t4(a, b, c);
+ INSERT INTO t4 VALUES('a', 1, 'one');
+ INSERT INTO t4 VALUES('a', 2, 'two');
+ INSERT INTO t4 VALUES('b', 1, 'three');
+ INSERT INTO t4 VALUES('b', 2, 'four');
+ SELECT (
+ SELECT c FROM (
+ SELECT * FROM t4 WHERE a=out.a ORDER BY b LIMIT 10 OFFSET 1
+ ) WHERE b=out.b
+ ) FROM t4 AS out;
+ }
+} {{} two {} four}
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/tkt-5d863f876e.test b/lang/sql/sqlite/test/tkt-5d863f876e.test
index 0a9017de..86024e30 100644
--- a/lang/sql/sqlite/test/tkt-5d863f876e.test
+++ b/lang/sql/sqlite/test/tkt-5d863f876e.test
@@ -17,6 +17,8 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
source $testdir/lock_common.tcl
+set ::testprefix tkt-5d863f876e
+ifcapable !wal {finish_test ; return }
do_multiclient_test tn {
do_test $tn.1 {
diff --git a/lang/sql/sqlite/test/tkt-5ee23731f.test b/lang/sql/sqlite/test/tkt-5ee23731f.test
index 61c99741..761382a4 100644
--- a/lang/sql/sqlite/test/tkt-5ee23731f.test
+++ b/lang/sql/sqlite/test/tkt-5ee23731f.test
@@ -19,7 +19,7 @@ source $testdir/tester.tcl
do_test tkt-5ee237-1.1 {
db close
- file delete -force test.db
+ forcedelete test.db
sqlite3 db test.db
db eval {
CREATE TABLE t1(x UNIQUE);
diff --git a/lang/sql/sqlite/test/tkt-6bfb98dfc0.test b/lang/sql/sqlite/test/tkt-6bfb98dfc0.test
new file mode 100644
index 00000000..675a3fc2
--- /dev/null
+++ b/lang/sql/sqlite/test/tkt-6bfb98dfc0.test
@@ -0,0 +1,61 @@
+# 2013 March 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. Specifically,
+# it tests that ticket [6bfb98dfc0]
+#
+# The final INSERT in the script below reports that the database is
+# corrupt (SQLITE_CORRUPT) and aborts even though the database is not
+# corrupt.
+#
+# PRAGMA page_size=512;
+# CREATE TABLE t1(x INTEGER PRIMARY KEY, y);
+# INSERT INTO t1 VALUES(1,randomblob(400));
+# INSERT INTO t1 VALUES(2,randomblob(400));
+# INSERT INTO t1 SELECT x+2, randomblob(400) FROM t1;
+# INSERT INTO t1 SELECT x+4, randomblob(400) FROM t1;
+# INSERT INTO t1 SELECT x+8, randomblob(400) FROM t1;
+# INSERT INTO t1 SELECT x+16, randomblob(400) FROM t1;
+# INSERT INTO t1 SELECT x+32, randomblob(400) FROM t1;
+# INSERT INTO t1 SELECT x+64, randomblob(400) FROM t1 WHERE x<10;
+# CREATE TRIGGER r1 AFTER INSERT ON t1 WHEN new.x=74 BEGIN
+# DELETE FROM t1;
+# INSERT INTO t1 VALUES(75, randomblob(400));
+# INSERT INTO t1 VALUES(76, randomblob(400));
+# END;
+# INSERT INTO t1 VALUES(74, randomblob(400));
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+do_test tkt-6bfb98dfc0.100 {
+ db eval {
+ PRAGMA page_size=512;
+ CREATE TABLE t1(x INTEGER PRIMARY KEY, y);
+ INSERT INTO t1 VALUES(1,randomblob(400));
+ INSERT INTO t1 VALUES(2,randomblob(400));
+ INSERT INTO t1 SELECT x+2, randomblob(400) FROM t1;
+ INSERT INTO t1 SELECT x+4, randomblob(400) FROM t1;
+ INSERT INTO t1 SELECT x+8, randomblob(400) FROM t1;
+ INSERT INTO t1 SELECT x+16, randomblob(400) FROM t1;
+ INSERT INTO t1 SELECT x+32, randomblob(400) FROM t1;
+ INSERT INTO t1 SELECT x+64, randomblob(400) FROM t1 WHERE x<10;
+ CREATE TRIGGER r1 AFTER INSERT ON t1 WHEN new.x=74 BEGIN
+ DELETE FROM t1;
+ INSERT INTO t1 VALUES(75, randomblob(400));
+ INSERT INTO t1 VALUES(76, randomblob(400));
+ END;
+ INSERT INTO t1 VALUES(74, randomblob(400));
+ SELECT x, length(y) FROM t1 ORDER BY x;
+ }
+} {75 400 76 400}
+
+finish_test
diff --git a/lang/sql/sqlite/test/tkt-78e04e52ea.test b/lang/sql/sqlite/test/tkt-78e04e52ea.test
index 9524d845..975e5b3d 100644
--- a/lang/sql/sqlite/test/tkt-78e04e52ea.test
+++ b/lang/sql/sqlite/test/tkt-78e04e52ea.test
@@ -18,23 +18,23 @@ source $testdir/tester.tcl
do_test tkt-78e04-1.0 {
execsql {
- CREATE TABLE ""("" UNIQUE);
+ CREATE TABLE ""("" UNIQUE, x CHAR(100));
CREATE TABLE t2(x);
- INSERT INTO "" VALUES(1);
+ INSERT INTO ""("") VALUES(1);
INSERT INTO t2 VALUES(2);
SELECT * FROM "", t2;
}
-} {1 2}
+} {1 {} 2}
do_test tkt-78e04-1.1 {
catchsql {
- INSERT INTO "" VALUES(1);
+ INSERT INTO ""("") VALUES(1);
}
-} {1 {column is not unique}}
+} {1 {UNIQUE constraint failed: .}}
do_test tkt-78e04-1.2 {
execsql {
PRAGMA table_info("");
}
-} {0 {} {} 0 {} 0}
+} {0 {} {} 0 {} 0 1 x CHAR(100) 0 {} 0}
do_test tkt-78e04-1.3 {
execsql {
CREATE INDEX i1 ON ""("" COLLATE nocase);
@@ -42,9 +42,9 @@ do_test tkt-78e04-1.3 {
} {}
do_test tkt-78e04-1.4 {
execsql {
- EXPLAIN QUERY PLAN SELECT * FROM "" WHERE "" LIKE 'abc%';
+ EXPLAIN QUERY PLAN SELECT "" FROM "" WHERE "" LIKE 'abc%';
}
-} {0 0 0 {SCAN TABLE (~500000 rows)}}
+} {0 0 0 {SCAN TABLE USING COVERING INDEX i1}}
do_test tkt-78e04-1.5 {
execsql {
DROP TABLE "";
@@ -57,12 +57,12 @@ do_test tkt-78e04-2.1 {
CREATE INDEX "" ON t2(x);
EXPLAIN QUERY PLAN SELECT * FROM t2 WHERE x=5;
}
-} {0 0 0 {SEARCH TABLE t2 USING COVERING INDEX (x=?) (~10 rows)}}
+} {0 0 0 {SEARCH TABLE t2 USING COVERING INDEX (x=?)}}
do_test tkt-78e04-2.2 {
execsql {
DROP INDEX "";
EXPLAIN QUERY PLAN SELECT * FROM t2 WHERE x=2;
}
-} {0 0 0 {SCAN TABLE t2 (~100000 rows)}}
+} {0 0 0 {SCAN TABLE t2}}
finish_test
diff --git a/lang/sql/sqlite/test/tkt-7a31705a7e6.test b/lang/sql/sqlite/test/tkt-7a31705a7e6.test
new file mode 100644
index 00000000..e3e40291
--- /dev/null
+++ b/lang/sql/sqlite/test/tkt-7a31705a7e6.test
@@ -0,0 +1,25 @@
+# 2013 February 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. Specifically,
+# it tests that ticket [7a31705a7e6c95d514e6f20a6900f436bbc9fed8] in the
+# name resolver has been fixed.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+do_execsql_test tkt-7a31705a7e6-1.1 {
+ CREATE TABLE t1 (a INTEGER PRIMARY KEY);
+ CREATE TABLE t2 (a INTEGER PRIMARY KEY, b INTEGER);
+ CREATE TABLE t2x (b INTEGER PRIMARY KEY);
+ SELECT t1.a FROM ((t1 JOIN t2 ON t1.a=t2.a) AS x JOIN t2x ON x.b=t2x.b) as y;
+} {}
diff --git a/lang/sql/sqlite/test/tkt-7bbfb7d442.test b/lang/sql/sqlite/test/tkt-7bbfb7d442.test
new file mode 100644
index 00000000..56d4caeb
--- /dev/null
+++ b/lang/sql/sqlite/test/tkt-7bbfb7d442.test
@@ -0,0 +1,154 @@
+# 2011 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.
+#
+#***********************************************************************
+# This file implements regression tests for SQLite library.
+#
+# This file implements tests to verify that ticket [7bbfb7d442] has been
+# fixed.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix tkt-7bbfb7d442
+
+do_execsql_test 1.1 {
+ CREATE TABLE t1(a, b);
+ INSERT INTO t1 VALUES(1, 'one');
+ INSERT INTO t1 VALUES(2, 'two');
+ INSERT INTO t1 VALUES(3, 'three');
+
+ CREATE TABLE t2(c, d);
+ INSERT INTO t2 VALUES('one', 'I');
+ INSERT INTO t2 VALUES('two', 'II');
+ INSERT INTO t2 VALUES('three', 'III');
+
+ CREATE TABLE t3(t3_a PRIMARY KEY, t3_d);
+ CREATE TRIGGER t3t AFTER INSERT ON t3 WHEN new.t3_d IS NULL BEGIN
+ UPDATE t3 SET t3_d = (
+ SELECT d FROM
+ (SELECT * FROM t2 WHERE (new.t3_a%2)=(rowid%2) LIMIT 10),
+ (SELECT * FROM t1 WHERE (new.t3_a%2)=(rowid%2) LIMIT 10)
+ WHERE a = new.t3_a AND b = c
+ ) WHERE t3_a = new.t3_a;
+ END;
+}
+
+do_execsql_test 1.2 {
+ INSERT INTO t3(t3_a) VALUES(1);
+ INSERT INTO t3(t3_a) VALUES(2);
+ INSERT INTO t3(t3_a) VALUES(3);
+ SELECT * FROM t3;
+} {1 I 2 II 3 III}
+
+do_execsql_test 1.3 { DELETE FROM t3 }
+
+ifcapable compound {
+ do_execsql_test 1.4 {
+ INSERT INTO t3(t3_a) SELECT 1 UNION SELECT 2 UNION SELECT 3;
+ SELECT * FROM t3;
+ } {1 I 2 II 3 III}
+}
+
+
+
+#-------------------------------------------------------------------------
+# The following test case - 2.* - is from the original bug report as
+# posted to the mailing list.
+#
+do_execsql_test 2.1 {
+ CREATE TABLE InventoryControl (
+ InventoryControlId INTEGER PRIMARY KEY AUTOINCREMENT,
+ SKU INTEGER NOT NULL,
+ Variant INTEGER NOT NULL DEFAULT 0,
+ ControlDate DATE NOT NULL,
+ ControlState INTEGER NOT NULL DEFAULT -1,
+ DeliveredQty VARCHAR(30)
+ );
+
+ CREATE TRIGGER TGR_InventoryControl_AfterInsert
+ AFTER INSERT ON InventoryControl
+ FOR EACH ROW WHEN NEW.ControlState=-1 BEGIN
+
+ INSERT OR REPLACE INTO InventoryControl(
+ InventoryControlId,SKU,Variant,ControlDate,ControlState,DeliveredQty
+ ) SELECT
+ T1.InventoryControlId AS InventoryControlId,
+ T1.SKU AS SKU,
+ T1.Variant AS Variant,
+ T1.ControlDate AS ControlDate,
+ 1 AS ControlState,
+ COALESCE(T2.DeliveredQty,0) AS DeliveredQty
+ FROM (
+ SELECT
+ NEW.InventoryControlId AS InventoryControlId,
+ II.SKU AS SKU,
+ II.Variant AS Variant,
+ COALESCE(LastClosedIC.ControlDate,NEW.ControlDate) AS ControlDate
+ FROM
+ InventoryItem II
+ LEFT JOIN
+ InventoryControl LastClosedIC
+ ON LastClosedIC.InventoryControlId IN ( SELECT 99999 )
+ WHERE
+ II.SKU=NEW.SKU AND
+ II.Variant=NEW.Variant
+ ) T1
+ LEFT JOIN (
+ SELECT
+ TD.SKU AS SKU,
+ TD.Variant AS Variant,
+ 10 AS DeliveredQty
+ FROM
+ TransactionDetail TD
+ WHERE
+ TD.SKU=NEW.SKU AND
+ TD.Variant=NEW.Variant
+ ) T2
+ ON T2.SKU=T1.SKU AND
+ T2.Variant=T1.Variant;
+ END;
+
+ CREATE TABLE InventoryItem (
+ SKU INTEGER NOT NULL,
+ Variant INTEGER NOT NULL DEFAULT 0,
+ DeptCode INTEGER NOT NULL,
+ GroupCode INTEGER NOT NULL,
+ ItemDescription VARCHAR(120) NOT NULL,
+ PRIMARY KEY(SKU, Variant)
+ );
+
+ INSERT INTO InventoryItem VALUES(220,0,1,170,'Scoth Tampon Recurer');
+ INSERT INTO InventoryItem VALUES(31,0,1,110,'Fromage');
+
+ CREATE TABLE TransactionDetail (
+ TransactionId INTEGER NOT NULL,
+ SKU INTEGER NOT NULL,
+ Variant INTEGER NOT NULL DEFAULT 0,
+ PRIMARY KEY(TransactionId, SKU, Variant)
+ );
+ INSERT INTO TransactionDetail(TransactionId, SKU, Variant) VALUES(44, 31, 0);
+
+
+ INSERT INTO InventoryControl(SKU, Variant, ControlDate) SELECT
+ II.SKU AS SKU, II.Variant AS Variant, '2011-08-30' AS ControlDate
+ FROM InventoryItem II;
+}
+
+do_execsql_test 2.2 {
+ SELECT SKU, DeliveredQty FROM InventoryControl WHERE SKU=31
+} {31 10}
+
+do_execsql_test 2.3 {
+ SELECT CASE WHEN DeliveredQty=10 THEN "TEST PASSED!" ELSE "TEST FAILED!" END
+ FROM InventoryControl WHERE SKU=31;
+} {{TEST PASSED!}}
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/tkt-80ba201079.test b/lang/sql/sqlite/test/tkt-80ba201079.test
index 95e99b5a..ea0799b5 100644
--- a/lang/sql/sqlite/test/tkt-80ba201079.test
+++ b/lang/sql/sqlite/test/tkt-80ba201079.test
@@ -17,7 +17,7 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
-set ::testprefix tkt-80ba2
+set ::testprefix tkt-80ba201079
do_test tkt-80ba2-100 {
db eval {
@@ -164,11 +164,13 @@ do_execsql_test 303 {
(b='B' AND c IN (SELECT c FROM t1))
} {A B C D E}
-do_execsql_test 304 {
- SELECT * FROM t1, t2 WHERE
- (a='A' AND d='E') OR
- (b='B' AND c IN (SELECT 'B' UNION SELECT 'C' UNION SELECT 'D'))
-} {A B C D E}
+ifcapable compound {
+ do_execsql_test 304 {
+ SELECT * FROM t1, t2 WHERE
+ (a='A' AND d='E') OR
+ (b='B' AND c IN (SELECT 'B' UNION SELECT 'C' UNION SELECT 'D'))
+ } {A B C D E}
+}
do_execsql_test 305 {
SELECT * FROM t1, t2 WHERE
@@ -182,10 +184,12 @@ do_execsql_test 306 {
(a='A' AND d='E')
} {A B C D E}
-do_execsql_test 307 {
- SELECT * FROM t1, t2 WHERE
- (b='B' AND c IN (SELECT 'B' UNION SELECT 'C' UNION SELECT 'D')) OR
- (a='A' AND d='E')
-} {A B C D E}
+ifcapable compound {
+ do_execsql_test 307 {
+ SELECT * FROM t1, t2 WHERE
+ (b='B' AND c IN (SELECT 'B' UNION SELECT 'C' UNION SELECT 'D')) OR
+ (a='A' AND d='E')
+ } {A B C D E}
+}
finish_test
diff --git a/lang/sql/sqlite/test/tkt-868145d012.test b/lang/sql/sqlite/test/tkt-868145d012.test
new file mode 100644
index 00000000..145d159e
--- /dev/null
+++ b/lang/sql/sqlite/test/tkt-868145d012.test
@@ -0,0 +1,64 @@
+# 2013 March 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. Specifically,
+# it tests that ticket [868145d012a1] is fixed.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+do_execsql_test tkt-868145d012.100 {
+ CREATE TABLE p (
+ id INTEGER PRIMARY KEY,
+ uid VARCHAR(36),
+ t INTEGER
+ );
+
+ CREATE TABLE pa (
+ id INTEGER PRIMARY KEY,
+ a_uid VARCHAR(36)
+ );
+
+ CREATE TABLE a (
+ id INTEGER PRIMARY KEY,
+ uid VARCHAR(36),
+ t INTEGER
+ );
+
+ INSERT INTO pa VALUES(1,'1234');
+ INSERT INTO pa VALUES(2,'2345');
+ INSERT INTO p VALUES(3,'1234',97);
+ INSERT INTO p VALUES(4,'1234',98);
+ INSERT INTO a VALUES(5,'1234',98);
+ INSERT INTO a VALUES(6,'1234',99);
+} {}
+do_execsql_test tkt-868145d012.110 {
+ SELECT DISTINCT pa.id, p.id, a.id
+ FROM
+ pa
+ LEFT JOIN p ON p.uid='1234'
+ LEFT JOIN a ON a.uid=pa.a_uid
+ WHERE
+ a.t=p.t
+ ;
+} {1 4 5}
+do_execsql_test tkt-868145d012.120 {
+ SELECT DISTINCT pa.id, p.id, a.id
+ FROM
+ pa
+ LEFT JOIN p ON p.uid='1234'
+ LEFT JOIN a ON a.uid=pa.a_uid AND a.t=p.t
+ ORDER BY 1, 2, 3
+ ;
+} {1 3 {} 1 4 5 2 3 {} 2 4 {}}
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/tkt-91e2e8ba6f.test b/lang/sql/sqlite/test/tkt-91e2e8ba6f.test
new file mode 100644
index 00000000..57f13740
--- /dev/null
+++ b/lang/sql/sqlite/test/tkt-91e2e8ba6f.test
@@ -0,0 +1,52 @@
+# 2011 June 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 contains tests for SQLite. Specifically, it tests that SQLite
+# does not crash and an error is returned if localhost() fails. This
+# is the problem reported by ticket 91e2e8ba6f.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+set testprefix tkt-91e2e8ba6f
+
+
+do_execsql_test 1.1 {
+ CREATE TABLE t1(x INTEGER, y REAL);
+ INSERT INTO t1 VALUES(11, 11);
+} {}
+
+do_execsql_test 1.2 {
+ SELECT x/10, y/10 FROM t1;
+} {1 1.1}
+
+do_execsql_test 1.3 {
+ SELECT x/10, y/10 FROM (SELECT * FROM t1);
+} {1 1.1}
+
+do_execsql_test 1.4 {
+ SELECT x/10, y/10 FROM (SELECT * FROM t1 LIMIT 5 OFFSET 0);
+} {1 1.1}
+
+do_execsql_test 1.5 {
+ SELECT x/10, y/10 FROM (SELECT * FROM t1 LIMIT 5 OFFSET 0) LIMIT 5 OFFSET 0;
+} {1 1.1}
+
+do_execsql_test 1.6 {
+ SELECT a.x/10, a.y/10 FROM
+ (SELECT * FROM t1 LIMIT 5 OFFSET 0) AS a, t1 AS b WHERE a.x = b.x
+ LIMIT 5 OFFSET 0;
+} {1 1.1}
+
+do_execsql_test 1.7 {
+ CREATE VIEW v1 AS SELECT * FROM t1 LIMIT 5;
+ SELECT a.x/10, a.y/10 FROM v1 AS a, t1 AS b WHERE a.x = b.x LIMIT 5 OFFSET 0;
+} {1 1.1}
+
+finish_test
diff --git a/lang/sql/sqlite/test/tkt-94c04eaadb.test b/lang/sql/sqlite/test/tkt-94c04eaadb.test
index cce8a98e..9de8aea2 100644
--- a/lang/sql/sqlite/test/tkt-94c04eaadb.test
+++ b/lang/sql/sqlite/test/tkt-94c04eaadb.test
@@ -27,7 +27,7 @@ do_test tkt-94c94-1.1 {
# Grow the file to larger than 4096MB (2^32 bytes)
db close
-if {[catch {fake_big_file 4096 [pwd]/test.db} msg]} {
+if {[catch {fake_big_file 4096 [get_pwd]/test.db} msg]} {
puts "**** Unable to create a file larger than 4096 MB. *****"
finish_test
return
@@ -44,7 +44,6 @@ do_test tkt-94c94-2.1 {
execsql { CREATE TABLE t2(x, y) } db
} {}
do_test tkt-94c94-2.2 {
-breakpoint
execsql { INSERT INTO t2 VALUES(1, 2) } db2
} {}
do_test tkt-94c94-2.3 {
diff --git a/lang/sql/sqlite/test/tkt-9f2eb3abac.test b/lang/sql/sqlite/test/tkt-9f2eb3abac.test
new file mode 100644
index 00000000..5b93733a
--- /dev/null
+++ b/lang/sql/sqlite/test/tkt-9f2eb3abac.test
@@ -0,0 +1,79 @@
+
+# 2013 August 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/malloc_common.tcl
+set ::testprefix tkt-9f2eb3abac
+
+do_execsql_test 1.1 {
+ CREATE TABLE t1(a,b,c,d,e, PRIMARY KEY(a,b,c,d,e));
+ SELECT * FROM t1 WHERE a=? AND b=? AND c=? AND d=? AND e=?;
+} {}
+
+do_execsql_test 1.2 {
+ CREATE TABLE "a" (
+ "b" integer NOT NULL,
+ "c" integer NOT NULL,
+ PRIMARY KEY ("b", "c")
+ );
+
+ CREATE TABLE "d" (
+ "e" integer NOT NULL,
+ "g" integer NOT NULL,
+ "f" integer NOT NULL,
+ "h" integer NOT NULL,
+ "i" character(10) NOT NULL,
+ "j" int,
+ PRIMARY KEY ("e", "g", "f", "h")
+ );
+
+ CREATE TABLE "d_to_a" (
+ "f_e" integer NOT NULL,
+ "f_g" integer NOT NULL,
+ "f_f" integer NOT NULL,
+ "f_h" integer NOT NULL,
+ "t_b" integer NOT NULL,
+ "t_c" integer NOT NULL,
+ "r" character NOT NULL,
+ "s" integer,
+ PRIMARY KEY ("f_e", "f_g", "f_f", "f_h", "t_b", "t_c")
+ );
+
+ INSERT INTO d (g, e, h, f, j, i) VALUES ( 1, 1, 1, 1, 1, 1 );
+ INSERT INTO a (b, c) VALUES ( 1, 1 );
+ INSERT INTO d_to_a VALUES (1, 1, 1, 1, 1, 1, 1, 1);
+
+ DELETE FROM d_to_a
+ WHERE f_g = 1 AND f_e = 1 AND f_h = 1 AND f_f = 1 AND t_b = 1 AND t_c = 1;
+
+ SELECT * FROM d_to_a;
+} {}
+
+faultsim_delete_and_reopen
+do_execsql_test 2.0 { CREATE TABLE t1(a,b,c,d,e, PRIMARY KEY(a,b,c,d,e)) }
+do_execsql_test 2.1 { CREATE TABLE t2(x) }
+faultsim_save_and_close
+
+do_faultsim_test 3 -faults oom* -prep {
+ faultsim_restore_and_reopen
+ execsql { SELECT 1 FROM sqlite_master }
+} -body {
+ execsql { SELECT * FROM t1,t2 WHERE a=? AND b=? AND c=? AND d=? AND e=? }
+} -test {
+ faultsim_test_result {0 {}}
+}
+
+finish_test
+
diff --git a/lang/sql/sqlite/test/tkt-a7b7803e.test b/lang/sql/sqlite/test/tkt-a7b7803e.test
new file mode 100644
index 00000000..b617cf6d
--- /dev/null
+++ b/lang/sql/sqlite/test/tkt-a7b7803e.test
@@ -0,0 +1,84 @@
+# 2012 December 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. Specifically,
+# it tests that ticket [a7b7803e8d1e8699cd8a460a38133b98892d2e17] has
+# been fixed.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+source $testdir/lock_common.tcl
+source $testdir/malloc_common.tcl
+
+do_test tkt-a7b7803e.1 {
+ db eval {
+ CREATE TABLE t1(a,b);
+ INSERT INTO t1 VALUES(0,'first'),(99,'fuzzy');
+ SELECT (t1.a==0) AS x, b
+ FROM t1
+ WHERE a=0 OR x;
+ }
+} {1 first}
+do_test tkt-a7b7803e.2 {
+ db eval {
+ SELECT a, (t1.b='fuzzy') AS x
+ FROM t1
+ WHERE x
+ }
+} {99 1}
+do_test tkt-a7b7803e.3 {
+ db eval {
+ SELECT (a=99) AS x, (t1.b='fuzzy') AS y, *
+ FROM t1
+ WHERE x AND y
+ }
+} {1 1 99 fuzzy}
+do_test tkt-a7b7803e.4 {
+ db eval {
+ SELECT (a=99) AS x, (t1.b='first') AS y, *
+ FROM t1
+ WHERE x OR y
+ ORDER BY a
+ }
+} {0 1 0 first 1 0 99 fuzzy}
+do_test tkt-a7b7803e.5 {
+ db eval {
+ SELECT (M.a=99) AS x, M.b, (N.b='first') AS y, N.b
+ FROM t1 M, t1 N
+ WHERE x OR y
+ ORDER BY M.a, N.a
+ }
+} {0 first 1 first 1 fuzzy 1 first 1 fuzzy 0 fuzzy}
+do_test tkt-a7b7803e.6 {
+ db eval {
+ SELECT (M.a=99) AS x, M.b, (N.b='first') AS y, N.b
+ FROM t1 M, t1 N
+ WHERE x AND y
+ ORDER BY M.a, N.a
+ }
+} {1 fuzzy 1 first}
+do_test tkt-a7b7803e.7 {
+ db eval {
+ SELECT (M.a=99) AS x, M.b, (N.b='first') AS y, N.b
+ FROM t1 M JOIN t1 N ON x AND y
+ ORDER BY M.a, N.a
+ }
+} {1 fuzzy 1 first}
+do_test tkt-a7b7803e.8 {
+ db eval {
+ SELECT (M.a=99) AS x, M.b, (N.b='first') AS y, N.b
+ FROM t1 M JOIN t1 N ON x
+ ORDER BY M.a, N.a
+ }
+} {1 fuzzy 1 first 1 fuzzy 0 fuzzy}
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/tkt-b1d3a2e531.test b/lang/sql/sqlite/test/tkt-b1d3a2e531.test
new file mode 100644
index 00000000..745bbe86
--- /dev/null
+++ b/lang/sql/sqlite/test/tkt-b1d3a2e531.test
@@ -0,0 +1,109 @@
+# 2011 August 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 foreign keys. Specifically, it tests
+# that ticket b1d3a2e531 has been fixed.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+ifcapable {!foreignkey||!trigger} {
+ finish_test
+ return
+}
+set testprefix tkt-b1d3a2e531
+
+do_execsql_test 1.0 { PRAGMA foreign_keys = ON }
+
+do_execsql_test 1.1 {
+ CREATE TABLE pp(x PRIMARY KEY);
+ CREATE TABLE cc(y REFERENCES pp DEFERRABLE INITIALLY DEFERRED);
+ INSERT INTO pp VALUES('abc');
+ INSERT INTO cc VALUES('abc');
+}
+do_execsql_test 1.2 {
+ BEGIN;
+ DROP TABLE pp;
+ DROP TABLE cc;
+ COMMIT;
+}
+do_execsql_test 1.3 {
+ CREATE TABLE pp(x PRIMARY KEY);
+ CREATE TABLE cc(y REFERENCES pp DEFERRABLE INITIALLY DEFERRED);
+ INSERT INTO pp VALUES('abc');
+ INSERT INTO cc VALUES('abc');
+}
+do_execsql_test 1.4 {
+ BEGIN;
+ DROP TABLE cc;
+ DROP TABLE pp;
+ COMMIT;
+}
+
+do_execsql_test 2.1 {
+ CREATE TABLE pp(x PRIMARY KEY);
+ CREATE TABLE cc(
+ y INTEGER PRIMARY KEY REFERENCES pp DEFERRABLE INITIALLY DEFERRED
+ );
+ INSERT INTO pp VALUES(5);
+ INSERT INTO cc VALUES(5);
+}
+do_execsql_test 2.2 {
+ BEGIN;
+ DROP TABLE pp;
+ DROP TABLE cc;
+ COMMIT;
+}
+do_execsql_test 2.3 {
+ CREATE TABLE pp(x PRIMARY KEY);
+ CREATE TABLE cc(
+ y INTEGER PRIMARY KEY REFERENCES pp DEFERRABLE INITIALLY DEFERRED
+ );
+ INSERT INTO pp VALUES(5);
+ INSERT INTO cc VALUES(5);
+}
+do_execsql_test 2.4 {
+ BEGIN;
+ DROP TABLE cc;
+ DROP TABLE pp;
+ COMMIT;
+}
+
+do_execsql_test 3.1 {
+ CREATE TABLE pp1(x PRIMARY KEY);
+ CREATE TABLE cc1(y REFERENCES pp1 DEFERRABLE INITIALLY DEFERRED);
+
+ CREATE TABLE pp2(x PRIMARY KEY);
+ CREATE TABLE cc2(y REFERENCES pp1 DEFERRABLE INITIALLY DEFERRED);
+
+ INSERT INTO pp1 VALUES(2200);
+ INSERT INTO cc1 VALUES(NULL);
+
+ INSERT INTO pp2 VALUES(2200);
+ INSERT INTO cc2 VALUES(2200);
+}
+do_catchsql_test 3.2 {
+ BEGIN;
+ DELETE FROM pp2;
+ DROP TABLE pp1;
+ DROP TABLE cc1;
+ COMMIT;
+} {1 {FOREIGN KEY constraint failed}}
+do_catchsql_test 3.3 {
+ DROP TABLE cc2;
+ COMMIT;
+} {0 {}}
+
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/tkt-b72787b1.test b/lang/sql/sqlite/test/tkt-b72787b1.test
index 11ea41ed..dea3f49a 100644
--- a/lang/sql/sqlite/test/tkt-b72787b1.test
+++ b/lang/sql/sqlite/test/tkt-b72787b1.test
@@ -35,6 +35,11 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
+ifcapable !compound {
+ finish_test
+ return
+}
+
unset -nocomplain ::STMT
proc runsql {} {
db eval {CREATE TABLE IF NOT EXISTS t4(q)}
diff --git a/lang/sql/sqlite/test/tkt-bd484a090c.test b/lang/sql/sqlite/test/tkt-bd484a090c.test
new file mode 100644
index 00000000..3d2b5999
--- /dev/null
+++ b/lang/sql/sqlite/test/tkt-bd484a090c.test
@@ -0,0 +1,38 @@
+# 2011 June 21
+#
+# May you 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 for SQLite. Specifically, it tests that SQLite
+# does not crash and an error is returned if localhost() fails. This
+# is the problem reported by ticket bd484a090c.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+set testprefix tkt-bd484a090c
+
+
+do_test 1.1 {
+ lindex [catchsql { SELECT datetime('now', 'localtime') }] 0
+} {0}
+do_test 1.2 {
+ lindex [catchsql { SELECT datetime('now', 'utc') }] 0
+} {0}
+
+sqlite3_test_control SQLITE_TESTCTRL_LOCALTIME_FAULT 1
+
+do_test 2.1 {
+ catchsql { SELECT datetime('now', 'localtime') }
+} {1 {local time unavailable}}
+do_test 2.2 {
+ catchsql { SELECT datetime('now', 'utc') }
+} {1 {local time unavailable}}
+
+sqlite3_test_control SQLITE_TESTCTRL_LOCALTIME_FAULT 0
+
+finish_test
diff --git a/lang/sql/sqlite/test/tkt-bdc6bbbb38.test b/lang/sql/sqlite/test/tkt-bdc6bbbb38.test
new file mode 100644
index 00000000..8b0d55df
--- /dev/null
+++ b/lang/sql/sqlite/test/tkt-bdc6bbbb38.test
@@ -0,0 +1,90 @@
+# 2012 May 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 verify that ticket [bdc6bbbb38] has been
+# fixed.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix tkt-bdc6bbbb38
+
+# If SQLITE_ENABLE_FTS3 is defined, omit this file.
+ifcapable !fts3 { finish_test ; return }
+set sqlite_fts3_enable_parentheses 1
+
+foreach {tn idxdir} {1 ASC 2 DESC} {
+ execsql { DROP TABLE IF EXISTS t2 }
+
+ do_execsql_test $tn.1.1 "CREATE VIRTUAL TABLE t2 USING fts4(x, order=$idxdir)"
+ do_execsql_test $tn.1.2 { INSERT INTO t2 VALUES('a b c') }
+
+ do_execsql_test $tn.1.3 {
+ SELECT offsets(t2) FROM t2 WHERE t2 MATCH 'a AND d OR b' ORDER BY docid ASC
+ } {
+ {0 0 0 1 0 2 2 1}
+ }
+ do_execsql_test $tn.1.4 {
+ SELECT snippet(t2,'[',']') FROM t2 WHERE t2 MATCH 'a AND d OR b'
+ ORDER BY docid ASC
+ } {
+ {[a] [b] c}
+ }
+ do_execsql_test $tn.1.5 { INSERT INTO t2 VALUES('a c d') }
+ do_execsql_test $tn.1.6 {
+ SELECT offsets(t2) FROM t2 WHERE t2 MATCH 'a AND d OR b' ORDER BY docid ASC
+ } {
+ {0 0 0 1 0 2 2 1}
+ {0 0 0 1 0 1 4 1}
+ }
+ do_execsql_test $tn.1.7 {
+ SELECT snippet(t2,'[',']') FROM t2 WHERE t2 MATCH 'a AND d OR b'
+ ORDER BY docid ASC
+ } {
+ {[a] [b] c}
+ {[a] c [d]}
+ }
+
+ execsql { DROP TABLE IF EXISTS t3 }
+ do_execsql_test $tn.2.1 "CREATE VIRTUAL TABLE t3 USING fts4(x, order=$idxdir)"
+ do_execsql_test $tn.2.2 { INSERT INTO t3 VALUES('a c d') }
+ do_execsql_test $tn.2.3 {
+ SELECT offsets(t3) FROM t3 WHERE t3 MATCH 'a AND d OR b' ORDER BY docid DESC
+ } {
+ {0 0 0 1 0 1 4 1}
+ }
+ do_execsql_test $tn.2.4 {
+ SELECT snippet(t3,'[',']') FROM t3 WHERE t3 MATCH 'a AND d OR b'
+ ORDER BY docid DESC
+ } {
+ {[a] c [d]}
+ }
+ do_execsql_test $tn.2.5 {
+ INSERT INTO t3 VALUES('a b c');
+ }
+ do_execsql_test $tn.2.6 {
+ SELECT offsets(t3) FROM t3 WHERE t3 MATCH 'a AND d OR b' ORDER BY docid DESC
+ } {
+ {0 0 0 1 0 2 2 1}
+ {0 0 0 1 0 1 4 1}
+ }
+ do_execsql_test $tn.2.7 {
+ SELECT snippet(t3,'[',']') FROM t3 WHERE t3 MATCH 'a AND d OR b'
+ ORDER BY docid DESC
+ } {
+ {[a] [b] c}
+ {[a] c [d]}
+ }
+}
+
+set sqlite_fts3_enable_parentheses 0
+finish_test
diff --git a/lang/sql/sqlite/test/tkt-c48d99d690.test b/lang/sql/sqlite/test/tkt-c48d99d690.test
new file mode 100644
index 00000000..6d1b9dbe
--- /dev/null
+++ b/lang/sql/sqlite/test/tkt-c48d99d690.test
@@ -0,0 +1,25 @@
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+set ::testprefix tkt-c48d99d690
+
+do_test 1.0 {
+ execsql {
+ CREATE TABLE t1(a, b);
+ CREATE TABLE t2(a, b);
+ INSERT INTO t1 VALUES('one' , 1);
+ INSERT INTO t1 VALUES('two' , 5);
+ INSERT INTO t1 VALUES('two' , 2);
+ INSERT INTO t1 VALUES('three', 3);
+ PRAGMA count_changes = 1;
+ }
+} {}
+
+do_test 1.1 {
+ execsql { INSERT INTO t2 SELECT * FROM t1 }
+} {4}
+
+do_test 1.2 { execsql VACUUM } {}
+
+finish_test
diff --git a/lang/sql/sqlite/test/tkt-cbd054fa6b.test b/lang/sql/sqlite/test/tkt-cbd054fa6b.test
index 6e7455b3..2951233a 100644
--- a/lang/sql/sqlite/test/tkt-cbd054fa6b.test
+++ b/lang/sql/sqlite/test/tkt-cbd054fa6b.test
@@ -16,11 +16,26 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
-ifcapable !stat2 {
+ifcapable !stat4&&!stat3 {
finish_test
return
}
+proc s {blob} {
+ set ret ""
+ binary scan $blob c* bytes
+ foreach b $bytes {
+ set t [binary format c $b]
+ if {[string is print $t]} {
+ append ret $t
+ } else {
+ append ret .
+ }
+ }
+ return $ret
+}
+db function s s
+
do_test tkt-cbd05-1.1 {
db eval {
CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT UNIQUE NOT NULL);
@@ -39,14 +54,26 @@ do_test tkt-cbd05-1.1 {
}
} {10}
do_test tkt-cbd05-1.2 {
- db eval {
- ANALYZE;
+ db eval { ANALYZE; }
+ ifcapable stat4 {
+ db eval {
+ PRAGMA writable_schema = 1;
+ CREATE VIEW vvv AS
+ SELECT tbl,idx,neq,nlt,ndlt,test_extract(sample,0) AS sample
+ FROM sqlite_stat4;
+ PRAGMA writable_schema = 0;
+ }
+ } else {
+ db eval {
+ CREATE VIEW vvv AS
+ SELECT tbl,idx,neq,nlt,ndlt,sample FROM sqlite_stat3;
+ }
}
} {}
do_test tkt-cbd05-1.3 {
execsql {
- SELECT tbl,idx,group_concat(sample,' ')
- FROM sqlite_stat2
+ SELECT tbl,idx,group_concat(s(sample),' ')
+ FROM vvv
WHERE idx = 't1_x'
GROUP BY tbl,idx
}
@@ -77,8 +104,8 @@ do_test tkt-cbd05-2.2 {
} {}
do_test tkt-cbd05-2.3 {
execsql {
- SELECT tbl,idx,group_concat(sample,' ')
- FROM sqlite_stat2
+ SELECT tbl,idx,group_concat(s(sample),' ')
+ FROM vvv
WHERE idx = 't1_x'
GROUP BY tbl,idx
}
diff --git a/lang/sql/sqlite/test/tkt-d11f09d36e.test b/lang/sql/sqlite/test/tkt-d11f09d36e.test
index 70657706..ffd3d219 100644
--- a/lang/sql/sqlite/test/tkt-d11f09d36e.test
+++ b/lang/sql/sqlite/test/tkt-d11f09d36e.test
@@ -59,4 +59,3 @@ do_test tkt-d11f09d36e.5 {
} {ok}
finish_test
-
diff --git a/lang/sql/sqlite/test/tkt-d635236375.test b/lang/sql/sqlite/test/tkt-d635236375.test
new file mode 100644
index 00000000..3fc78226
--- /dev/null
+++ b/lang/sql/sqlite/test/tkt-d635236375.test
@@ -0,0 +1,38 @@
+# 2011 August 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 file is testing that bug [d63523637517386191d634e]
+# has been fixed.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+set ::testprefix tkt-d635236375
+
+do_test 1.0 {
+ execsql {
+ CREATE TABLE t1(id1 INTEGER PRIMARY KEY);
+ INSERT INTO t1 VALUES(9999);
+ CREATE TABLE t2(id2 INTEGER PRIMARY KEY);
+ INSERT INTO t2 VALUES(12345);
+ INSERT INTO t2 VALUES(54321);
+ SELECT DISTINCT id1 AS x, id1 AS y FROM t1, t2;
+ }
+} {9999 9999}
+do_test 1.1 {
+ execsql {
+ SELECT count(*) FROM t1, t2 GROUP BY id1, id1;
+ }
+} {2}
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/tkt-d82e3f3721.test b/lang/sql/sqlite/test/tkt-d82e3f3721.test
index 31f7d342..da932d1e 100644
--- a/lang/sql/sqlite/test/tkt-d82e3f3721.test
+++ b/lang/sql/sqlite/test/tkt-d82e3f3721.test
@@ -17,6 +17,11 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
+ifcapable !compound {
+ finish_test
+ return
+}
+
do_test tkt-d82e3-1.1 {
db eval {
CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b);
diff --git a/lang/sql/sqlite/test/tkt-f3e5abed55.test b/lang/sql/sqlite/test/tkt-f3e5abed55.test
index 241c1612..3c793d4f 100644
--- a/lang/sql/sqlite/test/tkt-f3e5abed55.test
+++ b/lang/sql/sqlite/test/tkt-f3e5abed55.test
@@ -14,8 +14,8 @@ set testdir [file dirname $argv0]
source $testdir/tester.tcl
source $testdir/malloc_common.tcl
-foreach f [glob -nocomplain test.db*mj*] { file delete -force $f }
-file delete -force test.db2
+foreach f [glob -nocomplain test.db*mj*] { forcedelete $f }
+forcedelete test.db2
do_test tkt-f3e5abed55-1.1 {
execsql {
@@ -51,7 +51,7 @@ do_test tkt-f3e5abed55-1.5 {
do_test tkt-f3e5abed55-1.6 {
glob -nocomplain test.db*mj*
} {}
-foreach f [glob -nocomplain test.db*mj*] { file delete -force $f }
+foreach f [glob -nocomplain test.db*mj*] { forcedelete $f }
db close
db2 close
@@ -114,4 +114,3 @@ if {[permutation]!="inmemory_journal"} {
finish_test
-
diff --git a/lang/sql/sqlite/test/tkt-f777251dc7a.test b/lang/sql/sqlite/test/tkt-f777251dc7a.test
index 6f0b43fa..af6f71ad 100644
--- a/lang/sql/sqlite/test/tkt-f777251dc7a.test
+++ b/lang/sql/sqlite/test/tkt-f777251dc7a.test
@@ -17,6 +17,11 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
+ifcapable !compound {
+ finish_test
+ return
+}
+
do_test tkt-f7772-1.1 {
execsql {
CREATE TEMP TABLE t1(x UNIQUE);
@@ -37,7 +42,7 @@ do_test tkt-f7772-1.2 {
BEGIN IMMEDIATE;
SELECT x, force_rollback(), EXISTS(SELECT 1 FROM t3 WHERE w=x) FROM t2;
}
-} {1 {callback requested query abort}}
+} {1 {abort due to ROLLBACK}}
do_test tkt-f7772-1.3 {
sqlite3_get_autocommit db
} {1}
diff --git a/lang/sql/sqlite/test/tkt-f973c7ac31.test b/lang/sql/sqlite/test/tkt-f973c7ac31.test
index 882e86a0..45430905 100644
--- a/lang/sql/sqlite/test/tkt-f973c7ac31.test
+++ b/lang/sql/sqlite/test/tkt-f973c7ac31.test
@@ -84,4 +84,3 @@ foreach {tn sql} {
finish_test
-
diff --git a/lang/sql/sqlite/test/tkt-fa7bf5ec.test b/lang/sql/sqlite/test/tkt-fa7bf5ec.test
new file mode 100644
index 00000000..34f12b96
--- /dev/null
+++ b/lang/sql/sqlite/test/tkt-fa7bf5ec.test
@@ -0,0 +1,39 @@
+# 2011 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.
+#
+#***********************************************************************
+# This file implements regression tests for SQLite library. Specifically,
+# it tests that ticket [fa7bf5ec94801e7e2030e41eefe5d9dd96eaacfd] has
+# been resolved.
+#
+# The problem described by this ticket was that the sqlite3ExprCompare()
+# function was saying that expressions (x='a') and (x='A') were identical
+# because it was using sqlite3StrICmp() instead of strcmp() to compare string
+# literals. That was causing the query optimizer for aggregate queries to
+# believe that both count() operations were identical, and thus only
+# computing the first count() and making a copy of the result for the
+# second count().
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+do_test tkt-fa7bf5ec-1 {
+ execsql {
+ CREATE TABLE t1(x);
+ INSERT INTO t1 VALUES ('a');
+ INSERT INTO t1 VALUES ('A');
+ INSERT INTO t1 VALUES ('A');
+ SELECT count(CASE WHEN x='a' THEN 1 END),
+ count(CASE WHEN x='A' THEN 1 END)
+ FROM t1;
+ }
+} {1 2}
+
+finish_test
diff --git a/lang/sql/sqlite/test/tkt-fc7bd6358f.test b/lang/sql/sqlite/test/tkt-fc7bd6358f.test
new file mode 100644
index 00000000..a1b13c46
--- /dev/null
+++ b/lang/sql/sqlite/test/tkt-fc7bd6358f.test
@@ -0,0 +1,78 @@
+# 2013 March 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. Specifically,
+# it tests that ticket [fc7bd6358f]:
+#
+# The following SQL yields an incorrect result (zero rows) in all
+# versions of SQLite between 3.6.14 and 3.7.15.2:
+#
+# CREATE TABLE t(textid TEXT);
+# INSERT INTO t VALUES('12');
+# INSERT INTO t VALUES('34');
+# CREATE TABLE i(intid INTEGER PRIMARY KEY);
+# INSERT INTO i VALUES(12);
+# INSERT INTO i VALUES(34);
+#
+# SELECT t1.textid AS a, i.intid AS b, t2.textid AS c
+# FROM t t1, i, t t2
+# WHERE t1.textid = i.intid
+# AND t1.textid = t2.textid;
+#
+# The correct result should be two rows, one with 12|12|12 and the other
+# with 34|34|34. With this bug, no rows are returned. Bisecting shows that
+# this bug was introduced with check-in [dd4d67a67454] on 2009-04-23.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+do_test tkt-fc7bd6358f.100 {
+ db eval {
+ CREATE TABLE t(textid TEXT);
+ INSERT INTO t VALUES('12');
+ INSERT INTO t VALUES('34');
+ CREATE TABLE i(intid INTEGER PRIMARY KEY);
+ INSERT INTO i VALUES(12);
+ INSERT INTO i VALUES(34);
+ }
+} {}
+unset -nocomplain from
+unset -nocomplain where
+unset -nocomplain a
+unset -nocomplain b
+foreach {a from} {
+ 1 {FROM t t1, i, t t2}
+ 2 {FROM i, t t1, t t2}
+ 3 {FROM t t1, t t2, i}
+} {
+ foreach {b where} {
+ 1 {WHERE t1.textid=i.intid AND t1.textid=t2.textid}
+ 2 {WHERE i.intid=t1.textid AND t1.textid=t2.textid}
+ 3 {WHERE t1.textid=i.intid AND i.intid=t2.textid}
+ 4 {WHERE t1.textid=i.intid AND t2.textid=i.intid}
+ 5 {WHERE i.intid=t1.textid AND i.intid=t2.textid}
+ 6 {WHERE i.intid=t1.textid AND t2.textid=i.intid}
+ 7 {WHERE t1.textid=t2.textid AND i.intid=t2.textid}
+ 8 {WHERE t1.textid=t2.textid AND t2.textid=i.intid}
+ } {
+ do_test tkt-fc7bd6358f.110.$a.$b.1 {
+ db eval {PRAGMA automatic_index=ON}
+ db eval "SELECT t1.textid, i.intid, t2.textid $from $where"
+ } {12 12 12 34 34 34}
+ do_test tkt-fc7bd6358f.110.$a.$b.2 {
+ db eval {PRAGMA automatic_index=OFF}
+ db eval "SELECT t1.textid, i.intid, t2.textid $from $where"
+ } {12 12 12 34 34 34}
+ }
+}
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/tkt1567.test b/lang/sql/sqlite/test/tkt1567.test
index 6c4548a3..cb1a6be5 100644
--- a/lang/sql/sqlite/test/tkt1567.test
+++ b/lang/sql/sqlite/test/tkt1567.test
@@ -40,7 +40,7 @@ do_test tkt1567-1.4 {
catchsql {
UPDATE t1 SET a = CASE WHEN rowid<90 THEN substr(a,1,10) ELSE '9999' END;
}
-} {1 {column a is not unique}}
+} {1 {UNIQUE constraint failed: t1.a}}
do_test tkt1567-1.5 {
execsql {
COMMIT;
@@ -48,4 +48,35 @@ do_test tkt1567-1.5 {
} {}
integrity_check tkt1567-1.6
+do_test tkt1567-2.1 {
+ execsql {
+ CREATE TABLE t2(a TEXT PRIMARY KEY, rowid INT) WITHOUT rowid;
+ }
+ set bigstr abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
+ for {set i 0} {$i<100} {incr i} {
+ set x [format %5d [expr $i*2]]
+ set sql "INSERT INTO t2 VALUES('$x-$bigstr', $i+1)"
+ execsql $sql
+ }
+} {}
+integrity_check tkt1567-2.2
+
+do_test tkt1567-2.3 {
+ execsql {
+ BEGIN;
+ UPDATE t2 SET a = a||'x' WHERE rowid%2==0;
+ }
+} {}
+do_test tkt1567-2.4 {
+ catchsql {
+ UPDATE t2 SET a = CASE WHEN rowid<90 THEN substr(a,1,10) ELSE '9999' END;
+ }
+} {1 {UNIQUE constraint failed: t2.a}}
+do_test tkt1567-2.5 {
+ execsql {
+ COMMIT;
+ }
+} {}
+integrity_check tkt1567-2.6
+
finish_test
diff --git a/lang/sql/sqlite/test/tkt1667.test b/lang/sql/sqlite/test/tkt1667.test
index 9883a208..63815061 100644
--- a/lang/sql/sqlite/test/tkt1667.test
+++ b/lang/sql/sqlite/test/tkt1667.test
@@ -25,7 +25,7 @@ ifcapable !autovacuum||!tclvar {
}
db close
-file delete -force test.db test.db-journal
+forcedelete test.db test.db-journal
# Set the pending byte offset such that the page it is on is
# the first autovacuum pointer map page in the file (assume a page
diff --git a/lang/sql/sqlite/test/tkt1873.test b/lang/sql/sqlite/test/tkt1873.test
index 85a52832..9930790c 100644
--- a/lang/sql/sqlite/test/tkt1873.test
+++ b/lang/sql/sqlite/test/tkt1873.test
@@ -24,7 +24,7 @@ ifcapable !attach {
return
}
-file delete -force test2.db test2.db-journal
+forcedelete test2.db test2.db-journal
do_test tkt1873-1.1 {
execsql {
diff --git a/lang/sql/sqlite/test/tkt2409.test b/lang/sql/sqlite/test/tkt2409.test
index 9ac65424..936f57c9 100644
--- a/lang/sql/sqlite/test/tkt2409.test
+++ b/lang/sql/sqlite/test/tkt2409.test
@@ -107,7 +107,7 @@ do_test tkt2409-1.2 {
integrity_check tkt2409-1.3
# Check that the transaction was rolled back. Because the INSERT
-# statement in which the "I/O error" occured did not open a statement
+# statement in which the "I/O error" occurred did not open a statement
# transaction, SQLite had no choice but to roll back the transaction.
#
do_test tkt2409-1.4 {
@@ -175,7 +175,7 @@ do_test tkt2409-3.2 {
integrity_check tkt2409-3.3
# Check that the transaction was rolled back. Because the INSERT
-# statement in which the "I/O error" occured did not open a statement
+# statement in which the "I/O error" occurred did not open a statement
# transaction, SQLite had no choice but to roll back the transaction.
#
do_test tkt2409-3.4 {
diff --git a/lang/sql/sqlite/test/tkt2686.test b/lang/sql/sqlite/test/tkt2686.test
index c03c6868..20447bba 100644
--- a/lang/sql/sqlite/test/tkt2686.test
+++ b/lang/sql/sqlite/test/tkt2686.test
@@ -49,7 +49,7 @@ for {set i 1} {$i<2000} {incr i} {
}
db close
-file delete -force test.db test.db-journal
+forcedelete test.db test.db-journal
sqlite3 db test.db
db eval {
diff --git a/lang/sql/sqlite/test/tkt2817.test b/lang/sql/sqlite/test/tkt2817.test
index 46b7fe36..579cf2f7 100644
--- a/lang/sql/sqlite/test/tkt2817.test
+++ b/lang/sql/sqlite/test/tkt2817.test
@@ -48,7 +48,7 @@ integrity_check tkt2817-1.3
# same name. #2817 did not cause a problem with these tests.
#
db close
-file delete -force test.db
+forcedelete test.db
sqlite3 db test.db
do_test tkt2817-2.0 {
execsql {
diff --git a/lang/sql/sqlite/test/tkt2820.test b/lang/sql/sqlite/test/tkt2820.test
index 106c1e55..11c4cd3a 100644
--- a/lang/sql/sqlite/test/tkt2820.test
+++ b/lang/sql/sqlite/test/tkt2820.test
@@ -25,7 +25,7 @@ source $testdir/tester.tcl
proc test_schema_change {testid init ddl res} {
db close
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db test.db
execsql $init
do_test tkt2820-$testid.1 {
@@ -70,7 +70,7 @@ test_schema_change 3 {
#
do_test tkt2820-4.1 {
db close
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db test.db
db eval {
CREATE TABLE t1(a INTEGER PRIMARY KEY);
diff --git a/lang/sql/sqlite/test/tkt2822.test b/lang/sql/sqlite/test/tkt2822.test
index 281e5dc9..d0b16338 100644
--- a/lang/sql/sqlite/test/tkt2822.test
+++ b/lang/sql/sqlite/test/tkt2822.test
@@ -273,11 +273,21 @@ do_test tkt2822-7.1 {
SELECT * FROM t7 ORDER BY 0;
}
} {1 {1st ORDER BY term out of range - should be between 1 and 25}}
-do_test tkt2822-7.2 {
+do_test tkt2822-7.2.1 {
catchsql {
SELECT * FROM t7 ORDER BY 1, 0;
}
} {1 {2nd ORDER BY term out of range - should be between 1 and 25}}
+do_test tkt2822-7.2.2 {
+ catchsql {
+ SELECT * FROM t7 ORDER BY 1, 26;
+ }
+} {1 {2nd ORDER BY term out of range - should be between 1 and 25}}
+do_test tkt2822-7.2.3 {
+ catchsql {
+ SELECT * FROM t7 ORDER BY 1, 65536;
+ }
+} {1 {2nd ORDER BY term out of range - should be between 1 and 25}}
do_test tkt2822-7.3 {
catchsql {
SELECT * FROM t7 ORDER BY 1, 2, 0;
diff --git a/lang/sql/sqlite/test/tkt2854.test b/lang/sql/sqlite/test/tkt2854.test
index 862524a7..914ddd1b 100644
--- a/lang/sql/sqlite/test/tkt2854.test
+++ b/lang/sql/sqlite/test/tkt2854.test
@@ -128,7 +128,7 @@ do_test tkt2854-1.18 {
# attached db cannot be locked, the internal exclusive flag used by
# shared-cache users is correctly cleared.
do_test tkt2854-1.19 {
- file delete -force test2.db test2.db-journal
+ forcedelete test2.db test2.db-journal
sqlite3 db4 test2.db
execsql { CREATE TABLE def(d, e, f) } db4
execsql { ATTACH 'test2.db' AS aux } db
diff --git a/lang/sql/sqlite/test/tkt3442.test b/lang/sql/sqlite/test/tkt3442.test
index ae03949d..ee9169ce 100644
--- a/lang/sql/sqlite/test/tkt3442.test
+++ b/lang/sql/sqlite/test/tkt3442.test
@@ -49,10 +49,10 @@ proc EQP {sql} {
ifcapable explain {
do_test tkt3442-1.2 {
EQP { SELECT node FROM listhash WHERE id='5000' LIMIT 1; }
- } {0 0 0 {SEARCH TABLE listhash USING INDEX ididx (id=?) (~1 rows)}}
+ } {0 0 0 {SEARCH TABLE listhash USING INDEX ididx (id=?)}}
do_test tkt3442-1.3 {
EQP { SELECT node FROM listhash WHERE id="5000" LIMIT 1; }
- } {0 0 0 {SEARCH TABLE listhash USING INDEX ididx (id=?) (~1 rows)}}
+ } {0 0 0 {SEARCH TABLE listhash USING INDEX ididx (id=?)}}
}
@@ -61,7 +61,7 @@ ifcapable explain {
ifcapable explain {
do_test tkt3442-1.4 {
EQP { SELECT node FROM listhash WHERE id=5000 LIMIT 1; }
- } {0 0 0 {SEARCH TABLE listhash USING INDEX ididx (id=?) (~1 rows)}}
+ } {0 0 0 {SEARCH TABLE listhash USING INDEX ididx (id=?)}}
}
do_test tkt3442-1.5 {
catchsql {
diff --git a/lang/sql/sqlite/test/tkt3457.test b/lang/sql/sqlite/test/tkt3457.test
index 71eb4246..04757413 100644
--- a/lang/sql/sqlite/test/tkt3457.test
+++ b/lang/sql/sqlite/test/tkt3457.test
@@ -46,8 +46,8 @@ do_test tkt3457-1.1 {
INSERT INTO t1 VALUES(4, 5, 6);
}
- file copy -force test.db bak.db
- file copy -force test.db-journal bak.db-journal
+ forcecopy test.db bak.db
+ forcecopy test.db-journal bak.db-journal
# Fix the first journal-header in the journal-file. Because the
# journal file has not yet been synced, the 8-byte magic string at the
@@ -62,26 +62,40 @@ do_test tkt3457-1.1 {
execsql COMMIT
} {}
+# Disable fchmod to make sure SQLite itself does not try to change the
+# permission bits on us
+#
+catch {
+ test_syscall install fchmod
+ test_syscall fault 1 1
+}
+
do_test tkt3457-1.2 {
- file copy -force bak.db-journal test.db-journal
+ forcecopy bak.db-journal test.db-journal
file attributes test.db-journal -permissions ---------
catchsql { SELECT * FROM t1 }
} {1 {unable to open database file}}
do_test tkt3457-1.3 {
- file copy -force bak.db-journal test.db-journal
+ forcecopy bak.db-journal test.db-journal
file attributes test.db-journal -permissions -w--w--w-
catchsql { SELECT * FROM t1 }
} {1 {unable to open database file}}
do_test tkt3457-1.4 {
- file copy -force bak.db-journal test.db-journal
+ forcecopy bak.db-journal test.db-journal
file attributes test.db-journal -permissions r--r--r--
catchsql { SELECT * FROM t1 }
} {1 {unable to open database file}}
do_test tkt3457-1.5 {
- file copy -force bak.db-journal test.db-journal
+ forcecopy bak.db-journal test.db-journal
file attributes test.db-journal -permissions rw-rw-rw-
catchsql { SELECT * FROM t1 }
} {0 {1 2 3 4 5 6}}
+# Reenable fchmod
+catch {
+ test_syscall uninstall
+ test_syscall fault 0 0
+}
+
finish_test
diff --git a/lang/sql/sqlite/test/tkt3527.test b/lang/sql/sqlite/test/tkt3527.test
index 34e9e612..da3d05ac 100644
--- a/lang/sql/sqlite/test/tkt3527.test
+++ b/lang/sql/sqlite/test/tkt3527.test
@@ -18,6 +18,11 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
+ifcapable !compound {
+ finish_test
+ return
+}
+
do_test tkt3527-1.1 {
db eval {
CREATE TABLE Element (
@@ -47,8 +52,8 @@ do_test tkt3527-1.1 {
INSERT INTO Element VALUES(5,'Elem5');
INSERT INTO ElemOr Values(3,4);
INSERT INTO ElemOr Values(3,5);
- INSERT INTO ElemAnd VALUES(1,3,1,1,1);
- INSERT INTO ElemAnd VALUES(1,2,1,1,1);
+ INSERT INTO ElemAnd VALUES(1,3,'a','b','c');
+ INSERT INTO ElemAnd VALUES(1,2,'x','y','z');
CREATE VIEW ElemView1 AS
SELECT
@@ -107,12 +112,12 @@ do_test tkt3527-1.1 {
SELECT * FROM ElemView1;
}
-} {1 1 Elem1 2 1 1 1 0 0 1 1 Elem1 3 1 1 1 0 0 3 3 Elem3 4 {} {} {} 0 1 3 3 Elem3 5 {} {} {} 0 1}
+} {1 1 Elem1 2 x y z 0 0 1 1 Elem1 3 a b c 0 0 3 3 Elem3 4 {} {} {} 0 1 3 3 Elem3 5 {} {} {} 0 1}
do_test tkt3527-1.2 {
db eval {
SELECT * FROM ElemView2;
}
-} {1 1 Elem1 2 1 1 1 0 0 1 1 Elem1 3 1 1 1 0 0 1.3 3 Elem3 4 {} {} {} 1 1 1.3 3 Elem3 5 {} {} {} 1 1 3 3 Elem3 4 {} {} {} 0 1 3 3 Elem3 5 {} {} {} 0 1}
+} {1 1 Elem1 2 x y z 0 0 1 1 Elem1 3 a b c 0 0 1.3 3 Elem3 4 {} {} {} 1 1 1.3 3 Elem3 5 {} {} {} 1 1 3 3 Elem3 4 {} {} {} 0 1 3 3 Elem3 5 {} {} {} 0 1}
finish_test
diff --git a/lang/sql/sqlite/test/tkt35xx.test b/lang/sql/sqlite/test/tkt35xx.test
index d2a83cde..3b911c12 100644
--- a/lang/sql/sqlite/test/tkt35xx.test
+++ b/lang/sql/sqlite/test/tkt35xx.test
@@ -50,7 +50,7 @@ do_test tkt35xx-1.1 {
# Trigger the problem using statement rollback.
#
db close
-file delete test.db
+delete_file test.db
sqlite3 db test.db
set big [string repeat abcdefghij 22] ;# 220 byte string
do_test tkt35xx-1.2.1 {
@@ -74,7 +74,7 @@ do_test tkt35xx-1.2.2 {
DROP TABLE t5;
INSERT INTO t3(a, b) SELECT c, d FROM t4;
}
-} {1 {PRIMARY KEY must be unique}}
+} {1 {UNIQUE constraint failed: t3.a}}
do_test tkt35xx-1.2.3 {
# Show that the transaction has not been rolled back.
catchsql BEGIN
diff --git a/lang/sql/sqlite/test/tkt3762.test b/lang/sql/sqlite/test/tkt3762.test
index c24041c9..424b1e64 100644
--- a/lang/sql/sqlite/test/tkt3762.test
+++ b/lang/sql/sqlite/test/tkt3762.test
@@ -10,8 +10,8 @@
#***********************************************************************
#
# Ticket #3762: Make sure that an incremental vacuum that reduces the
-# size of the database file such that a pointer-map page is elemented
-# can be correctly rolled back.
+# size of the database file such that if a pointer-map page is eliminated
+# it can be correctly rolled back.
#
# That ticket #3762 has been fixed has already been verified by the
# savepoint6.test test script. But this script is simplier and a
diff --git a/lang/sql/sqlite/test/tkt3773.test b/lang/sql/sqlite/test/tkt3773.test
index 0dc414e5..3f5a1a32 100644
--- a/lang/sql/sqlite/test/tkt3773.test
+++ b/lang/sql/sqlite/test/tkt3773.test
@@ -18,6 +18,11 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
+ifcapable !compound {
+ finish_test
+ return
+}
+
do_test tkt3773-1.1 {
db eval {
CREATE TABLE t1(a,b);
diff --git a/lang/sql/sqlite/test/tkt3793.test b/lang/sql/sqlite/test/tkt3793.test
index 2b5f2bab..074aab2d 100644
--- a/lang/sql/sqlite/test/tkt3793.test
+++ b/lang/sql/sqlite/test/tkt3793.test
@@ -100,16 +100,18 @@ set x 0
# Note: Before the bug was fixed, if [db2] was opened with the "-fullmutex 1"
# option, then this test case would cause an assert() to fail.
#
-set ::busyconnection db1
-db1 eval {SELECT * FROM t2 ORDER BY a LIMIT 20} {
- do_test tkt3793-2.[incr x] { set ::busyconnection } db1
- set ::busyconnection db2
-
- db2 eval { SELECT count(*) FROM t2 }
- do_test tkt3793-2.[incr x] { set ::busyconnection } db2
+ifcapable threadsafe {
set ::busyconnection db1
+ db1 eval {SELECT * FROM t2 ORDER BY a LIMIT 20} {
+ do_test tkt3793-2.[incr x] { set ::busyconnection } db1
+ set ::busyconnection db2
+
+ db2 eval { SELECT count(*) FROM t2 }
+ do_test tkt3793-2.[incr x] { set ::busyconnection } db2
+ set ::busyconnection db1
+ }
}
-
+
do_test tkt3793-3 {
db1 close
db2 close
diff --git a/lang/sql/sqlite/test/tkt3838.test b/lang/sql/sqlite/test/tkt3838.test
index 4fb5c55a..fa937acd 100644
--- a/lang/sql/sqlite/test/tkt3838.test
+++ b/lang/sql/sqlite/test/tkt3838.test
@@ -25,7 +25,7 @@ ifcapable !altertable {
return
}
-do_test tkt3838-1.1 {
+do_realnum_test tkt3838-1.1 {
db eval {
PRAGMA encoding=UTF16;
CREATE TABLE t1(x);
@@ -38,4 +38,21 @@ do_test tkt3838-1.1 {
}
} {2 999 9e+99 xyzzy}
+ifcapable trigger {
+ do_test tkt3838-1.2 {
+ db eval {
+ CREATE TABLE log(y);
+ CREATE TRIGGER r1 AFTER INSERT ON T1 BEGIN
+ INSERT INTO log VALUES(new.x);
+ END;
+ INSERT INTO t1(x) VALUES(123);
+ ALTER TABLE T1 RENAME TO XYZ2;
+ INSERT INTO xyz2(x) VALUES(456);
+ ALTER TABLE xyz2 RENAME TO pqr3;
+ INSERT INTO pqr3(x) VALUES(789);
+ SELECT * FROM log;
+ }
+ } {123 456 789}
+}
+
finish_test
diff --git a/lang/sql/sqlite/test/tkt3918.test b/lang/sql/sqlite/test/tkt3918.test
index c46ad8f6..e20ee152 100644
--- a/lang/sql/sqlite/test/tkt3918.test
+++ b/lang/sql/sqlite/test/tkt3918.test
@@ -57,4 +57,3 @@ do_test tkt3918.5 {
} {}
finish_test
-
diff --git a/lang/sql/sqlite/test/tkt3922.test b/lang/sql/sqlite/test/tkt3922.test
index 6506dced..86bf5fec 100644
--- a/lang/sql/sqlite/test/tkt3922.test
+++ b/lang/sql/sqlite/test/tkt3922.test
@@ -36,21 +36,21 @@ if {[working_64bit_int]} {
}
} {-1 integer}
}
-do_test tkt3922.2 {
+do_realnum_test tkt3922.2 {
execsql {
DELETE FROM t1;
INSERT INTO t1 VALUES('-9223372036854775809');
SELECT a, typeof(a) FROM t1;
}
} {-9.22337203685478e+18 real}
-do_test tkt3922.3 {
+do_realnum_test tkt3922.3 {
execsql {
DELETE FROM t1;
INSERT INTO t1 VALUES('-9223372036854776832');
SELECT a, typeof(a) FROM t1;
}
} {-9.22337203685478e+18 real}
-do_test tkt3922.4 {
+do_realnum_test tkt3922.4 {
execsql {
DELETE FROM t1;
INSERT INTO t1 VALUES('-9223372036854776833');
@@ -78,7 +78,7 @@ if {[working_64bit_int]} {
}
} {1 integer}
}
-do_test tkt3922.6 {
+do_realnum_test tkt3922.6 {
execsql {
DELETE FROM t1;
INSERT INTO t1 VALUES('9223372036854775808');
diff --git a/lang/sql/sqlite/test/tkt3929.test b/lang/sql/sqlite/test/tkt3929.test
index 3ed4d288..db02bb84 100644
--- a/lang/sql/sqlite/test/tkt3929.test
+++ b/lang/sql/sqlite/test/tkt3929.test
@@ -50,4 +50,3 @@ do_test tkt3930-1.2 {
integrity_check tkt3930-1.3
finish_test
-
diff --git a/lang/sql/sqlite/test/tpch01.test b/lang/sql/sqlite/test/tpch01.test
new file mode 100644
index 00000000..2d099d63
--- /dev/null
+++ b/lang/sql/sqlite/test/tpch01.test
@@ -0,0 +1,187 @@
+# 2013-09-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.
+#
+#***********************************************************************
+#
+# TPC-H test queries.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix tpch01
+
+do_execsql_test tpch01-1.0 {
+ CREATE TABLE NATION ( N_NATIONKEY INTEGER NOT NULL,
+ N_NAME CHAR(25) NOT NULL,
+ N_REGIONKEY INTEGER NOT NULL,
+ N_COMMENT VARCHAR(152));
+ CREATE TABLE REGION ( R_REGIONKEY INTEGER NOT NULL,
+ R_NAME CHAR(25) NOT NULL,
+ R_COMMENT VARCHAR(152));
+ CREATE TABLE PART ( P_PARTKEY INTEGER NOT NULL,
+ P_NAME VARCHAR(55) NOT NULL,
+ P_MFGR CHAR(25) NOT NULL,
+ P_BRAND CHAR(10) NOT NULL,
+ P_TYPE VARCHAR(25) NOT NULL,
+ P_SIZE INTEGER NOT NULL,
+ P_CONTAINER CHAR(10) NOT NULL,
+ P_RETAILPRICE DECIMAL(15,2) NOT NULL,
+ P_COMMENT VARCHAR(23) NOT NULL );
+ CREATE TABLE SUPPLIER ( S_SUPPKEY INTEGER NOT NULL,
+ S_NAME CHAR(25) NOT NULL,
+ S_ADDRESS VARCHAR(40) NOT NULL,
+ S_NATIONKEY INTEGER NOT NULL,
+ S_PHONE CHAR(15) NOT NULL,
+ S_ACCTBAL DECIMAL(15,2) NOT NULL,
+ S_COMMENT VARCHAR(101) NOT NULL);
+ CREATE TABLE PARTSUPP ( PS_PARTKEY INTEGER NOT NULL,
+ PS_SUPPKEY INTEGER NOT NULL,
+ PS_AVAILQTY INTEGER NOT NULL,
+ PS_SUPPLYCOST DECIMAL(15,2) NOT NULL,
+ PS_COMMENT VARCHAR(199) NOT NULL );
+ CREATE TABLE CUSTOMER ( C_CUSTKEY INTEGER NOT NULL,
+ C_NAME VARCHAR(25) NOT NULL,
+ C_ADDRESS VARCHAR(40) NOT NULL,
+ C_NATIONKEY INTEGER NOT NULL,
+ C_PHONE CHAR(15) NOT NULL,
+ C_ACCTBAL DECIMAL(15,2) NOT NULL,
+ C_MKTSEGMENT CHAR(10) NOT NULL,
+ C_COMMENT VARCHAR(117) NOT NULL);
+ CREATE TABLE ORDERS ( O_ORDERKEY INTEGER NOT NULL,
+ O_CUSTKEY INTEGER NOT NULL,
+ O_ORDERSTATUS CHAR(1) NOT NULL,
+ O_TOTALPRICE DECIMAL(15,2) NOT NULL,
+ O_ORDERDATE DATE NOT NULL,
+ O_ORDERPRIORITY CHAR(15) NOT NULL,
+ O_CLERK CHAR(15) NOT NULL,
+ O_SHIPPRIORITY INTEGER NOT NULL,
+ O_COMMENT VARCHAR(79) NOT NULL);
+ CREATE TABLE LINEITEM ( L_ORDERKEY INTEGER NOT NULL,
+ L_PARTKEY INTEGER NOT NULL,
+ L_SUPPKEY INTEGER NOT NULL,
+ L_LINENUMBER INTEGER NOT NULL,
+ L_QUANTITY DECIMAL(15,2) NOT NULL,
+ L_EXTENDEDPRICE DECIMAL(15,2) NOT NULL,
+ L_DISCOUNT DECIMAL(15,2) NOT NULL,
+ L_TAX DECIMAL(15,2) NOT NULL,
+ L_RETURNFLAG CHAR(1) NOT NULL,
+ L_LINESTATUS CHAR(1) NOT NULL,
+ L_SHIPDATE DATE NOT NULL,
+ L_COMMITDATE DATE NOT NULL,
+ L_RECEIPTDATE DATE NOT NULL,
+ L_SHIPINSTRUCT CHAR(25) NOT NULL,
+ L_SHIPMODE CHAR(10) NOT NULL,
+ L_COMMENT VARCHAR(44) NOT NULL);
+ CREATE INDEX npki on nation(N_NATIONKEY);
+ CREATE INDEX rpki on region(R_REGIONKEY);
+ CREATE INDEX ppki on part(P_PARTKEY);
+ CREATE INDEX spki on supplier(S_SUPPKEY);
+ CREATE INDEX pspki on partsupp(PS_PARTKEY, PS_SUPPKEY);
+ CREATE INDEX cpki on customer(C_CUSTKEY);
+ CREATE INDEX opki on orders(O_ORDERKEY);
+ CREATE INDEX lpki on lineitem(L_ORDERKEY, L_LINENUMBER);
+ CREATE INDEX nrki on nation(n_regionkey);
+ CREATE INDEX snki on supplier(s_nationkey);
+ CREATE INDEX cnki on customer(c_nationkey);
+ CREATE INDEX ocki on orders(O_CUSTKEY);
+ CREATE INDEX odi on orders(O_ORDERDATE);
+ CREATE INDEX lpki2 on lineitem(L_PARTKEY);
+ CREATE INDEX lski on lineitem(L_SUPPKEY);
+ CREATE INDEX lsdi on lineitem(L_SHIPDATE);
+ CREATE INDEX lcdi on lineitem(L_COMMITDATE);
+ CREATE INDEX lrdi on lineitem(L_RECEIPTDATE);
+ CREATE INDEX bootleg_nni on nation(N_NAME);
+ CREATE INDEX bootleg_psi on part(p_size);
+ CREATE INDEX bootleg_pti on part(p_type);
+ ANALYZE sqlite_master;
+ INSERT INTO sqlite_stat1 VALUES('LINEITEM','lrdi','600572 236');
+ INSERT INTO sqlite_stat1 VALUES('LINEITEM','lcdi','600572 244');
+ INSERT INTO sqlite_stat1 VALUES('LINEITEM','lsdi','600572 238');
+ INSERT INTO sqlite_stat1 VALUES('LINEITEM','lski','600572 601');
+ INSERT INTO sqlite_stat1 VALUES('LINEITEM','lpki2','600572 31');
+ INSERT INTO sqlite_stat1 VALUES('LINEITEM','lpki','600572 5 1');
+ INSERT INTO sqlite_stat1 VALUES('ORDERS','odi','150000 63');
+ INSERT INTO sqlite_stat1 VALUES('ORDERS','ocki','150000 15');
+ INSERT INTO sqlite_stat1 VALUES('ORDERS','opki','150000 1');
+ INSERT INTO sqlite_stat1 VALUES('CUSTOMER','cnki','15000 600');
+ INSERT INTO sqlite_stat1 VALUES('CUSTOMER','cpki','15000 1');
+ INSERT INTO sqlite_stat1 VALUES('PARTSUPP','pspki','80000 4 1');
+ INSERT INTO sqlite_stat1 VALUES('SUPPLIER','snki','1000 40');
+ INSERT INTO sqlite_stat1 VALUES('SUPPLIER','spki','1000 1');
+ INSERT INTO sqlite_stat1 VALUES('PART','bootleg_pti','20000 134');
+ INSERT INTO sqlite_stat1 VALUES('PART','bootleg_psi','20000 400');
+ INSERT INTO sqlite_stat1 VALUES('PART','ppki','20000 1');
+ INSERT INTO sqlite_stat1 VALUES('REGION','rpki','5 1');
+ INSERT INTO sqlite_stat1 VALUES('NATION','bootleg_nni','25 1');
+ INSERT INTO sqlite_stat1 VALUES('NATION','nrki','25 5');
+ INSERT INTO sqlite_stat1 VALUES('NATION','npki','25 1');
+ ANALYZE sqlite_master;
+} {}
+
+do_test tpch01-1.1 {
+ unset -nocomplain ::eqpres
+ set ::eqpres [db eval {EXPLAIN QUERY PLAN
+ select
+ o_year,
+ sum(case
+ when nation = 'EGYPT' then volume
+ else 0
+ end) / sum(volume) as mkt_share
+ from
+ (
+ select
+ strftime('%Y', o_orderdate) as o_year,
+ l_extendedprice * (1 - l_discount) as volume,
+ n2.n_name as nation
+ from
+ part,
+ supplier,
+ lineitem,
+ orders,
+ customer,
+ nation n1,
+ nation n2,
+ region
+ where
+ p_partkey = l_partkey
+ and s_suppkey = l_suppkey
+ and l_orderkey = o_orderkey
+ and o_custkey = c_custkey
+ and c_nationkey = n1.n_nationkey
+ and n1.n_regionkey = r_regionkey
+ and r_name = 'MIDDLE EAST'
+ and s_nationkey = n2.n_nationkey
+ and o_orderdate between '1995-01-01' and '1996-12-31'
+ and p_type = 'LARGE PLATED STEEL'
+ ) as all_nations
+ group by
+ o_year
+ order by
+ o_year;}]
+ set ::eqpres
+} {/0 0 0 {SEARCH TABLE part USING INDEX bootleg_pti .P_TYPE=..} 0 1 2 {SEARCH TABLE lineitem USING INDEX lpki2 .L_PARTKEY=..}.*/}
+do_test tpch01-1.1b {
+ set ::eqpres
+} {/.* customer .* nation AS n1 .* nation AS n2 .*/}
+
+do_eqp_test tpch01-1.2 {
+select
+ c_custkey, c_name, sum(l_extendedprice * (1 - l_discount)) as revenue,
+ c_acctbal, n_name, c_address, c_phone, c_comment
+from
+ customer, orders, lineitem, nation
+where
+ c_custkey = o_custkey and l_orderkey = o_orderkey
+ and o_orderdate >= '1994-08-01' and o_orderdate < date('1994-08-01', '+3 month')
+ and l_returnflag = 'R' and c_nationkey = n_nationkey
+group by
+ c_custkey, c_name, c_acctbal, c_phone, n_name, c_address, c_comment
+order by
+ revenue desc;
+} {0 0 1 {SEARCH TABLE orders USING INDEX odi (O_ORDERDATE>? AND O_ORDERDATE<?)} 0 1 0 {SEARCH TABLE customer USING INDEX cpki (C_CUSTKEY=?)} 0 2 3 {SEARCH TABLE nation USING INDEX npki (N_NATIONKEY=?)} 0 3 2 {SEARCH TABLE lineitem USING INDEX lpki (L_ORDERKEY=?)} 0 0 0 {USE TEMP B-TREE FOR GROUP BY} 0 0 0 {USE TEMP B-TREE FOR ORDER BY}}
diff --git a/lang/sql/sqlite/test/trace2.test b/lang/sql/sqlite/test/trace2.test
index a70dd89d..8f68d875 100644
--- a/lang/sql/sqlite/test/trace2.test
+++ b/lang/sql/sqlite/test/trace2.test
@@ -128,24 +128,26 @@ ifcapable fts3 {
INSERT INTO x1 VALUES('North northwest wind between 8 and 14 mph');
} {
"INSERT INTO x1 VALUES('North northwest wind between 8 and 14 mph');"
+ "-- DELETE FROM 'main'.'x1_segdir' WHERE level = ?"
"-- INSERT INTO 'main'.'x1_content' VALUES(?,(?))"
"-- REPLACE INTO 'main'.'x1_docsize' VALUES(?,?)"
- "-- SELECT value FROM 'main'.'x1_stat' WHERE id=0"
- "-- REPLACE INTO 'main'.'x1_stat' VALUES(0,?)"
+ "-- SELECT value FROM 'main'.'x1_stat' WHERE id=?"
+ "-- REPLACE INTO 'main'.'x1_stat' VALUES(?,?)"
"-- SELECT (SELECT max(idx) FROM 'main'.'x1_segdir' WHERE level = ?) + 1"
"-- SELECT coalesce((SELECT max(blockid) FROM 'main'.'x1_segments') + 1, 1)"
- "-- INSERT INTO 'main'.'x1_segdir' VALUES(?,?,?,?,?,?)"
+ "-- REPLACE INTO 'main'.'x1_segdir' VALUES(?,?,?,?,?,?)"
}
do_trace_test 2.3 {
INSERT INTO x1(x1) VALUES('optimize');
} {
"INSERT INTO x1(x1) VALUES('optimize');"
- "-- SELECT idx, start_block, leaves_end_block, end_block, root FROM 'main'.'x1_segdir' ORDER BY level DESC, idx ASC"
- "-- SELECT count(*), max(level) FROM 'main'.'x1_segdir'"
+ "-- SELECT DISTINCT level / (1024 * ?) FROM 'main'.'x1_segdir'"
+ "-- SELECT idx, start_block, leaves_end_block, end_block, root FROM 'main'.'x1_segdir' WHERE level BETWEEN ? AND ?ORDER BY level DESC, idx ASC"
+ "-- SELECT max(level) FROM 'main'.'x1_segdir' WHERE level BETWEEN ? AND ?"
"-- SELECT coalesce((SELECT max(blockid) FROM 'main'.'x1_segments') + 1, 1)"
- "-- DELETE FROM 'main'.'x1_segdir'"
- "-- INSERT INTO 'main'.'x1_segdir' VALUES(?,?,?,?,?,?)"
+ "-- DELETE FROM 'main'.'x1_segdir' WHERE level BETWEEN ? AND ?"
+ "-- REPLACE INTO 'main'.'x1_segdir' VALUES(?,?,?,?,?,?)"
}
}
diff --git a/lang/sql/sqlite/test/trans2.test b/lang/sql/sqlite/test/trans2.test
index cfd3e677..36a2f998 100644
--- a/lang/sql/sqlite/test/trans2.test
+++ b/lang/sql/sqlite/test/trans2.test
@@ -161,7 +161,7 @@ for {set i 2} {$i<=30} {incr i} {
z = CASE WHEN id<$max_rowid
THEN zeroblob((random()&65535)%5000 + 1000) END;
}
- } {1 {t1.z may not be NULL}}
+ } {1 {NOT NULL constraint failed: t1.z}}
do_test trans2-$i.11 {
db eval {SELECT md5sum(u1), md5sum(u2) FROM t1 ORDER BY id}
} $newres
@@ -185,7 +185,7 @@ for {set i 2} {$i<=30} {incr i} {
z = CASE WHEN id<$max1
THEN zeroblob((random()&65535)%5000 + 1000) END;
}
- } {1 {t1.z may not be NULL}}
+ } {1 {NOT NULL constraint failed: t1.z}}
do_test trans2-$i.31 {
db eval {SELECT md5sum(u1), md5sum(u2) FROM t1 ORDER BY id}
} $origres
diff --git a/lang/sql/sqlite/test/trans3.test b/lang/sql/sqlite/test/trans3.test
index ab7db6a2..d5b316be 100644
--- a/lang/sql/sqlite/test/trans3.test
+++ b/lang/sql/sqlite/test/trans3.test
@@ -64,14 +64,13 @@ do_test trans3-1.5 {
}
} errmsg]
lappend x $errmsg
-} {1 {cannot rollback transaction - SQL statements in progress}}
+} {1 {abort due to ROLLBACK}}
do_test trans3-1.6 {
set ::ecode
-} {SQLITE_BUSY}
+} {}
do_test trans3-1.7 {
- db eval COMMIT
db eval {SELECT * FROM t1}
-} {1 2 3 4 5}
+} {1 2 3 4}
unset -nocomplain ecode
finish_test
diff --git a/lang/sql/sqlite/test/transitive1.test b/lang/sql/sqlite/test/transitive1.test
new file mode 100644
index 00000000..200dc610
--- /dev/null
+++ b/lang/sql/sqlite/test/transitive1.test
@@ -0,0 +1,284 @@
+# 2013 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. The
+# focus of this script is testing of transitive WHERE clause constraints
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+do_execsql_test transitive1-100 {
+ CREATE TABLE t1(a TEXT, b TEXT, c TEXT COLLATE NOCASE);
+ INSERT INTO t1 VALUES('abc','abc','Abc');
+ INSERT INTO t1 VALUES('def','def','def');
+ INSERT INTO t1 VALUES('ghi','ghi','GHI');
+ CREATE INDEX t1a1 ON t1(a);
+ CREATE INDEX t1a2 ON t1(a COLLATE nocase);
+
+ SELECT * FROM t1 WHERE a=b AND c=b AND c='DEF';
+} {def def def}
+do_execsql_test transitive1-110 {
+ SELECT * FROM t1 WHERE a=b AND c=b AND c>='DEF' ORDER BY +a;
+} {def def def ghi ghi GHI}
+do_execsql_test transitive1-120 {
+ SELECT * FROM t1 WHERE a=b AND c=b AND c<='DEF' ORDER BY +a;
+} {abc abc Abc def def def}
+
+do_execsql_test transitive1-200 {
+ CREATE TABLE t2(a INTEGER, b INTEGER, c TEXT);
+ INSERT INTO t2 VALUES(100,100,100);
+ INSERT INTO t2 VALUES(20,20,20);
+ INSERT INTO t2 VALUES(3,3,3);
+
+ SELECT * FROM t2 WHERE a=b AND c=b AND c=20;
+} {20 20 20}
+do_execsql_test transitive1-210 {
+ SELECT * FROM t2 WHERE a=b AND c=b AND c>=20 ORDER BY +a;
+} {3 3 3 20 20 20}
+do_execsql_test transitive1-220 {
+ SELECT * FROM t2 WHERE a=b AND c=b AND c<=20 ORDER BY +a;
+} {20 20 20 100 100 100}
+
+# Test cases for ticket [[d805526eae253103] 2013-07-08
+# "Incorrect join result or assertion fault due to transitive constraints"
+#
+do_execsql_test transitive1-300 {
+ CREATE TABLE t301(w INTEGER PRIMARY KEY, x);
+ CREATE TABLE t302(y INTEGER UNIQUE, z);
+ INSERT INTO t301 VALUES(1,2),(3,4),(5,6);
+ INSERT INTO t302 VALUES(1,3),(3,6),(5,7);
+ SELECT *
+ FROM t301 CROSS JOIN t302
+ WHERE w=y AND y IS NOT NULL
+ ORDER BY +w;
+} {1 2 1 3 3 4 3 6 5 6 5 7}
+do_execsql_test transitive1-301 {
+ SELECT *
+ FROM t301 CROSS JOIN t302
+ WHERE w=y AND y IS NOT NULL
+ ORDER BY w;
+} {1 2 1 3 3 4 3 6 5 6 5 7}
+do_execsql_test transitive1-310 {
+ SELECT *
+ FROM t301 CROSS JOIN t302 ON w=y
+ WHERE y>1
+ ORDER BY +w
+} {3 4 3 6 5 6 5 7}
+do_execsql_test transitive1-311 {
+ SELECT *
+ FROM t301 CROSS JOIN t302 ON w=y
+ WHERE y>1
+ ORDER BY w
+} {3 4 3 6 5 6 5 7}
+do_execsql_test transitive1-312 {
+ SELECT *
+ FROM t301 CROSS JOIN t302 ON w=y
+ WHERE y>1
+ ORDER BY w DESC
+} {5 6 5 7 3 4 3 6}
+do_execsql_test transitive1-320 {
+ SELECT *
+ FROM t301 CROSS JOIN t302 ON w=y
+ WHERE y BETWEEN 2 AND 4;
+} {3 4 3 6}
+do_execsql_test transitive1-331 {
+ SELECT *
+ FROM t301 CROSS JOIN t302 ON w=y
+ WHERE y BETWEEN 1 AND 4
+ ORDER BY w;
+} {1 2 1 3 3 4 3 6}
+do_execsql_test transitive1-332 {
+ SELECT *
+ FROM t301 CROSS JOIN t302 ON w=y
+ WHERE y BETWEEN 1 AND 4
+ ORDER BY w DESC;
+} {3 4 3 6 1 2 1 3}
+
+# Ticket [c620261b5b5dc] circa 2013-10-28.
+# Make sureconstraints are not used with LEFT JOINs.
+#
+# The next case is from the ticket report. It outputs no rows in 3.8.1
+# prior to the bug-fix.
+#
+do_execsql_test transitive1-400 {
+ CREATE TABLE t401(a);
+ CREATE TABLE t402(b);
+ CREATE TABLE t403(c INTEGER PRIMARY KEY);
+ INSERT INTO t401 VALUES(1);
+ INSERT INTO t403 VALUES(1);
+ SELECT '1-row' FROM t401 LEFT JOIN t402 ON b=a JOIN t403 ON c=a;
+} {1-row}
+
+# The following is a script distilled from the XBMC project where the
+# bug was originally encountered. The correct answer is a single row
+# of output. Before the bug was fixed, zero rows were generated.
+#
+do_execsql_test transitive1-410 {
+ CREATE TABLE bookmark ( idBookmark integer primary key, idFile integer, timeInSeconds double, totalTimeInSeconds double, thumbNailImage text, player text, playerState text, type integer);
+ CREATE TABLE path ( idPath integer primary key, strPath text, strContent text, strScraper text, strHash text, scanRecursive integer, useFolderNames bool, strSettings text, noUpdate bool, exclude bool, dateAdded text);
+ INSERT INTO "path" VALUES(1,'/tmp/tvshows/','tvshows','metadata.tvdb.com','989B1CE5680A14F5F86123F751169B49',0,0,'<settings><setting id="absolutenumber" value="false" /><setting id="dvdorder" value="false" /><setting id="fanart" value="true" /><setting id="language" value="en" /></settings>',0,0,NULL);
+ INSERT INTO "path" VALUES(2,'/tmp/tvshows/The.Big.Bang.Theory/','','','85E1DAAB2F5FF6EAE8AEDF1B5C882D1E',NULL,NULL,NULL,NULL,NULL,'2013-10-23 18:58:43');
+ CREATE TABLE files ( idFile integer primary key, idPath integer, strFilename text, playCount integer, lastPlayed text, dateAdded text);
+ INSERT INTO "files" VALUES(1,2,'The.Big.Bang.Theory.S01E01.WEB-DL.AAC2.0.H264.mkv',NULL,NULL,'2013-10-23 18:57:36');
+ CREATE TABLE tvshow ( idShow integer primary key,c00 text,c01 text,c02 text,c03 text,c04 text,c05 text,c06 text,c07 text,c08 text,c09 text,c10 text,c11 text,c12 text,c13 text,c14 text,c15 text,c16 text,c17 text,c18 text,c19 text,c20 text,c21 text,c22 text,c23 text);
+ INSERT INTO "tvshow" VALUES(1,'The Big Bang Theory','Leonard Hofstadter and Sheldon Cooper are brilliant physicists, the kind of "beautiful minds" that understand how the universe works. But none of that genius helps them interact with people, especially women. All this begins to change when a free-spirited beauty named Penny moves in next door. Sheldon, Leonard''s roommate, is quite content spending his nights playing Klingon Boggle with their socially dysfunctional friends, fellow CalTech scientists Howard Wolowitz and Raj Koothrappali. However, Leonard sees in Penny a whole new universe of possibilities... including love.','','','9.200000','2007-09-24','<thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g13.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g23.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g18.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g17.jpg</thumb><thumb aspect="banner">http://
+ thetvdb.com/banners/graphical/80379-g6.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g5.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g2.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g11.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g12.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g19.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g3.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g4.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g15.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g22.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g7.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g10.jpg</thumb><thumb
+ aspect="banner">http://thetvdb.com/banners/graphical/80379-g24.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g8.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g9.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g14.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g16.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/graphical/80379-g21.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/text/80379-4.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/text/80379-2.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/text/80379-3.jpg</thumb><thumb aspect="banner">http://thetvdb.com/banners/text/80379-5.jpg</thumb><thumb aspect="poster" type="season" season="6">http://thetvdb.com/banners/seasons/80379-6-8.jpg</thumb><thumb aspect="poster" type="season" season="0">http://thetvdb.com/banners/seasons/80379-0-4.jpg</thumb><thumb aspect="poster" type="season"
+ season="1">http://thetvdb.com/banners/seasons/80379-1-12.jpg</thumb><thumb aspect="poster" type="season" season="3">http://thetvdb.com/banners/seasons/80379-3-9.jpg</thumb><thumb aspect="poster" type="season" season="2">http://thetvdb.com/banners/seasons/80379-2-11.jpg</thumb><thumb aspect="poster" type="season" season="5">http://thetvdb.com/banners/seasons/80379-5-9.jpg</thumb><thumb aspect="poster" type="season" season="4">http://thetvdb.com/banners/seasons/80379-4-8.jpg</thumb><thumb aspect="poster" type="season" season="7">http://thetvdb.com/banners/seasons/80379-7-3.jpg</thumb><thumb aspect="poster" type="season" season="3">http://thetvdb.com/banners/seasons/80379-3-4.jpg</thumb><thumb aspect="poster" type="season" season="4">http://thetvdb.com/banners/seasons/80379-4-5.jpg</thumb><thumb aspect="poster" type="season" season="2">http://thetvdb.com/banners/seasons/80379-2-9.jpg</thumb><thumb aspect="poster" type="season" season="0">http://thetvdb.com/banners/seasons/80379-0-2.jpg</thumb><thumb aspect="
+ poster" type="season" season="6">http://thetvdb.com/banners/seasons/80379-6-6.jpg</thumb><thumb aspect="poster" type="season" season="4">http://thetvdb.com/banners/seasons/80379-4-4.jpg</thumb><thumb aspect="poster" type="season" season="6">http://thetvdb.com/banners/seasons/80379-6-2.jpg</thumb><thumb aspect="poster" type="season" season="1">http://thetvdb.com/banners/seasons/80379-1-9.jpg</thumb><thumb aspect="poster" type="season" season="6">http://thetvdb.com/banners/seasons/80379-6-4.jpg</thumb><thumb aspect="poster" type="season" season="1">http://thetvdb.com/banners/seasons/80379-1.jpg</thumb><thumb aspect="poster" type="season" season="3">http://thetvdb.com/banners/seasons/80379-3.jpg</thumb><thumb aspect="poster" type="season" season="4">http://thetvdb.com/banners/seasons/80379-4-2.jpg</thumb><thumb aspect="poster" type="season" season="5">http://thetvdb.com/banners/seasons/80379-5-7.jpg</thumb><thumb aspect="poster" type="season" season="2">http://thetvdb.com/banners/seasons/80379-2-10.jpg</
+ thumb><thumb aspect="poster" type="season" season="6">http://thetvdb.com/banners/seasons/80379-6-5.jpg</thumb><thumb aspect="poster" type="season" season="1">http://thetvdb.com/banners/seasons/80379-1-5.jpg</thumb><thumb aspect="poster" type="season" season="5">http://thetvdb.com/banners/seasons/80379-5-4.jpg</thumb><thumb aspect="poster" type="season" season="4">http://thetvdb.com/banners/seasons/80379-4.jpg</thumb><thumb aspect="poster" type="season" season="6">http://thetvdb.com/banners/seasons/80379-6-3.jpg</thumb><thumb aspect="poster" type="season" season="5">http://thetvdb.com/banners/seasons/80379-5.jpg</thumb><thumb aspect="poster" type="season" season="3">http://thetvdb.com/banners/seasons/80379-3-6.jpg</thumb><thumb aspect="poster" type="season" season="2">http://thetvdb.com/banners/seasons/80379-2.jpg</thumb><thumb aspect="poster" type="season" season="7">http://thetvdb.com/banners/seasons/80379-7.jpg</thumb><thumb aspect="poster" type="season" season="1">http://thetvdb.com/banners/seasons/80379-
+ 1-7.jpg</thumb><thumb aspect="poster" type="season" season="5">http://thetvdb.com/banners/seasons/80379-5-2.jpg</thumb><thumb aspect="poster" type="season" season="5">http://thetvdb.com/banners/seasons/80379-5-3.jpg</thumb><thumb aspect="poster" type="season" season="7">http://thetvdb.com/banners/seasons/80379-7-2.jpg</thumb><thumb aspect="poster" type="season" season="1">http://thetvdb.com/banners/seasons/80379-1-2.jpg</thumb><thumb aspect="poster" type="season" season="2">http://thetvdb.com/banners/seasons/80379-2-5.jpg</thumb><thumb aspect="poster" type="season" season="4">http://thetvdb.com/banners/seasons/80379-4-3.jpg</thumb><thumb aspect="poster" type="season" season="5">http://thetvdb.com/banners/seasons/80379-5-5.jpg</thumb><thumb aspect="poster" type="season" season="0">http://thetvdb.com/banners/seasons/80379-0.jpg</thumb><thumb aspect="poster" type="season" season="3">http://thetvdb.com/banners/seasons/80379-3-5.jpg</thumb><thumb aspect="poster" type="season" season="1">http://thetvdb.com/banners/
+ seasons/80379-1-6.jpg</thumb><thumb aspect="poster" type="season" season="2">http://thetvdb.com/banners/seasons/80379-2-3.jpg</thumb><thumb aspect="poster" type="season" season="2">http://thetvdb.com/banners/seasons/80379-2-8.jpg</thumb><thumb aspect="poster" type="season" season="6">http://thetvdb.com/banners/seasons/80379-6-7.jpg</thumb><thumb aspect="poster" type="season" season="5">http://thetvdb.com/banners/seasons/80379-5-8.jpg</thumb><thumb aspect="poster" type="season" season="4">http://thetvdb.com/banners/seasons/80379-4-7.jpg</thumb><thumb aspect="poster" type="season" season="2">http://thetvdb.com/banners/seasons/80379-2-6.jpg</thumb><thumb aspect="poster" type="season" season="3">http://thetvdb.com/banners/seasons/80379-3-8.jpg</thumb><thumb aspect="poster" type="season" season="1">http://thetvdb.com/banners/seasons/80379-1-11.jpg</thumb><thumb aspect="poster" type="season" season="1">http://thetvdb.com/banners/seasons/80379-1-10.jpg</thumb><thumb aspect="poster" type="season" season="1">http://
+ thetvdb.com/banners/seasons/80379-1-8.jpg</thumb><thumb aspect="poster" type="season" season="3">http://thetvdb.com/banners/seasons/80379-3-7.jpg</thumb><thumb aspect="poster" type="season" season="2">http://thetvdb.com/banners/seasons/80379-2-4.jpg</thumb><thumb aspect="poster" type="season" season="1">http://thetvdb.com/banners/seasons/80379-1-3.jpg</thumb><thumb aspect="poster" type="season" season="1">http://thetvdb.com/banners/seasons/80379-1-4.jpg</thumb><thumb aspect="poster" type="season" season="3">http://thetvdb.com/banners/seasons/80379-3-3.jpg</thumb><thumb aspect="poster" type="season" season="2">http://thetvdb.com/banners/seasons/80379-2-7.jpg</thumb><thumb aspect="poster" type="season" season="6">http://thetvdb.com/banners/seasons/80379-6.jpg</thumb><thumb aspect="poster" type="season" season="2">http://thetvdb.com/banners/seasons/80379-2-2.jpg</thumb><thumb aspect="poster" type="season" season="5">http://thetvdb.com/banners/seasons/80379-5-6.jpg</thumb><thumb aspect="poster" type="season"
+ season="3">http://thetvdb.com/banners/seasons/80379-3-2.jpg</thumb><thumb aspect="poster" type="season" season="4">http://thetvdb.com/banners/seasons/80379-4-6.jpg</thumb><thumb aspect="banner" type="season" season="5">http://thetvdb.com/banners/seasonswide/80379-5.jpg</thumb><thumb aspect="banner" type="season" season="3">http://thetvdb.com/banners/seasonswide/80379-3-2.jpg</thumb><thumb aspect="banner" type="season" season="1">http://thetvdb.com/banners/seasonswide/80379-1-2.jpg</thumb><thumb aspect="banner" type="season" season="2">http://thetvdb.com/banners/seasonswide/80379-2-2.jpg</thumb><thumb aspect="banner" type="season" season="4">http://thetvdb.com/banners/seasonswide/80379-4-2.jpg</thumb><thumb aspect="banner" type="season" season="0">http://thetvdb.com/banners/seasonswide/80379-0.jpg</thumb><thumb aspect="banner" type="season" season="0">http://thetvdb.com/banners/seasonswide/80379-0-2.jpg</thumb><thumb aspect="banner" type="season" season="1">http://thetvdb.com/banners/seasonswide/80379-1.jpg</
+ thumb><thumb aspect="banner" type="season" season="2">http://thetvdb.com/banners/seasonswide/80379-2.jpg</thumb><thumb aspect="banner" type="season" season="4">http://thetvdb.com/banners/seasonswide/80379-4.jpg</thumb><thumb aspect="banner" type="season" season="3">http://thetvdb.com/banners/seasonswide/80379-3.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-22.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-18.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-13.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-10.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-16.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-1.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-9.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-2.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-19.jpg</
+ thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-8.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-4.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-20.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-23.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-7.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-3.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-12.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-11.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-15.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-21.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-14.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-17.jpg</thumb><thumb aspect="poster">http://thetvdb.com/banners/posters/80379-6.jpg</thumb><thumb
+ aspect="poster">http://thetvdb.com/banners/posters/80379-5.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-22.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-18.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-13.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-10.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-16.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-1.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-9.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-2.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-19.jpg</thumb><thumb aspect="
+ poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-8.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-4.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-20.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-23.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-7.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-3.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-12.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-11.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-15.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-21.jpg</
+ thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-14.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-17.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-6.jpg</thumb><thumb aspect="poster" type="season" season="-1">http://thetvdb.com/banners/posters/80379-5.jpg</thumb>','','Comedy','','<episodeguide><url cache="80379-en.xml">http://thetvdb.com/api/1D62F2F90030C444/series/80379/all/en.zip</url></episodeguide>','<fanart url="http://thetvdb.com/banners/"><thumb dim="1920x1080" colors="|192,185,169|19,20,25|57,70,89|" preview="_cache/fanart/original/80379-2.jpg">fanart/original/80379-2.jpg</thumb><thumb dim="1920x1080" colors="|94,28,16|194,18,38|0,0,8|" preview="_cache/fanart/original/80379-34.jpg">fanart/original/80379-34.jpg</thumb><thumb dim="1280x720" colors="|254,157,210|11,12,7|191,152,111|" preview="_cache/fanart/original/80379-4.jpg">fanart/original/80379-
+ 4.jpg</thumb><thumb dim="1920x1080" colors="" preview="_cache/fanart/original/80379-42.jpg">fanart/original/80379-42.jpg</thumb><thumb dim="1920x1080" colors="|236,187,155|136,136,128|254,254,252|" preview="_cache/fanart/original/80379-37.jpg">fanart/original/80379-37.jpg</thumb><thumb dim="1920x1080" colors="|112,102,152|116,109,116|235,152,146|" preview="_cache/fanart/original/80379-14.jpg">fanart/original/80379-14.jpg</thumb><thumb dim="1920x1080" colors="|150,158,161|174,75,121|150,98,58|" preview="_cache/fanart/original/80379-16.jpg">fanart/original/80379-16.jpg</thumb><thumb dim="1280x720" colors="|224,200,176|11,1,28|164,96,0|" preview="_cache/fanart/original/80379-1.jpg">fanart/original/80379-1.jpg</thumb><thumb dim="1920x1080" colors="" preview="_cache/fanart/original/80379-35.jpg">fanart/original/80379-35.jpg</thumb><thumb dim="1920x1080" colors="" preview="_cache/fanart/original/80379-40.jpg">fanart/original/80379-40.jpg</thumb><thumb dim="1920x1080" colors="|255,255,255|30,19,13|155,112,70|"
+ preview="_cache/fanart/original/80379-31.jpg">fanart/original/80379-31.jpg</thumb><thumb dim="1920x1080" colors="|241,195,172|84,54,106|254,221,206|" preview="_cache/fanart/original/80379-29.jpg">fanart/original/80379-29.jpg</thumb><thumb dim="1280x720" colors="|197,167,175|219,29,39|244,208,192|" preview="_cache/fanart/original/80379-11.jpg">fanart/original/80379-11.jpg</thumb><thumb dim="1280x720" colors="|195,129,97|244,192,168|219,148,118|" preview="_cache/fanart/original/80379-24.jpg">fanart/original/80379-24.jpg</thumb><thumb dim="1920x1080" colors="|14,10,11|255,255,255|175,167,164|" preview="_cache/fanart/original/80379-30.jpg">fanart/original/80379-30.jpg</thumb><thumb dim="1920x1080" colors="" preview="_cache/fanart/original/80379-19.jpg">fanart/original/80379-19.jpg</thumb><thumb dim="1920x1080" colors="|246,199,69|98,55,38|161,127,82|" preview="_cache/fanart/original/80379-9.jpg">fanart/original/80379-9.jpg</thumb><thumb dim="1280x720" colors="|129,22,14|48,50,39|223,182,64|" preview="_cache/
+ fanart/original/80379-13.jpg">fanart/original/80379-13.jpg</thumb><thumb dim="1920x1080" colors="" preview="_cache/fanart/original/80379-45.jpg">fanart/original/80379-45.jpg</thumb><thumb dim="1920x1080" colors="" preview="_cache/fanart/original/80379-33.jpg">fanart/original/80379-33.jpg</thumb><thumb dim="1280x720" colors="|103,77,60|224,180,153|129,100,84|" preview="_cache/fanart/original/80379-10.jpg">fanart/original/80379-10.jpg</thumb><thumb dim="1920x1080" colors="" preview="_cache/fanart/original/80379-23.jpg">fanart/original/80379-23.jpg</thumb><thumb dim="1280x720" colors="|219,29,39|0,4,10|88,117,135|" preview="_cache/fanart/original/80379-12.jpg">fanart/original/80379-12.jpg</thumb><thumb dim="1920x1080" colors="|226,209,165|51,18,9|89,54,24|" preview="_cache/fanart/original/80379-5.jpg">fanart/original/80379-5.jpg</thumb><thumb dim="1280x720" colors="" preview="_cache/fanart/original/80379-26.jpg">fanart/original/80379-26.jpg</thumb><thumb dim="1280x720" colors="|249,251,229|126,47,53|251,226,
+ 107|" preview="_cache/fanart/original/80379-27.jpg">fanart/original/80379-27.jpg</thumb><thumb dim="1920x1080" colors="|233,218,65|30,27,46|173,53,18|" preview="_cache/fanart/original/80379-32.jpg">fanart/original/80379-32.jpg</thumb><thumb dim="1280x720" colors="|248,248,248|64,54,78|188,193,196|" preview="_cache/fanart/original/80379-3.jpg">fanart/original/80379-3.jpg</thumb><thumb dim="1280x720" colors="" preview="_cache/fanart/original/80379-25.jpg">fanart/original/80379-25.jpg</thumb><thumb dim="1280x720" colors="|159,150,133|59,39,32|168,147,104|" preview="_cache/fanart/original/80379-7.jpg">fanart/original/80379-7.jpg</thumb><thumb dim="1920x1080" colors="|221,191,157|11,7,6|237,146,102|" preview="_cache/fanart/original/80379-21.jpg">fanart/original/80379-21.jpg</thumb><thumb dim="1280x720" colors="" preview="_cache/fanart/original/80379-28.jpg">fanart/original/80379-28.jpg</thumb><thumb dim="1920x1080" colors="" preview="_cache/fanart/original/80379-36.jpg">fanart/original/80379-36.jpg</thumb><thumb
+ dim="1920x1080" colors="|253,237,186|33,25,22|245,144,38|" preview="_cache/fanart/original/80379-38.jpg">fanart/original/80379-38.jpg</thumb><thumb dim="1920x1080" colors="|174,111,68|243,115,50|252,226,45|" preview="_cache/fanart/original/80379-20.jpg">fanart/original/80379-20.jpg</thumb><thumb dim="1920x1080" colors="|63,56,123|87,59,47|63,56,123|" preview="_cache/fanart/original/80379-17.jpg">fanart/original/80379-17.jpg</thumb><thumb dim="1920x1080" colors="" preview="_cache/fanart/original/80379-43.jpg">fanart/original/80379-43.jpg</thumb><thumb dim="1280x720" colors="|69,68,161|142,118,142|222,191,137|" preview="_cache/fanart/original/80379-22.jpg">fanart/original/80379-22.jpg</thumb><thumb dim="1280x720" colors="|1,108,206|242,209,192|250,197,163|" preview="_cache/fanart/original/80379-15.jpg">fanart/original/80379-15.jpg</thumb><thumb dim="1280x720" colors="|239,229,237|0,0,0|167,136,115|" preview="_cache/fanart/original/80379-18.jpg">fanart/original/80379-18.jpg</thumb><thumb dim="1280x720" colors=""
+ preview="_cache/fanart/original/80379-6.jpg">fanart/original/80379-6.jpg</thumb><thumb dim="1280x720" colors="" preview="_cache/fanart/original/80379-8.jpg">fanart/original/80379-8.jpg</thumb><thumb dim="1280x720" colors="" preview="_cache/fanart/original/80379-41.jpg">fanart/original/80379-41.jpg</thumb><thumb dim="1920x1080" colors="" preview="_cache/fanart/original/80379-44.jpg">fanart/original/80379-44.jpg</thumb><thumb dim="1280x720" colors="" preview="_cache/fanart/original/80379-39.jpg">fanart/original/80379-39.jpg</thumb></fanart>','80379','TV-PG','CBS','','/tmp/tvshows/The.Big.Bang.Theory/','1',NULL,NULL,NULL,NULL,NULL,NULL);
+ CREATE TABLE episode ( idEpisode integer primary key, idFile integer,c00 text,c01 text,c02 text,c03 text,c04 text,c05 text,c06 text,c07 text,c08 text,c09 text,c10 text,c11 text,c12 varchar(24),c13 varchar(24),c14 text,c15 text,c16 text,c17 varchar(24),c18 text,c19 text,c20 text,c21 text,c22 text,c23 text, idShow integer);
+ INSERT INTO "episode" VALUES(1,1,'Pilot','Brilliant physicist roommates Leonard and Sheldon meet their new neighbor Penny, who begins showing them that as much as they know about science, they know little about actual living.','','7.700000','Chuck Lorre / Bill Prady','2007-09-24','<thumb>http://thetvdb.com/banners/episodes/80379/332484.jpg</thumb>','',NULL,'1800','James Burrows','','1','1','','-1','-1','-1','/tmp/tvshows/The.Big.Bang.Theory/The.Big.Bang.Theory.S01E01.WEB-DL.AAC2.0.H264.mkv','2','332484',NULL,NULL,NULL,1);
+ CREATE TABLE tvshowlinkpath (idShow integer, idPath integer);
+ INSERT INTO "tvshowlinkpath" VALUES(1,2);
+ CREATE TABLE seasons ( idSeason integer primary key, idShow integer, season integer);
+ INSERT INTO "seasons" VALUES(1,1,-1);
+ INSERT INTO "seasons" VALUES(2,1,0);
+ INSERT INTO "seasons" VALUES(3,1,1);
+ INSERT INTO "seasons" VALUES(4,1,2);
+ INSERT INTO "seasons" VALUES(5,1,3);
+ INSERT INTO "seasons" VALUES(6,1,4);
+ INSERT INTO "seasons" VALUES(7,1,5);
+ INSERT INTO "seasons" VALUES(8,1,6);
+ INSERT INTO "seasons" VALUES(9,1,7);
+ CREATE TABLE art(art_id INTEGER PRIMARY KEY, media_id INTEGER, media_type TEXT, type TEXT, url TEXT);
+ INSERT INTO "art" VALUES(1,1,'actor','thumb','http://thetvdb.com/banners/actors/73597.jpg');
+ INSERT INTO "art" VALUES(2,2,'actor','thumb','http://thetvdb.com/banners/actors/73596.jpg');
+ INSERT INTO "art" VALUES(3,3,'actor','thumb','http://thetvdb.com/banners/actors/73595.jpg');
+ INSERT INTO "art" VALUES(4,4,'actor','thumb','http://thetvdb.com/banners/actors/73599.jpg');
+ INSERT INTO "art" VALUES(5,5,'actor','thumb','http://thetvdb.com/banners/actors/73598.jpg');
+ INSERT INTO "art" VALUES(6,6,'actor','thumb','http://thetvdb.com/banners/actors/283158.jpg');
+ INSERT INTO "art" VALUES(7,7,'actor','thumb','http://thetvdb.com/banners/actors/283157.jpg');
+ INSERT INTO "art" VALUES(8,8,'actor','thumb','http://thetvdb.com/banners/actors/91271.jpg');
+ INSERT INTO "art" VALUES(9,9,'actor','thumb','http://thetvdb.com/banners/actors/294178.jpg');
+ INSERT INTO "art" VALUES(10,10,'actor','thumb','http://thetvdb.com/banners/actors/283159.jpg');
+ INSERT INTO "art" VALUES(11,1,'tvshow','banner','http://thetvdb.com/banners/graphical/80379-g13.jpg');
+ INSERT INTO "art" VALUES(12,1,'tvshow','fanart','http://thetvdb.com/banners/fanart/original/80379-2.jpg');
+ INSERT INTO "art" VALUES(13,1,'tvshow','poster','http://thetvdb.com/banners/posters/80379-22.jpg');
+ INSERT INTO "art" VALUES(14,1,'season','poster','http://thetvdb.com/banners/posters/80379-22.jpg');
+ INSERT INTO "art" VALUES(15,2,'season','banner','http://thetvdb.com/banners/seasonswide/80379-0.jpg');
+ INSERT INTO "art" VALUES(16,2,'season','poster','http://thetvdb.com/banners/seasons/80379-0-4.jpg');
+ INSERT INTO "art" VALUES(17,3,'season','banner','http://thetvdb.com/banners/seasonswide/80379-1-2.jpg');
+ INSERT INTO "art" VALUES(18,3,'season','poster','http://thetvdb.com/banners/seasons/80379-1-12.jpg');
+ INSERT INTO "art" VALUES(19,4,'season','banner','http://thetvdb.com/banners/seasonswide/80379-2-2.jpg');
+ INSERT INTO "art" VALUES(20,4,'season','poster','http://thetvdb.com/banners/seasons/80379-2-11.jpg');
+ INSERT INTO "art" VALUES(21,5,'season','banner','http://thetvdb.com/banners/seasonswide/80379-3-2.jpg');
+ INSERT INTO "art" VALUES(22,5,'season','poster','http://thetvdb.com/banners/seasons/80379-3-9.jpg');
+ INSERT INTO "art" VALUES(23,6,'season','banner','http://thetvdb.com/banners/seasonswide/80379-4-2.jpg');
+ INSERT INTO "art" VALUES(24,6,'season','poster','http://thetvdb.com/banners/seasons/80379-4-8.jpg');
+ INSERT INTO "art" VALUES(25,7,'season','banner','http://thetvdb.com/banners/seasonswide/80379-5.jpg');
+ INSERT INTO "art" VALUES(26,7,'season','poster','http://thetvdb.com/banners/seasons/80379-5-9.jpg');
+ INSERT INTO "art" VALUES(27,8,'season','poster','http://thetvdb.com/banners/seasons/80379-6-8.jpg');
+ INSERT INTO "art" VALUES(28,9,'season','poster','http://thetvdb.com/banners/seasons/80379-7-3.jpg');
+ INSERT INTO "art" VALUES(29,1,'episode','thumb','http://thetvdb.com/banners/episodes/80379/332484.jpg');
+ CREATE INDEX ix_bookmark ON bookmark (idFile, type);
+ CREATE INDEX ix_path ON path ( strPath );
+ CREATE INDEX ix_files ON files ( idPath, strFilename );
+ CREATE UNIQUE INDEX ix_episode_file_1 on episode (idEpisode, idFile);
+ CREATE UNIQUE INDEX id_episode_file_2 on episode (idFile, idEpisode);
+ CREATE INDEX ix_episode_season_episode on episode (c12, c13);
+ CREATE INDEX ix_episode_bookmark on episode (c17);
+ CREATE INDEX ix_episode_show1 on episode(idEpisode,idShow);
+ CREATE INDEX ix_episode_show2 on episode(idShow,idEpisode);
+ CREATE UNIQUE INDEX ix_tvshowlinkpath_1 ON tvshowlinkpath ( idShow, idPath );
+ CREATE UNIQUE INDEX ix_tvshowlinkpath_2 ON tvshowlinkpath ( idPath, idShow );
+ CREATE INDEX ixEpisodeBasePath ON episode ( c19 );
+ CREATE INDEX ixTVShowBasePath on tvshow ( c17 );
+ CREATE INDEX ix_seasons ON seasons (idShow, season);
+ CREATE INDEX ix_art ON art(media_id, media_type, type);
+ CREATE VIEW episodeview
+ AS
+ SELECT episode.*,
+ files.strfilename AS strFileName,
+ path.strpath AS strPath,
+ files.playcount AS playCount,
+ files.lastplayed AS lastPlayed,
+ files.dateadded AS dateAdded,
+ tvshow.c00 AS strTitle,
+ tvshow.c14 AS strStudio,
+ tvshow.c05 AS premiered,
+ tvshow.c13 AS mpaa,
+ tvshow.c16 AS strShowPath,
+ bookmark.timeinseconds AS resumeTimeInSeconds,
+ bookmark.totaltimeinseconds AS totalTimeInSeconds,
+ seasons.idseason AS idSeason
+ FROM episode
+ JOIN files
+ ON files.idfile = episode.idfile
+ JOIN tvshow
+ ON tvshow.idshow = episode.idshow
+ LEFT JOIN seasons
+ ON seasons.idshow = episode.idshow
+ AND seasons.season = episode.c12
+ JOIN path
+ ON files.idpath = path.idpath
+ LEFT JOIN bookmark
+ ON bookmark.idfile = episode.idfile
+ AND bookmark.type = 1;
+ CREATE VIEW tvshowview
+ AS
+ SELECT tvshow.*,
+ path.strpath AS strPath,
+ path.dateadded AS dateAdded,
+ Max(files.lastplayed) AS lastPlayed,
+ NULLIF(Count(episode.c12), 0) AS totalCount,
+ Count(files.playcount) AS watchedcount,
+ NULLIF(Count(DISTINCT( episode.c12 )), 0) AS totalSeasons
+ FROM tvshow
+ LEFT JOIN tvshowlinkpath
+ ON tvshowlinkpath.idshow = tvshow.idshow
+ LEFT JOIN path
+ ON path.idpath = tvshowlinkpath.idpath
+ LEFT JOIN episode
+ ON episode.idshow = tvshow.idshow
+ LEFT JOIN files
+ ON files.idfile = episode.idfile
+ GROUP BY tvshow.idshow;
+ SELECT
+ episodeview.c12,
+ path.strPath,
+ tvshowview.c00,
+ tvshowview.c01,
+ tvshowview.c05,
+ tvshowview.c08,
+ tvshowview.c14,
+ tvshowview.c13,
+ seasons.idSeason,
+ count(1),
+ count(files.playCount)
+ FROM episodeview
+ JOIN tvshowview ON tvshowview.idShow = episodeview.idShow
+ JOIN seasons ON (seasons.idShow = tvshowview.idShow
+ AND seasons.season = episodeview.c12)
+ JOIN files ON files.idFile = episodeview.idFile
+ JOIN tvshowlinkpath ON tvshowlinkpath.idShow = tvshowview.idShow
+ JOIN path ON path.idPath = tvshowlinkpath.idPath
+ WHERE tvshowview.idShow = 1
+ GROUP BY episodeview.c12;
+} {1 /tmp/tvshows/The.Big.Bang.Theory/ {The Big Bang Theory} {Leonard Hofstadter and Sheldon Cooper are brilliant physicists, the kind of "beautiful minds" that understand how the universe works. But none of that genius helps them interact with people, especially women. All this begins to change when a free-spirited beauty named Penny moves in next door. Sheldon, Leonard's roommate, is quite content spending his nights playing Klingon Boggle with their socially dysfunctional friends, fellow CalTech scientists Howard Wolowitz and Raj Koothrappali. However, Leonard sees in Penny a whole new universe of possibilities... including love.} 2007-09-24 Comedy CBS TV-PG 3 1 0}
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/trigger1.test b/lang/sql/sqlite/test/trigger1.test
index 622aff2d..1ebe12c8 100644
--- a/lang/sql/sqlite/test/trigger1.test
+++ b/lang/sql/sqlite/test/trigger1.test
@@ -11,25 +11,25 @@
# with the database COMMIT/ROLLBACK logic.
#
# 1. CREATE and DROP TRIGGER tests
-# trig-1.1: Error if table does not exist
-# trig-1.2: Error if trigger already exists
-# trig-1.3: Created triggers are deleted if the transaction is rolled back
-# trig-1.4: DROP TRIGGER removes trigger
-# trig-1.5: Dropped triggers are restored if the transaction is rolled back
-# trig-1.6: Error if dropped trigger doesn't exist
-# trig-1.7: Dropping the table automatically drops all triggers
-# trig-1.8: A trigger created on a TEMP table is not inserted into sqlite_master
-# trig-1.9: Ensure that we cannot create a trigger on sqlite_master
-# trig-1.10:
-# trig-1.11:
-# trig-1.12: Ensure that INSTEAD OF triggers cannot be created on tables
-# trig-1.13: Ensure that AFTER triggers cannot be created on views
-# trig-1.14: Ensure that BEFORE triggers cannot be created on views
+# trigger1-1.1: Error if table does not exist
+# trigger1-1.2: Error if trigger already exists
+# trigger1-1.3: Created triggers are deleted if the transaction is rolled back
+# trigger1-1.4: DROP TRIGGER removes trigger
+# trigger1-1.5: Dropped triggers are restored if the transaction is rolled back
+# trigger1-1.6: Error if dropped trigger doesn't exist
+# trigger1-1.7: Dropping the table automatically drops all triggers
+# trigger1-1.8: A trigger created on a TEMP table is not inserted into sqlite_master
+# trigger1-1.9: Ensure that we cannot create a trigger on sqlite_master
+# trigger1-1.10:
+# trigger1-1.11:
+# trigger1-1.12: Ensure that INSTEAD OF triggers cannot be created on tables
+# trigger1-1.13: Ensure that AFTER triggers cannot be created on views
+# trigger1-1.14: Ensure that BEFORE triggers cannot be created on views
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
-ifcapable {!trigger} {
+ifcapable !trigger||!compound {
finish_test
return
}
@@ -210,7 +210,7 @@ do_test trigger1-1.12 {
delete from t1 WHERE a=old.a+2;
end;
}
-} {1 {cannot create INSTEAD OF trigger on table: main.t1}}
+} {1 {cannot create INSTEAD OF trigger on table: t1}}
ifcapable view {
# Ensure that we cannot create BEFORE triggers on views
@@ -221,7 +221,7 @@ do_test trigger1-1.13 {
delete from t1 WHERE a=old.a+2;
end;
}
-} {1 {cannot create BEFORE trigger on view: main.v1}}
+} {1 {cannot create BEFORE trigger on view: v1}}
# Ensure that we cannot create AFTER triggers on views
do_test trigger1-1.14 {
catchsql {
@@ -231,7 +231,7 @@ do_test trigger1-1.14 {
delete from t1 WHERE a=old.a+2;
end;
}
-} {1 {cannot create AFTER trigger on view: main.v1}}
+} {1 {cannot create AFTER trigger on view: v1}}
} ;# ifcapable view
# Check for memory leaks in the trigger parser
@@ -265,42 +265,54 @@ ifcapable tempdb {
END;
}
} {0 {}}
- do_test trigger-3.2 {
+ do_test trigger1-3.2 {
catchsql {
INSERT INTO t1 VALUES(1,2);
SELECT * FROM t2;
}
} {1 {no such table: main.t2}}
- do_test trigger-3.3 {
+ do_test trigger1-3.3 {
db close
set rc [catch {sqlite3 db test.db} err]
if {$rc} {lappend rc $err}
set rc
} {0}
- do_test trigger-3.4 {
+ do_test trigger1-3.4 {
catchsql {
INSERT INTO t1 VALUES(1,2);
SELECT * FROM t2;
}
} {1 {no such table: main.t2}}
- do_test trigger-3.5 {
+ do_test trigger1-3.5 {
catchsql {
CREATE TEMP TABLE t2(x,y);
INSERT INTO t1 VALUES(1,2);
SELECT * FROM t2;
}
} {1 {no such table: main.t2}}
- do_test trigger-3.6 {
+ do_test trigger1-3.6.1 {
catchsql {
DROP TRIGGER r1;
CREATE TEMP TRIGGER r1 AFTER INSERT ON t1 BEGIN
+ INSERT INTO t2 VALUES(NEW.a,NEW.b), (NEW.b*100, NEW.a*100);
+ END;
+ INSERT INTO t1 VALUES(1,2);
+ SELECT * FROM t2;
+ }
+ } {0 {1 2 200 100}}
+ do_test trigger1-3.6.2 {
+ catchsql {
+ DROP TRIGGER r1;
+ DELETE FROM t1;
+ DELETE FROM t2;
+ CREATE TEMP TRIGGER r1 AFTER INSERT ON t1 BEGIN
INSERT INTO t2 VALUES(NEW.a,NEW.b);
END;
INSERT INTO t1 VALUES(1,2);
SELECT * FROM t2;
}
} {0 {1 2}}
- do_test trigger-3.7 {
+ do_test trigger1-3.7 {
execsql {
DROP TABLE t2;
CREATE TABLE t2(x,y);
@@ -308,7 +320,7 @@ ifcapable tempdb {
}
} {}
- # There are two versions of trigger-3.8 and trigger-3.9. One that uses
+ # There are two versions of trigger1-3.8 and trigger1-3.9. One that uses
# compound SELECT statements, and another that does not.
ifcapable compound {
do_test trigger1-3.8 {
@@ -411,6 +423,7 @@ do_test trigger1-6.2 {
do_test trigger1-6.3 {
catchsql {DELETE FROM t2}
} {1 {deletes are not permitted}}
+verify_ex_errcode trigger1-6.3b SQLITE_CONSTRAINT_TRIGGER
do_test trigger1-6.4 {
execsql {SELECT * FROM t2}
} {3 4 7 8}
@@ -434,7 +447,7 @@ do_test trigger1-6.8 {
execsql {SELECT * FROM t2}
} {3 4 7 8}
-integrity_check trigger-7.1
+integrity_check trigger1-7.1
# Check to make sure the name of a trigger can be quoted so that keywords
# can be used as trigger names. Ticket #468
@@ -479,7 +492,7 @@ do_test trigger1-8.6 {
ifcapable conflict {
# Make sure REPLACE works inside of triggers.
#
- # There are two versions of trigger-9.1 and trigger-9.2. One that uses
+ # There are two versions of trigger1-9.1 and trigger1-9.2. One that uses
# compound SELECT statements, and another that does not.
ifcapable compound {
do_test trigger1-9.1 {
@@ -534,8 +547,8 @@ ifcapable conflict {
# example, that you can drop and re-create tables referenced by triggers.
ifcapable tempdb&&attach {
do_test trigger1-10.0 {
- file delete -force test2.db
- file delete -force test2.db-journal
+ forcedelete test2.db
+ forcedelete test2.db-journal
execsql {
ATTACH 'test2.db' AS aux;
}
@@ -600,7 +613,7 @@ ifcapable tempdb&&attach {
SELECT * FROM insert_log;
}
} {main 11 12 13 temp 14 15 16 aux 17 18 19}
- do_test trigger1-10.8 {
+ do_test trigger1-10.9 {
# Drop and re-create the insert_log table in a different database. Note
# that we can change the column names because the trigger programs don't
# use them explicitly.
diff --git a/lang/sql/sqlite/test/trigger2.test b/lang/sql/sqlite/test/trigger2.test
index b4b922a5..7b939bda 100644
--- a/lang/sql/sqlite/test/trigger2.test
+++ b/lang/sql/sqlite/test/trigger2.test
@@ -497,7 +497,7 @@ ifcapable conflict {
catchsql {
INSERT OR ABORT INTO tbl values (2, 2, 3);
}
- } {1 {column a is not unique}}
+ } {1 {UNIQUE constraint failed: tbl.a}}
do_test trigger2-6.1c {
execsql {
SELECT * from tbl;
@@ -507,7 +507,7 @@ ifcapable conflict {
catchsql {
INSERT OR FAIL INTO tbl values (2, 2, 3);
}
- } {1 {column a is not unique}}
+ } {1 {UNIQUE constraint failed: tbl.a}}
do_test trigger2-6.1e {
execsql {
SELECT * from tbl;
@@ -523,7 +523,7 @@ ifcapable conflict {
catchsql {
INSERT OR ROLLBACK INTO tbl values (3, 2, 3);
}
- } {1 {column a is not unique}}
+ } {1 {UNIQUE constraint failed: tbl.a}}
do_test trigger2-6.1h {
execsql {
SELECT * from tbl;
@@ -551,7 +551,7 @@ ifcapable conflict {
catchsql {
UPDATE OR ABORT tbl SET a = 4 WHERE a = 1;
}
- } {1 {column a is not unique}}
+ } {1 {UNIQUE constraint failed: tbl.a}}
do_test trigger2-6.2c {
execsql {
SELECT * from tbl;
@@ -561,7 +561,7 @@ ifcapable conflict {
catchsql {
UPDATE OR FAIL tbl SET a = 4 WHERE a = 1;
}
- } {1 {column a is not unique}}
+ } {1 {UNIQUE constraint failed: tbl.a}}
do_test trigger2-6.2e {
execsql {
SELECT * from tbl;
@@ -583,7 +583,7 @@ ifcapable conflict {
catchsql {
UPDATE OR ROLLBACK tbl SET a = 4 WHERE a = 1;
}
- } {1 {column a is not unique}}
+ } {1 {UNIQUE constraint failed: tbl.a}}
do_test trigger2-6.2h {
execsql {
SELECT * from tbl;
diff --git a/lang/sql/sqlite/test/trigger3.test b/lang/sql/sqlite/test/trigger3.test
index 34d19700..fe91b9dc 100644
--- a/lang/sql/sqlite/test/trigger3.test
+++ b/lang/sql/sqlite/test/trigger3.test
@@ -45,6 +45,7 @@ do_test trigger3-1.1 {
INSERT INTO tbl VALUES (1, 5, 6);
}
} {1 {Trigger abort}}
+verify_ex_errcode trigger3-1.1b SQLITE_CONSTRAINT_TRIGGER
do_test trigger3-1.2 {
execsql {
SELECT * FROM tbl;
@@ -63,6 +64,7 @@ do_test trigger3-2.1 {
INSERT INTO tbl VALUES (2, 5, 6);
}
} {1 {Trigger fail}}
+verify_ex_errcode trigger3-2.1b SQLITE_CONSTRAINT_TRIGGER
do_test trigger3-2.2 {
execsql {
SELECT * FROM tbl;
@@ -77,6 +79,7 @@ do_test trigger3-3.1 {
INSERT INTO tbl VALUES (3, 5, 6);
}
} {1 {Trigger rollback}}
+verify_ex_errcode trigger3-3.1b SQLITE_CONSTRAINT_TRIGGER
do_test trigger3-3.2 {
execsql {
SELECT * FROM tbl;
@@ -92,6 +95,7 @@ do_test trigger3-3.3 {
INSERT INTO tbl VALUES (3, 9, 10);
}
} {1 {Trigger rollback}}
+verify_ex_errcode trigger3-3.3b SQLITE_CONSTRAINT_TRIGGER
do_test trigger3-3.4 {
execsql {SELECT * FROM tbl}
} {}
@@ -172,6 +176,7 @@ do_test trigger3-7.1 {
INSERT INTO tbl_view VALUES(1, 2, 3);
}
} {1 {View rollback}}
+verify_ex_errcode trigger3-7.1b SQLITE_CONSTRAINT_TRIGGER
do_test trigger3-7.2 {
catchsql {
INSERT INTO tbl_view VALUES(2, 2, 3);
@@ -182,6 +187,7 @@ do_test trigger3-7.3 {
INSERT INTO tbl_view VALUES(3, 2, 3);
}
} {1 {View abort}}
+verify_ex_errcode trigger3-7.3b SQLITE_CONSTRAINT_TRIGGER
} ;# ifcapable view
diff --git a/lang/sql/sqlite/test/trigger4.test b/lang/sql/sqlite/test/trigger4.test
index 0e44ce6c..a05a5e73 100644
--- a/lang/sql/sqlite/test/trigger4.test
+++ b/lang/sql/sqlite/test/trigger4.test
@@ -130,8 +130,8 @@ do_test trigger4-3.7 {
do_test trigger4-4.1 {
db close
- file delete -force trigtest.db
- file delete -force trigtest.db-journal
+ forcedelete trigtest.db
+ forcedelete trigtest.db-journal
sqlite3 db trigtest.db
catchsql {drop table tbl; drop view vw}
execsql {
@@ -195,6 +195,6 @@ do_test trigger4-7.2 {
integrity_check trigger4-99.9
db close
-file delete -force trigtest.db trigtest.db-journal
+forcedelete trigtest.db trigtest.db-journal
finish_test
diff --git a/lang/sql/sqlite/test/triggerA.test b/lang/sql/sqlite/test/triggerA.test
index 9f93db5c..821e2d90 100644
--- a/lang/sql/sqlite/test/triggerA.test
+++ b/lang/sql/sqlite/test/triggerA.test
@@ -192,6 +192,13 @@ do_test triggerA-2.10 {
SELECT * FROM result4 ORDER BY a;
}
} {3 305 3 9900305 4 404 4 9900404 5 504 5 9900504}
+do_test triggerA-2.11 {
+ db eval {
+ DELETE FROM result4;
+ UPDATE v5 SET b = main.v5.b+9900000 WHERE main.v5.x BETWEEN 3 AND 5;
+ SELECT * FROM result4 ORDER BY a;
+ }
+} {3 305 3 9900305 4 404 4 9900404 5 504 5 9900504}
# Only run the reamining tests if memory debugging is turned on.
#
@@ -205,16 +212,16 @@ source $testdir/malloc_common.tcl
# Save a copy of the current database configuration.
#
db close
-file delete -force test.db-triggerA
-file copy test.db test.db-triggerA
+forcedelete test.db-triggerA
+copy_file test.db test.db-triggerA
sqlite3 db test.db
# Run malloc tests on the INSTEAD OF trigger firing.
#
do_malloc_test triggerA-3 -tclprep {
db close
- file delete -force test.db test.db-journal
- file copy -force test.db-triggerA test.db
+ forcedelete test.db test.db-journal
+ forcecopy test.db-triggerA test.db
sqlite3 db test.db
sqlite3_extended_result_codes db 1
db eval {SELECT * FROM v5; -- warm up the cache}
@@ -225,6 +232,6 @@ do_malloc_test triggerA-3 -tclprep {
# Clean up the saved database copy.
#
-file delete -force test.db-triggerA
+forcedelete test.db-triggerA
finish_test
diff --git a/lang/sql/sqlite/test/triggerC.test b/lang/sql/sqlite/test/triggerC.test
index 694d069d..14cc0f01 100644
--- a/lang/sql/sqlite/test/triggerC.test
+++ b/lang/sql/sqlite/test/triggerC.test
@@ -157,7 +157,7 @@ do_test triggerC-1.14 {
} {}
do_test triggerC-1.15 {
catchsql { UPDATE OR ROLLBACK t1 SET a=100 }
-} {1 {PRIMARY KEY must be unique}}
+} {1 {UNIQUE constraint failed: t1.a}}
#-------------------------------------------------------------------------
@@ -222,31 +222,31 @@ foreach {n tdefn rc} {
execsql $tdefn
catchsql {
INSERT INTO t2 VALUES(10);
- SELECT * FROM t2;
+ SELECT * FROM t2 ORDER BY rowid;
}
} $rc
}
do_test triggerC-2.2 {
- execsql {
+ execsql "
CREATE TABLE t22(x);
CREATE TRIGGER t22a AFTER INSERT ON t22 BEGIN
INSERT INTO t22 SELECT x + (SELECT max(x) FROM t22) FROM t22;
END;
CREATE TRIGGER t22b BEFORE INSERT ON t22 BEGIN
- SELECT CASE WHEN (SELECT count(*) FROM t22) >= 100
+ SELECT CASE WHEN (SELECT count(*) FROM t22) >= [expr $SQLITE_MAX_TRIGGER_DEPTH / 2]
THEN RAISE(IGNORE)
ELSE NULL END;
END;
INSERT INTO t22 VALUES(1);
SELECT count(*) FROM t22;
- }
-} {100}
+ "
+} [list [expr $SQLITE_MAX_TRIGGER_DEPTH / 2]]
do_test triggerC-2.3 {
- execsql {
+ execsql "
CREATE TABLE t23(x PRIMARY KEY);
CREATE TRIGGER t23a AFTER INSERT ON t23 BEGIN
@@ -254,15 +254,15 @@ do_test triggerC-2.3 {
END;
CREATE TRIGGER t23b BEFORE INSERT ON t23 BEGIN
- SELECT CASE WHEN new.x>500
+ SELECT CASE WHEN new.x>[expr $SQLITE_MAX_TRIGGER_DEPTH / 2]
THEN RAISE(IGNORE)
ELSE NULL END;
END;
INSERT INTO t23 VALUES(1);
SELECT count(*) FROM t23;
- }
-} {500}
+ "
+} [list [expr $SQLITE_MAX_TRIGGER_DEPTH / 2]]
#-----------------------------------------------------------------------
@@ -288,12 +288,12 @@ do_test triggerC-3.1.3 {
} {}
do_test triggerC-3.2.1 {
- execsql {
+ execsql "
CREATE TABLE t3b(x);
- CREATE TRIGGER t3bi AFTER INSERT ON t3b WHEN new.x<2000 BEGIN
+ CREATE TRIGGER t3bi AFTER INSERT ON t3b WHEN new.x<[expr $SQLITE_MAX_TRIGGER_DEPTH * 2] BEGIN
INSERT INTO t3b VALUES(new.x+1);
END;
- }
+ "
catchsql {
INSERT INTO t3b VALUES(1);
}
@@ -303,39 +303,39 @@ do_test triggerC-3.2.2 {
} {}
do_test triggerC-3.3.1 {
- catchsql {
- INSERT INTO t3b VALUES(1001);
- }
+ catchsql "
+ INSERT INTO t3b VALUES([expr $SQLITE_MAX_TRIGGER_DEPTH + 1]);
+ "
} {0 {}}
do_test triggerC-3.3.2 {
db eval {SELECT count(*), max(x), min(x) FROM t3b}
-} {1000 2000 1001}
+} [list $SQLITE_MAX_TRIGGER_DEPTH [expr $SQLITE_MAX_TRIGGER_DEPTH * 2] [expr $SQLITE_MAX_TRIGGER_DEPTH + 1]]
do_test triggerC-3.4.1 {
- catchsql {
+ catchsql "
DELETE FROM t3b;
- INSERT INTO t3b VALUES(999);
- }
+ INSERT INTO t3b VALUES([expr $SQLITE_MAX_TRIGGER_DEPTH - 1]);
+ "
} {1 {too many levels of trigger recursion}}
do_test triggerC-3.4.2 {
db eval {SELECT count(*), max(x), min(x) FROM t3b}
} {0 {} {}}
do_test triggerC-3.5.1 {
- sqlite3_limit db SQLITE_LIMIT_TRIGGER_DEPTH 100
- catchsql {
- INSERT INTO t3b VALUES(1901);
- }
+ sqlite3_limit db SQLITE_LIMIT_TRIGGER_DEPTH [expr $SQLITE_MAX_TRIGGER_DEPTH / 10]
+ catchsql "
+ INSERT INTO t3b VALUES([expr ($SQLITE_MAX_TRIGGER_DEPTH * 2) - ($SQLITE_MAX_TRIGGER_DEPTH / 10) + 1]);
+ "
} {0 {}}
do_test triggerC-3.5.2 {
db eval {SELECT count(*), max(x), min(x) FROM t3b}
-} {100 2000 1901}
+} [list [expr $SQLITE_MAX_TRIGGER_DEPTH / 10] [expr $SQLITE_MAX_TRIGGER_DEPTH * 2] [expr ($SQLITE_MAX_TRIGGER_DEPTH * 2) - ($SQLITE_MAX_TRIGGER_DEPTH / 10) + 1]]
do_test triggerC-3.5.3 {
- catchsql {
+ catchsql "
DELETE FROM t3b;
- INSERT INTO t3b VALUES(1900);
- }
+ INSERT INTO t3b VALUES([expr ($SQLITE_MAX_TRIGGER_DEPTH * 2) - ($SQLITE_MAX_TRIGGER_DEPTH / 10)]);
+ "
} {1 {too many levels of trigger recursion}}
do_test triggerC-3.5.4 {
db eval {SELECT count(*), max(x), min(x) FROM t3b}
@@ -343,25 +343,25 @@ do_test triggerC-3.5.4 {
do_test triggerC-3.6.1 {
sqlite3_limit db SQLITE_LIMIT_TRIGGER_DEPTH 1
- catchsql {
- INSERT INTO t3b VALUES(2000);
- }
+ catchsql "
+ INSERT INTO t3b VALUES([expr $SQLITE_MAX_TRIGGER_DEPTH * 2]);
+ "
} {0 {}}
do_test triggerC-3.6.2 {
db eval {SELECT count(*), max(x), min(x) FROM t3b}
-} {1 2000 2000}
+} [list 1 [expr $SQLITE_MAX_TRIGGER_DEPTH * 2] [expr $SQLITE_MAX_TRIGGER_DEPTH * 2]]
do_test triggerC-3.6.3 {
- catchsql {
+ catchsql "
DELETE FROM t3b;
- INSERT INTO t3b VALUES(1999);
- }
+ INSERT INTO t3b VALUES([expr ($SQLITE_MAX_TRIGGER_DEPTH * 2) - 1]);
+ "
} {1 {too many levels of trigger recursion}}
do_test triggerC-3.6.4 {
db eval {SELECT count(*), max(x), min(x) FROM t3b}
} {0 {} {}}
-sqlite3_limit db SQLITE_LIMIT_TRIGGER_DEPTH 1000
-
+sqlite3_limit db SQLITE_LIMIT_TRIGGER_DEPTH $SQLITE_MAX_TRIGGER_DEPTH
+
#-----------------------------------------------------------------------
# This next block of tests, triggerC-4.*, checks that affinity
@@ -547,7 +547,7 @@ foreach {n insert log} {
eval concat [execsql "
DELETE FROM log;
$insert ;
- SELECT * FROM log;
+ SELECT * FROM log ORDER BY rowid;
"]
} [join $log " "]
}
@@ -584,8 +584,8 @@ foreach {n dml t5g t5} {
execsql "
BEGIN;
$dml ;
- SELECT * FROM t5g;
- SELECT * FROM t5;
+ SELECT * FROM t5g ORDER BY rowid;
+ SELECT * FROM t5 ORDER BY rowid;
ROLLBACK;
"
} [concat $t5g $t5]
@@ -611,8 +611,8 @@ foreach {n dml t5g t5} {
execsql "
BEGIN;
$dml ;
- SELECT * FROM t5g;
- SELECT * FROM t5;
+ SELECT * FROM t5g ORDER BY rowid;
+ SELECT * FROM t5 ORDER BY rowid;
ROLLBACK;
"
} [concat $t5g $t5]
@@ -633,8 +633,8 @@ foreach {n dml t5g t5} {
execsql "
BEGIN;
$dml ;
- SELECT * FROM t5g;
- SELECT * FROM t5;
+ SELECT * FROM t5g ORDER BY rowid;
+ SELECT * FROM t5 ORDER BY rowid;
ROLLBACK;
"
} [concat $t5g $t5]
@@ -918,7 +918,7 @@ do_test triggerC-11.4 {
do_test triggerC-12.1 {
db close
- file delete -force test.db
+ forcedelete test.db
sqlite3 db test.db
execsql {
@@ -949,6 +949,48 @@ do_catchsql_test triggerC-13.2 {
UPDATE t12 SET a=a+1, b=b+1;
} {1 {too many levels of trigger recursion}}
+#-------------------------------------------------------------------------
+# The following tests seek to verify that constant values (i.e. literals)
+# are not factored out of loops within trigger programs. SQLite does
+# not factor constants out of loops within trigger programs as it may only
+# do so in code generated before the first table or index is opened. And
+# by the time a trigger program is coded, at least one table or index has
+# always been opened.
+#
+# At one point, due to a bug allowing constant factoring within triggers,
+# the following SQL would produce the wrong result.
+#
+set SQL {
+ CREATE TABLE t1(a, b, c);
+ CREATE INDEX i1 ON t1(a, c);
+ CREATE INDEX i2 ON t1(b, c);
+ INSERT INTO t1 VALUES(1, 2, 3);
+
+ CREATE TABLE t2(e, f);
+ CREATE INDEX i3 ON t2(e);
+ INSERT INTO t2 VALUES(1234567, 3);
+
+ CREATE TABLE empty(x);
+ CREATE TABLE not_empty(x);
+ INSERT INTO not_empty VALUES(2);
+
+ CREATE TABLE t4(x);
+ CREATE TABLE t5(g, h, i);
+
+ CREATE TRIGGER trig BEFORE INSERT ON t4 BEGIN
+ INSERT INTO t5 SELECT * FROM t1 WHERE
+ (a IN (SELECT x FROM empty) OR b IN (SELECT x FROM not_empty))
+ AND c IN (SELECT f FROM t2 WHERE e=1234567);
+ END;
+
+ INSERT INTO t4 VALUES(0);
+ SELECT * FROM t5;
+}
+reset_db
+do_execsql_test triggerC-14.1 $SQL {1 2 3}
+reset_db
+optimization_control db factor-constants 0
+do_execsql_test triggerC-14.2 $SQL {1 2 3}
finish_test
diff --git a/lang/sql/sqlite/test/triggerD.test b/lang/sql/sqlite/test/triggerD.test
index 08945081..a5dd4bdd 100644
--- a/lang/sql/sqlite/test/triggerD.test
+++ b/lang/sql/sqlite/test/triggerD.test
@@ -14,6 +14,12 @@
# the use of these columns in triggers will refer to the column and not
# to the actual ROWID. Ticket [34d2ae1c6d08b5271ba5e5592936d4a1d913ffe3]
#
+# Also, verify that triggers created like this:
+#
+# CREATE TRIGGER attached.trig AFTER INSERT ON attached.tab ...
+#
+# can be reparsed as a main database. Ticket [d6ddba6706353915ceedc56b4e3]
+#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -171,4 +177,43 @@ do_test triggerD-3.2 {
} {10003 20004}
+#############################################################################
+#
+# Ticket [d6ddba6706353915ceedc56b4e3e72ecb4d77ba4]
+#
+# The following syntax really should not be allowed:
+#
+# CREATE TRIGGER xyz.trig BEFORE UPDATE ON xyz.tab BEGIN ...
+#
+# But a long-standing bug does allow it. And the "xyz.tab" slips into
+# the sqlite_master table. We cannot fix the bug simply by disallowing
+# "xyz.tab" since that could break legacy applications. We have to
+# fix the system so that the "xyz." on "xyz.tab" is ignored.
+# Verify that this is the case.
+#
+do_test triggerD-4.1 {
+ db close
+ forcedelete test.db test2.db
+ sqlite3 db test.db
+ db eval {
+ CREATE TABLE t1(x);
+ ATTACH 'test2.db' AS db2;
+ CREATE TABLE db2.t2(y);
+ CREATE TABLE db2.log(z);
+ CREATE TRIGGER db2.trig AFTER INSERT ON db2.t2 BEGIN
+ INSERT INTO log(z) VALUES(new.y);
+ END;
+ INSERT INTO t2 VALUES(123);
+ SELECT * FROM log;
+ }
+} {123}
+do_test triggerD-4.2 {
+ sqlite3 db2 test2.db
+ db2 eval {
+ INSERT INTO t2 VALUES(234);
+ SELECT * FROM log;
+ }
+} {123 234}
+db2 close
+
finish_test
diff --git a/lang/sql/sqlite/test/triggerE.test b/lang/sql/sqlite/test/triggerE.test
new file mode 100644
index 00000000..e2727bbd
--- /dev/null
+++ b/lang/sql/sqlite/test/triggerE.test
@@ -0,0 +1,112 @@
+# 2009 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 tests the effects of SQL variable references embedded in
+# triggers. If the user attempts to create such a trigger, it is an
+# error. However, if an existing trigger definition is read from
+# the sqlite_master table, the variable reference always evaluates
+# to NULL.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+ifcapable {!trigger} {
+ finish_test
+ return
+}
+set testprefix triggerE
+
+do_execsql_test 1.0 {
+ CREATE TABLE t1(a, b);
+ CREATE TABLE t2(c, d);
+ CREATE TABLE t3(e, f);
+}
+
+# forcedelete test.db2
+# do_execsql_test 1.1 {
+# ATTACH 'test.db2' AS aux;
+# CREATE TABLE aux.t4(x);
+# INSERT INTO aux.t4 VALUES(5);
+#
+# CREATE TRIGGER tr1 AFTER INSERT ON t1 WHEN new.a IN (SELECT x FROM aux.t4)
+# BEGIN
+# SELECT 1;
+# END;
+# }
+# do_execsql_test 1.2 { INSERT INTO t1 VALUES(1,1); }
+# do_execsql_test 1.3 { INSERT INTO t1 VALUES(5,5); }
+
+#-------------------------------------------------------------------------
+# Attempt to create various triggers that use bound variables.
+#
+set errmsg "trigger cannot use variables"
+foreach {tn defn} {
+ 1 { AFTER INSERT ON t1 WHEN new.a = ? BEGIN SELECT 1; END; }
+ 2 { BEFORE DELETE ON t1 BEGIN SELECT ?; END; }
+ 3 { BEFORE DELETE ON t1 BEGIN SELECT * FROM (SELECT * FROM (SELECT ?)); END; }
+ 5 { BEFORE DELETE ON t1 BEGIN SELECT * FROM t2 GROUP BY ?; END; }
+ 6 { BEFORE DELETE ON t1 BEGIN SELECT * FROM t2 LIMIT ?; END; }
+ 7 { BEFORE DELETE ON t1 BEGIN SELECT * FROM t2 ORDER BY ?; END; }
+ 8 { BEFORE UPDATE ON t1 BEGIN UPDATE t2 SET c = ?; END; }
+ 9 { BEFORE UPDATE ON t1 BEGIN UPDATE t2 SET c = 1 WHERE d = ?; END; }
+} {
+ catchsql {drop trigger tr1}
+ do_catchsql_test 1.1.$tn "CREATE TRIGGER tr1 $defn" [list 1 $errmsg]
+ do_catchsql_test 1.2.$tn "CREATE TEMP TRIGGER tr1 $defn" [list 1 $errmsg]
+}
+
+#-------------------------------------------------------------------------
+# Test that variable references within trigger definitions loaded from
+# the sqlite_master table are automatically converted to NULL.
+#
+do_execsql_test 2.1 {
+ PRAGMA writable_schema = 1;
+ INSERT INTO sqlite_master VALUES('trigger', 'tr1', 't1', 0,
+ 'CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN
+ INSERT INTO t2 VALUES(?1, ?2);
+ END'
+ );
+
+ INSERT INTO sqlite_master VALUES('trigger', 'tr2', 't3', 0,
+ 'CREATE TRIGGER tr2 AFTER INSERT ON t3 WHEN ?1 IS NULL BEGIN
+ UPDATE t2 SET c=d WHERE c IS ?2;
+ END'
+ );
+}
+db close
+sqlite3 db test.db
+
+do_execsql_test 2.2.1 {
+ INSERT INTO t1 VALUES(1, 2);
+ SELECT * FROM t2;
+} {{} {}}
+do_test 2.2.2 {
+ set one 3
+ execsql {
+ DELETE FROM t2;
+ INSERT INTO t1 VALUES($one, ?1);
+ SELECT * FROM t2;
+ }
+} {{} {}}
+do_execsql_test 2.2.3 { SELECT * FROM t1 } {1 2 3 3}
+
+do_execsql_test 2.3 {
+ DELETE FROM t2;
+ INSERT INTO t2 VALUES('x', 'y');
+ INSERT INTO t2 VALUES(NULL, 'z');
+ INSERT INTO t3 VALUES(1, 2);
+ SELECT * FROM t3;
+ SELECT * FROM t2;
+} {1 2 x y z z}
+
+finish_test
+
+
diff --git a/lang/sql/sqlite/test/types3.test b/lang/sql/sqlite/test/types3.test
index 33f2595c..807ae84f 100644
--- a/lang/sql/sqlite/test/types3.test
+++ b/lang/sql/sqlite/test/types3.test
@@ -21,7 +21,7 @@ source $testdir/tester.tcl
# A variable with only a string representation comes in as TEXT
do_test types3-1.1 {
set V {}
- append V {}
+ append V x
concat [tcl_variable_type V] [execsql {SELECT typeof(:V)}]
} {string text}
diff --git a/lang/sql/sqlite/test/unique.test b/lang/sql/sqlite/test/unique.test
index 56c49eed..04581c23 100644
--- a/lang/sql/sqlite/test/unique.test
+++ b/lang/sql/sqlite/test/unique.test
@@ -47,7 +47,8 @@ do_test unique-1.3 {
catchsql {
INSERT INTO t1(a,b,c) VALUES(1,3,4)
}
-} {1 {column a is not unique}}
+} {1 {UNIQUE constraint failed: t1.a}}
+verify_ex_errcode unique-1.3b SQLITE_CONSTRAINT_PRIMARYKEY
do_test unique-1.4 {
execsql {
SELECT * FROM t1 ORDER BY a;
@@ -57,7 +58,8 @@ do_test unique-1.5 {
catchsql {
INSERT INTO t1(a,b,c) VALUES(3,2,4)
}
-} {1 {column b is not unique}}
+} {1 {UNIQUE constraint failed: t1.b}}
+verify_ex_errcode unique-1.5b SQLITE_CONSTRAINT_UNIQUE
do_test unique-1.6 {
execsql {
SELECT * FROM t1 ORDER BY a;
@@ -98,7 +100,8 @@ do_test unique-2.3 {
catchsql {
INSERT INTO t2 VALUES(1,5);
}
-} {1 {column a is not unique}}
+} {1 {UNIQUE constraint failed: t2.a}}
+verify_ex_errcode unique-2.3b SQLITE_CONSTRAINT_UNIQUE
do_test unique-2.4 {
catchsql {
SELECT * FROM t2 ORDER BY a
@@ -124,7 +127,8 @@ do_test unique-2.8 {
catchsql {
CREATE UNIQUE INDEX i2 ON t2(a);
}
-} {1 {indexed columns are not unique}}
+} {1 {UNIQUE constraint failed: t2.a}}
+verify_ex_errcode unique-2.8b SQLITE_CONSTRAINT_UNIQUE
do_test unique-2.9 {
catchsql {
CREATE INDEX i2 ON t2(a);
@@ -162,7 +166,8 @@ do_test unique-3.4 {
INSERT INTO t3(a,b,c,d) VALUES(1,4,3,5);
SELECT * FROM t3 ORDER BY a,b,c,d;
}
-} {1 {columns a, c, d are not unique}}
+} {1 {UNIQUE constraint failed: t3.a, t3.c, t3.d}}
+verify_ex_errcode unique-3.4b SQLITE_CONSTRAINT_UNIQUE
integrity_check unique-3.5
# Make sure NULLs are distinct as far as the UNIQUE tests are
@@ -216,7 +221,8 @@ do_test unique-4.9 {
} {0 {}}
do_test unique-4.10 {
catchsql {CREATE UNIQUE INDEX i4c ON t4(b)}
-} {1 {indexed columns are not unique}}
+} {1 {UNIQUE constraint failed: t4.b}}
+verify_ex_errcode unique-4.10b SQLITE_CONSTRAINT_UNIQUE
integrity_check unique-4.99
# Test the error message generation logic. In particular, make sure we
@@ -248,6 +254,8 @@ do_test unique-5.2 {
catchsql {
INSERT INTO t5 VALUES(1,2,3,4,5,6);
}
-} {1 {columns first_column_with_long_name, second_column_with_long_name, third_column_with_long_name, fourth_column_with_long_name, fifth_column_with_long_name, sixth_column_with_long_name are not unique}}
+} {1 {UNIQUE constraint failed: t5.first_column_with_long_name, t5.second_column_with_long_name, t5.third_column_with_long_name, t5.fourth_column_with_long_name, t5.fifth_column_with_long_name, t5.sixth_column_with_long_name}}
+verify_ex_errcode unique-5.2b SQLITE_CONSTRAINT_UNIQUE
+
finish_test
diff --git a/lang/sql/sqlite/test/unixexcl.test b/lang/sql/sqlite/test/unixexcl.test
index 057ae0af..0147e6bb 100644
--- a/lang/sql/sqlite/test/unixexcl.test
+++ b/lang/sql/sqlite/test/unixexcl.test
@@ -80,4 +80,49 @@ do_multiclient_test tn {
} {0 {hello world}}
}
+do_multiclient_test tn {
+ do_test unixexcl-3.$tn.1 {
+ code1 { db close; sqlite3 db file:test.db?psow=0 -vfs unix-excl -uri 1 }
+ code2 { db2 close; sqlite3 db2 file:test.db?psow=0 -vfs unix-excl -uri 1 }
+ sql1 {
+ PRAGMA auto_vacuum = 0;
+ PRAGMA journal_mode = WAL;
+ CREATE TABLE t1(a, b);
+ INSERT INTO t1 VALUES(1, 2);
+ }
+ } {wal}
+
+ if {$tn==1} {
+ do_test unixexcl-3.$tn.1.multiproc {
+ csql2 { SELECT * FROM t1; }
+ } {1 {database is locked}}
+ } else {
+ do_test unixexcl-3.$tn.1.singleproc {
+ sql2 { SELECT * FROM t1; }
+ } {1 2}
+
+ do_test unixexcl-3.$tn.2 {
+ sql2 {
+ BEGIN;
+ SELECT * FROM t1;
+ }
+ } {1 2}
+ do_test unixexcl-3.$tn.3 {
+ sql1 { PRAGMA wal_checkpoint; INSERT INTO t1 VALUES(3, 4); }
+ } {0 3 3}
+ do_test unixexcl-3.$tn.4 {
+ sql2 { SELECT * FROM t1; }
+ } {1 2}
+ do_test unixexcl-3.$tn.5 {
+ sql1 { SELECT * FROM t1; }
+ } {1 2 3 4}
+ do_test unixexcl-3.$tn.6 {
+ sql2 { COMMIT; SELECT * FROM t1; }
+ } {1 2 3 4}
+ do_test unixexcl-3.$tn.7 {
+ sql1 { PRAGMA wal_checkpoint; }
+ } {0 4 4}
+ }
+}
+
finish_test
diff --git a/lang/sql/sqlite/test/unordered.test b/lang/sql/sqlite/test/unordered.test
index ca4beaca..d8f7aa6a 100644
--- a/lang/sql/sqlite/test/unordered.test
+++ b/lang/sql/sqlite/test/unordered.test
@@ -31,32 +31,37 @@ do_execsql_test 1.0 {
} {}
foreach idxmode {ordered unordered} {
+ catchsql { DELETE FROM sqlite_stat2 }
+ catchsql { DELETE FROM sqlite_stat3 }
if {$idxmode == "unordered"} {
execsql { UPDATE sqlite_stat1 SET stat = stat || ' unordered' }
- db close
- sqlite3 db test.db
}
+ db close
+ sqlite3 db test.db
foreach {tn sql r(ordered) r(unordered)} {
1 "SELECT * FROM t1 ORDER BY a"
- {0 0 0 {SCAN TABLE t1 USING INDEX i1 (~128 rows)}}
- {0 0 0 {SCAN TABLE t1 (~128 rows)} 0 0 0 {USE TEMP B-TREE FOR ORDER BY}}
+ {0 0 0 {SCAN TABLE t1 USING INDEX i1}}
+ {0 0 0 {SCAN TABLE t1} 0 0 0 {USE TEMP B-TREE FOR ORDER BY}}
2 "SELECT * FROM t1 WHERE a >?"
- {0 0 0 {SEARCH TABLE t1 USING INDEX i1 (a>?) (~32 rows)}}
- {0 0 0 {SCAN TABLE t1 (~42 rows)}}
+ {0 0 0 {SEARCH TABLE t1 USING INDEX i1 (a>?)}}
+ {0 0 0 {SCAN TABLE t1}}
3 "SELECT * FROM t1 WHERE a = ? ORDER BY rowid"
- {0 0 0 {SEARCH TABLE t1 USING INDEX i1 (a=?) (~1 rows)}}
- {0 0 0 {SEARCH TABLE t1 USING INDEX i1 (a=?) (~1 rows)}
+ {0 0 0 {SEARCH TABLE t1 USING INDEX i1 (a=?)}}
+ {0 0 0 {SEARCH TABLE t1 USING INDEX i1 (a=?)}
0 0 0 {USE TEMP B-TREE FOR ORDER BY}}
4 "SELECT max(a) FROM t1"
- {0 0 0 {SEARCH TABLE t1 USING COVERING INDEX i1 (~1 rows)}}
- {0 0 0 {SEARCH TABLE t1 (~1 rows)}}
+ {0 0 0 {SEARCH TABLE t1 USING COVERING INDEX i1}}
+ {0 0 0 {SEARCH TABLE t1}}
5 "SELECT group_concat(b) FROM t1 GROUP BY a"
- {0 0 0 {SCAN TABLE t1 USING INDEX i1 (~128 rows)}}
- {0 0 0 {SCAN TABLE t1 (~128 rows)} 0 0 0 {USE TEMP B-TREE FOR GROUP BY}}
+ {0 0 0 {SCAN TABLE t1 USING INDEX i1}}
+ {0 0 0 {SCAN TABLE t1} 0 0 0 {USE TEMP B-TREE FOR GROUP BY}}
6 "SELECT * FROM t1 WHERE a = ?"
- {0 0 0 {SEARCH TABLE t1 USING INDEX i1 (a=?) (~1 rows)}}
- {0 0 0 {SEARCH TABLE t1 USING INDEX i1 (a=?) (~1 rows)}}
+ {0 0 0 {SEARCH TABLE t1 USING INDEX i1 (a=?)}}
+ {0 0 0 {SEARCH TABLE t1 USING INDEX i1 (a=?)}}
+ 7 "SELECT count(*) FROM t1"
+ {0 0 0 {SCAN TABLE t1 USING COVERING INDEX i1}}
+ {0 0 0 {SCAN TABLE t1}}
} {
do_eqp_test 1.$idxmode.$tn $sql $r($idxmode)
}
diff --git a/lang/sql/sqlite/test/update.test b/lang/sql/sqlite/test/update.test
index a6fef7d9..e67b0efd 100644
--- a/lang/sql/sqlite/test/update.test
+++ b/lang/sql/sqlite/test/update.test
@@ -452,7 +452,7 @@ do_test update-10.3 {
UPDATE t1 SET a=1, e=10 WHERE f=7;
SELECT * FROM t1;
}
-} {1 {PRIMARY KEY must be unique}}
+} {1 {UNIQUE constraint failed: t1.a}}
do_test update-10.4 {
catchsql {
SELECT * FROM t1;
@@ -469,7 +469,7 @@ do_test update-10.6 {
UPDATE t1 SET b=2, e=12 WHERE f=7;
SELECT * FROM t1;
}
-} {1 {column b is not unique}}
+} {1 {UNIQUE constraint failed: t1.b}}
do_test update-10.7 {
catchsql {
SELECT * FROM t1;
@@ -486,7 +486,7 @@ do_test update-10.9 {
UPDATE t1 SET c=3, d=4, e=14 WHERE f=7;
SELECT * FROM t1;
}
-} {1 {columns c, d are not unique}}
+} {1 {UNIQUE constraint failed: t1.c, t1.d}}
do_test update-10.10 {
catchsql {
SELECT * FROM t1;
diff --git a/lang/sql/sqlite/test/uri.test b/lang/sql/sqlite/test/uri.test
new file mode 100644
index 00000000..af1ad672
--- /dev/null
+++ b/lang/sql/sqlite/test/uri.test
@@ -0,0 +1,325 @@
+# 2011 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.
+#
+#***********************************************************************
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+# Test organization:
+#
+# 1.*: That file names are correctly extracted from URIs.
+# 2.*: That URI options (query parameters) are correctly extracted from URIs.
+# 3.*: That specifying an unknown VFS causes an error.
+# 4.*: Tests for specifying other options (other than "vfs").
+# 5.*: Test using a different VFS with an attached database.
+# 6.*: Test that authorities other than "" and localhost cause errors.
+# 7.*: Test that a read-write db can be attached to a read-only connection.
+#
+
+set testprefix uri
+db close
+sqlite3_shutdown
+sqlite3_config_uri 1
+
+#-------------------------------------------------------------------------
+# Test that file names are correctly extracted from URIs.
+#
+foreach {tn uri file} {
+ 1 test.db test.db
+ 2 file:test.db test.db
+ 3 file://PWD/test.db test.db
+ 4 file:PWD/test.db test.db
+ 5 file:test.db?mork=1 test.db
+ 6 file:test.db?mork=1&tonglor=2 test.db
+ 7 file:test.db?mork=1#boris test.db
+ 8 file:test.db#boris test.db
+ 9 test.db#boris test.db#boris
+ 10 file:test%2Edb test.db
+ 11 file file
+ 12 http:test.db http:test.db
+ 13 file:test.db%00extra test.db
+ 14 file:testdb%00.db%00extra testdb
+
+ 15 test.db?mork=1#boris test.db?mork=1#boris
+ 16 file://localhostPWD/test.db%3Fhello test.db?hello
+} {
+
+
+ ifcapable !curdir { if {$tn==3} break }
+
+ if {$tcl_platform(platform)=="windows"} {
+ #
+ # NOTE: Due to limits on legal characters for file names imposed by
+ # Windows, we must skip the final two tests here (i.e. the
+ # question mark is illegal in a file name on Windows).
+ #
+ if {$tn>14} break
+
+ #
+ # NOTE: On Windows, we need to account for the fact that the current
+ # directory does not start with a forward slash.
+ #
+ set uri [string map [list PWD/ /[test_pwd /]] $uri]
+ } else {
+ set uri [string map [list PWD/ [test_pwd /]] $uri]
+ }
+
+ if {[file isdir $file]} {error "$file is a directory"}
+ forcedelete $file
+ do_test 1.$tn.1 { file exists $file } 0
+ set DB [sqlite3_open $uri]
+ do_test 1.$tn.2 { file exists $file } 1
+ sqlite3_close $DB
+ forcedelete $file
+
+ do_test 1.$tn.3 { file exists $file } 0
+ sqlite3 db xxx.db
+ catchsql { ATTACH $uri AS aux }
+ do_test 1.$tn.4 { file exists $file } 1
+ db close
+}
+
+#-------------------------------------------------------------------------
+# Test that URI query parameters are passed through to the VFS layer
+# correctly.
+#
+testvfs tvfs2
+testvfs tvfs -default 1
+tvfs filter xOpen
+tvfs script open_method
+proc open_method {method file arglist} {
+ set ::arglist $arglist
+}
+foreach {tn uri kvlist} {
+ 1 file:test.db?hello=world {hello world}
+ 2 file:test.db?hello&world {hello {} world {}}
+ 3 file:test.db?hello=1&world=2&vfs=tvfs {hello 1 world 2 vfs tvfs}
+ 4 file:test.db?hello=1&world=2&vfs=tvfs2 {}
+ 5 file:test.db?%68%65%6C%6C%6F=%77%6F%72%6C%64 {hello world}
+ 6 file:testdb%00.db?hello%00extra=world%00ex {hello world}
+ 7 file:testdb%00.db?hello%00=world%00 {hello world}
+ 8 file:testdb%00.db?=world&xyz=abc {xyz abc}
+ 9 file:test.db?%00hello=world&xyz=abc {xyz abc}
+ 10 file:test.db?hello=%00world&xyz= {hello {} xyz {}}
+ 11 file:test.db?=#ravada {}
+ 12 file:test.db?&&&&&&&&hello=world&&&&&&& {hello world}
+
+ 13 test.db?&&&&&&&&hello=world&&&&&&& {}
+ 14 http:test.db?hello&world {}
+} {
+
+ if {$tcl_platform(platform) == "windows" && $tn>12} {
+ continue
+ }
+
+ set ::arglist ""
+ set DB [sqlite3_open $uri]
+ do_test 2.$tn.1 { set ::arglist } $kvlist
+ sqlite3_close $DB
+
+ sqlite3 db xxx.db
+ set ::arglist ""
+ execsql { ATTACH $uri AS aux }
+ do_test 2.$tn.2 { set ::arglist } $kvlist
+ db close
+}
+tvfs delete
+tvfs2 delete
+
+#-------------------------------------------------------------------------
+# Test that specifying a non-existent VFS raises an error.
+#
+do_test 3.1 {
+ list [catch { sqlite3 db "file:test.db?vfs=nosuchvfs" } msg] $msg
+} {1 {no such vfs: nosuchvfs}}
+
+#-------------------------------------------------------------------------
+# Test some of the other options (other than "vfs").
+#
+foreach {tn mode create_ok write_ok readonly_ok} {
+ 1 ro 0 0 1
+ 2 rw 0 1 0
+ 3 rwc 1 1 0
+} {
+ catch { db close }
+ forcedelete test.db
+
+ set A(1) {0 {}}
+ set A(0) {1 {unable to open database file}}
+ do_test 4.1.$tn.1 {
+ list [catch {sqlite3 db "file:test.db?mode=$mode"} msg] $msg
+ } $A($create_ok)
+
+ catch { db close }
+ forcedelete test.db
+ sqlite3 db test.db
+ db eval { CREATE TABLE t1(a, b) }
+ db close
+
+ set A(1) {0 {}}
+ set A(0) {1 {attempt to write a readonly database}}
+ do_test 4.1.$tn.2 {
+ sqlite3 db "file:test.db?mode=$mode"
+ catchsql { INSERT INTO t1 VALUES(1, 2) }
+ } $A($write_ok)
+
+ set A(1) {0 {}}
+ set A(0) [list 1 "access mode not allowed: $mode"]
+ do_test 4.1.$tn.3 {
+ list [catch {sqlite3 db "file:test.db?mode=$mode" -readonly 1} msg] $msg
+ } $A($readonly_ok)
+}
+
+set orig [sqlite3_enable_shared_cache]
+foreach {tn options sc_default is_shared} {
+ 1 "" 1 1
+ 2 "cache=private" 1 0
+ 3 "cache=shared" 1 1
+ 4 "" 0 0
+ 5 "cache=private" 0 0
+ 6 "cache=shared" 0 1
+} {
+ catch { db close }
+ forcedelete test.db
+
+ sqlite3_enable_shared_cache 1
+ sqlite3 db2 test.db
+ db2 eval {CREATE TABLE t1(a, b)}
+
+ sqlite3_enable_shared_cache $sc_default
+ sqlite3 db "file:test.db?$options"
+ db eval {SELECT * FROM t1}
+
+ set A(1) {1 {database table is locked: t1}}
+ set A(0) {0 {}}
+ do_test 4.2.$tn {
+ db2 eval {BEGIN; INSERT INTO t1 VALUES(1, 2);}
+ catchsql { SELECT * FROM t1 }
+ } $A($is_shared)
+
+ db2 close
+}
+
+do_test 4.3.1 {
+ list [catch {sqlite3 db "file:test.db?mode=rc"} msg] $msg
+} {1 {no such access mode: rc}}
+do_test 4.3.2 {
+ list [catch {sqlite3 db "file:test.db?cache=public"} msg] $msg
+} {1 {no such cache mode: public}}
+
+#-------------------------------------------------------------------------
+# Test that things work if an ATTACHed database uses a different VFS than
+# the main database. The important point is that for all operations
+# involving the ATTACHed database, the correct versions of the following
+# VFS are used for all operations involving the attached database.
+#
+# xOpen
+# xDelete
+# xAccess
+# xFullPathname
+#
+
+# This block of code creates two VFS - "tvfs1" and "tvfs2". Each time one
+# of the above methods is called using "tvfs1", global variable ::T1(X) is
+# set, where X is the file-name the method is called on. Calls to the above
+# methods using "tvfs2" set entries in the global T2 array.
+#
+ifcapable wal {
+ testvfs tvfs1
+ tvfs1 filter {xOpen xDelete xAccess xFullPathname}
+ tvfs1 script tvfs1_callback
+ proc tvfs1_callback {method filename args} {
+ set ::T1([file tail $filename]) 1
+ }
+ testvfs tvfs2
+ tvfs2 filter {xOpen xDelete xAccess xFullPathname}
+ tvfs2 script tvfs2_callback
+ proc tvfs2_callback {method filename args} {
+ set ::T2([file tail $filename]) 1
+ }
+
+ catch {db close}
+ eval forcedelete [glob test.db*]
+ do_test 5.1.1 {
+ sqlite3 db file:test.db1?vfs=tvfs1
+ execsql {
+ ATTACH 'file:test.db2?vfs=tvfs2' AS aux;
+ PRAGMA main.journal_mode = PERSIST;
+ PRAGMA aux.journal_mode = PERSIST;
+ CREATE TABLE t1(a, b);
+ CREATE TABLE aux.t2(a, b);
+ PRAGMA main.journal_mode = WAL;
+ PRAGMA aux.journal_mode = WAL;
+ INSERT INTO t1 VALUES('x', 'y');
+ INSERT INTO t2 VALUES('x', 'y');
+ }
+ lsort [array names ::T1]
+ } {test.db1 test.db1-journal test.db1-wal}
+
+ do_test 5.1.2 {
+ lsort [array names ::T2]
+ } {test.db2 test.db2-journal test.db2-wal}
+ db close
+
+ tvfs1 delete
+ tvfs2 delete
+}
+
+#-------------------------------------------------------------------------
+# Check that only "" and "localhost" are acceptable as authorities.
+#
+catch {db close}
+foreach {tn uri res} {
+ 1 "file://localhost/PWD/test.db" {not an error}
+ 2 "file:///PWD/test.db" {not an error}
+ 3 "file:/PWD/test.db" {not an error}
+ 4 "file://l%6Fcalhost/PWD/test.db" {invalid uri authority: l%6Fcalhost}
+ 5 "file://lbcalhost/PWD/test.db" {invalid uri authority: lbcalhost}
+ 6 "file://x/PWD/test.db" {invalid uri authority: x}
+} {
+
+ if {$tcl_platform(platform)=="windows"} {
+ set uri [string map [list PWD [string range [get_pwd] 3 end]] $uri]
+ } else {
+ set uri [string map [list PWD [string range [get_pwd] 1 end]] $uri]
+ }
+
+ do_test 6.$tn {
+ set DB [sqlite3_open $uri]
+ sqlite3_errmsg $DB
+ } $res
+ catch { sqlite3_close $DB }
+}
+
+forcedelete test.db test.db2
+do_test 7.1 {
+ sqlite3 db test.db
+ execsql {
+ CREATE TABLE t1(a, b);
+ INSERT INTO t1 VALUES(1, 2);
+ ATTACH 'test.db2' AS aux;
+ CREATE TABLE aux.t2(a, b);
+ INSERT INTO t1 VALUES('a', 'b');
+ }
+ db close
+} {}
+do_test 7.2 {
+ sqlite3 db file:test.db?mode=ro
+ execsql { ATTACH 'file:test.db2?mode=rw' AS aux }
+} {}
+do_execsql_test 7.3 {
+ INSERT INTO t2 VALUES('c', 'd')
+} {}
+do_catchsql_test 7.4 {
+ INSERT INTO t1 VALUES(3, 4)
+} {1 {attempt to write a readonly database}}
+
+finish_test
diff --git a/lang/sql/sqlite/test/vacuum.test b/lang/sql/sqlite/test/vacuum.test
index 34be57ce..57429c29 100644
--- a/lang/sql/sqlite/test/vacuum.test
+++ b/lang/sql/sqlite/test/vacuum.test
@@ -208,7 +208,7 @@ db3 close
do_test vacuum-3.1 {
db close
db2 close
- file delete test.db
+ delete_file test.db
sqlite3 db test.db
execsql {
PRAGMA empty_result_callbacks=on;
@@ -234,7 +234,7 @@ do_test vacuum-4.2 {
ifcapable view {
do_test vacuum-5.1 {
db close
- file delete -force test.db
+ forcedelete test.db
sqlite3 db test.db
catchsql {
CREATE TABLE Test (TestID int primary key);
@@ -290,10 +290,10 @@ ifcapable {bloblit} {
}
# Check what happens when an in-memory database is vacuumed. The
-# [file delete] command covers us in case the library was compiled
+# [delete_file] command covers us in case the library was compiled
# without in-memory database support.
#
-file delete -force :memory:
+forcedelete :memory:
do_test vacuum-7.0 {
sqlite3 db2 :memory:
execsql {
@@ -337,8 +337,8 @@ db2 close
# Ticket #873. VACUUM a database that has ' in its name.
#
do_test vacuum-8.1 {
- file delete -force a'z.db
- file delete -force a'z.db-journal
+ forcedelete a'z.db
+ forcedelete a'z.db-journal
sqlite3 db2 a'z.db
execsql {
CREATE TABLE t1(t);
@@ -383,6 +383,22 @@ ifcapable {autoinc} {
} $::cksum
}
-file delete -force {a'z.db}
+forcedelete {a'z.db}
+
+# Test that "PRAGMA count_changes" does not interfere with VACUUM or cause
+# it to return any rows to the user.
+#
+do_test vacuum-10.1 {
+ db close
+ forcedelete test.db
+ sqlite3 db test.db
+ execsql {
+ CREATE TABLE t8(a, b);
+ INSERT INTO t8 VALUES('a', 'b');
+ INSERT INTO t8 VALUES('c', 'd');
+ PRAGMA count_changes = 1;
+ }
+} {}
+do_test vacuum-10.2 { execsql VACUUM } {}
finish_test
diff --git a/lang/sql/sqlite/test/vacuum2.test b/lang/sql/sqlite/test/vacuum2.test
index 35524bb2..b3bfab30 100644
--- a/lang/sql/sqlite/test/vacuum2.test
+++ b/lang/sql/sqlite/test/vacuum2.test
@@ -135,7 +135,7 @@ db2 close
ifcapable autovacuum {
do_test vacuum2-4.1 {
db close
- file delete -force test.db
+ forcedelete test.db
sqlite3 db test.db
execsql {
pragma auto_vacuum=1;
diff --git a/lang/sql/sqlite/test/vacuum3.test b/lang/sql/sqlite/test/vacuum3.test
index f6b75d70..484a7d44 100644
--- a/lang/sql/sqlite/test/vacuum3.test
+++ b/lang/sql/sqlite/test/vacuum3.test
@@ -196,7 +196,7 @@ foreach {request actual} [list \
do_test vacuum3-4.1 {
db close
- file delete test.db
+ delete_file test.db
sqlite3 db test.db
execsql {
PRAGMA page_size=1024;
diff --git a/lang/sql/sqlite/test/veryquick.test b/lang/sql/sqlite/test/veryquick.test
index ca82b22b..c8d6ce8f 100644
--- a/lang/sql/sqlite/test/veryquick.test
+++ b/lang/sql/sqlite/test/veryquick.test
@@ -16,4 +16,3 @@ source $testdir/permutations.test
run_test_suite veryquick
finish_test
-
diff --git a/lang/sql/sqlite/test/view.test b/lang/sql/sqlite/test/view.test
index a87d2770..779f77b6 100644
--- a/lang/sql/sqlite/test/view.test
+++ b/lang/sql/sqlite/test/view.test
@@ -458,7 +458,7 @@ do_test view-12.1 {
ifcapable attach {
do_test view-13.1 {
- file delete -force test2.db
+ forcedelete test2.db
catchsql {
ATTACH 'test2.db' AS two;
CREATE TABLE two.t2(x,y);
@@ -576,4 +576,39 @@ do_test view-20.1 {
}
} {}
+# Ticket [d58ccbb3f1b]: Prevent Table.nRef overflow.
+db close
+sqlite3 db :memory:
+do_test view-21.1 {
+ catchsql {
+ CREATE TABLE t1(x);
+ INSERT INTO t1 VALUES(5);
+ CREATE VIEW v1 AS SELECT x*2 FROM t1;
+ CREATE VIEW v2 AS SELECT * FROM v1 UNION SELECT * FROM v1;
+ CREATE VIEW v4 AS SELECT * FROM v2 UNION SELECT * FROM v2;
+ CREATE VIEW v8 AS SELECT * FROM v4 UNION SELECT * FROM v4;
+ CREATE VIEW v16 AS SELECT * FROM v8 UNION SELECT * FROM v8;
+ CREATE VIEW v32 AS SELECT * FROM v16 UNION SELECT * FROM v16;
+ CREATE VIEW v64 AS SELECT * FROM v32 UNION SELECT * FROM v32;
+ CREATE VIEW v128 AS SELECT * FROM v64 UNION SELECT * FROM v64;
+ CREATE VIEW v256 AS SELECT * FROM v128 UNION SELECT * FROM v128;
+ CREATE VIEW v512 AS SELECT * FROM v256 UNION SELECT * FROM v256;
+ CREATE VIEW v1024 AS SELECT * FROM v512 UNION SELECT * FROM v512;
+ CREATE VIEW v2048 AS SELECT * FROM v1024 UNION SELECT * FROM v1024;
+ CREATE VIEW v4096 AS SELECT * FROM v2048 UNION SELECT * FROM v2048;
+ CREATE VIEW v8192 AS SELECT * FROM v4096 UNION SELECT * FROM v4096;
+ CREATE VIEW v16384 AS SELECT * FROM v8192 UNION SELECT * FROM v8192;
+ CREATE VIEW v32768 AS SELECT * FROM v16384 UNION SELECT * FROM v16384;
+ CREATE VIEW vx AS SELECT * FROM v32768 UNION SELECT * FROM v32768;
+ }
+} {1 {too many references to "v1": max 65535}}
+ifcapable progress {
+ do_test view-21.2 {
+ db progress 1000 {expr 1}
+ catchsql {
+ SELECT * FROM v32768;
+ }
+ } {1 interrupted}
+}
+
finish_test
diff --git a/lang/sql/sqlite/test/vtab1.test b/lang/sql/sqlite/test/vtab1.test
index 088ca267..891165c8 100644
--- a/lang/sql/sqlite/test/vtab1.test
+++ b/lang/sql/sqlite/test/vtab1.test
@@ -15,6 +15,7 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
+set testprefix vtab1
ifcapable !vtab||!schema_pragmas {
finish_test
@@ -43,6 +44,9 @@ ifcapable !vtab||!schema_pragmas {
#
# vtab1-14.*: Test 'IN' constraints - i.e. "SELECT * FROM t1 WHERE id IN(...)"
#
+# vtab1-18.*: Check that the LIKE optimization is not applied when the lhs
+# is a virtual table column.
+#
#----------------------------------------------------------------------
@@ -51,7 +55,7 @@ ifcapable !vtab||!schema_pragmas {
# We cannot create a virtual table if the module has not been registered.
#
-do_test vtab1-1.1 {
+do_test vtab1-1.1.1 {
explain {
CREATE VIRTUAL TABLE t1 USING echo;
}
@@ -59,6 +63,11 @@ do_test vtab1-1.1 {
CREATE VIRTUAL TABLE t1 USING echo;
}
} {1 {no such module: echo}}
+do_test vtab1-1.1.2 {
+ catchsql {
+ CREATE VIRTUAL TABLE IF NOT EXISTS t1 USING echo;
+ }
+} {1 {no such module: echo}}
do_test vtab1-1.2 {
execsql {
SELECT name FROM sqlite_master ORDER BY 1
@@ -75,11 +84,16 @@ register_echo_module [sqlite3_connection_pointer db]
# The "echo" module does not invoke sqlite3_declare_vtab() if it is
# passed zero arguments.
#
-do_test vtab1-1.3 {
+do_test vtab1-1.3.1 {
catchsql {
CREATE VIRTUAL TABLE t1 USING echo;
}
} {1 {vtable constructor did not declare schema: t1}}
+do_test vtab1-1.3.2 {
+ catchsql {
+ CREATE VIRTUAL TABLE IF NOT EXISTS t1 USING echo;
+ }
+} {1 {vtable constructor did not declare schema: t1}}
do_test vtab1-1.4 {
execsql {
SELECT name FROM sqlite_master ORDER BY 1
@@ -90,11 +104,16 @@ do_test vtab1-1.4 {
# the virtual table if it is passed an argument that does not correspond
# to an existing real table in the same database.
#
-do_test vtab1-1.5 {
+do_test vtab1-1.5.1 {
catchsql {
CREATE VIRTUAL TABLE t1 USING echo(no_such_table);
}
} {1 {vtable constructor failed: t1}}
+do_test vtab1-1.5.2 {
+ catchsql {
+ CREATE VIRTUAL TABLE IF NOT EXISTS t1 USING echo(no_such_table);
+ }
+} {1 {vtable constructor failed: t1}}
do_test vtab1-1.6 {
execsql {
SELECT name FROM sqlite_master ORDER BY 1
@@ -128,17 +147,27 @@ do_test vtab-1.2152.4 {
# select an illegal table-name (i.e a reserved name or the name of a
# table that already exists).
#
-do_test vtab1-1.7 {
+do_test vtab1-1.7.1 {
catchsql {
CREATE VIRTUAL TABLE sqlite_master USING echo;
}
} {1 {object name reserved for internal use: sqlite_master}}
-do_test vtab1-1.8 {
+do_test vtab1-1.7.2 {
+ catchsql {
+ CREATE VIRTUAL TABLE IF NOT EXISTS sqlite_master USING echo;
+ }
+} {1 {object name reserved for internal use: sqlite_master}}
+do_test vtab1-1.8.1 {
catchsql {
CREATE TABLE treal(a, b, c);
CREATE VIRTUAL TABLE treal USING echo(treal);
}
} {1 {table treal already exists}}
+do_test vtab1-1.8.2 {
+ catchsql {
+ CREATE VIRTUAL TABLE IF NOT EXISTS treal USING echo(treal);
+ }
+} {0 {}}
do_test vtab1-1.9 {
execsql {
DROP TABLE treal;
@@ -589,8 +618,9 @@ do_test vtab1-5-6 {
do_test vtab1-5-7 {
filter $::echo_module
} [list \
- xFilter {SELECT rowid, * FROM 't2' WHERE d = ?} \
xFilter {SELECT rowid, * FROM 't1'} \
+ xFilter {SELECT rowid, * FROM 't2' WHERE d = ?} \
+ xFilter {SELECT rowid, * FROM 't2' WHERE d = ?} \
]
execsql {
@@ -724,8 +754,8 @@ do_test vtab1-6-8.4 {
} {}
execsql {PRAGMA count_changes=OFF}
-file delete -force test2.db
-file delete -force test2.db-journal
+forcedelete test2.db
+forcedelete test2.db-journal
sqlite3 db2 test2.db
execsql {
CREATE TABLE techo(a PRIMARY KEY, b, c);
@@ -1014,10 +1044,10 @@ do_test vtab1.12-1 {
# First test outside of a transaction.
do_test vtab1.12-2 {
catchsql { INSERT INTO echo_c SELECT * FROM b; }
-} {1 {echo-vtab-error: column a is not unique}}
+} {1 {echo-vtab-error: UNIQUE constraint failed: c.a}}
do_test vtab1.12-2.1 {
sqlite3_errmsg db
-} {echo-vtab-error: column a is not unique}
+} {echo-vtab-error: UNIQUE constraint failed: c.a}
do_test vtab1.12-3 {
execsql { SELECT * FROM c }
} {3 G H}
@@ -1026,7 +1056,7 @@ do_test vtab1.12-3 {
do_test vtab1.12-4 {
execsql {BEGIN}
catchsql { INSERT INTO echo_c SELECT * FROM b; }
-} {1 {echo-vtab-error: column a is not unique}}
+} {1 {echo-vtab-error: UNIQUE constraint failed: c.a}}
do_test vtab1.12-5 {
execsql { SELECT * FROM c }
} {3 G H}
@@ -1066,12 +1096,54 @@ do_test vtab1.13-3 {
} {15 {} 16}
-do_test vtab1-14.1 {
- execsql { DELETE FROM c }
- set echo_module ""
- execsql { SELECT * FROM echo_c WHERE rowid IN (1, 2, 3) }
- set echo_module
-} [list xBestIndex {SELECT rowid, * FROM 'c'} xFilter {SELECT rowid, * FROM 'c'}]
+do_test vtab1-14.001 {
+ execsql {SELECT rowid, * FROM echo_c WHERE +rowid IN (1,2,3)}
+} {1 3 G H 2 {} 15 16 3 15 {} 16}
+do_test vtab1-14.002 {
+ execsql {SELECT rowid, * FROM echo_c WHERE rowid IN (1,2,3)}
+} {1 3 G H 2 {} 15 16 3 15 {} 16}
+do_test vtab1-14.003 {
+ execsql {SELECT rowid, * FROM echo_c WHERE +rowid IN (0,1,5,2,'a',3,NULL)}
+} {1 3 G H 2 {} 15 16 3 15 {} 16}
+do_test vtab1-14.004 {
+ execsql {SELECT rowid, * FROM echo_c WHERE rowid IN (0,1,5,'a',2,3,NULL)}
+} {1 3 G H 2 {} 15 16 3 15 {} 16}
+do_test vtab1-14.005 {
+ execsql {SELECT rowid, * FROM echo_c WHERE rowid NOT IN (0,1,5,'a',2,3)}
+} {}
+do_test vtab1-14.006 {
+ execsql {SELECT rowid, * FROM echo_c WHERE rowid NOT IN (0,5,'a',2,3)}
+} {1 3 G H}
+do_test vtab1-14.007 {
+ execsql {SELECT rowid, * FROM echo_c WHERE +rowid NOT IN (0,5,'a',2,3,NULL)}
+} {}
+do_test vtab1-14.008 {
+ execsql {SELECT rowid, * FROM echo_c WHERE rowid NOT IN (0,5,'a',2,3,NULL)}
+} {}
+do_test vtab1-14.011 {
+ execsql {SELECT * FROM echo_c WHERE +a IN (1,3,8,'x',NULL,15,24)}
+} {3 G H 15 {} 16}
+do_test vtab1-14.012 {
+ execsql {SELECT * FROM echo_c WHERE a IN (1,3,8,'x',NULL,15,24)}
+} {3 G H 15 {} 16}
+do_test vtab1-14.013 {
+ execsql {SELECT * FROM echo_c WHERE a NOT IN (1,8,'x',15,24)}
+} {3 G H}
+do_test vtab1-14.014 {
+ execsql {SELECT * FROM echo_c WHERE a NOT IN (1,8,'x',NULL,15,24)}
+} {}
+do_test vtab1-14.015 {
+ execsql {SELECT * FROM echo_c WHERE +a NOT IN (1,8,'x',NULL,15,24)}
+} {}
+
+
+
+#do_test vtab1-14.1 {
+# execsql { DELETE FROM c }
+# set echo_module ""
+# execsql { SELECT * FROM echo_c WHERE rowid IN (1, 2, 3) }
+# set echo_module
+#} {/.*xBestIndex {SELECT rowid, . FROM 'c' WHERE rowid = .} xFilter {SELECT rowid, . FROM 'c'} 1/}
do_test vtab1-14.2 {
set echo_module ""
@@ -1085,11 +1157,11 @@ do_test vtab1-14.3 {
set echo_module
} [list xBestIndex {SELECT rowid, * FROM 'c' WHERE a = ?} xFilter {SELECT rowid, * FROM 'c' WHERE a = ?} 1]
-do_test vtab1-14.4 {
- set echo_module ""
- execsql { SELECT * FROM echo_c WHERE a IN (1, 2) }
- set echo_module
-} [list xBestIndex {SELECT rowid, * FROM 'c'} xFilter {SELECT rowid, * FROM 'c'}]
+#do_test vtab1-14.4 {
+# set echo_module ""
+# execsql { SELECT * FROM echo_c WHERE a IN (1, 2) }
+# set echo_module
+#} {/xBestIndex {SELECT rowid, . FROM 'c' WHERE a = .} xFilter {SELECT rowid, . FROM 'c' WHERE a = .} 1/}
do_test vtab1-15.1 {
execsql {
@@ -1182,5 +1254,149 @@ do_test vtab1-17.1 {
catchsql { CREATE VIRTUAL TABLE t4 USING echo(t3); }
} {1 {vtable constructor failed: t4}}
+# This test verifies that ticket 48f29963 is fixed.
+#
+do_test vtab1-17.1 {
+ execsql {
+ CREATE TABLE t5(a, b);
+ CREATE VIRTUAL TABLE e5 USING echo_v2(t5);
+ BEGIN;
+ INSERT INTO e5 VALUES(1, 2);
+ DROP TABLE e5;
+ SAVEPOINT one;
+ ROLLBACK TO one;
+ COMMIT;
+ }
+} {}
+
+do_test vtab1-17.2 {
+ execsql { DELETE FROM sqlite_master WHERE sql LIKE 'insert%' }
+} {}
+
+#-------------------------------------------------------------------------
+# The following tests - vtab1-18.* - test that the optimization of LIKE
+# constraints in where.c plays well with virtual tables.
+#
+# 18.1.*: Case-insensitive LIKE.
+# 18.2.*: Case-sensitive LIKE.
+#
unset -nocomplain echo_module_begin_fail
+
+do_execsql_test 18.1.0 {
+ CREATE TABLE t6(a, b TEXT);
+ CREATE INDEX i6 ON t6(b, a);
+ INSERT INTO t6 VALUES(1, 'Peter');
+ INSERT INTO t6 VALUES(2, 'Andrew');
+ INSERT INTO t6 VALUES(3, 'James');
+ INSERT INTO t6 VALUES(4, 'John');
+ INSERT INTO t6 VALUES(5, 'Phillip');
+ INSERT INTO t6 VALUES(6, 'Bartholomew');
+ CREATE VIRTUAL TABLE e6 USING echo(t6);
+}
+
+foreach {tn sql res filter} {
+ 1.1 "SELECT a FROM e6 WHERE b>'James'" {4 1 5}
+ {xFilter {SELECT rowid, * FROM 't6' WHERE b > ?} James}
+
+ 1.2 "SELECT a FROM e6 WHERE b>='J' AND b<'K'" {3 4}
+ {xFilter {SELECT rowid, * FROM 't6' WHERE b >= ? AND b < ?} J K}
+
+ 1.3 "SELECT a FROM e6 WHERE b LIKE 'J%'" {3 4}
+ {xFilter {SELECT rowid, * FROM 't6'}}
+
+ 1.4 "SELECT a FROM e6 WHERE b LIKE 'j%'" {3 4}
+ {xFilter {SELECT rowid, * FROM 't6'}}
+} {
+ set echo_module {}
+ do_execsql_test 18.$tn.1 $sql $res
+ do_test 18.$tn.2 { lrange $::echo_module 2 end } $filter
+}
+
+do_execsql_test 18.2.0 { PRAGMA case_sensitive_like = ON }
+foreach {tn sql res filter} {
+ 2.1 "SELECT a FROM e6 WHERE b LIKE 'J%'" {3 4}
+ {xFilter {SELECT rowid, * FROM 't6'}}
+
+ 2.2 "SELECT a FROM e6 WHERE b LIKE 'j%'" {}
+ {xFilter {SELECT rowid, * FROM 't6'}}
+} {
+ set echo_module {}
+ do_execsql_test 18.$tn.1 $sql $res
+ do_test 18.$tn.2 { lrange $::echo_module 2 end } $filter
+}
+do_execsql_test 18.2.x { PRAGMA case_sensitive_like = OFF }
+
+#-------------------------------------------------------------------------
+# Test that an existing module may not be overridden.
+#
+do_test 19.1 {
+ sqlite3 db2 test.db
+ register_echo_module [sqlite3_connection_pointer db2]
+} SQLITE_OK
+do_test 19.2 {
+ register_echo_module [sqlite3_connection_pointer db2]
+} SQLITE_MISUSE
+do_test 19.3 {
+ db2 close
+} {}
+
+#-------------------------------------------------------------------------
+# Test that the bug fixed by [b0c1ba655d69] really is fixed.
+#
+do_execsql_test 20.1 {
+ CREATE TABLE t7 (a, b);
+ CREATE TABLE t8 (c, d);
+ CREATE INDEX i2 ON t7(a);
+ CREATE INDEX i3 ON t7(b);
+ CREATE INDEX i4 ON t8(c);
+ CREATE INDEX i5 ON t8(d);
+
+ CREATE VIRTUAL TABLE t7v USING echo(t7);
+ CREATE VIRTUAL TABLE t8v USING echo(t8);
+}
+
+do_test 20.2 {
+ for {set i 0} {$i < 1000} {incr i} {
+ db eval {INSERT INTO t7 VALUES($i, $i)}
+ db eval {INSERT INTO t8 VALUES($i, $i)}
+ }
+} {}
+
+do_execsql_test 20.3 {
+ SELECT a, b FROM (
+ SELECT a, b FROM t7 WHERE a=11 OR b=12
+ UNION ALL
+ SELECT c, d FROM t8 WHERE c=5 OR d=6
+ )
+ ORDER BY 1, 2;
+} {5 5 6 6 11 11 12 12}
+
+do_execsql_test 20.4 {
+ SELECT a, b FROM (
+ SELECT a, b FROM t7v WHERE a=11 OR b=12
+ UNION ALL
+ SELECT c, d FROM t8v WHERE c=5 OR d=6
+ )
+ ORDER BY 1, 2;
+} {5 5 6 6 11 11 12 12}
+
+#-------------------------------------------------------------------------
+#
+do_execsql_test 21.1 {
+ CREATE TABLE t9(a,b,c);
+ CREATE VIRTUAL TABLE t9v USING echo(t9);
+
+ INSERT INTO t9 VALUES(1,2,3);
+ INSERT INTO t9 VALUES(3,2,1);
+ INSERT INTO t9 VALUES(2,2,2);
+}
+
+do_execsql_test 21.2 {
+ SELECT * FROM t9v WHERE a<b;
+} {1 2 3}
+
+do_execsql_test 21.3 {
+ SELECT * FROM t9v WHERE a=b;
+} {2 2 2}
+
finish_test
diff --git a/lang/sql/sqlite/test/vtab6.test b/lang/sql/sqlite/test/vtab6.test
index 96e45bf5..10bf286a 100644
--- a/lang/sql/sqlite/test/vtab6.test
+++ b/lang/sql/sqlite/test/vtab6.test
@@ -561,12 +561,12 @@ do_test vtab6-11.4.1 {
catchsql {
SELECT a, b, c FROM ab NATURAL JOIN bc;
}
-} {1 {table bc: xBestIndex returned an invalid plan}}
+} {1 {table ab: xBestIndex returned an invalid plan}}
do_test vtab6-11.4.2 {
catchsql {
SELECT a, b, c FROM bc NATURAL JOIN ab;
}
-} {1 {table ab: xBestIndex returned an invalid plan}}
+} {1 {table bc: xBestIndex returned an invalid plan}}
unset ::echo_module_ignore_usable
diff --git a/lang/sql/sqlite/test/vtab7.test b/lang/sql/sqlite/test/vtab7.test
index d1b1f590..162bab5e 100644
--- a/lang/sql/sqlite/test/vtab7.test
+++ b/lang/sql/sqlite/test/vtab7.test
@@ -134,8 +134,8 @@ execsql {DROP TABLE newtab}
# Write to an attached database from xSync().
ifcapable attach {
do_test vtab7-3.1 {
- file delete -force test2.db
- file delete -force test2.db-journal
+ forcedelete test2.db
+ forcedelete test2.db-journal
execsql {
ATTACH 'test2.db' AS db2;
CREATE TABLE db2.stuff(description, shape, color);
diff --git a/lang/sql/sqlite/test/vtabC.test b/lang/sql/sqlite/test/vtabC.test
index 824d4ca2..ca78b706 100644
--- a/lang/sql/sqlite/test/vtabC.test
+++ b/lang/sql/sqlite/test/vtabC.test
@@ -31,7 +31,7 @@ ifcapable !trigger { finish_test ; return }
unset -nocomplain N
for {set N 1} {$N<=20} {incr N} {
db close
- file delete -force test.db test.db-journal
+ forcedelete test.db test.db-journal
sqlite3 db test.db
register_echo_module [sqlite3_connection_pointer db]
diff --git a/lang/sql/sqlite/test/vtabD.test b/lang/sql/sqlite/test/vtabD.test
index 509ba457..589f5189 100644
--- a/lang/sql/sqlite/test/vtabD.test
+++ b/lang/sql/sqlite/test/vtabD.test
@@ -49,17 +49,15 @@ do_test vtabD-1.5 {
do_test vtabD-1.6 {
execsql { SELECT * FROM tv1 WHERE a < 500 OR b = 810000 }
} [execsql {
- SELECT * FROM t1 WHERE a < 500
- UNION ALL
- SELECT * FROM t1 WHERE b = 810000 AND NOT (a < 500)
+ SELECT * FROM t1 WHERE a < 500;
+ SELECT * FROM t1 WHERE b = 810000 AND NOT (a < 500);
}]
do_test vtabD-1.7 {
execsql { SELECT * FROM tv1 WHERE a < 90000 OR b = 8100000000 }
} [execsql {
- SELECT * FROM t1 WHERE a < 90000
- UNION ALL
- SELECT * FROM t1 WHERE b = 8100000000 AND NOT (a < 90000)
+ SELECT * FROM t1 WHERE a < 90000;
+ SELECT * FROM t1 WHERE b = 8100000000 AND NOT (a < 90000);
}]
if {[working_64bit_int]} {
diff --git a/lang/sql/sqlite/test/vtabF.test b/lang/sql/sqlite/test/vtabF.test
new file mode 100644
index 00000000..b9341ea5
--- /dev/null
+++ b/lang/sql/sqlite/test/vtabF.test
@@ -0,0 +1,45 @@
+# 2011 Aug 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 checks to make sure IS NOT NULL constraints work on
+# virtual tables.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+ifcapable !vtab||!schema_pragmas { finish_test ; return }
+
+# Register the echo module
+register_echo_module [sqlite3_connection_pointer db]
+
+do_test vtabE-1.1 {
+ execsql {
+ CREATE TABLE t1(a, b);
+ CREATE INDEX i1 ON t1(a);
+ CREATE INDEX i2 ON t1(b);
+ INSERT INTO t1 VALUES(10,110);
+ INSERT INTO t1 VALUES(11,111);
+ INSERT INTO t1 SELECT a+2, b+2 FROM t1;
+ INSERT INTO t1 SELECT null, b+4 FROM t1;
+ INSERT INTO t1 SELECT null, b+8 FROM t1;
+ INSERT INTO t1 SELECT null, b+16 FROM t1;
+ ANALYZE;
+ CREATE VIRTUAL TABLE tv1 USING echo(t1);
+ SELECT b FROM t1 WHERE a IS NOT NULL;
+ }
+} {110 111 112 113}
+do_test vtabE-1.2 {
+ execsql {SELECT b FROM tv1 WHERE a IS NOT NULL}
+} {110 111 112 113}
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/vtab_shared.test b/lang/sql/sqlite/test/vtab_shared.test
index ce2e432f..13237a8d 100644
--- a/lang/sql/sqlite/test/vtab_shared.test
+++ b/lang/sql/sqlite/test/vtab_shared.test
@@ -116,7 +116,6 @@ do_test vtab_shared-1.10 {
} {1 {database table is locked: sqlite_master}}
do_test vtab_shared-1.11 {
-breakpoint
execsql {
CREATE VIRTUAL TABLE t2 USING echo(t0);
CREATE VIRTUAL TABLE t3 USING echo(t0);
@@ -124,23 +123,25 @@ breakpoint
execsql { SELECT * FROM t3 } db2
} {1 2 3 4 5 6}
-do_test vtab_shared-1.12.1 {
- db close
- execsql {
- SELECT * FROM t1 UNION ALL
- SELECT * FROM t2 UNION ALL
- SELECT * FROM t3
- } db2
-} {1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6}
-do_test vtab_shared-1.12.2 {
- sqlite3 db test.db
- register_echo_module [sqlite3_connection_pointer db]
- execsql {
- SELECT * FROM t1 UNION ALL
- SELECT * FROM t2 UNION ALL
- SELECT * FROM t3
- } db
-} {1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6}
+ifcapable compound {
+ do_test vtab_shared-1.12.1 {
+ db close
+ execsql {
+ SELECT * FROM t1 UNION ALL
+ SELECT * FROM t2 UNION ALL
+ SELECT * FROM t3
+ } db2
+ } {1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6}
+ do_test vtab_shared-1.12.2 {
+ sqlite3 db test.db
+ register_echo_module [sqlite3_connection_pointer db]
+ execsql {
+ SELECT * FROM t1 UNION ALL
+ SELECT * FROM t2 UNION ALL
+ SELECT * FROM t3
+ } db
+ } {1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6}
+}
# Try a rename or two.
#
diff --git a/lang/sql/sqlite/test/wal.test b/lang/sql/sqlite/test/wal.test
index 1aa70e05..3a69de54 100644
--- a/lang/sql/sqlite/test/wal.test
+++ b/lang/sql/sqlite/test/wal.test
@@ -25,7 +25,7 @@ ifcapable !wal {finish_test ; return }
proc reopen_db {} {
catch { db close }
- file delete -force test.db test.db-wal test.db-wal-summary
+ forcedelete test.db test.db-wal test.db-wal-summary
sqlite3_wal db test.db
}
@@ -211,8 +211,8 @@ do_test wal-4.4.5 {
execsql { SELECT count(*) FROM t2 }
} {1}
do_test wal-4.4.6 {
- file copy -force test.db test2.db
- file copy -force test.db-wal test2.db-wal
+ forcecopy test.db test2.db
+ forcecopy test.db-wal test2.db-wal
sqlite3 db2 test2.db
execsql { SELECT count(*) FROM t2 ; SELECT count(*) FROM t1 } db2
} {1 2}
@@ -269,8 +269,8 @@ do_test wal-4.5.5 {
execsql { SELECT count(*) FROM t2 ; SELECT count(*) FROM t1 }
} {1 2}
do_test wal-4.5.6 {
- file copy -force test.db test2.db
- file copy -force test.db-wal test2.db-wal
+ forcecopy test.db test2.db
+ forcecopy test.db-wal test2.db-wal
sqlite3 db2 test2.db
execsql { SELECT count(*) FROM t2 ; SELECT count(*) FROM t1 } db2
} {1 2}
@@ -322,7 +322,7 @@ do_test wal-5.4 {
INSERT INTO t3 VALUES('abc');
}
catchsql { INSERT INTO t3 VALUES('abc') }
-} {1 {column x is not unique}}
+} {1 {UNIQUE constraint failed: t3.x}}
do_test wal-5.5 {
execsql {
COMMIT;
@@ -334,7 +334,7 @@ db close
foreach sector {512 4096} {
sqlite3_simulate_device -sectorsize $sector
foreach pgsz {512 1024 2048 4096} {
- file delete -force test.db test.db-wal
+ forcedelete test.db test.db-wal
do_test wal-6.$sector.$pgsz.1 {
sqlite3 db test.db -vfs devsym
execsql "
@@ -357,7 +357,7 @@ foreach sector {512 4096} {
}
do_test wal-7.1 {
- file delete -force test.db test.db-wal
+ forcedelete test.db test.db-wal
sqlite3_wal db test.db
execsql {
PRAGMA page_size = 1024;
@@ -377,7 +377,7 @@ do_test wal-7.2 {
do_test wal-8.1 {
reopen_db
catch { db close }
- file delete -force test.db test.db-wal
+ forcedelete test.db test.db-wal
sqlite3 db test.db
db function blob blob
@@ -416,6 +416,7 @@ do_test wal-8.3 {
do_test wal-9.1 {
reopen_db
execsql {
+ PRAGMA cache_size=2000;
CREATE TABLE t1(x PRIMARY KEY);
INSERT INTO t1 VALUES(blob(900));
INSERT INTO t1 VALUES(blob(900));
@@ -435,9 +436,9 @@ do_test wal-9.2 {
} {ok}
do_test wal-9.3 {
- file delete -force test2.db test2.db-wal
- file copy test.db test2.db
- file copy test.db-wal test2.db-wal
+ forcedelete test2.db test2.db-wal
+ copy_file test.db test2.db
+ copy_file test.db-wal test2.db-wal
sqlite3_wal db3 test2.db
execsql {PRAGMA integrity_check } db3
} {ok}
@@ -545,7 +546,7 @@ do_multiclient_test tn {
} {1 2 3 4 5 6 7 8 9 10}
do_test wal-10.$tn.12 {
catchsql { PRAGMA wal_checkpoint }
- } {0 {0 13 13}} ;# Reader no longer block checkpoints
+ } {0 {0 7 7}} ;# Reader no longer block checkpoints
do_test wal-10.$tn.13 {
execsql { INSERT INTO t1 VALUES(11, 12) }
sql2 {SELECT * FROM t1}
@@ -555,7 +556,7 @@ do_multiclient_test tn {
#
do_test wal-10.$tn.14 {
catchsql { PRAGMA wal_checkpoint }
- } {0 {0 15 13}}
+ } {0 {0 8 7}}
# The following series of test cases used to verify another blocking
# case in WAL - a case which no longer blocks.
@@ -565,10 +566,10 @@ do_multiclient_test tn {
} {1 2 3 4 5 6 7 8 9 10 11 12}
do_test wal-10.$tn.16 {
catchsql { PRAGMA wal_checkpoint }
- } {0 {0 15 15}}
+ } {0 {0 8 8}}
do_test wal-10.$tn.17 {
execsql { PRAGMA wal_checkpoint }
- } {0 15 15}
+ } {0 8 8}
do_test wal-10.$tn.18 {
sql3 { BEGIN; SELECT * FROM t1 }
} {1 2 3 4 5 6 7 8 9 10 11 12}
@@ -591,13 +592,13 @@ do_multiclient_test tn {
#
do_test wal-10.$tn.23 {
execsql { PRAGMA wal_checkpoint }
- } {0 17 17}
+ } {0 9 9}
do_test wal-10.$tn.24 {
sql2 { BEGIN; SELECT * FROM t1; }
} {1 2 3 4 5 6 7 8 9 10 11 12 13 14}
do_test wal-10.$tn.25 {
execsql { PRAGMA wal_checkpoint }
- } {0 17 17}
+ } {0 9 9}
do_test wal-10.$tn.26 {
catchsql { INSERT INTO t1 VALUES(15, 16) }
} {0 {}}
@@ -614,11 +615,11 @@ do_multiclient_test tn {
do_test wal-10.$tn.29 {
execsql { INSERT INTO t1 VALUES(19, 20) }
catchsql { PRAGMA wal_checkpoint }
- } {0 {0 6 0}}
+ } {0 {0 3 0}}
do_test wal-10.$tn.30 {
code3 { sqlite3_finalize $::STMT }
execsql { PRAGMA wal_checkpoint }
- } {0 6 0}
+ } {0 3 0}
# At one point, if a reader failed to upgrade to a writer because it
# was reading an old snapshot, the write-locks were not being released.
@@ -657,7 +658,7 @@ do_multiclient_test tn {
} {a b c d}
do_test wal-10.$tn.36 {
catchsql { PRAGMA wal_checkpoint }
- } {0 {0 16 16}}
+ } {0 {0 8 8}}
do_test wal-10.$tn.36 {
sql3 { INSERT INTO t1 VALUES('e', 'f') }
sql2 { SELECT * FROM t1 }
@@ -665,7 +666,7 @@ do_multiclient_test tn {
do_test wal-10.$tn.37 {
sql2 COMMIT
execsql { PRAGMA wal_checkpoint }
- } {0 18 18}
+ } {0 9 9}
}
#-------------------------------------------------------------------------
@@ -726,6 +727,9 @@ do_test wal-11.9 {
list [expr [file size test.db]/1024] [log_deleted test.db-wal]
} {37 1}
sqlite3_wal db test.db
+set nWal 39
+if {[permutation]!="mmap"} {set nWal 37}
+ifcapable !mmap {set nWal 37}
do_test wal-11.10 {
execsql {
PRAGMA cache_size = 10;
@@ -734,7 +738,7 @@ do_test wal-11.10 {
SELECT count(*) FROM t1;
}
list [expr [file size test.db]/1024] [file size test.db-wal]
-} [list 37 [wal_file_size 37 1024]]
+} [list 37 [wal_file_size $nWal 1024]]
do_test wal-11.11 {
execsql {
SELECT count(*) FROM t1;
@@ -744,7 +748,7 @@ do_test wal-11.11 {
} {32 16}
do_test wal-11.12 {
list [expr [file size test.db]/1024] [file size test.db-wal]
-} [list 37 [wal_file_size 37 1024]]
+} [list 37 [wal_file_size $nWal 1024]]
do_test wal-11.13 {
execsql {
INSERT INTO t1 VALUES( blob(900) );
@@ -754,7 +758,7 @@ do_test wal-11.13 {
} {17 ok}
do_test wal-11.14 {
list [expr [file size test.db]/1024] [file size test.db-wal]
-} [list 37 [wal_file_size 37 1024]]
+} [list 37 [wal_file_size $nWal 1024]]
#-------------------------------------------------------------------------
@@ -786,8 +790,8 @@ do_test wal-12.3 {
list [expr [file size test.db]/1024] [expr [file size test.db-wal]/1044]
} {3 2}
do_test wal-12.4 {
- file copy -force test.db test2.db
- file copy -force test.db-wal test2.db-wal
+ forcecopy test.db test2.db
+ forcecopy test.db-wal test2.db-wal
sqlite3_wal db2 test2.db
execsql { SELECT * FROM t2 } db2
} {B 1}
@@ -804,8 +808,8 @@ do_test wal-12.5 {
execsql { SELECT * FROM t2 }
} {B 2}
do_test wal-12.6 {
- file copy -force test.db test2.db
- file copy -force test.db-wal test2.db-wal
+ forcecopy test.db test2.db
+ forcecopy test.db-wal test2.db-wal
sqlite3_wal db2 test2.db
execsql { SELECT * FROM t2 } db2
} {B 2}
@@ -848,7 +852,6 @@ do_test wal-13.1.2 {
sqlite3 db test.db
execsql { SELECT * FROM t2 }
} {B 2}
-breakpoint
do_test wal-13.1.3 {
db close
file exists test.db-wal
@@ -909,7 +912,7 @@ do_multiclient_test tn {
catch { db close }
catch { db2 close }
catch { db3 close }
-file delete -force test.db test.db-wal
+forcedelete test.db test.db-wal
sqlite3 db test.db
sqlite3 db2 test.db
do_test wal-14 {
@@ -947,7 +950,7 @@ catch { db2 close }
# The following block of tests - wal-15.* - focus on testing the
# implementation of the sqlite3_wal_checkpoint() interface.
#
-file delete -force test.db test.db-wal
+forcedelete test.db test.db-wal
sqlite3 db test.db
do_test wal-15.1 {
execsql {
@@ -1039,12 +1042,12 @@ foreach {tn ckpt_cmd ckpt_res ckpt_main ckpt_aux} {
5 {sqlite3_wal_checkpoint db aux} SQLITE_OK 0 1
6 {sqlite3_wal_checkpoint db temp} SQLITE_OK 0 0
7 {db eval "PRAGMA main.wal_checkpoint"} {0 10 10} 1 0
- 8 {db eval "PRAGMA aux.wal_checkpoint"} {0 16 16} 0 1
+ 8 {db eval "PRAGMA aux.wal_checkpoint"} {0 13 13} 0 1
9 {db eval "PRAGMA temp.wal_checkpoint"} {0 -1 -1} 0 0
} {
do_test wal-16.$tn.1 {
- file delete -force test2.db test2.db-wal test2.db-journal
- file delete -force test.db test.db-wal test.db-journal
+ forcedelete test2.db test2.db-wal test2.db-journal
+ forcedelete test.db test.db-wal test.db-journal
sqlite3 db test.db
execsql {
@@ -1053,7 +1056,8 @@ foreach {tn ckpt_cmd ckpt_res ckpt_main ckpt_aux} {
PRAGMA aux.auto_vacuum = 0;
PRAGMA main.journal_mode = WAL;
PRAGMA aux.journal_mode = WAL;
- PRAGMA synchronous = NORMAL;
+ PRAGMA main.synchronous = NORMAL;
+ PRAGMA aux.synchronous = NORMAL;
}
} {wal wal}
@@ -1071,7 +1075,7 @@ foreach {tn ckpt_cmd ckpt_res ckpt_main ckpt_aux} {
} [list [expr 1*1024] [wal_file_size 10 1024]]
do_test wal-16.$tn.3 {
list [file size test2.db] [file size test2.db-wal]
- } [list [expr 1*1024] [wal_file_size 16 1024]]
+ } [list [expr 1*1024] [wal_file_size 13 1024]]
do_test wal-16.$tn.4 [list eval $ckpt_cmd] $ckpt_res
@@ -1081,7 +1085,7 @@ foreach {tn ckpt_cmd ckpt_res ckpt_main ckpt_aux} {
do_test wal-16.$tn.6 {
list [file size test2.db] [file size test2.db-wal]
- } [list [expr ($ckpt_aux ? 7 : 1)*1024] [wal_file_size 16 1024]]
+ } [list [expr ($ckpt_aux ? 7 : 1)*1024] [wal_file_size 13 1024]]
catch { db close }
}
@@ -1116,7 +1120,7 @@ foreach {tn sectorsize logsize} "
6 4096 [wal_file_size 176 512]
7 8192 [wal_file_size 184 512]
" {
- file delete -force test.db test.db-wal test.db-journal
+ forcedelete test.db test.db-wal test.db-journal
sqlite3_simulate_device -sectorsize $sectorsize
sqlite3 db test.db -vfs devsym
@@ -1124,6 +1128,7 @@ foreach {tn sectorsize logsize} "
execsql {
PRAGMA auto_vacuum = 0;
PRAGMA page_size = 512;
+ PRAGMA cache_size = -2000;
PRAGMA journal_mode = WAL;
PRAGMA synchronous = FULL;
}
@@ -1160,7 +1165,7 @@ sqlite3_test_control_pending_byte $old_pending_byte
# wal-18.2.* When the page-size field that occurs at the start of a log
# file is a power of 2 greater than 16384 or smaller than 512.
#
-file delete -force test.db test.db-wal test.db-journal
+forcedelete test.db test.db-wal test.db-journal
do_test wal-18.0 {
sqlite3 db test.db
execsql {
@@ -1178,8 +1183,8 @@ do_test wal-18.0 {
INSERT INTO t1 VALUES(5, 6); -- frames 5 and 6
}
- file copy -force test.db testX.db
- file copy -force test.db-wal testX.db-wal
+ forcecopy test.db testX.db
+ forcecopy test.db-wal testX.db-wal
db close
list [file size testX.db] [file size testX.db-wal]
} [list [expr 3*1024] [wal_file_size 6 1024]]
@@ -1195,8 +1200,8 @@ foreach {nFrame result} {
6 {0 0 1 2 3 4 5 6}
} {
do_test wal-18.1.$nFrame {
- file copy -force testX.db test.db
- file copy -force testX.db-wal test.db-wal
+ forcecopy testX.db test.db
+ forcecopy testX.db-wal test.db-wal
hexio_write test.db-wal [expr 24 + $nFrame*(24+1024) + 20] 00000000
@@ -1220,10 +1225,11 @@ proc logcksum {ckv1 ckv2 blob} {
upvar $ckv1 c1
upvar $ckv2 c2
- set scanpattern I*
- if {$::tcl_platform(byteOrder) eq "littleEndian"} {
- set scanpattern i*
- }
+ # Since the magic number at the start of the -wal file header is
+ # 931071618 that indicates that the content should always be read as
+ # little-endian.
+ #
+ set scanpattern i*
binary scan $blob $scanpattern values
foreach {v1 v2} $values {
@@ -1232,7 +1238,7 @@ proc logcksum {ckv1 ckv2 blob} {
}
}
-file copy -force test.db testX.db
+forcecopy test.db testX.db
foreach {tn pgsz works} {
1 128 0
2 256 0
@@ -1253,8 +1259,8 @@ foreach {tn pgsz works} {
}
for {set pg 1} {$pg <= 3} {incr pg} {
- file copy -force testX.db test.db
- file delete -force test.db-wal
+ forcecopy testX.db test.db
+ forcedelete test.db-wal
# Check that the database now exists and consists of three pages. And
# that there is no associated wal file.
@@ -1321,7 +1327,7 @@ foreach {tn pgsz works} {
# snapshot.
#
do_test wal-19.1 {
- file delete -force test.db test.db-wal test.db-journal
+ forcedelete test.db test.db-wal test.db-journal
sqlite3 db test.db
sqlite3 db2 test.db
execsql {
@@ -1370,7 +1376,7 @@ do_test wal-19.4 {
#
do_test wal-20.1 {
catch {db close}
- file delete -force test.db test.db-wal test.db-journal
+ forcedelete test.db test.db-wal test.db-journal
sqlite3 db test.db
execsql {
PRAGMA journal_mode = WAL;
@@ -1474,9 +1480,13 @@ foreach pgsz {512 1024 2048 4096 8192 16384 32768 65536} {
# Test that when 1 or more pages are recovered from a WAL file,
# sqlite3_log() is invoked to report this to the user.
#
-set walfile [file nativename [file join [pwd] test.db-wal]]
+ifcapable curdir {
+ set walfile [file nativename [file join [get_pwd] test.db-wal]]
+} else {
+ set walfile test.db-wal
+}
catch {db close}
-file delete -force test.db
+forcedelete test.db
do_test wal-23.1 {
faultsim_delete_and_reopen
execsql {
@@ -1501,10 +1511,10 @@ do_test wal-23.3 {
faultsim_restore_and_reopen
execsql { SELECT * FROM t1 }
} {1 2 3 4}
-set nPage [expr 2+$AUTOVACUUM]
do_test wal-23.4 {
set ::log
-} [list SQLITE_OK "Recovered $nPage frames from WAL file $walfile"]
+} [list SQLITE_NOTICE_RECOVER_WAL \
+ "recovered 2 frames from WAL file $walfile"]
ifcapable autovacuum {
@@ -1550,9 +1560,13 @@ ifcapable autovacuum {
}
file size test.db
} [expr 3 * 1024]
+
+ # WAL file now contains a single frame - the new root page for table t1.
+ # It would be two frames (the new root page and a padding frame) if the
+ # ZERO_DAMAGE flag were not set.
do_test 24.5 {
file size test.db-wal
- } 2128
+ } [wal_file_size 1 1024]
}
db close
diff --git a/lang/sql/sqlite/test/wal2.test b/lang/sql/sqlite/test/wal2.test
index 82234330..b331d5ed 100644
--- a/lang/sql/sqlite/test/wal2.test
+++ b/lang/sql/sqlite/test/wal2.test
@@ -23,6 +23,18 @@ set testprefix wal2
ifcapable !wal {finish_test ; return }
+set sqlite_sync_count 0
+proc cond_incr_sync_count {adj} {
+ global sqlite_sync_count
+ if {$::tcl_platform(platform) == "windows"} {
+ incr sqlite_sync_count $adj
+ } {
+ ifcapable !dirsync {
+ incr sqlite_sync_count $adj
+ }
+ }
+}
+
proc set_tvfs_hdr {file args} {
# Set $nHdr to the number of bytes in the wal-index header:
@@ -34,6 +46,7 @@ proc set_tvfs_hdr {file args} {
}
set blob [tvfs shm $file]
+ if {$::tcl_platform(byteOrder)=="bigEndian"} {set fmt I} {set fmt i}
if {[llength $args]} {
set ia [lindex $args 0]
@@ -42,11 +55,11 @@ proc set_tvfs_hdr {file args} {
set ib [lindex $args 1]
}
binary scan $blob a[expr $nHdr*2]a* dummy tail
- set blob [binary format i${nInt}i${nInt}a* $ia $ib $tail]
+ set blob [binary format ${fmt}${nInt}${fmt}${nInt}a* $ia $ib $tail]
tvfs shm $file $blob
}
- binary scan $blob i${nInt} ints
+ binary scan $blob ${fmt}${nInt} ints
return $ints
}
@@ -73,7 +86,7 @@ proc incr_tvfs_hdr {file idx incrval} {
#
# 2. Attempt to read the database using the reader. Before the reader
# has a chance to snapshot the wal-index header, increment one
-# of the the integer fields (so that the reader ends up with a corrupted
+# of the integer fields (so that the reader ends up with a corrupted
# header).
#
# 3. Check that the reader recovers the wal-index and reads the correct
@@ -113,9 +126,11 @@ set RECOVER [list \
{1 7 unlock exclusive} {0 1 unlock exclusive} \
]
set READ [list \
- {4 1 lock exclusive} {4 1 unlock exclusive} \
{4 1 lock shared} {4 1 unlock shared} \
]
+set INITSLOT [list \
+ {4 1 lock exclusive} {4 1 unlock exclusive} \
+]
foreach {tn iInsert res wal_index_hdr_mod wal_locks} "
2 5 {5 15} 0 {$RECOVER $READ}
@@ -128,7 +143,7 @@ foreach {tn iInsert res wal_index_hdr_mod wal_locks} "
9 12 {12 78} 7 {$RECOVER $READ}
10 13 {13 91} 8 {$RECOVER $READ}
11 14 {14 105} 9 {$RECOVER $READ}
- 12 15 {15 120} -1 {$READ}
+ 12 15 {15 120} -1 {$INITSLOT $READ}
" {
do_test wal2-1.$tn.1 {
@@ -152,7 +167,7 @@ foreach {tn iInsert res wal_index_hdr_mod wal_locks} "
db close
db2 close
tvfs delete
-file delete -force test.db test.db-wal test.db-journal
+forcedelete test.db test.db-wal test.db-journal
#-------------------------------------------------------------------------
# This test case is very similar to the previous one, except, after
@@ -259,7 +274,7 @@ foreach {tn iInsert res0 res1 wal_index_hdr_mod} {
db close
db2 close
tvfs delete
-file delete -force test.db test.db-wal test.db-journal
+forcedelete test.db test.db-wal test.db-journal
if 0 {
@@ -332,7 +347,7 @@ do_test wal2-3.5 {
} {0 0}
db close
tvfs delete
-file delete -force test.db test.db-wal test.db-journal
+forcedelete test.db test.db-wal test.db-journal
}
@@ -349,7 +364,9 @@ do_test wal2-4.1 {
INSERT INTO data VALUES('need xShmOpen to see this');
PRAGMA wal_checkpoint;
}
-} {wal 0 5 5}
+ # Three pages in the WAL file at this point: One copy of page 1 and two
+ # of the root page for table "data".
+} {wal 0 3 3}
do_test wal2-4.2 {
db close
testvfs tvfs -noshm 1
@@ -429,7 +446,7 @@ tvfs delete
# connection silently remains in exclusive mode.
#
do_test wal2-6.1.1 {
- file delete -force test.db test.db-wal test.db-journal
+ forcedelete test.db test.db-wal test.db-journal
sqlite3 db test.db
execsql {
Pragma Journal_Mode = Wal;
@@ -472,7 +489,7 @@ do_test wal2-6.1.6 {
db close
do_test wal2-6.2.1 {
- file delete -force test.db test.db-wal test.db-journal
+ forcedelete test.db test.db-wal test.db-journal
sqlite3 db test.db
execsql {
Pragma Locking_Mode = Exclusive;
@@ -540,7 +557,7 @@ do_test wal2-6.2.9 {
db close
do_test wal2-6.3.1 {
- file delete -force test.db test.db-wal test.db-journal
+ forcedelete test.db test.db-wal test.db-journal
sqlite3 db test.db
execsql {
PRAGMA journal_mode = WAL;
@@ -585,7 +602,7 @@ db close
# as expected when a WAL database is used with locking_mode=exclusive.
#
do_test wal2-6.4.1 {
- file delete -force test.db test.db-wal test.db-journal
+ forcedelete test.db test.db-wal test.db-journal
proc tvfs_cb {method args} {
set ::shm_file [lindex $args 0]
if {$method == "xShmLock"} { lappend ::locks [lindex $args 2] }
@@ -594,6 +611,7 @@ do_test wal2-6.4.1 {
testvfs tvfs
tvfs script tvfs_cb
sqlite3 db test.db -vfs tvfs
+ set {} {}
} {}
set RECOVERY {
@@ -717,7 +735,7 @@ do_test wal2-6.5.1 {
INSERT INTO t2 VALUES('I', 'II');
PRAGMA journal_mode;
}
-} {wal exclusive 0 3 3 wal}
+} {wal exclusive 0 2 2 wal}
do_test wal2-6.5.2 {
execsql {
PRAGMA locking_mode = normal;
@@ -728,7 +746,7 @@ do_test wal2-6.5.2 {
} {normal exclusive I II III IV}
do_test wal2-6.5.3 {
execsql { PRAGMA wal_checkpoint }
-} {0 4 4}
+} {0 2 2}
db close
proc lock_control {method filename handle spec} {
@@ -780,7 +798,7 @@ T delete
# Test a theory about the checksum algorithm. Theory was false and this
# test did not provoke a bug.
#
-file delete -force test.db test.db-wal test.db-journal
+forcedelete test.db test.db-wal test.db-journal
do_test wal2-7.1.1 {
sqlite3 db test.db
execsql {
@@ -791,8 +809,8 @@ do_test wal2-7.1.1 {
file size test.db
} {4096}
do_test wal2-7.1.2 {
- file copy -force test.db test2.db
- file copy -force test.db-wal test2.db-wal
+ forcecopy test.db test2.db
+ forcecopy test.db-wal test2.db-wal
hexio_write test2.db-wal 48 FF
} {1}
do_test wal2-7.1.3 {
@@ -802,7 +820,7 @@ do_test wal2-7.1.3 {
} {}
db close
db2 close
-file delete -force test.db test.db-wal test.db-journal
+forcedelete test.db test.db-wal test.db-journal
do_test wal2-8.1.2 {
sqlite3 db test.db
execsql {
@@ -858,7 +876,7 @@ testvfs tvfs
tvfs script get_name
tvfs filter xShmOpen
-file delete -force test.db test.db-wal test.db-journal
+forcedelete test.db test.db-wal test.db-journal
do_test wal2-9.1 {
sqlite3 db test.db -vfs tvfs
execsql {
@@ -1027,7 +1045,10 @@ tvfs delete
#
if {$::tcl_platform(platform) == "unix"} {
faultsim_delete_and_reopen
- set umask [exec /bin/sh -c umask]
+ # Changed on 2012-02-13: umask is deliberately ignored for -wal files.
+ #set umask [exec /bin/sh -c umask]
+ set umask 0
+
do_test wal2-12.1 {
sqlite3 db test.db
@@ -1163,14 +1184,15 @@ if {$::tcl_platform(platform) == "unix"} {
# Test that "PRAGMA checkpoint_fullsync" appears to be working.
#
foreach {tn sql reslist} {
- 1 { } {8 0 3 0 5 0}
- 2 { PRAGMA checkpoint_fullfsync = 1 } {8 4 3 2 5 2}
- 3 { PRAGMA checkpoint_fullfsync = 0 } {8 0 3 0 5 0}
+ 1 { } {10 0 4 0 6 0}
+ 2 { PRAGMA checkpoint_fullfsync = 1 } {10 4 4 2 6 2}
+ 3 { PRAGMA checkpoint_fullfsync = 0 } {10 0 4 0 6 0}
} {
faultsim_delete_and_reopen
execsql {PRAGMA auto_vacuum = 0}
execsql $sql
+ do_execsql_test wal2-14.$tn.0 { PRAGMA page_size = 4096 } {}
do_execsql_test wal2-14.$tn.1 { PRAGMA journal_mode = WAL } {wal}
set sqlite_sync_count 0
@@ -1179,16 +1201,17 @@ foreach {tn sql reslist} {
do_execsql_test wal2-14.$tn.2 {
PRAGMA wal_autocheckpoint = 10;
CREATE TABLE t1(a, b); -- 2 wal syncs
- INSERT INTO t1 VALUES(1, 2); -- 1 wal sync
+ INSERT INTO t1 VALUES(1, 2); -- 2 wal sync
PRAGMA wal_checkpoint; -- 1 wal sync, 1 db sync
BEGIN;
INSERT INTO t1 VALUES(3, 4);
INSERT INTO t1 VALUES(5, 6);
- COMMIT; -- 1 wal sync
+ COMMIT; -- 2 wal sync
PRAGMA wal_checkpoint; -- 1 wal sync, 1 db sync
- } {10 0 5 5 0 2 2}
+ } {10 0 3 3 0 1 1}
do_test wal2-14.$tn.3 {
+ cond_incr_sync_count 1
list $sqlite_sync_count $sqlite_fullsync_count
} [lrange $reslist 0 1]
@@ -1219,22 +1242,22 @@ catch { db close }
# PRAGMA fullfsync
# PRAGMA synchronous
#
-foreach {tn settings commit_sync ckpt_sync} {
- 1 {0 0 off} {0 0} {0 0}
- 2 {0 0 normal} {0 0} {2 0}
- 3 {0 0 full} {1 0} {2 0}
-
- 4 {0 1 off} {0 0} {0 0}
- 5 {0 1 normal} {0 0} {0 2}
- 6 {0 1 full} {0 1} {0 2}
-
- 7 {1 0 off} {0 0} {0 0}
- 8 {1 0 normal} {0 0} {0 2}
- 9 {1 0 full} {1 0} {0 2}
-
- 10 {1 1 off} {0 0} {0 0}
- 11 {1 1 normal} {0 0} {0 2}
- 12 {1 1 full} {0 1} {0 2}
+foreach {tn settings restart_sync commit_sync ckpt_sync} {
+ 1 {0 0 off} {0 0} {0 0} {0 0}
+ 2 {0 0 normal} {1 0} {0 0} {2 0}
+ 3 {0 0 full} {2 0} {1 0} {2 0}
+
+ 4 {0 1 off} {0 0} {0 0} {0 0}
+ 5 {0 1 normal} {0 1} {0 0} {0 2}
+ 6 {0 1 full} {0 2} {0 1} {0 2}
+
+ 7 {1 0 off} {0 0} {0 0} {0 0}
+ 8 {1 0 normal} {1 0} {0 0} {0 2}
+ 9 {1 0 full} {2 0} {1 0} {0 2}
+
+ 10 {1 1 off} {0 0} {0 0} {0 0}
+ 11 {1 1 normal} {0 1} {0 0} {0 2}
+ 12 {1 1 full} {0 2} {0 1} {0 2}
} {
forcedelete test.db
@@ -1247,30 +1270,39 @@ foreach {tn settings commit_sync ckpt_sync} {
sqlite3 db test.db
do_execsql_test 15.$tn.1 "
+ PRAGMA page_size = 4096;
CREATE TABLE t1(x);
+ PRAGMA wal_autocheckpoint = OFF;
PRAGMA journal_mode = WAL;
PRAGMA checkpoint_fullfsync = [lindex $settings 0];
PRAGMA fullfsync = [lindex $settings 1];
PRAGMA synchronous = [lindex $settings 2];
- " {wal}
+ " {0 wal}
do_test 15.$tn.2 {
set sync(normal) 0
set sync(full) 0
execsql { INSERT INTO t1 VALUES('abc') }
list $::sync(normal) $::sync(full)
- } $commit_sync
+ } $restart_sync
do_test 15.$tn.3 {
set sync(normal) 0
set sync(full) 0
- execsql { INSERT INTO t1 VALUES('def') }
+ execsql { INSERT INTO t1 VALUES('abc') }
list $::sync(normal) $::sync(full)
} $commit_sync
do_test 15.$tn.4 {
set sync(normal) 0
set sync(full) 0
+ execsql { INSERT INTO t1 VALUES('def') }
+ list $::sync(normal) $::sync(full)
+ } $commit_sync
+
+ do_test 15.$tn.5 {
+ set sync(normal) 0
+ set sync(full) 0
execsql { PRAGMA wal_checkpoint }
list $::sync(normal) $::sync(full)
} $ckpt_sync
diff --git a/lang/sql/sqlite/test/wal3.test b/lang/sql/sqlite/test/wal3.test
index bd296154..18e6075a 100644
--- a/lang/sql/sqlite/test/wal3.test
+++ b/lang/sql/sqlite/test/wal3.test
@@ -94,9 +94,9 @@ for {set i 1} {$i < 50} {incr i} {
# Check that the file-system in its current state can be recovered.
#
- file copy -force test.db test2.db
- file copy -force test.db-wal test2.db-wal
- file delete -force test2.db-journal
+ forcecopy test.db test2.db
+ forcecopy test.db-wal test2.db-wal
+ forcedelete test2.db-journal
sqlite3 db2 test2.db
do_test wal3-1.$i.5 {
execsql { SELECT count(*) FROM t1 } db2
@@ -208,7 +208,7 @@ foreach {tn syncmode synccount} {
lappend ::syncs [file tail $filename] $flags
}
do_test wal3-3.$tn {
- file delete -force test.db test.db-wal test.db-journal
+ forcedelete test.db test.db-wal test.db-journal
testvfs T
T filter {}
@@ -217,6 +217,7 @@ foreach {tn syncmode synccount} {
execsql "PRAGMA synchronous = $syncmode"
execsql { PRAGMA journal_mode = WAL }
+ execsql { CREATE TABLE filler(a,b,c); }
set ::syncs [list]
T filter xSync
@@ -411,7 +412,7 @@ T delete
catch {db close}
testvfs T -default 1
do_test wal3-6.1.1 {
- file delete -force test.db test.db-journal test.db wal
+ forcedelete test.db test.db-journal test.db wal
sqlite3 db test.db
execsql { PRAGMA auto_vacuum = off }
execsql { PRAGMA journal_mode = WAL }
@@ -428,7 +429,7 @@ do_test wal3-6.1.2 {
} {o t t f}
do_test wal3-6.1.3 {
execsql { PRAGMA wal_checkpoint } db2
-} {0 7 7}
+} {0 4 4}
# At this point the log file has been fully checkpointed. However,
# connection [db3] holds a lock that prevents the log from being wrapped.
@@ -492,7 +493,7 @@ db2 close
db close
do_test wal3-6.2.1 {
- file delete -force test.db test.db-journal test.db wal
+ forcedelete test.db test.db-journal test.db wal
sqlite3 db test.db
sqlite3 db2 test.db
execsql { PRAGMA auto_vacuum = off }
@@ -517,7 +518,7 @@ proc lock_callback {method file handle spec} {
}
do_test wal3-6.2.2 {
execsql { PRAGMA wal_checkpoint }
-} {0 7 7}
+} {0 4 4}
do_test wal3-6.2.3 {
set ::R
} {h h l b}
@@ -558,7 +559,7 @@ T delete
catch {db close}
testvfs T -default 1
do_test wal3-7.1.1 {
- file delete -force test.db test.db-journal test.db wal
+ forcedelete test.db test.db-journal test.db wal
sqlite3 db test.db
execsql {
PRAGMA journal_mode = WAL;
@@ -615,7 +616,7 @@ T delete
#-------------------------------------------------------------------------
#
do_test wal3-8.1 {
- file delete -force test.db test.db-journal test.db wal
+ forcedelete test.db test.db-journal test.db wal
sqlite3 db test.db
sqlite3 db2 test.db
execsql {
@@ -627,7 +628,7 @@ do_test wal3-8.1 {
INSERT INTO b VALUES('Markazi');
PRAGMA wal_checkpoint;
}
-} {wal 0 9 9}
+} {wal 0 5 5}
do_test wal3-8.2 {
execsql { SELECT * FROM b }
} {Tehran Qom Markazi}
@@ -654,7 +655,7 @@ T filter xShmLock
T script lock_callback
proc lock_callback {method file handle spec} {
- if {$spec == "4 1 unlock exclusive"} {
+ if {$spec == "1 7 unlock exclusive"} {
T filter {}
set ::r [catchsql { SELECT * FROM b } db2]
}
@@ -707,9 +708,9 @@ T delete
# and continues.
#
set nConn 50
-if { [string match *BSD $tcl_platform(os)] } { set nConn 35 }
+if { [string match *BSD $tcl_platform(os)] } { set nConn 25 }
do_test wal3-9.0 {
- file delete -force test.db test.db-journal test.db wal
+ forcedelete test.db test.db-journal test.db wal
sqlite3 db test.db
execsql {
PRAGMA page_size = 1024;
@@ -784,4 +785,3 @@ do_multiclient_test tn {
}
finish_test
-
diff --git a/lang/sql/sqlite/test/wal4.test b/lang/sql/sqlite/test/wal4.test
index 22ccfea7..c7a43813 100644
--- a/lang/sql/sqlite/test/wal4.test
+++ b/lang/sql/sqlite/test/wal4.test
@@ -31,7 +31,7 @@ do_test wal4-1.2 {
# Save a copy of the file-system containing the wal and wal-index files
# only (no database file).
faultsim_save_and_close
- file delete -force sv_test.db
+ forcedelete sv_test.db
} {}
do_test wal4-1.3 {
diff --git a/lang/sql/sqlite/test/wal5.test b/lang/sql/sqlite/test/wal5.test
index ad6bcfc7..68750f14 100644
--- a/lang/sql/sqlite/test/wal5.test
+++ b/lang/sql/sqlite/test/wal5.test
@@ -197,9 +197,9 @@ foreach {testprefix do_wal_checkpoint} {
INSERT INTO t2 VALUES(1, 2);
}
} {}
- do_test 2.2.$tn.2 { file_page_counts } {1 5 1 5}
- do_test 2.1.$tn.3 { code1 { do_wal_checkpoint db } } {0 5 5}
- do_test 2.1.$tn.4 { file_page_counts } {2 5 2 5}
+ do_test 2.2.$tn.2 { file_page_counts } {1 3 1 3}
+ do_test 2.1.$tn.3 { code1 { do_wal_checkpoint db } } {0 3 3}
+ do_test 2.1.$tn.4 { file_page_counts } {2 3 2 3}
}
do_multiclient_test tn {
@@ -213,10 +213,10 @@ foreach {testprefix do_wal_checkpoint} {
INSERT INTO t2 VALUES(3, 4);
}
} {}
- do_test 2.2.$tn.2 { file_page_counts } {1 5 1 7}
+ do_test 2.2.$tn.2 { file_page_counts } {1 3 1 4}
do_test 2.2.$tn.3 { sql2 { BEGIN; SELECT * FROM t1 } } {1 2}
- do_test 2.2.$tn.4 { code1 { do_wal_checkpoint db -mode restart } } {1 5 5}
- do_test 2.2.$tn.5 { file_page_counts } {2 5 2 7}
+ do_test 2.2.$tn.4 { code1 { do_wal_checkpoint db -mode restart } } {1 3 3}
+ do_test 2.2.$tn.5 { file_page_counts } {2 3 2 4}
}
do_multiclient_test tn {
@@ -229,13 +229,22 @@ foreach {testprefix do_wal_checkpoint} {
INSERT INTO t2 VALUES(1, 2);
}
} {}
- do_test 2.3.$tn.2 { file_page_counts } {1 5 1 5}
+ do_test 2.3.$tn.2 { file_page_counts } {1 3 1 3}
do_test 2.3.$tn.3 { sql2 { BEGIN; SELECT * FROM t1 } } {1 2}
do_test 2.3.$tn.4 { sql1 { INSERT INTO t1 VALUES(3, 4) } } {}
do_test 2.3.$tn.5 { sql1 { INSERT INTO t2 VALUES(3, 4) } } {}
- do_test 2.3.$tn.6 { file_page_counts } {1 7 1 7}
- do_test 2.3.$tn.7 { code1 { do_wal_checkpoint db -mode full } } {1 7 5}
- do_test 2.3.$tn.8 { file_page_counts } {1 7 2 7}
+ do_test 2.3.$tn.6 { file_page_counts } {1 4 1 4}
+ do_test 2.3.$tn.7 { code1 { do_wal_checkpoint db -mode full } } {1 4 3}
+
+ # The checkpoint above only writes page 1 of the db file. The other
+ # page (page 2) is locked by the read-transaction opened by the
+ # [sql2] commmand above. So normally, the db is 1 page in size here.
+ # However, in mmap() mode, the db is pre-allocated to 2 pages at the
+ # start of the checkpoint, even though page 2 cannot be written.
+ set nDb 2
+ if {[permutation]!="mmap"} {set nDb 1}
+ ifcapable !mmap {set nDb 1}
+ do_test 2.3.$tn.8 { file_page_counts } [list $nDb 4 2 4]
}
# Check that checkpoints block on the correct locks. And respond correctly
@@ -256,18 +265,18 @@ foreach {testprefix do_wal_checkpoint} {
# processes holding all three types of locks.
#
foreach {tn1 checkpoint busy_on ckpt_expected expected} {
- 1 PASSIVE - {0 5 5} -
- 2 TYPO - {0 5 5} -
+ 1 PASSIVE - {0 3 3} -
+ 2 TYPO - {0 3 3} -
- 3 FULL - {0 7 7} 2
- 4 FULL 1 {1 5 5} 1
- 5 FULL 2 {1 7 5} 2
- 6 FULL 3 {0 7 7} 2
+ 3 FULL - {0 4 4} 2
+ 4 FULL 1 {1 3 3} 1
+ 5 FULL 2 {1 4 3} 2
+ 6 FULL 3 {0 4 4} 2
- 7 RESTART - {0 7 7} 3
- 8 RESTART 1 {1 5 5} 1
- 9 RESTART 2 {1 7 5} 2
- 10 RESTART 3 {1 7 7} 3
+ 7 RESTART - {0 4 4} 3
+ 8 RESTART 1 {1 3 3} 1
+ 9 RESTART 2 {1 4 3} 2
+ 10 RESTART 3 {1 4 4} 3
} {
do_multiclient_test tn {
@@ -343,4 +352,3 @@ foreach {testprefix do_wal_checkpoint} {
finish_test
-
diff --git a/lang/sql/sqlite/test/wal6.test b/lang/sql/sqlite/test/wal6.test
index 6fae48e9..2498907e 100644
--- a/lang/sql/sqlite/test/wal6.test
+++ b/lang/sql/sqlite/test/wal6.test
@@ -14,6 +14,7 @@
#
set testdir [file dirname $argv0]
+set testprefix wal6
source $testdir/tester.tcl
source $testdir/lock_common.tcl
source $testdir/wal_common.tcl
@@ -29,62 +30,168 @@ forcedelete test.db
set all_journal_modes {delete persist truncate memory off}
foreach jmode $all_journal_modes {
- do_test wal6-1.0.$jmode {
+ do_test wal6-1.0.$jmode {
sqlite3 db test.db
execsql "PRAGMA journal_mode = $jmode;"
- } $jmode
+ } $jmode
- do_test wal6-1.1.$jmode {
- execsql {
- CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
- INSERT INTO t1 VALUES(1,2);
- SELECT * FROM t1;
- }
- } {1 2}
+ do_test wal6-1.1.$jmode {
+ execsql {
+ CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
+ INSERT INTO t1 VALUES(1,2);
+ SELECT * FROM t1;
+ }
+ } {1 2}
# Under Windows, you'll get an error trying to delete
-# a file this is already opened. For now, make sure
-# we get that error, then close the first connection
+# a file this is already opened. Close the first connection
# so the other tests work.
if {$tcl_platform(platform)=="windows"} {
if {$jmode=="persist" || $jmode=="truncate"} {
- do_test wal6-1.2.$jmode.win {
- sqlite3 db2 test.db
- catchsql {
- PRAGMA journal_mode=WAL;
- } db2
- } {1 {disk I/O error}}
- db2 close
- db close
+ db close
}
}
- do_test wal6-1.2.$jmode {
- sqlite3 db2 test.db
- execsql {
- PRAGMA journal_mode=WAL;
- INSERT INTO t1 VALUES(3,4);
- SELECT * FROM t1 ORDER BY a;
- } db2
- } {wal 1 2 3 4}
+ do_test wal6-1.2.$jmode {
+ sqlite3 db2 test.db
+ execsql {
+ PRAGMA journal_mode=WAL;
+ INSERT INTO t1 VALUES(3,4);
+ SELECT * FROM t1 ORDER BY a;
+ } db2
+ } {wal 1 2 3 4}
if {$tcl_platform(platform)=="windows"} {
if {$jmode=="persist" || $jmode=="truncate"} {
- sqlite3 db test.db
+ sqlite3 db test.db
}
}
- do_test wal6-1.3.$jmode {
- execsql {
- SELECT * FROM t1 ORDER BY a;
- }
- } {1 2 3 4}
+ do_test wal6-1.3.$jmode {
+ execsql {
+ SELECT * FROM t1 ORDER BY a;
+ }
+ } {1 2 3 4}
- db close
- db2 close
+ db close
+ db2 close
forcedelete test.db
}
+#-------------------------------------------------------------------------
+# Test that SQLITE_BUSY_SNAPSHOT is returned as expected.
+#
+reset_db
+sqlite3 db2 test.db
+
+do_execsql_test 2.1 {
+ PRAGMA journal_mode = WAL;
+ CREATE TABLE t1(a PRIMARY KEY, b TEXT);
+ INSERT INTO t1 VALUES(1, 'one');
+ INSERT INTO t1 VALUES(2, 'two');
+ BEGIN;
+ SELECT * FROM t1;
+} {wal 1 one 2 two}
+
+do_test 2.2 {
+ execsql {
+ SELECT * FROM t1;
+ INSERT INTO t1 VALUES(3, 'three');
+ } db2
+} {1 one 2 two}
+
+do_catchsql_test 2.3 {
+ INSERT INTO t1 VALUES('x', 'x')
+} {1 {database is locked}}
+
+do_test 2.4 {
+ list [sqlite3_errcode db] [sqlite3_extended_errcode db]
+} {SQLITE_BUSY SQLITE_BUSY_SNAPSHOT}
+
+do_execsql_test 2.5 {
+ SELECT * FROM t1;
+ COMMIT;
+ INSERT INTO t1 VALUES('x', 'x')
+} {1 one 2 two}
+
+proc test3 {prefix} {
+ do_test $prefix.1 {
+ execsql { SELECT count(*) FROM t1 }
+ } {0}
+ do_test $prefix.2 {
+ execsql { INSERT INTO t1 VALUES('x', 'x') } db2
+ } {}
+ do_test $prefix.3 {
+ execsql { INSERT INTO t1 VALUES('y', 'y') }
+ } {}
+ do_test $prefix.4 {
+ execsql { SELECT count(*) FROM t1 }
+ } {2}
+}
+
+do_execsql_test 2.6.1 { DELETE FROM t1 }
+test3 2.6.2
+
+db func test3 test3
+do_execsql_test 2.6.3 { DELETE FROM t1 }
+db eval {SELECT test3('2.6.4')}
+
+do_test 2.x {
+ db2 close
+} {}
+
+#-------------------------------------------------------------------------
+# Check that if BEGIN IMMEDIATE fails, it does not leave the user with
+# an open read-transaction (unless one was already open before the BEGIN
+# IMMEDIATE). Even if there are other active VMs.
+#
+
+proc test4 {prefix} {
+ do_test $prefix.1 {
+ catchsql { BEGIN IMMEDIATE }
+ } {1 {database is locked}}
+
+ do_test $prefix.2 {
+ execsql { COMMIT } db2
+ } {}
+
+ do_test $prefix.3 {
+ execsql { BEGIN IMMEDIATE }
+ } {}
+ do_test $prefix.4 {
+ execsql { COMMIT }
+ } {}
+}
+
+reset_db
+sqlite3 db2 test.db
+do_execsql_test 3.1 {
+ PRAGMA journal_mode = WAL;
+ CREATE TABLE ab(a PRIMARY KEY, b);
+} {wal}
+
+do_test 3.2.1 {
+ execsql {
+ BEGIN;
+ INSERT INTO ab VALUES(1, 2);
+ } db2
+} {}
+test4 3.2.2
+
+db func test4 test4
+do_test 3.3.1 {
+ execsql {
+ BEGIN;
+ INSERT INTO ab VALUES(3, 4);
+ } db2
+} {}
+
+db eval {SELECT test4('3.3.2')}
+
+do_test 3.x {
+ db2 close
+} {}
+
finish_test
diff --git a/lang/sql/sqlite/test/wal7.test b/lang/sql/sqlite/test/wal7.test
new file mode 100644
index 00000000..cacfaeda
--- /dev/null
+++ b/lang/sql/sqlite/test/wal7.test
@@ -0,0 +1,118 @@
+# 2011 May 16
+#
+# The author disclaims copyright to this source code. In place of
+# a legal notice, here is a blessing:
+#
+# May you do good and not evil.
+# May you find forgiveness for yourself and forgive others.
+# May you share freely, never taking more than you give.
+#
+#***********************************************************************
+# This file implements regression tests for SQLite library. The
+# focus of this file is testing the PRAGMA journal_size_limit when
+# in WAL mode.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+ifcapable !wal {finish_test ; return }
+
+# Case 1: No size limit. Journal can get large.
+#
+do_test wal7-1.0 {
+ db close
+ forcedelete test.db
+ sqlite3 db test.db
+ db eval {
+ PRAGMA page_size=1024;
+ PRAGMA journal_mode=WAL;
+ PRAGMA wal_autocheckpoint=50; -- 50 pages
+ CREATE TABLE t1(x, y UNIQUE);
+ INSERT INTO t1 VALUES(1,2);
+ INSERT INTO t1 VALUES(zeroblob(200000),4);
+ CREATE TABLE t2(z);
+ DELETE FROM t1;
+ INSERT INTO t2 SELECT x FROM t1;
+ }
+ expr {[file size test.db-wal]>50*1100}
+} 1
+do_test wal7-1.1 {
+ db eval {PRAGMA wal_checkpoint}
+ expr {[file size test.db-wal]>50*1100}
+} 1
+do_test wal7-1.2 {
+ db eval {INSERT INTO t2 VALUES('hi');}
+ expr {[file size test.db-wal]>50*1100}
+} 1
+
+# Case 2: Size limit at half the autocheckpoint size.
+#
+do_test wal7-2.0 {
+ db close
+ forcedelete test.db
+ sqlite3 db test.db
+ db eval {
+ PRAGMA page_size=1024;
+ PRAGMA journal_mode=WAL;
+ PRAGMA wal_autocheckpoint=50; -- 50 pages
+ PRAGMA journal_size_limit=25000;
+ CREATE TABLE t1(x, y UNIQUE);
+ INSERT INTO t1 VALUES(1,2);
+ INSERT INTO t1 VALUES(zeroblob(200000),4);
+ CREATE TABLE t2(z);
+ DELETE FROM t1;
+ INSERT INTO t2 VALUES(1);
+ }
+ file size test.db-wal
+} 25000
+
+
+# Case 3: Size limit of zero.
+#
+do_test wal7-3.0 {
+ db close
+ forcedelete test.db
+ sqlite3 db test.db
+ db eval {
+ PRAGMA page_size=1024;
+ PRAGMA journal_mode=WAL;
+ PRAGMA wal_autocheckpoint=50; -- 50 pages
+ PRAGMA journal_size_limit=0;
+ CREATE TABLE t1(x, y UNIQUE);
+ INSERT INTO t1 VALUES(1,2);
+ INSERT INTO t1 VALUES(zeroblob(200000),4);
+ CREATE TABLE t2(z);
+ DELETE FROM t1;
+ INSERT INTO t2 VALUES(1);
+ }
+ set sz [file size test.db-wal]
+ expr {$sz>0 && $sz<13700}
+} 1
+
+
+# Case 4: Size limit set before going WAL
+#
+do_test wal7-4.0 {
+ db close
+ forcedelete test.db
+ sqlite3 db test.db
+ db eval {
+ PRAGMA page_size=1024;
+ PRAGMA journal_size_limit=25000;
+ PRAGMA journal_mode=WAL;
+ PRAGMA wal_autocheckpoint=50; -- 50 pages
+ CREATE TABLE t1(x, y UNIQUE);
+ INSERT INTO t1 VALUES(1,2);
+ INSERT INTO t1 VALUES(zeroblob(200000),4);
+ CREATE TABLE t2(z);
+ DELETE FROM t1;
+ INSERT INTO t2 VALUES(1);
+ }
+ set sz [file size test.db-wal]
+} 25000
+
+
+
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/wal8.test b/lang/sql/sqlite/test/wal8.test
new file mode 100644
index 00000000..0682fce3
--- /dev/null
+++ b/lang/sql/sqlite/test/wal8.test
@@ -0,0 +1,90 @@
+# 2012 February 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 operation of the library in
+# "PRAGMA journal_mode=WAL" mode.
+#
+# Specifically, it tests the case where a connection opens an empty
+# file. Then, another connection opens the same file and initializes
+# the connection as a WAL database. Following this, the first connection
+# executes a "PRAGMA page_size = XXX" command to set its expected page
+# size, and then queries the database.
+#
+# This is an unusual case, as normally SQLite is able to glean the page
+# size from the database file as soon as it is opened (even before the
+# first read transaction is executed), and the "PRAGMA page_size = XXX"
+# is a no-op.
+#
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set ::testprefix wal8
+ifcapable !wal {finish_test ; return }
+
+db close
+forcedelete test.db test.db-wal
+
+sqlite3 db test.db
+sqlite3 db2 test.db
+
+do_test 1.0 {
+ execsql {
+ PRAGMA journal_mode = wal;
+ CREATE TABLE t1(a, b);
+ INSERT INTO t1 VALUES(1, 2);
+ } db2
+} {wal}
+
+do_catchsql_test 1.1 {
+ PRAGMA page_size = 4096;
+ VACUUM;
+} {0 {}}
+
+db close
+db2 close
+forcedelete test.db test.db-wal
+
+sqlite3 db test.db
+sqlite3 db2 test.db
+
+do_test 2.0 {
+ execsql {
+ CREATE TABLE t1(a, b);
+ INSERT INTO t1 VALUES(1, 2);
+ PRAGMA journal_mode = wal;
+ } db2
+} {wal}
+
+do_catchsql_test 2.1 {
+ PRAGMA page_size = 4096;
+ VACUUM;
+} {0 {}}
+
+db close
+db2 close
+forcedelete test.db test.db-wal
+
+sqlite3 db test.db
+sqlite3 db2 test.db
+
+do_test 3.0 {
+ execsql {
+ PRAGMA journal_mode = wal;
+ CREATE TABLE t1(a, b);
+ INSERT INTO t1 VALUES(1, 2);
+ } db2
+} {wal}
+
+do_execsql_test 3.1 {
+ PRAGMA page_size = 4096;
+ SELECT name FROM sqlite_master;
+} {t1}
+
+finish_test
diff --git a/lang/sql/sqlite/test/wal9.test b/lang/sql/sqlite/test/wal9.test
new file mode 100644
index 00000000..ae2a52bb
--- /dev/null
+++ b/lang/sql/sqlite/test/wal9.test
@@ -0,0 +1,94 @@
+# 2012 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.
+#
+#***********************************************************************
+#
+# This test case tests that a problem causing a failing assert() has
+# been fixed. The problem occurred if a writer process with a subset
+# of the *shm file mapped rolled back a transaction begun after the
+# entire WAL file was checkpointed into the db file (i.e. a transaction
+# that would have restarted the WAL file from the beginning).
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix wal9
+
+sqlite3 db2 test.db
+
+do_execsql_test 1.0 {
+ PRAGMA page_size = 1024;
+ PRAGMA journal_mode = WAL;
+ PRAGMA wal_autocheckpoint = 0;
+ CREATE TABLE t(x);
+} {wal 0}
+
+do_test 1.1 {
+ execsql "SELECT * FROM t" db2
+} {}
+
+do_execsql_test 1.2 {
+ BEGIN;
+ INSERT INTO t VALUES(randomblob(100));
+ INSERT INTO t SELECT randomblob(100) FROM t;
+ INSERT INTO t SELECT randomblob(100) FROM t;
+ INSERT INTO t SELECT randomblob(100) FROM t;
+ INSERT INTO t SELECT randomblob(100) FROM t;
+ INSERT INTO t SELECT randomblob(100) FROM t;
+ INSERT INTO t SELECT randomblob(100) FROM t;
+ INSERT INTO t SELECT randomblob(100) FROM t;
+
+ INSERT INTO t SELECT randomblob(100) FROM t;
+ INSERT INTO t SELECT randomblob(100) FROM t;
+ INSERT INTO t SELECT randomblob(100) FROM t;
+ INSERT INTO t SELECT randomblob(100) FROM t;
+ INSERT INTO t SELECT randomblob(100) FROM t;
+ INSERT INTO t SELECT randomblob(100) FROM t;
+ INSERT INTO t SELECT randomblob(100) FROM t;
+ INSERT INTO t SELECT randomblob(100) FROM t;
+
+ INSERT INTO t SELECT randomblob(100) FROM t;
+ INSERT INTO t SELECT randomblob(100) FROM t;
+ COMMIT;
+} {}
+
+# Check file sizes are as expected. The real requirement here is that
+# the *shm file is now more than one chunk (>32KiB).
+#
+# The sizes of various files are slightly different in normal and
+# auto-vacuum mode.
+do_test 1.3 { file size test.db } {1024}
+do_test 1.4 { expr {[file size test.db-wal]>(1500*1024)} } {1}
+do_test 1.5 { expr {[file size test.db-shm]>32768} } {1}
+do_test 1.6 {
+ foreach {a b c} [db eval {PRAGMA wal_checkpoint}] break
+ list [expr {$a==0}] [expr {$b>14500}] [expr {$c>14500}] [expr {$b==$c}]
+} {1 1 1 1}
+
+# At this point connection [db2] has mapped the first 32KB of the *shm file
+# only. Because the entire WAL file has been checkpointed, it is not
+# necessary to map any more of the *-shm file to read or write the database
+# (since all data will be read directly from the db file).
+#
+# However, at one point if a transaction that had not yet written to the
+# WAL file was rolled back an assert() attempting to verify that the entire
+# *-shm file was mapped would fail. If NDEBUG was defined (and the assert()
+# disabled) this bug caused SQLite to ignore the return code of a mmap()
+# call.
+#
+do_test 1.7 {
+ execsql {
+ BEGIN;
+ INSERT INTO t VALUES('hello');
+ ROLLBACK;
+ } db2
+} {}
+db2 close
+
+finish_test
diff --git a/lang/sql/sqlite/test/walbak.test b/lang/sql/sqlite/test/walbak.test
index fe5b99e1..303a628a 100644
--- a/lang/sql/sqlite/test/walbak.test
+++ b/lang/sql/sqlite/test/walbak.test
@@ -48,7 +48,7 @@ do_test walbak-1.0 {
}
} {wal}
do_test walbak-1.1 {
- file delete -force bak.db bak.db-journal bak.db-wal
+ forcedelete bak.db bak.db-journal bak.db-wal
db backup bak.db
file size bak.db
} [expr 3*1024]
@@ -79,6 +79,9 @@ do_test walbak-1.6 {
execsql { PRAGMA wal_checkpoint }
list [file size test.db] [file size test.db-wal]
} [list [expr 3*1024] [wal_file_size 6 1024]]
+do_test walbak-1.6.1 {
+ hexio_read test.db 18 2
+} {0202}
do_test walbak-1.7 {
execsql {
CREATE TABLE t2(a, b);
@@ -106,7 +109,7 @@ proc sig {{db db}} {
}
}
db close
-file delete test.db
+delete_file test.db
sqlite3 db test.db
do_test walbak-2.1 {
execsql { PRAGMA journal_mode = WAL }
@@ -236,7 +239,7 @@ foreach {tn setup} {
}
} {
- foreach f [glob -nocomplain test.db*] { file delete -force $f }
+ foreach f [glob -nocomplain test.db*] { forcedelete $f }
eval $setup
@@ -271,9 +274,84 @@ foreach {tn setup} {
execsql { SELECT * FROM t1 }
} {1 2 3 4 5 6 7 8}
+ # Check that [db] is still in WAL mode.
+ do_test walbak-3.$tn.5 {
+ execsql { PRAGMA journal_mode }
+ } {wal}
+ do_test walbak-3.$tn.6 {
+ execsql { PRAGMA wal_checkpoint }
+ hexio_read test.db 18 2
+ } {0202}
+
+ # If it was not an in-memory database, check that [db2] is still in
+ # rollback mode.
+ if {[file exists test.db2]} {
+ do_test walbak-3.$tn.7 {
+ execsql { PRAGMA journal_mode } db2
+ } {wal}
+ do_test walbak-3.$tn.8 {
+ execsql { PRAGMA wal_checkpoint }
+ hexio_read test.db 18 2
+ } {0202}
+ }
+
db close
db2 close
}
+#-------------------------------------------------------------------------
+# Test that the following holds when a backup operation is run:
+#
+# Source | Destination inital | Destination final
+# ---------------------------------------------------
+# Rollback Rollback Rollback
+# Rollback WAL WAL
+# WAL Rollback WAL
+# WAL WAL WAL
+#
+foreach {tn src dest dest_final} {
+ 1 delete delete delete
+ 2 delete wal wal
+ 3 wal delete wal
+ 4 wal wal wal
+} {
+ catch { db close }
+ catch { db2 close }
+ forcedelete test.db test.db2
+
+ do_test walbak-4.$tn.1 {
+ sqlite3 db test.db
+ db eval "PRAGMA journal_mode = $src"
+ db eval {
+ CREATE TABLE t1(a, b);
+ INSERT INTO t1 VALUES('I', 'II');
+ INSERT INTO t1 VALUES('III', 'IV');
+ }
+
+ sqlite3 db2 test.db2
+ db2 eval "PRAGMA journal_mode = $dest"
+ db2 eval {
+ CREATE TABLE t2(x, y);
+ INSERT INTO t2 VALUES('1', '2');
+ INSERT INTO t2 VALUES('3', '4');
+ }
+ } {}
+
+ do_test walbak-4.$tn.2 { execsql { PRAGMA journal_mode } db } $src
+ do_test walbak-4.$tn.3 { execsql { PRAGMA journal_mode } db2 } $dest
+
+ do_test walbak-4.$tn.4 { db backup test.db2 } {}
+ do_test walbak-4.$tn.5 {
+ execsql { SELECT * FROM t1 } db2
+ } {I II III IV}
+ do_test walbak-4.$tn.5 { execsql { PRAGMA journal_mode } db2 } $dest_final
+
+
+ db2 close
+ do_test walbak-4.$tn.6 { file exists test.db2-wal } 0
+ sqlite3 db2 test.db2
+ do_test walbak-4.$tn.7 { execsql { PRAGMA journal_mode } db2 } $dest_final
+}
+
finish_test
diff --git a/lang/sql/sqlite/test/walbig.test b/lang/sql/sqlite/test/walbig.test
index 9ceb8ede..c43b7e25 100644
--- a/lang/sql/sqlite/test/walbig.test
+++ b/lang/sql/sqlite/test/walbig.test
@@ -17,6 +17,11 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
+ifcapable !wal {
+ finish_test
+ return
+}
+
# Do not use a codec for this file, as the database is manipulated using
# external methods (the [fake_big_file] and [hexio_write] commands).
#
@@ -47,7 +52,7 @@ do_test walbig-1.0 {
} {wal}
db close
-if {[catch {fake_big_file 5000 [pwd]/test.db}]} {
+if {[catch {fake_big_file 5000 [get_pwd]/test.db}]} {
puts "**** Unable to create a file larger than 5000 MB. *****"
finish_test
return
diff --git a/lang/sql/sqlite/test/walcksum.test b/lang/sql/sqlite/test/walcksum.test
index b2c4a905..3005a758 100644
--- a/lang/sql/sqlite/test/walcksum.test
+++ b/lang/sql/sqlite/test/walcksum.test
@@ -153,7 +153,7 @@ foreach endian {big little} {
#
do_test walcksum-1.$endian.1 {
catch { db close }
- file delete -force test.db test.db-wal test.db-journal
+ forcedelete test.db test.db-wal test.db-journal
sqlite3 db test.db
execsql {
PRAGMA page_size = 1024;
@@ -172,8 +172,8 @@ foreach endian {big little} {
INSERT INTO t1 VALUES(21, 'twentyone');
}
- file copy -force test.db test2.db
- file copy -force test.db-wal test2.db-wal
+ forcecopy test.db test2.db
+ forcecopy test.db-wal test2.db-wal
db close
list [file size test2.db] [file size test2.db-wal]
@@ -199,8 +199,8 @@ foreach endian {big little} {
} {1}
}
do_test walcksum-1.$endian.4.1 {
- file copy -force test2.db test.db
- file copy -force test2.db-wal test.db-wal
+ forcecopy test2.db test.db
+ forcecopy test2.db-wal test.db-wal
sqlite3 db test.db
execsql { SELECT a FROM t1 }
} {1 2 3 5 8 13 21}
@@ -248,8 +248,8 @@ foreach endian {big little} {
# Now that both the recoverer and non-recoverer have added frames to the
# log file, check that it can still be recovered.
#
- file copy -force test.db test2.db
- file copy -force test.db-wal test2.db-wal
+ forcecopy test.db test2.db
+ forcecopy test.db-wal test2.db-wal
do_test walcksum-1.$endian.7.11 {
sqlite3 db3 test2.db
execsql {
@@ -294,7 +294,7 @@ foreach endian {big little} {
# formatted (and can be recovered by a second process if required).
#
do_test walcksum-2.1 {
- file delete -force test.db test.db-wal test.db-journal
+ forcedelete test.db test.db-wal test.db-journal
sqlite3 db test.db
execsql {
PRAGMA synchronous = NORMAL;
@@ -322,8 +322,8 @@ do_test walcksum-2.1 {
COMMIT;
}
- file copy -force test.db test2.db
- file copy -force test.db-wal test2.db-wal
+ forcecopy test.db test2.db
+ forcecopy test.db-wal test2.db-wal
sqlite3 db2 test2.db
execsql {
@@ -340,7 +340,7 @@ catch { db2 close }
# invalid as a result.
#
do_test walcksum-3.1 {
- file delete -force test.db test.db-wal test.db-journal
+ forcedelete test.db test.db-wal test.db-journal
sqlite3 db test.db
execsql {
@@ -356,13 +356,13 @@ do_test walcksum-3.1 {
file size test.db-wal
} [wal_file_size 1 1024]
do_test walcksum-3.2 {
- file copy -force test.db-wal test2.db-wal
- file copy -force test.db test2.db
+ forcecopy test.db-wal test2.db-wal
+ forcecopy test.db test2.db
sqlite3 db2 test2.db
execsql { SELECT a FROM t1 } db2
} {1 2 3}
db2 close
-file copy -force test.db test2.db
+forcecopy test.db test2.db
foreach incr {1 2 3 20 40 60 80 100 120 140 160 180 200 220 240 253 254 255} {
@@ -370,7 +370,7 @@ foreach incr {1 2 3 20 40 60 80 100 120 140 160 180 200 220 240 253 254 255} {
set FAIL 0
for {set iOff 0} {$iOff < [wal_file_size 1 1024]} {incr iOff} {
- file copy -force test.db-wal test2.db-wal
+ forcecopy test.db-wal test2.db-wal
set fd [open test2.db-wal r+]
fconfigure $fd -encoding binary
fconfigure $fd -translation binary
@@ -390,4 +390,3 @@ foreach incr {1 2 3 20 40 60 80 100 120 140 160 180 200 220 240 253 254 255} {
}
finish_test
-
diff --git a/lang/sql/sqlite/test/walcrash.test b/lang/sql/sqlite/test/walcrash.test
index 0ef21fff..2a647188 100644
--- a/lang/sql/sqlite/test/walcrash.test
+++ b/lang/sql/sqlite/test/walcrash.test
@@ -37,7 +37,7 @@ set REPEATS 100
# walcrash-1.*
#
for {set i 1} {$i < $REPEATS} {incr i} {
- file delete -force test.db test.db-wal
+ forcedelete test.db test.db-wal
do_test walcrash-1.$i.1 {
crashsql -delay 4 -file test.db-wal -seed [incr seed] {
PRAGMA journal_mode = WAL;
@@ -74,9 +74,9 @@ for {set i 1} {$i < $REPEATS} {incr i} {
# walcrash-2.*
#
for {set i 1} {$i < $REPEATS} {incr i} {
- file delete -force test.db test.db-wal
+ forcedelete test.db test.db-wal
do_test walcrash-2.$i.1 {
- crashsql -delay 4 -file test.db-wal -seed [incr seed] {
+ crashsql -delay 5 -file test.db-wal -seed [incr seed] {
PRAGMA journal_mode = WAL;
CREATE TABLE t1(a PRIMARY KEY, b);
INSERT INTO t1 VALUES(1, 2);
@@ -111,8 +111,8 @@ for {set i 1} {$i < $REPEATS} {incr i} {
# walcrash-3.*
#
# for {set i 1} {$i < $REPEATS} {incr i} {
-# file delete -force test.db test.db-wal
-# file delete -force test2.db test2.db-wal
+# forcedelete test.db test.db-wal
+# forcedelete test2.db test2.db-wal
#
# do_test walcrash-3.$i.1 {
# crashsql -delay 2 -file test2.db-wal -seed [incr seed] {
@@ -143,11 +143,11 @@ for {set i 1} {$i < $REPEATS} {incr i} {
# walcrash-4.*
#
for {set i 1} {$i < $REPEATS} {incr i} {
- file delete -force test.db test.db-wal
- file delete -force test2.db test2.db-wal
+ forcedelete test.db test.db-wal
+ forcedelete test2.db test2.db-wal
do_test walcrash-4.$i.1 {
- crashsql -delay 3 -file test.db-wal -seed [incr seed] -blocksize 4096 {
+ crashsql -delay 4 -file test.db-wal -seed [incr seed] -blocksize 4096 {
PRAGMA journal_mode = WAL;
PRAGMA page_size = 1024;
CREATE TABLE t1(a PRIMARY KEY, b);
@@ -171,11 +171,11 @@ for {set i 1} {$i < $REPEATS} {incr i} {
# walcrash-5.*
#
for {set i 1} {$i < $REPEATS} {incr i} {
- file delete -force test.db test.db-wal
- file delete -force test2.db test2.db-wal
+ forcedelete test.db test.db-wal
+ forcedelete test2.db test2.db-wal
do_test walcrash-5.$i.1 {
- crashsql -delay 11 -file test.db-wal -seed [incr seed] -blocksize 4096 {
+ crashsql -delay 13 -file test.db-wal -seed [incr seed] -blocksize 4096 {
PRAGMA journal_mode = WAL;
PRAGMA page_size = 1024;
BEGIN;
@@ -212,11 +212,11 @@ for {set i 1} {$i < $REPEATS} {incr i} {
# walcrash-6.*
#
for {set i 1} {$i < $REPEATS} {incr i} {
- file delete -force test.db test.db-wal
- file delete -force test2.db test2.db-wal
+ forcedelete test.db test.db-wal
+ forcedelete test2.db test2.db-wal
do_test walcrash-6.$i.1 {
- crashsql -delay 12 -file test.db-wal -seed [incr seed] -blocksize 512 {
+ crashsql -delay 14 -file test.db-wal -seed [incr seed] -blocksize 512 {
PRAGMA journal_mode = WAL;
PRAGMA page_size = 1024;
BEGIN;
@@ -234,9 +234,9 @@ for {set i 1} {$i < $REPEATS} {incr i} {
INSERT INTO t1 SELECT randomblob(900) FROM t1 LIMIT 4; /* 32 */
PRAGMA wal_checkpoint;
- INSERT INTO t1 VALUES(randomblob(900));
- INSERT INTO t1 VALUES(randomblob(900));
- INSERT INTO t1 VALUES(randomblob(900));
+ INSERT INTO t1 VALUES(randomblob(9000));
+ INSERT INTO t1 VALUES(randomblob(9000));
+ INSERT INTO t1 VALUES(randomblob(9000));
}
} {1 {child process exited abnormally}}
@@ -262,7 +262,7 @@ for {set i 1} {$i < $REPEATS} {incr i} {
# based on the log file.
#
for {set i 1} {$i < $REPEATS} {incr i} {
- file delete -force test.db test.db-wal
+ forcedelete test.db test.db-wal
# Select a page-size for this test.
#
@@ -293,4 +293,3 @@ for {set i 1} {$i < $REPEATS} {incr i} {
}
finish_test
-
diff --git a/lang/sql/sqlite/test/walcrash2.test b/lang/sql/sqlite/test/walcrash2.test
index 7116281c..9c93bcde 100644
--- a/lang/sql/sqlite/test/walcrash2.test
+++ b/lang/sql/sqlite/test/walcrash2.test
@@ -96,4 +96,3 @@ do_test walcrash2-1.3 {
catch { db2 close }
finish_test
-
diff --git a/lang/sql/sqlite/test/walcrash3.test b/lang/sql/sqlite/test/walcrash3.test
new file mode 100644
index 00000000..71dfb455
--- /dev/null
+++ b/lang/sql/sqlite/test/walcrash3.test
@@ -0,0 +1,128 @@
+# 2011 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 test simulates an application crash immediately following a
+# system call to truncate a file. Specifically, the system call that
+# truncates the WAL file if "PRAGMA journal_size_limit" is configured.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+ifcapable !wal {finish_test ; return }
+set testprefix walcrash3
+
+db close
+testvfs tvfs
+tvfs filter {xTruncate xWrite}
+tvfs script tvfs_callback
+proc tvfs_callback {args} {}
+
+sqlite3 db test.db -vfs tvfs
+do_execsql_test 1.1 {
+ PRAGMA page_size = 1024;
+ PRAGMA journal_mode = WAL;
+ PRAGMA wal_autocheckpoint = 128;
+ PRAGMA journal_size_limit = 16384;
+
+ CREATE TABLE t1(a BLOB, b BLOB, UNIQUE(a, b));
+ INSERT INTO t1 VALUES(randomblob(10), randomblob(1000));
+} {wal 128 16384}
+
+proc tvfs_callback {method file arglist} {
+ if {$::state==1} {
+ foreach f [glob -nocomplain xx_test.*] { forcedelete $f }
+ foreach f [glob -nocomplain test.*] { forcecopy $f "xx_$f" }
+ set ::state 2
+ }
+ if {$::state==0 && $method=="xTruncate" && [file tail $file]=="test.db-wal"} {
+ set ::state 1
+ }
+}
+
+for {set i 2} {$i<1000} {incr i} {
+
+ # If the WAL file is truncated within the following, within the following
+ # xWrite call the [tvfs_callback] makes a copy of the database and WAL
+ # files set sets $::state to 2. So that the copied files are in the same
+ # state as the real database and WAL files would be if an application crash
+ # occurred immediately following the xTruncate().
+ #
+ set ::state 0
+ do_execsql_test 1.$i.1 {
+ INSERT INTO t1 VALUES(randomblob(10), randomblob(1000));
+ }
+
+ # If a copy was made, open it and run the integrity-check.
+ #
+ if {$::state==2} {
+ sqlite3 db2 xx_test.db
+ do_test 1.$i.2 { execsql { PRAGMA integrity_check } db2 } "ok"
+ do_test 1.$i.3 { execsql { SELECT count(*) FROM t1 } db2 } [expr $i-1]
+ db2 close
+ }
+}
+catch { db close }
+tvfs delete
+
+#--------------------------------------------------------------------------
+#
+catch { db close }
+forcedelete test.db
+
+do_test 2.1 {
+ sqlite3 db test.db
+ execsql {
+ PRAGMA page_size = 512;
+ PRAGMA journal_mode = WAL;
+ PRAGMA wal_autocheckpoint = 128;
+ CREATE TABLE t1(a PRIMARY KEY, b);
+ INSERT INTO t1 VALUES(randomblob(25), randomblob(200));
+ }
+
+ for {set i 0} {$i < 1500} {incr i} {
+ execsql { INSERT INTO t1 VALUES(randomblob(25), randomblob(200)) }
+ }
+
+ db_save
+ db close
+} {}
+
+set nInitialErr [set_test_counter errors]
+for {set i 2} {$i<10000 && [set_test_counter errors]==$nInitialErr} {incr i} {
+
+ do_test 2.$i.1 {
+ catch { db close }
+ db_restore
+ crashsql -delay 2 -file test.db-wal -seed $i {
+ SELECT * FROM sqlite_master;
+ PRAGMA synchronous = full;
+ PRAGMA wal_checkpoint;
+ BEGIN;
+ INSERT INTO t1 VALUES(randomblob(26), randomblob(200));
+ INSERT INTO t1 VALUES(randomblob(26), randomblob(200));
+ INSERT INTO t1 VALUES(randomblob(26), randomblob(200));
+ INSERT INTO t1 VALUES(randomblob(26), randomblob(200));
+ INSERT INTO t1 VALUES(randomblob(26), randomblob(200));
+ INSERT INTO t1 VALUES(randomblob(26), randomblob(200));
+ INSERT INTO t1 VALUES(randomblob(26), randomblob(200));
+ INSERT INTO t1 VALUES(randomblob(26), randomblob(200));
+ COMMIT;
+ }
+ } {1 {child process exited abnormally}}
+
+ do_test 2.$i.2 {
+ sqlite3 db test.db
+ execsql { PRAGMA integrity_check }
+ } {ok}
+}
+
+finish_test
diff --git a/lang/sql/sqlite/test/walfault.test b/lang/sql/sqlite/test/walfault.test
index 3a90f9c6..4e7064d5 100644
--- a/lang/sql/sqlite/test/walfault.test
+++ b/lang/sql/sqlite/test/walfault.test
@@ -123,7 +123,6 @@ do_faultsim_test walfault-3 -prep {
faultsim_test_result {0 {}}
}
-
#--------------------------------------------------------------------------
#
if {[permutation] != "inmemory_journal"} {
@@ -141,7 +140,9 @@ if {[permutation] != "inmemory_journal"} {
SELECT * FROM t1;
}
} -test {
- faultsim_test_result {0 {wal 0 7 7 a b}}
+ # Update: The following changed from {0 {wal 0 7 7 a b}} as a result
+ # of PSOW being set by default.
+ faultsim_test_result {0 {wal 0 5 5 a b}}
faultsim_integrity_check
}
}
@@ -465,7 +466,7 @@ do_test walfault-13-pre-1 {
COMMIT;
}
faultsim_save_and_close
- file delete sv_test.db-shm
+ delete_file sv_test.db-shm
} {}
do_faultsim_test walfault-13.1 -prep {
@@ -542,10 +543,48 @@ do_faultsim_test walfault-14 -prep {
INSERT INTO abc VALUES(randomblob(1500));
}
} -test {
- faultsim_test_result {0 {0 10 10}}
+ faultsim_test_result {0 {0 9 9}}
faultsim_integrity_check
set nRow [db eval {SELECT count(*) FROM abc}]
if {!(($nRow==2 && $testrc) || $nRow==3)} { error "Bad db content" }
}
+#-------------------------------------------------------------------------
+# Test fault-handling when switching out of exclusive-locking mode.
+#
+do_test walfault-14-pre {
+ faultsim_delete_and_reopen
+ execsql {
+ PRAGMA auto_vacuum = 0;
+ PRAGMA journal_mode = WAL;
+ BEGIN;
+ CREATE TABLE abc(a PRIMARY KEY);
+ INSERT INTO abc VALUES(randomblob(1500));
+ INSERT INTO abc VALUES(randomblob(1500));
+ COMMIT;
+ }
+ faultsim_save_and_close
+} {}
+do_faultsim_test walfault-14 -prep {
+ faultsim_restore_and_reopen
+ execsql {
+ SELECT count(*) FROM abc;
+ PRAGMA locking_mode = exclusive;
+ BEGIN;
+ INSERT INTO abc VALUES(randomblob(1500));
+ COMMIT;
+ }
+} -body {
+ db eval {
+ PRAGMA locking_mode = normal;
+ BEGIN;
+ INSERT INTO abc VALUES(randomblob(1500));
+ COMMIT;
+ }
+} -test {
+ faultsim_integrity_check
+ set nRow [db eval {SELECT count(*) FROM abc}]
+ if {$nRow!=3 && $nRow!=4} { error "Bad db content" }
+}
+
finish_test
diff --git a/lang/sql/sqlite/test/walmode.test b/lang/sql/sqlite/test/walmode.test
index 11113c6b..4e14d54d 100644
--- a/lang/sql/sqlite/test/walmode.test
+++ b/lang/sql/sqlite/test/walmode.test
@@ -295,7 +295,7 @@ db close
# loaded when sqlite3_prepare_v2() is called to compile the statement.
#
do_test walmode-7.0 {
- file delete -force test.db
+ forcedelete test.db
sqlite3 db test.db
execsql {
PRAGMA journal_mode = WAL;
diff --git a/lang/sql/sqlite/test/walnoshm.test b/lang/sql/sqlite/test/walnoshm.test
index de059dd5..d4082178 100644
--- a/lang/sql/sqlite/test/walnoshm.test
+++ b/lang/sql/sqlite/test/walnoshm.test
@@ -87,8 +87,8 @@ do_execsql_test 2.1.2 {
} {exclusive wal}
do_test 2.1.3 {
- file copy -force test.db test2.db
- file copy -force test.db-wal test2.db-wal
+ forcecopy test.db test2.db
+ forcecopy test.db-wal test2.db-wal
sqlite3 db2 test2.db
catchsql { SELECT * FROM t2 } db2
} {1 {unable to open database file}}
@@ -104,8 +104,8 @@ do_test 2.1.5 {
} {exclusive delete a b c d e f g h}
do_test 2.2.1 {
- file copy -force test.db test2.db
- file copy -force test.db-wal test2.db-wal
+ forcecopy test.db test2.db
+ forcecopy test.db-wal test2.db-wal
sqlite3 db3 test2.db -vfs tvfsshm
sqlite3 db2 test2.db
execsql { SELECT * FROM t2 } db3
diff --git a/lang/sql/sqlite/test/walpersist.test b/lang/sql/sqlite/test/walpersist.test
new file mode 100644
index 00000000..692728dd
--- /dev/null
+++ b/lang/sql/sqlite/test/walpersist.test
@@ -0,0 +1,126 @@
+# 2011 July 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 contains tests for using WAL with persistent WAL file mode.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+source $testdir/lock_common.tcl
+set ::testprefix walpersist
+
+ifcapable !wal {
+ finish_test
+ return
+}
+
+do_test walpersist-1.0 {
+ db eval {
+ PRAGMA journal_mode=WAL;
+ CREATE TABLE t1(a);
+ INSERT INTO t1 VALUES(randomblob(5000));
+ }
+ file exists test.db-wal
+} {1}
+do_test walpersist-1.1 {
+ file exists test.db-shm
+} {1}
+do_test walpersist-1.2 {
+ db close
+ list [file exists test.db] [file exists test.db-wal] [file exists test.db-shm]
+} {1 0 0}
+do_test walpersist-1.3 {
+ sqlite3 db test.db
+ db eval {SELECT length(a) FROM t1}
+} {5000}
+do_test walpersist-1.4 {
+ list [file exists test.db] [file exists test.db-wal] [file exists test.db-shm]
+} {1 1 1}
+do_test walpersist-1.5 {
+ file_control_persist_wal db -1
+} {0 0}
+do_test walpersist-1.6 {
+ file_control_persist_wal db 1
+} {0 1}
+do_test walpersist-1.7 {
+ file_control_persist_wal db -1
+} {0 1}
+do_test walpersist-1.8 {
+ file_control_persist_wal db 0
+} {0 0}
+do_test walpersist-1.9 {
+ file_control_persist_wal db -1
+} {0 0}
+do_test walpersist-1.10 {
+ file_control_persist_wal db 1
+} {0 1}
+do_test walpersist-1.11 {
+ db close
+ list [file exists test.db] [file exists test.db-wal] [file exists test.db-shm]
+} {1 1 1}
+
+# Make sure the journal_size_limit works to limit the size of the
+# persisted wal file. In persistent-wal mode, any non-negative
+# journal_size_limit causes the WAL file to be truncated to zero bytes
+# when closing.
+#
+forcedelete test.db test.db-shm test.db-wal
+do_test walpersist-2.1 {
+ sqlite3 db test.db
+ db eval {
+ PRAGMA journal_mode=WAL;
+ PRAGMA wal_autocheckpoint=OFF;
+ PRAGMA journal_size_limit=12000;
+ CREATE TABLE t1(x);
+ INSERT INTO t1 VALUES(randomblob(50000));
+ UPDATE t1 SET x=randomblob(50000);
+ }
+ expr {[file size test.db-wal]>100000}
+} {1}
+do_test walpersist-2.2 {
+ file_control_persist_wal db 1
+ db close
+ concat [file exists test.db-wal] [file size test.db-wal]
+} {1 0}
+do_test walpersist-2.3 {
+ sqlite3 db test.db
+ execsql { PRAGMA integrity_check }
+} {ok}
+
+do_test 3.1 {
+ catch {db close}
+ forcedelete test.db test.db-shm test.db-wal
+ sqlite3 db test.db
+ execsql {
+ PRAGMA page_size = 1024;
+ PRAGMA journal_mode = WAL;
+ PRAGMA wal_autocheckpoint=128;
+ PRAGMA journal_size_limit=16384;
+ CREATE TABLE t1(a, b, PRIMARY KEY(a, b));
+ }
+} {wal 128 16384}
+do_test 3.2 {
+ for {set i 0} {$i<200} {incr i} {
+ execsql { INSERT INTO t1 VALUES(randomblob(500), randomblob(500)) }
+ }
+ file_control_persist_wal db 1
+ db close
+} {}
+do_test walpersist-3.3 {
+ file size test.db-wal
+} {0}
+do_test walpersist-3.4 {
+ sqlite3 db test.db
+ execsql { PRAGMA integrity_check }
+} {ok}
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/walro.test b/lang/sql/sqlite/test/walro.test
new file mode 100644
index 00000000..f1ed275a
--- /dev/null
+++ b/lang/sql/sqlite/test/walro.test
@@ -0,0 +1,293 @@
+# 2011 May 09
+#
+# The author disclaims copyright to this source code. In place of
+# a legal notice, here is a blessing:
+#
+# May you 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 for using WAL databases in read-only mode.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+source $testdir/lock_common.tcl
+set ::testprefix walro
+
+# These tests are only going to work on unix.
+#
+if {$::tcl_platform(platform) != "unix"} {
+ finish_test
+ return
+}
+
+# And only if the build is WAL-capable.
+#
+ifcapable !wal {
+ finish_test
+ return
+}
+
+do_multiclient_test tn {
+ # Do not run tests with the connections in the same process.
+ #
+ if {$tn==2} continue
+
+ # Close all connections and delete the database.
+ #
+ code1 { db close }
+ code2 { db2 close }
+ code3 { db3 close }
+ forcedelete test.db
+ forcedelete walro
+
+ foreach c {code1 code2 code3} {
+ $c {
+ sqlite3_shutdown
+ sqlite3_config_uri 1
+ }
+ }
+
+ file mkdir walro
+
+ do_test 1.1.1 {
+ code2 { sqlite3 db2 test.db }
+ sql2 {
+ PRAGMA auto_vacuum = 0;
+ PRAGMA journal_mode = WAL;
+ CREATE TABLE t1(x, y);
+ INSERT INTO t1 VALUES('a', 'b');
+ }
+ file exists test.db-shm
+ } {1}
+
+ do_test 1.1.2 {
+ file attributes test.db-shm -permissions r--r--r--
+ code1 { sqlite3 db file:test.db?readonly_shm=1 }
+ } {}
+
+ do_test 1.1.3 { sql1 "SELECT * FROM t1" } {a b}
+ do_test 1.1.4 { sql2 "INSERT INTO t1 VALUES('c', 'd')" } {}
+ do_test 1.1.5 { sql1 "SELECT * FROM t1" } {a b c d}
+
+ # Check that the read-only connection cannot write or checkpoint the db.
+ #
+ do_test 1.1.6 {
+ csql1 "INSERT INTO t1 VALUES('e', 'f')"
+ } {1 {attempt to write a readonly database}}
+ do_test 1.1.7 {
+ csql1 "PRAGMA wal_checkpoint"
+ } {1 {attempt to write a readonly database}}
+
+ do_test 1.1.9 { sql2 "INSERT INTO t1 VALUES('e', 'f')" } {}
+ do_test 1.1.10 { sql1 "SELECT * FROM t1" } {a b c d e f}
+
+ do_test 1.1.11 {
+ sql2 {
+ INSERT INTO t1 VALUES('g', 'h');
+ PRAGMA wal_checkpoint;
+ }
+ set {} {}
+ } {}
+ do_test 1.1.12 { sql1 "SELECT * FROM t1" } {a b c d e f g h}
+ do_test 1.1.13 { sql2 "INSERT INTO t1 VALUES('i', 'j')" } {}
+
+ do_test 1.2.1 {
+ code2 { db2 close }
+ code1 { db close }
+ list [file exists test.db-wal] [file exists test.db-shm]
+ } {1 1}
+ do_test 1.2.2 {
+ code1 { sqlite3 db file:test.db?readonly_shm=1 }
+ sql1 { SELECT * FROM t1 }
+ } {a b c d e f g h i j}
+
+ do_test 1.2.3 {
+ code1 { db close }
+ file attributes test.db-shm -permissions rw-r--r--
+ hexio_write test.db-shm 0 01020304
+ file attributes test.db-shm -permissions r--r--r--
+ code1 { sqlite3 db file:test.db?readonly_shm=1 }
+ csql1 { SELECT * FROM t1 }
+ } {1 {attempt to write a readonly database}}
+ do_test 1.2.4 {
+ code1 { sqlite3_extended_errcode db }
+ } {SQLITE_READONLY_RECOVERY}
+
+ do_test 1.2.5 {
+ file attributes test.db-shm -permissions rw-r--r--
+ code2 { sqlite3 db2 test.db }
+ sql2 "SELECT * FROM t1"
+ } {a b c d e f g h i j}
+ file attributes test.db-shm -permissions r--r--r--
+ do_test 1.2.6 { sql1 "SELECT * FROM t1" } {a b c d e f g h i j}
+
+ do_test 1.2.7 {
+ sql2 {
+ PRAGMA wal_checkpoint;
+ INSERT INTO t1 VALUES('k', 'l');
+ }
+ set {} {}
+ } {}
+ do_test 1.2.8 { sql1 "SELECT * FROM t1" } {a b c d e f g h i j k l}
+
+ # Now check that if the readonly_shm option is not supplied, or if it
+ # is set to zero, it is not possible to connect to the database without
+ # read-write access to the shm.
+ do_test 1.3.1 {
+ code1 { db close }
+ code1 { sqlite3 db test.db }
+ csql1 { SELECT * FROM t1 }
+ } {1 {unable to open database file}}
+
+ # Also test that if the -shm file can be opened for read/write access,
+ # it is not if readonly_shm=1 is present in the URI.
+ do_test 1.3.2.1 {
+ code1 { db close }
+ code2 { db2 close }
+ file exists test.db-shm
+ } {0}
+ do_test 1.3.2.2 {
+ code1 { sqlite3 db file:test.db?readonly_shm=1 }
+ csql1 { SELECT * FROM sqlite_master }
+ } {1 {unable to open database file}}
+ do_test 1.3.2.3 {
+ code1 { db close }
+ close [open test.db-shm w]
+ file attributes test.db-shm -permissions r--r--r--
+ code1 { sqlite3 db file:test.db?readonly_shm=1 }
+ csql1 { SELECT * FROM t1 }
+ } {1 {attempt to write a readonly database}}
+ do_test 1.3.2.4 {
+ code1 { sqlite3_extended_errcode db }
+ } {SQLITE_READONLY_RECOVERY}
+
+ #-----------------------------------------------------------------------
+ # Test cases 1.4.* check that checkpoints and log wraps don't prevent
+ # read-only connections from reading the database.
+ do_test 1.4.1 {
+ code1 { db close }
+ forcedelete test.db-shm
+ file exists test.db-shm
+ } {0}
+
+ # Open one read-only and one read-write connection. Write some data
+ # and then run a checkpoint using the read-write connection. Then
+ # check the read-only connection can still read.
+ do_test 1.4.2 {
+ code1 { sqlite3 db file:test.db?readonly_shm=1 }
+ code2 { sqlite3 db2 test.db }
+ csql2 {
+ INSERT INTO t1 VALUES(1, 2);
+ INSERT INTO t1 VALUES(3, 4);
+ INSERT INTO t1 VALUES(5, 6);
+ PRAGMA wal_checkpoint;
+ }
+ } {0 {0 3 3}}
+ do_test 1.4.3 {
+ csql1 { SELECT * FROM t1 }
+ } {0 {a b c d e f g h i j k l 1 2 3 4 5 6}}
+
+ # Using the read-write connection, open a transaction and write lots
+ # of data - causing a cache spill and a log wrap. Then check that the
+ # read-only connection can still read the database.
+ do_test 1.4.4.1 {
+ csql2 {
+ PRAGMA cache_size = 10;
+ BEGIN;
+ CREATE TABLE t2(x, y);
+ INSERT INTO t2 VALUES('abc', 'xyz');
+ INSERT INTO t2 SELECT x||y, y||x FROM t2;
+ INSERT INTO t2 SELECT x||y, y||x FROM t2;
+ INSERT INTO t2 SELECT x||y, y||x FROM t2;
+ INSERT INTO t2 SELECT x||y, y||x FROM t2;
+ INSERT INTO t2 SELECT x||y, y||x FROM t2;
+ INSERT INTO t2 SELECT x||y, y||x FROM t2;
+ INSERT INTO t2 SELECT x||y, y||x FROM t2;
+ INSERT INTO t2 SELECT x||y, y||x FROM t2;
+ INSERT INTO t2 SELECT x||y, y||x FROM t2;
+ }
+ file size test.db-wal
+ } {147800}
+ do_test 1.4.4.2 {
+ csql1 { SELECT * FROM t1 }
+ } {0 {a b c d e f g h i j k l 1 2 3 4 5 6}}
+ do_test 1.4.4.3 {
+ csql2 COMMIT
+ csql1 { SELECT count(*) FROM t2 }
+ } {0 512}
+ do_test 1.4.5 {
+ code2 { db2 close }
+ code1 { db close }
+ } {}
+}
+
+forcedelete test.db
+
+#-----------------------------------------------------------------------
+# Test cases 2.* check that a read-only connection may read the
+# database file while a checkpoint operation is ongoing.
+#
+do_multiclient_test tn {
+ # Do not run tests with the connections in the same process.
+ #
+ if {$tn==2} continue
+
+ # Close all connections and delete the database.
+ #
+ code1 { db close }
+ code2 { db2 close }
+ code3 { db3 close }
+ forcedelete test.db
+ forcedelete walro
+
+ foreach c {code1 code2 code3} {
+ $c {
+ sqlite3_shutdown
+ sqlite3_config_uri 1
+ }
+ }
+
+ proc tv_hook {x file args} {
+ if {[file tail $file]=="test.db-wal"} {
+ do_test 2.1.2 {
+ code2 { sqlite3 db2 file:test.db?readonly_shm=1 }
+ csql2 { SELECT count(*) FROM t2 }
+ } {0 4}
+ do_test 2.1.3 {
+ code2 { db2 close }
+ } {}
+ }
+ }
+
+ do_test 2.1.1 {
+ testvfs tv -default 1 -fullshm 1
+ tv script tv_hook
+ tv filter {}
+ code1 { sqlite3 db test.db }
+ csql1 {
+ PRAGMA auto_vacuum = 0;
+ PRAGMA journal_mode = WAL;
+ BEGIN;
+ CREATE TABLE t2(x, y);
+ INSERT INTO t2 VALUES('abc', 'xyz');
+ INSERT INTO t2 SELECT x||y, y||x FROM t2;
+ INSERT INTO t2 SELECT x||y, y||x FROM t2;
+ COMMIT;
+ }
+ } {0 wal}
+
+ tv filter xSync
+ set res [csql1 { PRAGMA wal_checkpoint }]
+ do_test 2.1.4 { set res } {0 {0 2 2}}
+
+ do_test 2.1.5 {
+ code1 { db close }
+ code1 { tv delete }
+ } {}
+}
+
+finish_test
diff --git a/lang/sql/sqlite/test/walshared.test b/lang/sql/sqlite/test/walshared.test
index 73a3fb8b..fbbdeb4d 100644
--- a/lang/sql/sqlite/test/walshared.test
+++ b/lang/sql/sqlite/test/walshared.test
@@ -60,4 +60,3 @@ do_test walshared-1.4 {
sqlite3_enable_shared_cache $::enable_shared_cache
finish_test
-
diff --git a/lang/sql/sqlite/test/walslow.test b/lang/sql/sqlite/test/walslow.test
index d7269528..83f29228 100644
--- a/lang/sql/sqlite/test/walslow.test
+++ b/lang/sql/sqlite/test/walslow.test
@@ -21,7 +21,7 @@ ifcapable !wal {finish_test ; return }
proc reopen_db {} {
catch { db close }
- file delete -force test.db test.db-wal
+ forcedelete test.db test.db-wal
sqlite3 db test.db
execsql { PRAGMA journal_mode = wal }
}
@@ -53,9 +53,9 @@ for {set seed 1} {$seed<10} {incr seed} {
} {ok}
do_test walslow-1.seed=$seed.$iTest.3 {
- file delete -force testX.db testX.db-wal
- file copy test.db testX.db
- file copy test.db-wal testX.db-wal
+ forcedelete testX.db testX.db-wal
+ copy_file test.db testX.db
+ copy_file test.db-wal testX.db-wal
sqlite3 db2 testX.db
execsql { PRAGMA journal_mode = WAL } db2
diff --git a/lang/sql/sqlite/test/walthread.test b/lang/sql/sqlite/test/walthread.test
index 9817c0e0..6249ce11 100644
--- a/lang/sql/sqlite/test/walthread.test
+++ b/lang/sql/sqlite/test/walthread.test
@@ -129,7 +129,7 @@ proc do_thread_test {args} {
puts "Running $P(testname) for $P(seconds) seconds..."
catch { db close }
- file delete -force test.db test.db-journal test.db-wal
+ forcedelete test.db test.db-journal test.db-wal
sqlite3 db test.db
eval $P(init)
@@ -277,8 +277,8 @@ do_thread_test2 walthread-1 -seconds $seconds(walthread-1) -init {
proc write_transaction {} {
db eval {
BEGIN;
- INSERT INTO t1 VALUES(randomblob(100));
- INSERT INTO t1 VALUES(randomblob(100));
+ INSERT INTO t1 VALUES(randomblob(101 + $::E(pid)));
+ INSERT INTO t1 VALUES(randomblob(101 + $::E(pid)));
INSERT INTO t1 SELECT md5sum(x) FROM t1;
COMMIT;
}
@@ -508,12 +508,12 @@ do_thread_test walthread-5 -seconds $seconds(walthread-5) -init {
COMMIT;
}
- file copy -force test.db-wal bak.db-wal
- file copy -force test.db bak.db
+ forcecopy test.db-wal bak.db-wal
+ forcecopy test.db bak.db
db close
- file copy -force bak.db-wal test.db-wal
- file copy -force bak.db test.db
+ forcecopy bak.db-wal test.db-wal
+ forcecopy bak.db test.db
if {[file size test.db-wal] < [log_file_size [expr 64*1024] 1024]} {
error "Somehow failed to create a large log file"
diff --git a/lang/sql/sqlite/test/where.test b/lang/sql/sqlite/test/where.test
index 9145bcc7..a50fe7eb 100644
--- a/lang/sql/sqlite/test/where.test
+++ b/lang/sql/sqlite/test/where.test
@@ -65,9 +65,9 @@ proc count sql {
do_test where-1.1.1 {
count {SELECT x, y, w FROM t1 WHERE w=10}
} {3 121 10 3}
-do_test where-1.1.2 {
- set sqlite_query_plan
-} {t1 i1w}
+do_eqp_test where-1.1.2 {
+ SELECT x, y, w FROM t1 WHERE w=10
+} {*SEARCH TABLE t1 USING INDEX i1w (w=?)*}
do_test where-1.1.3 {
db status step
} {0}
@@ -77,15 +77,15 @@ do_test where-1.1.4 {
do_test where-1.1.5 {
db status step
} {99}
-do_test where-1.1.6 {
- set sqlite_query_plan
-} {t1 {}}
+do_eqp_test where-1.1.6 {
+ SELECT x, y, w FROM t1 WHERE +w=10
+} {*SCAN TABLE t1*}
do_test where-1.1.7 {
count {SELECT x, y, w AS abc FROM t1 WHERE abc=10}
} {3 121 10 3}
-do_test where-1.1.8 {
- set sqlite_query_plan
-} {t1 i1w}
+do_eqp_test where-1.1.8 {
+ SELECT x, y, w AS abc FROM t1 WHERE abc=10
+} {*SEARCH TABLE t1 USING INDEX i1w (w=?)*}
do_test where-1.1.9 {
db status step
} {0}
@@ -104,21 +104,21 @@ do_test where-1.3.2 {
do_test where-1.4.1 {
count {SELECT w, x, y FROM t1 WHERE 11=w AND x>2}
} {11 3 144 3}
-do_test where-1.4.2 {
- set sqlite_query_plan
-} {t1 i1w}
+do_eqp_test where-1.4.2 {
+ SELECT w, x, y FROM t1 WHERE 11=w AND x>2
+} {*SEARCH TABLE t1 USING INDEX i1w (w=?)*}
do_test where-1.4.3 {
count {SELECT w AS a, x AS b, y FROM t1 WHERE 11=a AND b>2}
} {11 3 144 3}
-do_test where-1.4.4 {
- set sqlite_query_plan
-} {t1 i1w}
+do_eqp_test where-1.4.4 {
+ SELECT w AS a, x AS b, y FROM t1 WHERE 11=a AND b>2
+} {*SEARCH TABLE t1 USING INDEX i1w (w=?)*}
do_test where-1.5 {
count {SELECT x, y FROM t1 WHERE y<200 AND w=11 AND x>2}
} {3 144 3}
-do_test where-1.5.2 {
- set sqlite_query_plan
-} {t1 i1w}
+do_eqp_test where-1.5.2 {
+ SELECT x, y FROM t1 WHERE y<200 AND w=11 AND x>2
+} {*SEARCH TABLE t1 USING INDEX i1w (w=?)*}
do_test where-1.6 {
count {SELECT x, y FROM t1 WHERE y<200 AND x>2 AND w=11}
} {3 144 3}
@@ -128,13 +128,12 @@ do_test where-1.7 {
do_test where-1.8 {
count {SELECT x, y FROM t1 WHERE w>10 AND y=144 AND x=3}
} {3 144 3}
-do_test where-1.8.2 {
- set sqlite_query_plan
-} {t1 i1xy}
-do_test where-1.8.3 {
- count {SELECT x, y FROM t1 WHERE y=144 AND x=3}
- set sqlite_query_plan
-} {{} i1xy}
+do_eqp_test where-1.8.2 {
+ SELECT x, y FROM t1 WHERE w>10 AND y=144 AND x=3
+} {*SEARCH TABLE t1 USING INDEX i1xy (x=? AND y=?)*}
+do_eqp_test where-1.8.3 {
+ SELECT x, y FROM t1 WHERE y=144 AND x=3
+} {*SEARCH TABLE t1 USING COVERING INDEX i1xy (x=? AND y=?)*}
do_test where-1.9 {
count {SELECT x, y FROM t1 WHERE y=144 AND w>10 AND x=3}
} {3 144 3}
@@ -379,11 +378,26 @@ ifcapable subquery {
SELECT * FROM t1 WHERE rowid+0 IN (1,2,3,1234) order by 1;
}
} {1 0 4 2 1 9 3 1 16 102}
- do_test where-5.3 {
+ do_test where-5.3a {
count {
SELECT * FROM t1 WHERE w IN (-1,1,2,3) order by 1;
}
- } {1 0 4 2 1 9 3 1 16 14}
+ } {1 0 4 2 1 9 3 1 16 13}
+ do_test where-5.3b {
+ count {
+ SELECT * FROM t1 WHERE w IN (3,-1,1,2) order by 1;
+ }
+ } {1 0 4 2 1 9 3 1 16 13}
+ do_test where-5.3c {
+ count {
+ SELECT * FROM t1 WHERE w IN (3,2,-1,1,2) order by 1;
+ }
+ } {1 0 4 2 1 9 3 1 16 13}
+ do_test where-5.3d {
+ count {
+ SELECT * FROM t1 WHERE w IN (-1,1,2,3) order by 1 DESC;
+ }
+ } {3 1 16 2 1 9 1 0 4 12}
do_test where-5.4 {
count {
SELECT * FROM t1 WHERE w+0 IN (-1,1,2,3) order by 1;
@@ -452,6 +466,30 @@ ifcapable subquery {
SELECT * FROM t1 WHERE x IN (1,7) AND y IN (9,16) ORDER BY 1;
}
} {2 1 9 3 1 16 11}
+ do_test where-5.100 {
+ db eval {
+ SELECT w, x, y FROM t1 WHERE x IN (1,5) AND y IN (9,8,3025,1000,3969)
+ ORDER BY x, y
+ }
+ } {2 1 9 54 5 3025 62 5 3969}
+ do_test where-5.101 {
+ db eval {
+ SELECT w, x, y FROM t1 WHERE x IN (1,5) AND y IN (9,8,3025,1000,3969)
+ ORDER BY x DESC, y DESC
+ }
+ } {62 5 3969 54 5 3025 2 1 9}
+ do_test where-5.102 {
+ db eval {
+ SELECT w, x, y FROM t1 WHERE x IN (1,5) AND y IN (9,8,3025,1000,3969)
+ ORDER BY x DESC, y
+ }
+ } {54 5 3025 62 5 3969 2 1 9}
+ do_test where-5.103 {
+ db eval {
+ SELECT w, x, y FROM t1 WHERE x IN (1,5) AND y IN (9,8,3025,1000,3969)
+ ORDER BY x, y DESC
+ }
+ } {2 1 9 62 5 3969 54 5 3025}
}
# This procedure executes the SQL. Then it checks to see if the OP_Sort
@@ -511,11 +549,16 @@ do_test where-6.7 {
}
} {1 100 4 2 99 9 3 98 16 nosort}
ifcapable subquery {
- do_test where-6.8 {
+ do_test where-6.8a {
cksort {
SELECT * FROM t3 WHERE a IN (3,5,7,1,9,4,2) ORDER BY a LIMIT 3
}
- } {1 100 4 2 99 9 3 98 16 sort}
+ } {1 100 4 2 99 9 3 98 16 nosort}
+ do_test where-6.8b {
+ cksort {
+ SELECT * FROM t3 WHERE a IN (3,5,7,1,9,4,2) ORDER BY a DESC LIMIT 3
+ }
+ } {9 92 100 7 94 64 5 96 36 nosort}
}
do_test where-6.9.1 {
cksort {
@@ -561,7 +604,7 @@ do_test where-6.9.7 {
cksort {
SELECT * FROM t3 WHERE a=1 AND c>0 ORDER BY c,a LIMIT 3
}
-} {1 100 4 sort}
+} {1 100 4 nosort}
do_test where-6.9.8 {
cksort {
SELECT * FROM t3 WHERE a=1 AND c>0 ORDER BY a DESC, c ASC LIMIT 3
@@ -1079,41 +1122,44 @@ do_test where-13.12 {
# When optimizing out ORDER BY clauses, make sure that trailing terms
# of the ORDER BY clause do not reference other tables in a join.
#
+if {[permutation] != "no_optimization"} {
do_test where-14.1 {
execsql {
- CREATE TABLE t8(a INTEGER PRIMARY KEY, b TEXT UNIQUE);
- INSERT INTO t8 VALUES(1,'one');
- INSERT INTO t8 VALUES(4,'four');
+ CREATE TABLE t8(a INTEGER PRIMARY KEY, b TEXT UNIQUE, c CHAR(100));
+ INSERT INTO t8(a,b) VALUES(1,'one');
+ INSERT INTO t8(a,b) VALUES(4,'four');
}
cksort {
SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.a, y.b
}
-} {1/4 1/1 4/4 4/1 sort}
+} {1/4 1/1 4/4 4/1 nosort}
do_test where-14.2 {
cksort {
SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.a, y.b DESC
}
-} {1/1 1/4 4/1 4/4 sort}
+} {1/1 1/4 4/1 4/4 nosort}
do_test where-14.3 {
cksort {
SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.a, x.b
}
-} {1/1 1/4 4/1 4/4 nosort}
+} {1/4 1/1 4/4 4/1 nosort}
do_test where-14.4 {
cksort {
SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.a, x.b DESC
}
-} {1/1 1/4 4/1 4/4 nosort}
+} {1/4 1/1 4/4 4/1 nosort}
do_test where-14.5 {
+ # This test case changed from "nosort" to "sort". See ticket 2a5629202f.
cksort {
SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.b, x.a||x.b
}
-} {4/1 4/4 1/1 1/4 nosort}
+} {/4/[14] 4/[14] 1/[14] 1/[14] sort/}
do_test where-14.6 {
+ # This test case changed from "nosort" to "sort". See ticket 2a5629202f.
cksort {
SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.b, x.a||x.b DESC
}
-} {4/1 4/4 1/1 1/4 nosort}
+} {/4/[14] 4/[14] 1/[14] 1/[14] sort/}
do_test where-14.7 {
cksort {
SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.b, y.a||y.b
@@ -1128,7 +1174,7 @@ do_test where-14.7.2 {
cksort {
SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.b, x.a, x.a||x.b
}
-} {4/1 4/4 1/1 1/4 nosort}
+} {4/4 4/1 1/4 1/1 nosort}
do_test where-14.8 {
cksort {
SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.b, y.a||y.b DESC
@@ -1154,6 +1200,7 @@ do_test where-14.12 {
SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.b, y.a||x.b DESC
}
} {4/4 4/1 1/4 1/1 sort}
+} ;# {permutation != "no_optimization"}
# Ticket #2445.
#
@@ -1257,4 +1304,33 @@ do_test where-17.5 {
}
} {42 1 43 1}
+# Ticket [be84e357c035d068135f20bcfe82761bbf95006b] 2013-09-03
+# Segfault during query involving LEFT JOIN column in the ORDER BY clause.
+#
+do_execsql_test where-18.1 {
+ CREATE TABLE t181(a);
+ CREATE TABLE t182(b,c);
+ INSERT INTO t181 VALUES(1);
+ SELECT DISTINCT a FROM t181 LEFT JOIN t182 ON a=b ORDER BY c IS NULL;
+} {1}
+do_execsql_test where-18.2 {
+ SELECT DISTINCT a FROM t181 LEFT JOIN t182 ON a=b ORDER BY +c;
+} {1}
+do_execsql_test where-18.3 {
+ SELECT DISTINCT a FROM t181 LEFT JOIN t182 ON a=b ORDER BY c;
+} {1}
+do_execsql_test where-18.4 {
+ INSERT INTO t181 VALUES(1),(1),(1),(1);
+ SELECT DISTINCT a FROM t181 LEFT JOIN t182 ON a=b ORDER BY +c;
+} {1}
+do_execsql_test where-18.5 {
+ INSERT INTO t181 VALUES(2);
+ SELECT DISTINCT a FROM t181 LEFT JOIN t182 ON a=b ORDER BY c IS NULL, +a;
+} {1 2}
+do_execsql_test where-18.6 {
+ INSERT INTO t181 VALUES(2);
+ SELECT DISTINCT a FROM t181 LEFT JOIN t182 ON a=b ORDER BY +a, +c IS NULL;
+} {1 2}
+
+
finish_test
diff --git a/lang/sql/sqlite/test/where2.test b/lang/sql/sqlite/test/where2.test
index d61c0897..45ea486d 100644
--- a/lang/sql/sqlite/test/where2.test
+++ b/lang/sql/sqlite/test/where2.test
@@ -66,14 +66,24 @@ proc cksort {sql} {
# This procedure executes the SQL. Then it appends to the result the
# "sort" or "nosort" keyword (as in the cksort procedure above) then
-# it appends the ::sqlite_query_plan variable.
+# it appends the name 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
- return [concat $data $::sqlite_query_plan]
+ set eqp [execsql "EXPLAIN QUERY PLAN $sql"]
+ # puts eqp=$eqp
+ foreach {a b c x} $eqp {
+ if {[regexp { TABLE (\w+ AS )?(\w+) USING.* INDEX (\w+)\y} \
+ $x all as tab idx]} {
+ lappend data $tab $idx
+ } elseif {[regexp { TABLE (\w+ AS )?(\w+)\y} $x all as tab]} {
+ lappend data $tab *
+ }
+ }
+ return $data
}
@@ -167,24 +177,54 @@ ifcapable subquery {
}
} {99 6 10000 10006 100 6 10201 10207 sort t1 i1zyx}
}
- do_test where2-4.6 {
+ do_test where2-4.6a {
+ queryplan {
+ SELECT * FROM t1
+ WHERE x IN (1,2,3,4,5,6,7,8)
+ AND y IN (10000,10001,10002,10003,10004,10005)
+ ORDER BY x
+ }
+ } {99 6 10000 10006 nosort t1 i1xy}
+ do_test where2-4.6b {
+ queryplan {
+ SELECT * FROM t1
+ WHERE x IN (1,2,3,4,5,6,7,8)
+ AND y IN (10000,10001,10002,10003,10004,10005)
+ ORDER BY x DESC
+ }
+ } {99 6 10000 10006 nosort t1 i1xy}
+ do_test where2-4.6c {
+ queryplan {
+ SELECT * FROM t1
+ WHERE x IN (1,2,3,4,5,6,7,8)
+ AND y IN (10000,10001,10002,10003,10004,10005)
+ ORDER BY x, y
+ }
+ } {99 6 10000 10006 nosort t1 i1xy}
+ do_test where2-4.6d {
queryplan {
SELECT * FROM t1
WHERE x IN (1,2,3,4,5,6,7,8)
AND y IN (10000,10001,10002,10003,10004,10005)
- ORDER BY 2
+ ORDER BY x, y DESC
}
} {99 6 10000 10006 sort t1 i1xy}
# Duplicate entires on the RHS of an IN operator do not cause duplicate
# output rows.
#
- do_test where2-4.6 {
+ do_test where2-4.6x {
queryplan {
SELECT * FROM t1 WHERE z IN (10207,10006,10006,10207)
ORDER BY w
}
} {99 6 10000 10006 100 6 10201 10207 sort t1 i1zyx}
+ do_test where2-4.6y {
+ queryplan {
+ SELECT * FROM t1 WHERE z IN (10207,10006,10006,10207)
+ ORDER BY w DESC
+ }
+ } {100 6 10201 10207 99 6 10000 10006 sort t1 i1zyx}
ifcapable compound {
do_test where2-4.7 {
queryplan {
@@ -207,11 +247,16 @@ do_test where2-5.1 {
} {99 6 10000 10006 nosort t1 i1w}
ifcapable subquery {
- do_test where2-5.2 {
+ do_test where2-5.2a {
queryplan {
SELECT * FROM t1 WHERE w IN (99) ORDER BY w
}
- } {99 6 10000 10006 sort t1 i1w}
+ } {99 6 10000 10006 nosort t1 i1w}
+ do_test where2-5.2b {
+ queryplan {
+ SELECT * FROM t1 WHERE w IN (99) ORDER BY w DESC
+ }
+ } {99 6 10000 10006 nosort t1 i1w}
}
# Verify that OR clauses get translated into IN operators.
@@ -238,12 +283,12 @@ do_test where2-6.3 {
queryplan {
SELECT * FROM t1 WHERE w=99 OR w=100 OR 6=+w ORDER BY +w
}
-} {6 2 49 51 99 6 10000 10006 100 6 10201 10207 sort t1 {}}
+} {6 2 49 51 99 6 10000 10006 100 6 10201 10207 sort t1 *}
do_test where2-6.4 {
queryplan {
SELECT * FROM t1 WHERE w=99 OR +w=100 OR 6=w ORDER BY +w
}
-} {6 2 49 51 99 6 10000 10006 100 6 10201 10207 sort t1 {}}
+} {6 2 49 51 99 6 10000 10006 100 6 10201 10207 sort t1 *}
set ::idx {}
ifcapable subquery {set ::idx i1zyx}
@@ -262,14 +307,16 @@ do_test where2-6.6 {
}
} [list 1 0 4 4 2 1 9 10 sort a i1w b $::idx]
+if {[permutation] != "no_optimization"} {
+
# Ticket #2249. Make sure the OR optimization is not attempted if
# comparisons between columns of different affinities are needed.
#
do_test where2-6.7 {
execsql {
- CREATE TABLE t2249a(a TEXT UNIQUE);
+ CREATE TABLE t2249a(a TEXT UNIQUE, x CHAR(100));
CREATE TABLE t2249b(b INTEGER);
- INSERT INTO t2249a VALUES('0123');
+ INSERT INTO t2249a(a) VALUES('0123');
INSERT INTO t2249b VALUES(123);
}
queryplan {
@@ -277,56 +324,56 @@ do_test where2-6.7 {
-- will attempt to convert to NUMERIC before the comparison.
-- They will thus compare equal.
--
- SELECT * FROM t2249b CROSS JOIN t2249a WHERE a=b;
+ SELECT b,a FROM t2249b CROSS JOIN t2249a WHERE a=b;
}
-} {123 0123 nosort t2249b {} t2249a {}}
+} {123 0123 nosort t2249b * t2249a sqlite_autoindex_t2249a_1}
do_test where2-6.9 {
queryplan {
-- The + operator removes affinity from the rhs. No conversions
-- occur and the comparison is false. The result is an empty set.
--
- SELECT * FROM t2249b CROSS JOIN t2249a WHERE a=+b;
+ SELECT b,a FROM t2249b CROSS JOIN t2249a WHERE a=+b;
}
-} {nosort t2249b {} {} sqlite_autoindex_t2249a_1}
+} {nosort t2249b * t2249a sqlite_autoindex_t2249a_1}
do_test where2-6.9.2 {
# The same thing but with the expression flipped around.
queryplan {
- SELECT * FROM t2249b CROSS JOIN t2249a WHERE +b=a
+ SELECT b,a FROM t2249b CROSS JOIN t2249a WHERE +b=a
}
-} {nosort t2249b {} {} sqlite_autoindex_t2249a_1}
+} {nosort t2249b * t2249a sqlite_autoindex_t2249a_1}
do_test where2-6.10 {
queryplan {
-- Use + on both sides of the comparison to disable indices
-- completely. Make sure we get the same result.
--
- SELECT * FROM t2249b CROSS JOIN t2249a WHERE +a=+b;
+ SELECT b,a FROM t2249b CROSS JOIN t2249a WHERE +a=+b;
}
-} {nosort t2249b {} t2249a {}}
+} {nosort t2249b * t2249a sqlite_autoindex_t2249a_1}
do_test where2-6.11 {
# This will not attempt the OR optimization because of the a=b
# comparison.
queryplan {
- SELECT * FROM t2249b CROSS JOIN t2249a WHERE a=b OR a='hello';
+ SELECT b,a FROM t2249b CROSS JOIN t2249a WHERE a=b OR a='hello';
}
-} {123 0123 nosort t2249b {} t2249a {}}
+} {123 0123 nosort t2249b * t2249a sqlite_autoindex_t2249a_1}
do_test where2-6.11.2 {
# Permutations of the expression terms.
queryplan {
- SELECT * FROM t2249b CROSS JOIN t2249a WHERE b=a OR a='hello';
+ SELECT b,a FROM t2249b CROSS JOIN t2249a WHERE b=a OR a='hello';
}
-} {123 0123 nosort t2249b {} t2249a {}}
+} {123 0123 nosort t2249b * t2249a sqlite_autoindex_t2249a_1}
do_test where2-6.11.3 {
# Permutations of the expression terms.
queryplan {
- SELECT * FROM t2249b CROSS JOIN t2249a WHERE 'hello'=a OR b=a;
+ SELECT b,a FROM t2249b CROSS JOIN t2249a WHERE 'hello'=a OR b=a;
}
-} {123 0123 nosort t2249b {} t2249a {}}
+} {123 0123 nosort t2249b * t2249a sqlite_autoindex_t2249a_1}
do_test where2-6.11.4 {
# Permutations of the expression terms.
queryplan {
- SELECT * FROM t2249b CROSS JOIN t2249a WHERE a='hello' OR b=a;
+ SELECT b,a FROM t2249b CROSS JOIN t2249a WHERE a='hello' OR b=a;
}
-} {123 0123 nosort t2249b {} t2249a {}}
+} {123 0123 nosort t2249b * t2249a sqlite_autoindex_t2249a_1}
ifcapable explain&&subquery {
# These tests are not run if subquery support is not included in the
# build. This is because these tests test the "a = 1 OR a = 2" to
@@ -338,41 +385,41 @@ ifcapable explain&&subquery {
# the OR optimization to be used again. The result is now an empty
# set, the same as in where2-6.9.
queryplan {
- SELECT * FROM t2249b CROSS JOIN t2249a WHERE a=+b OR a='hello';
+ SELECT b,a FROM t2249b CROSS JOIN t2249a WHERE a=+b OR a='hello';
}
- } {nosort t2249b {} {} sqlite_autoindex_t2249a_1}
+ } {nosort t2249b * t2249a sqlite_autoindex_t2249a_1}
do_test where2-6.12.2 {
# In this case, the +b disables the affinity conflict and allows
# the OR optimization to be used again. The result is now an empty
# set, the same as in where2-6.9.
queryplan {
- SELECT * FROM t2249b CROSS JOIN t2249a WHERE a='hello' OR +b=a;
+ SELECT b,a FROM t2249b CROSS JOIN t2249a WHERE a='hello' OR +b=a;
}
- } {nosort t2249b {} {} sqlite_autoindex_t2249a_1}
+ } {nosort t2249b * t2249a sqlite_autoindex_t2249a_1}
do_test where2-6.12.3 {
# In this case, the +b disables the affinity conflict and allows
# the OR optimization to be used again. The result is now an empty
# set, the same as in where2-6.9.
queryplan {
- SELECT * FROM t2249b CROSS JOIN t2249a WHERE +b=a OR a='hello';
+ SELECT b,a FROM t2249b CROSS JOIN t2249a WHERE +b=a OR a='hello';
}
- } {nosort t2249b {} {} sqlite_autoindex_t2249a_1}
+ } {nosort t2249b * t2249a sqlite_autoindex_t2249a_1}
do_test where2-6.13 {
# The addition of +a on the second term disabled the OR optimization.
# But we should still get the same empty-set result as in where2-6.9.
queryplan {
- SELECT * FROM t2249b CROSS JOIN t2249a WHERE a=+b OR +a='hello';
+ SELECT b,a FROM t2249b CROSS JOIN t2249a WHERE a=+b OR +a='hello';
}
- } {nosort t2249b {} t2249a {}}
+ } {nosort t2249b * t2249a sqlite_autoindex_t2249a_1}
}
# Variations on the order of terms in a WHERE clause in order
# to make sure the OR optimizer can recognize them all.
do_test where2-6.20 {
queryplan {
- SELECT * FROM t2249a x CROSS JOIN t2249a y WHERE x.a=y.a
+ SELECT x.a, y.a FROM t2249a x CROSS JOIN t2249a y WHERE x.a=y.a
}
-} {0123 0123 nosort x {} {} sqlite_autoindex_t2249a_1}
+} {0123 0123 nosort x sqlite_autoindex_t2249a_1 y sqlite_autoindex_t2249a_1}
ifcapable explain&&subquery {
# These tests are not run if subquery support is not included in the
# build. This is because these tests test the "a = 1 OR a = 2" to
@@ -381,19 +428,22 @@ ifcapable explain&&subquery {
#
do_test where2-6.21 {
queryplan {
- SELECT * FROM t2249a x CROSS JOIN t2249a y WHERE x.a=y.a OR y.a='hello'
+ SELECT x.a,y.a FROM t2249a x CROSS JOIN t2249a y
+ WHERE x.a=y.a OR y.a='hello'
}
- } {0123 0123 nosort x {} {} sqlite_autoindex_t2249a_1}
+ } {0123 0123 nosort x sqlite_autoindex_t2249a_1 y sqlite_autoindex_t2249a_1}
do_test where2-6.22 {
queryplan {
- SELECT * FROM t2249a x CROSS JOIN t2249a y WHERE y.a=x.a OR y.a='hello'
+ SELECT x.a,y.a FROM t2249a x CROSS JOIN t2249a y
+ WHERE y.a=x.a OR y.a='hello'
}
- } {0123 0123 nosort x {} {} sqlite_autoindex_t2249a_1}
+ } {0123 0123 nosort x sqlite_autoindex_t2249a_1 y sqlite_autoindex_t2249a_1}
do_test where2-6.23 {
queryplan {
- SELECT * FROM t2249a x CROSS JOIN t2249a y WHERE y.a='hello' OR x.a=y.a
+ SELECT x.a,y.a FROM t2249a x CROSS JOIN t2249a y
+ WHERE y.a='hello' OR x.a=y.a
}
- } {0123 0123 nosort x {} {} sqlite_autoindex_t2249a_1}
+ } {0123 0123 nosort x sqlite_autoindex_t2249a_1 y sqlite_autoindex_t2249a_1}
}
# Unique queries (queries that are guaranteed to return only a single
@@ -429,6 +479,8 @@ do_test where2-7.4 {
}
} {1 2 3 2 3 nosort}
+} ;# if {[permutation] != "no_optimization"}
+
# Ticket #1807. Using IN constrains on multiple columns of
# a multi-column index.
#
@@ -650,5 +702,18 @@ do_test where2-11.4 {
}
} {4 8 10}
+# Verify that the OR clause is used in an outer loop even when
+# the OR clause scores slightly better on an inner loop.
+if {[permutation] != "no_optimization"} {
+do_execsql_test where2-12.1 {
+ CREATE TABLE t12(x INTEGER PRIMARY KEY, y INT, z CHAR(100));
+ CREATE INDEX t12y ON t12(y);
+ EXPLAIN QUERY PLAN
+ SELECT a.x, b.x
+ FROM t12 AS a JOIN t12 AS b ON a.y=b.x
+ WHERE (b.x=$abc OR b.y=$abc);
+} {/.*SEARCH TABLE t12 AS b .*SEARCH TABLE t12 AS b .*/}
+}
+
finish_test
diff --git a/lang/sql/sqlite/test/where3.test b/lang/sql/sqlite/test/where3.test
index ab75fdec..8fa9fa78 100644
--- a/lang/sql/sqlite/test/where3.test
+++ b/lang/sql/sqlite/test/where3.test
@@ -103,12 +103,22 @@ ifcapable explain {
}
# This procedure executes the SQL. Then it appends
-# the ::sqlite_query_plan variable.
+# the names of the table and index used
#
proc queryplan {sql} {
set ::sqlite_sort_count 0
set data [execsql $sql]
- return [concat $data $::sqlite_query_plan]
+ set eqp [execsql "EXPLAIN QUERY PLAN $sql"]
+ # puts eqp=$eqp
+ foreach {a b c x} $eqp {
+ if {[regexp { TABLE (\w+ AS )?(\w+) USING.* INDEX (\w+)\y} \
+ $x all as tab idx]} {
+ lappend data $tab $idx
+ } elseif {[regexp { TABLE (\w+ AS )?(\w+)\y} $x all as tab]} {
+ lappend data $tab *
+ }
+ }
+ return $data
}
@@ -144,73 +154,73 @@ do_test where3-2.1 {
SELECT * FROM tA, tB, tC LEFT JOIN tD ON dpk=cx
WHERE cpk=bx AND bpk=ax
}
-} {tA {} tB * tC * tD *}
+} {tA * tB * tC * tD *}
do_test where3-2.1.1 {
queryplan {
SELECT * FROM tA, tB, tC LEFT JOIN tD ON cx=dpk
WHERE cpk=bx AND bpk=ax
}
-} {tA {} tB * tC * tD *}
+} {tA * tB * tC * tD *}
do_test where3-2.1.2 {
queryplan {
SELECT * FROM tA, tB, tC LEFT JOIN tD ON cx=dpk
WHERE bx=cpk AND bpk=ax
}
-} {tA {} tB * tC * tD *}
+} {tA * tB * tC * tD *}
do_test where3-2.1.3 {
queryplan {
SELECT * FROM tA, tB, tC LEFT JOIN tD ON cx=dpk
WHERE bx=cpk AND ax=bpk
}
-} {tA {} tB * tC * tD *}
+} {tA * tB * tC * tD *}
do_test where3-2.1.4 {
queryplan {
SELECT * FROM tA, tB, tC LEFT JOIN tD ON dpk=cx
WHERE bx=cpk AND ax=bpk
}
-} {tA {} tB * tC * tD *}
+} {tA * tB * tC * tD *}
do_test where3-2.1.5 {
queryplan {
SELECT * FROM tA, tB, tC LEFT JOIN tD ON dpk=cx
WHERE cpk=bx AND ax=bpk
}
-} {tA {} tB * tC * tD *}
+} {tA * tB * tC * tD *}
do_test where3-2.2 {
queryplan {
SELECT * FROM tA, tB, tC LEFT JOIN tD ON dpk=cx
WHERE cpk=bx AND apk=bx
}
-} {tB {} tA * tC * tD *}
+} {tB * tA * tC * tD *}
do_test where3-2.3 {
queryplan {
SELECT * FROM tA, tB, tC LEFT JOIN tD ON dpk=cx
WHERE cpk=bx AND apk=bx
}
-} {tB {} tA * tC * tD *}
+} {tB * tA * tC * tD *}
do_test where3-2.4 {
queryplan {
SELECT * FROM tA, tB, tC LEFT JOIN tD ON dpk=cx
WHERE apk=cx AND bpk=ax
}
-} {tC {} tA * tB * tD *}
+} {tC * tA * tB * tD *}
do_test where3-2.5 {
queryplan {
SELECT * FROM tA, tB, tC LEFT JOIN tD ON dpk=cx
WHERE cpk=ax AND bpk=cx
}
-} {tA {} tC * tB * tD *}
+} {tA * tC * tB * tD *}
do_test where3-2.6 {
queryplan {
SELECT * FROM tA, tB, tC LEFT JOIN tD ON dpk=cx
WHERE bpk=cx AND apk=bx
}
-} {tC {} tB * tA * tD *}
+} {tC * tB * tA * tD *}
do_test where3-2.7 {
queryplan {
SELECT * FROM tA, tB, tC LEFT JOIN tD ON dpk=cx
WHERE cpk=bx AND apk=cx
}
-} {tB {} tC * tA * tD *}
+} {tB * tC * tA * tD *}
# Ticket [13f033c865f878953]
# If the outer loop must be a full table scan, do not let ANALYZE trick
@@ -226,17 +236,24 @@ do_execsql_test where3-3.0 {
ANALYZE;
explain query plan SELECT * FROM t302, t301 WHERE t302.x=5 AND t301.a=t302.y;
} {
- 0 0 0 {SCAN TABLE t302 (~1 rows)}
- 0 1 1 {SEARCH TABLE t301 USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)}
+ 0 0 0 {SCAN TABLE t302}
+ 0 1 1 {SEARCH TABLE t301 USING INTEGER PRIMARY KEY (rowid=?)}
}
do_execsql_test where3-3.1 {
explain query plan
SELECT * FROM t301, t302 WHERE t302.x=5 AND t301.a=t302.y;
} {
- 0 0 1 {SCAN TABLE t302 (~1 rows)}
- 0 1 0 {SEARCH TABLE t301 USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)}
+ 0 0 1 {SCAN TABLE t302}
+ 0 1 0 {SEARCH TABLE t301 USING INTEGER PRIMARY KEY (rowid=?)}
}
+do_execsql_test where3-3.2 {
+ SELECT * FROM t301 WHERE c=3 AND a IS NULL;
+} {}
+do_execsql_test where3-3.3 {
+ SELECT * FROM t301 WHERE c=3 AND a IS NOT NULL;
+} {1 2 3}
+if 0 { # Query planner no longer does this
# Verify that when there are multiple tables in a join which must be
# full table scans that the query planner attempts put the table with
# the fewest number of output rows as the outer loop.
@@ -248,26 +265,27 @@ do_execsql_test where3-4.0 {
EXPLAIN QUERY PLAN
SELECT * FROM t400, t401, t402 WHERE t402.z GLOB 'abc*';
} {
- 0 0 2 {SCAN TABLE t402 (~500000 rows)}
- 0 1 0 {SCAN TABLE t400 (~1000000 rows)}
- 0 2 1 {SCAN TABLE t401 (~1000000 rows)}
+ 0 0 2 {SCAN TABLE t402}
+ 0 1 0 {SCAN TABLE t400}
+ 0 2 1 {SCAN TABLE t401}
}
do_execsql_test where3-4.1 {
EXPLAIN QUERY PLAN
SELECT * FROM t400, t401, t402 WHERE t401.r GLOB 'abc*';
} {
- 0 0 1 {SCAN TABLE t401 (~500000 rows)}
- 0 1 0 {SCAN TABLE t400 (~1000000 rows)}
- 0 2 2 {SCAN TABLE t402 (~1000000 rows)}
+ 0 0 1 {SCAN TABLE t401}
+ 0 1 0 {SCAN TABLE t400}
+ 0 2 2 {SCAN TABLE t402}
}
do_execsql_test where3-4.2 {
EXPLAIN QUERY PLAN
SELECT * FROM t400, t401, t402 WHERE t400.c GLOB 'abc*';
} {
- 0 0 0 {SCAN TABLE t400 (~500000 rows)}
- 0 1 1 {SCAN TABLE t401 (~1000000 rows)}
- 0 2 2 {SCAN TABLE t402 (~1000000 rows)}
+ 0 0 0 {SCAN TABLE t400}
+ 0 1 1 {SCAN TABLE t401}
+ 0 2 2 {SCAN TABLE t402}
}
+} ;# endif
# Verify that a performance regression encountered by firefox
# has been fixed.
@@ -298,8 +316,8 @@ do_execsql_test where3-5.0 {
AND bbb.parent = 4
ORDER BY bbb.title COLLATE NOCASE ASC;
} {
- 0 0 0 {SEARCH TABLE aaa USING INDEX aaa_333 (fk=?) (~10 rows)}
- 0 1 1 {SEARCH TABLE bbb USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)}
+ 0 0 0 {SEARCH TABLE aaa USING INDEX aaa_333 (fk=?)}
+ 0 1 1 {SEARCH TABLE bbb USING INTEGER PRIMARY KEY (rowid=?)}
0 0 0 {USE TEMP B-TREE FOR ORDER BY}
}
do_execsql_test where3-5.1 {
@@ -311,8 +329,8 @@ do_execsql_test where3-5.1 {
AND bbb.parent = 4
ORDER BY bbb.title COLLATE NOCASE ASC;
} {
- 0 0 0 {SEARCH TABLE aaa USING INDEX aaa_333 (fk=?) (~10 rows)}
- 0 1 1 {SEARCH TABLE aaa AS bbb USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)}
+ 0 0 0 {SEARCH TABLE aaa USING INDEX aaa_333 (fk=?)}
+ 0 1 1 {SEARCH TABLE aaa AS bbb USING INTEGER PRIMARY KEY (rowid=?)}
0 0 0 {USE TEMP B-TREE FOR ORDER BY}
}
do_execsql_test where3-5.2 {
@@ -324,8 +342,8 @@ do_execsql_test where3-5.2 {
AND bbb.parent = 4
ORDER BY bbb.title COLLATE NOCASE ASC;
} {
- 0 0 1 {SEARCH TABLE aaa USING INDEX aaa_333 (fk=?) (~10 rows)}
- 0 1 0 {SEARCH TABLE bbb USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)}
+ 0 0 1 {SEARCH TABLE aaa USING INDEX aaa_333 (fk=?)}
+ 0 1 0 {SEARCH TABLE bbb USING INTEGER PRIMARY KEY (rowid=?)}
0 0 0 {USE TEMP B-TREE FOR ORDER BY}
}
do_execsql_test where3-5.3 {
@@ -337,9 +355,135 @@ do_execsql_test where3-5.3 {
AND bbb.parent = 4
ORDER BY bbb.title COLLATE NOCASE ASC;
} {
- 0 0 1 {SEARCH TABLE aaa USING INDEX aaa_333 (fk=?) (~10 rows)}
- 0 1 0 {SEARCH TABLE aaa AS bbb USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)}
+ 0 0 1 {SEARCH TABLE aaa USING INDEX aaa_333 (fk=?)}
+ 0 1 0 {SEARCH TABLE aaa AS bbb USING INTEGER PRIMARY KEY (rowid=?)}
0 0 0 {USE TEMP B-TREE FOR ORDER BY}
}
+# Name resolution with NATURAL JOIN and USING
+#
+do_test where3-6.setup {
+ db eval {
+ CREATE TABLE t6w(a, w);
+ INSERT INTO t6w VALUES(1, 'w-one');
+ INSERT INTO t6w VALUES(2, 'w-two');
+ INSERT INTO t6w VALUES(9, 'w-nine');
+ CREATE TABLE t6x(a, x);
+ INSERT INTO t6x VALUES(1, 'x-one');
+ INSERT INTO t6x VALUES(3, 'x-three');
+ INSERT INTO t6x VALUES(9, 'x-nine');
+ CREATE TABLE t6y(a, y);
+ INSERT INTO t6y VALUES(1, 'y-one');
+ INSERT INTO t6y VALUES(4, 'y-four');
+ INSERT INTO t6y VALUES(9, 'y-nine');
+ CREATE TABLE t6z(a, z);
+ INSERT INTO t6z VALUES(1, 'z-one');
+ INSERT INTO t6z VALUES(5, 'z-five');
+ INSERT INTO t6z VALUES(9, 'z-nine');
+ }
+} {}
+set cnt 0
+foreach predicate {
+ {}
+ {ORDER BY a}
+ {ORDER BY t6w.a}
+ {WHERE a>0}
+ {WHERE t6y.a>0}
+ {WHERE a>0 ORDER BY a}
+} {
+ incr cnt
+ do_test where3-6.$cnt.1 {
+ set sql "SELECT * FROM t6w NATURAL JOIN t6x NATURAL JOIN t6y"
+ append sql " NATURAL JOIN t6z "
+ append sql $::predicate
+ db eval $sql
+ } {1 w-one x-one y-one z-one 9 w-nine x-nine y-nine z-nine}
+ do_test where3-6.$cnt.2 {
+ set sql "SELECT * FROM t6w JOIN t6x USING(a) JOIN t6y USING(a)"
+ append sql " JOIN t6z USING(a) "
+ append sql $::predicate
+ db eval $sql
+ } {1 w-one x-one y-one z-one 9 w-nine x-nine y-nine z-nine}
+ do_test where3-6.$cnt.3 {
+ set sql "SELECT * FROM t6w NATURAL JOIN t6x JOIN t6y USING(a)"
+ append sql " JOIN t6z USING(a) "
+ append sql $::predicate
+ db eval $sql
+ } {1 w-one x-one y-one z-one 9 w-nine x-nine y-nine z-nine}
+ do_test where3-6.$cnt.4 {
+ set sql "SELECT * FROM t6w JOIN t6x USING(a) NATURAL JOIN t6y"
+ append sql " JOIN t6z USING(a) "
+ append sql $::predicate
+ db eval $sql
+ } {1 w-one x-one y-one z-one 9 w-nine x-nine y-nine z-nine}
+ do_test where3-6.$cnt.5 {
+ set sql "SELECT * FROM t6w JOIN t6x USING(a) JOIN t6y USING(a)"
+ append sql " NATURAL JOIN t6z "
+ append sql $::predicate
+ db eval $sql
+ } {1 w-one x-one y-one z-one 9 w-nine x-nine y-nine z-nine}
+ do_test where3-6.$cnt.6 {
+ set sql "SELECT * FROM t6w JOIN t6x USING(a) NATURAL JOIN t6y"
+ append sql " NATURAL JOIN t6z "
+ append sql $::predicate
+ db eval $sql
+ } {1 w-one x-one y-one z-one 9 w-nine x-nine y-nine z-nine}
+ do_test where3-6.$cnt.7 {
+ set sql "SELECT * FROM t6w NATURAL JOIN t6x JOIN t6y USING(a)"
+ append sql " NATURAL JOIN t6z "
+ append sql $::predicate
+ db eval $sql
+ } {1 w-one x-one y-one z-one 9 w-nine x-nine y-nine z-nine}
+ do_test where3-6.$cnt.8 {
+ set sql "SELECT * FROM t6w NATURAL JOIN t6x NATURAL JOIN t6y"
+ append sql " JOIN t6z USING(a) "
+ append sql $::predicate
+ db eval $sql
+ } {1 w-one x-one y-one z-one 9 w-nine x-nine y-nine z-nine}
+}
+
+do_execsql_test where3-7-setup {
+ CREATE TABLE t71(x1 INTEGER PRIMARY KEY, y1);
+ CREATE TABLE t72(x2 INTEGER PRIMARY KEY, y2);
+ CREATE TABLE t73(x3, y3);
+ CREATE TABLE t74(x4, y4);
+ INSERT INTO t71 VALUES(123,234);
+ INSERT INTO t72 VALUES(234,345);
+ INSERT INTO t73 VALUES(123,234);
+ INSERT INTO t74 VALUES(234,345);
+ INSERT INTO t74 VALUES(234,678);
+} {}
+foreach disabled_opt {none omit-noop-join all} {
+ optimization_control db all 1
+ optimization_control db $disabled_opt 0
+ do_execsql_test where3-7.$disabled_opt.1 {
+ SELECT x1 FROM t71 LEFT JOIN t72 ON x2=y1;
+ } {123}
+ do_execsql_test where3-7.$disabled_opt.2 {
+ SELECT x1 FROM t71 LEFT JOIN t72 ON x2=y1 WHERE y2 IS NULL;
+ } {}
+ do_execsql_test where3-7.$disabled_opt.3 {
+ SELECT x1 FROM t71 LEFT JOIN t72 ON x2=y1 WHERE y2 IS NOT NULL;
+ } {123}
+ do_execsql_test where3-7.$disabled_opt.4 {
+ SELECT x1 FROM t71 LEFT JOIN t72 ON x2=y1 AND y2 IS NULL;
+ } {123}
+ do_execsql_test where3-7.$disabled_opt.5 {
+ SELECT x1 FROM t71 LEFT JOIN t72 ON x2=y1 AND y2 IS NOT NULL;
+ } {123}
+ do_execsql_test where3-7.$disabled_opt.6 {
+ SELECT x3 FROM t73 LEFT JOIN t72 ON x2=y3;
+ } {123}
+ do_execsql_test where3-7.$disabled_opt.7 {
+ SELECT DISTINCT x3 FROM t73 LEFT JOIN t72 ON x2=y3;
+ } {123}
+ do_execsql_test where3-7.$disabled_opt.8 {
+ SELECT x3 FROM t73 LEFT JOIN t74 ON x4=y3;
+ } {123 123}
+ do_execsql_test where3-7.$disabled_opt.9 {
+ SELECT DISTINCT x3 FROM t73 LEFT JOIN t74 ON x4=y3;
+ } {123}
+}
+
+
finish_test
diff --git a/lang/sql/sqlite/test/where7.test b/lang/sql/sqlite/test/where7.test
index e34778c7..5032c698 100644
--- a/lang/sql/sqlite/test/where7.test
+++ b/lang/sql/sqlite/test/where7.test
@@ -10,8 +10,6 @@
#***********************************************************************
# This file implements regression tests for SQLite library. The
# focus of this file is testing the multi-index OR clause optimizer.
-#
-# $Id: where7.test,v 1.9 2009/06/07 23:45:11 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -23305,7 +23303,7 @@ do_test where7-2.1001.2 {
#
# The test case that follows is code from an actual
# application with identifiers change and unused columns
-# remove.
+# removed.
#
do_execsql_test where7-3.1 {
CREATE TABLE t301 (
@@ -23334,16 +23332,16 @@ do_execsql_test where7-3.1 {
EXPLAIN QUERY PLAN
SELECT t302.c1
- FROM t302 JOIN t301 ON t302.c8 = t301.c8
+ FROM t302 JOIN t301 ON t302.c8 = +t301.c8
WHERE t302.c2 = 19571
AND t302.c3 > 1287603136
AND (t301.c4 = 1407449685622784
OR t301.c8 = 1407424651264000)
ORDER BY t302.c5 LIMIT 200;
} {
- 0 0 1 {SEARCH TABLE t301 USING COVERING INDEX t301_c4 (c4=?) (~10 rows)}
- 0 0 1 {SEARCH TABLE t301 USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)}
- 0 1 0 {SEARCH TABLE t302 USING INDEX t302_c8_c3 (c8=? AND c3>?) (~2 rows)}
+ 0 0 1 {SEARCH TABLE t301 USING COVERING INDEX t301_c4 (c4=?)}
+ 0 0 1 {SEARCH TABLE t301 USING INTEGER PRIMARY KEY (rowid=?)}
+ 0 1 0 {SEARCH TABLE t302 USING INDEX t302_c8_c3 (c8=? AND c3>?)}
0 0 0 {USE TEMP B-TREE FOR ORDER BY}
}
diff --git a/lang/sql/sqlite/test/where8.test b/lang/sql/sqlite/test/where8.test
index a7d5edb3..287e4004 100644
--- a/lang/sql/sqlite/test/where8.test
+++ b/lang/sql/sqlite/test/where8.test
@@ -12,7 +12,6 @@
# is testing of where.c. More specifically, the focus is the optimization
# of WHERE clauses that feature the OR operator.
#
-# $Id: where8.test,v 1.9 2009/07/31 06:14:52 danielk1977 Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -211,9 +210,10 @@ do_test where8-3.4 {
do_test where8-3.5 {
execsql_status {
- SELECT a, d FROM t1, t2 WHERE (a = 2 OR a = 3) AND (d = a OR e = 'sixteen')
+ SELECT a, d FROM t1, t2 WHERE (a = 2 OR a = 3) AND (d = +a OR e = 'sixteen')
+ ORDER BY +a, +d;
}
-} {2 2 2 4 3 3 3 4 0 0}
+} {2 2 2 4 3 3 3 4 0 1}
do_test where8-3.6 {
# The first part of the WHERE clause in this query, (a=2 OR a=3) is
@@ -222,7 +222,7 @@ do_test where8-3.6 {
execsql_status {
SELECT a, d
FROM t1, t2
- WHERE (a = 2 OR a = 3) AND (d = a OR e = 'sixteen')
+ WHERE (a = 2 OR a = 3) AND (d = +a OR e = 'sixteen')
ORDER BY t1.rowid
}
} {2 2 2 4 3 3 3 4 0 1}
@@ -233,7 +233,7 @@ do_test where8-3.7 {
WHERE a = 2 AND (d = a OR e = 'sixteen')
ORDER BY t1.rowid
}
-} {2 2 2 4 0 0}
+} {/2 2 2 4 0 [01]/}
do_test where8-3.8 {
execsql_status {
SELECT a, d
@@ -268,7 +268,7 @@ do_test where8-3.12 {
execsql_status {
SELECT a, d FROM t1, t2 WHERE (a=d OR b=e) AND +a<5 ORDER BY a
}
-} {1 1 2 2 3 3 4 2 4 4 0 0}
+} {1 1 2 2 3 3 4 2 4 4 9 0}
do_test where8-3.13 {
execsql_status {
SELECT a, d FROM t1, t2 WHERE (a=d OR b=e) AND +a<5
@@ -290,6 +290,38 @@ do_test where8-3.15 {
}
} {I I I I I I I I I I II II II II II II II II II II III III III III III 9 1}
+
+do_test where8-3.21 {
+ execsql_status {
+ SELECT a, d FROM t1, (t2) WHERE (a=d OR b=e) AND a<5 ORDER BY a
+ }
+} {1 1 2 2 3 3 4 2 4 4 0 0}
+do_test where8-3.21.1 {
+ execsql_status {
+ SELECT a, d FROM t1, ((t2)) AS t3 WHERE (a=d OR b=e) AND a<5 ORDER BY a
+ }
+} {1 1 2 2 3 3 4 2 4 4 0 0}
+if {[permutation] != "no_optimization"} {
+do_test where8-3.21.2 {
+ execsql_status {
+ SELECT a, d FROM t1, ((SELECT * FROM t2)) AS t3 WHERE (a=d OR b=e) AND a<5 ORDER BY a
+ }
+} {1 1 2 2 3 3 4 2 4 4 0 0}
+}
+do_test where8-3.22 {
+ execsql_status {
+ SELECT a, d FROM ((((((t1))), (((t2))))))
+ WHERE (a=d OR b=e) AND a<5 ORDER BY a
+ }
+} {1 1 2 2 3 3 4 2 4 4 0 0}
+if {[permutation] != "no_optimization"} {
+do_test where8-3.23 {
+ execsql_status {
+ SELECT * FROM ((SELECT * FROM t2)) AS t3;
+ }
+} {1 {} I 2 four IV 3 {} IX 4 sixteen XVI 5 {} XXV 6 thirtysix XXXVI 7 fortynine XLIX 8 sixtyeight LXIV 9 eightyone LXXXIX 10 {} C 9 0}
+}
+
#-----------------------------------------------------------------------
# The following tests - where8-4.* - verify that adding or removing
# indexes does not change the results returned by various queries.
@@ -716,4 +748,13 @@ do_test where8-5.3 {
}
} {1 {}}
+# The OR optimization and WITHOUT ROWID
+#
+do_execsql_test where8-6.1 {
+ CREATE TABLE t600(a PRIMARY KEY, b) WITHOUT rowid;
+ CREATE INDEX t600b ON t600(b);
+ INSERT INTO t600 VALUES('state','screen'),('exact','dolphin'),('green','mercury');
+ SELECT a, b, '|' FROM t600 WHERE a=='state' OR b='mercury' ORDER BY +a;
+} {green mercury | state screen |}
+
finish_test
diff --git a/lang/sql/sqlite/test/where9.test b/lang/sql/sqlite/test/where9.test
index 9a180116..1c32ff82 100644
--- a/lang/sql/sqlite/test/where9.test
+++ b/lang/sql/sqlite/test/where9.test
@@ -11,12 +11,11 @@
# This file implements regression tests for SQLite library. The
# focus of this file is testing the multi-index OR clause optimizer.
#
-# $Id: where9.test,v 1.9 2009/06/05 17:09:12 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
-ifcapable !or_opt {
+ifcapable !or_opt||!compound {
finish_test
return
}
@@ -233,7 +232,7 @@ do_test where9-1.3.3 {
} {90 91 92 97 scan 98 sort 0}
do_test where9-1.3.4 {
count_steps {
- SELECT a FROM t4
+ SELECT a FROM (t4)
WHERE (b IS NULL AND c NOT NULL AND d NOT NULL)
OR (b NOT NULL AND c NOT NULL AND d IS NULL)
OR (b NOT NULL AND c IS NULL AND d NOT NULL)
@@ -363,9 +362,9 @@ ifcapable explain {
SELECT t2.a FROM t1, t2
WHERE t1.a=80 AND ((t1.c=t2.c AND t1.d=t2.d) OR t1.f=t2.f)
} {
- 0 0 0 {SEARCH TABLE t1 USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)}
- 0 1 1 {SEARCH TABLE t2 USING INDEX t2d (d=?) (~2 rows)}
- 0 1 1 {SEARCH TABLE t2 USING COVERING INDEX t2f (f=?) (~10 rows)}
+ 0 0 0 {SEARCH TABLE t1 USING INTEGER PRIMARY KEY (rowid=?)}
+ 0 1 1 {SEARCH TABLE t2 USING INDEX t2d (d=?)}
+ 0 1 1 {SEARCH TABLE t2 USING COVERING INDEX t2f (f=?)}
}
do_execsql_test where9-3.2 {
EXPLAIN QUERY PLAN
@@ -373,9 +372,9 @@ ifcapable explain {
FROM t1 LEFT JOIN t2 ON (t1.c+1=t2.c AND t1.d=t2.d) OR (t1.f||'x')=t2.f
WHERE t1.a=80
} {
- 0 0 0 {SEARCH TABLE t1 USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)}
- 0 1 1 {SEARCH TABLE t2 USING INDEX t2d (d=?) (~2 rows)}
- 0 1 1 {SEARCH TABLE t2 USING COVERING INDEX t2f (f=?) (~10 rows)}
+ 0 0 0 {SEARCH TABLE t1 USING INTEGER PRIMARY KEY (rowid=?)}
+ 0 1 1 {SEARCH TABLE t2 USING INDEX t2d (d=?)}
+ 0 1 1 {SEARCH TABLE t2 USING COVERING INDEX t2f (f=?)}
}
}
@@ -421,7 +420,7 @@ do_test where9-4.5 {
AND (c=31031 OR d IS NULL)
ORDER BY +a
}
-} {1 {cannot use index: t1b}}
+} {1 {no query solution}}
do_test where9-4.6 {
count_steps {
SELECT a FROM t1 NOT INDEXED
@@ -437,7 +436,7 @@ do_test where9-4.7 {
AND (c=31031 OR d IS NULL)
ORDER BY +a
}
-} {1 {cannot use index: t1c}}
+} {1 {no query solution}}
do_test where9-4.8 {
catchsql {
SELECT a FROM t1 INDEXED BY t1d
@@ -445,7 +444,7 @@ do_test where9-4.8 {
AND (c=31031 OR d IS NULL)
ORDER BY +a
}
-} {1 {cannot use index: t1d}}
+} {1 {no query solution}}
ifcapable explain {
# The (c=31031 OR d IS NULL) clause is preferred over b>1000 because
@@ -454,8 +453,8 @@ ifcapable explain {
do_execsql_test where9-5.1 {
EXPLAIN QUERY PLAN SELECT a FROM t1 WHERE b>1000 AND (c=31031 OR d IS NULL)
} {
- 0 0 0 {SEARCH TABLE t1 USING INDEX t1c (c=?) (~10 rows)}
- 0 0 0 {SEARCH TABLE t1 USING INDEX t1d (d=?) (~10 rows)}
+ 0 0 0 {SEARCH TABLE t1 USING INDEX t1c (c=?)}
+ 0 0 0 {SEARCH TABLE t1 USING INDEX t1d (d=?)}
}
# In contrast, b=1000 is preferred over any OR-clause.
@@ -463,7 +462,7 @@ ifcapable explain {
do_execsql_test where9-5.2 {
EXPLAIN QUERY PLAN SELECT a FROM t1 WHERE b=1000 AND (c=31031 OR d IS NULL)
} {
- 0 0 0 {SEARCH TABLE t1 USING INDEX t1b (b=?) (~5 rows)}
+ 0 0 0 {SEARCH TABLE t1 USING INDEX t1b (b=?)}
}
# Likewise, inequalities in an AND are preferred over inequalities in
@@ -472,7 +471,7 @@ ifcapable explain {
do_execsql_test where9-5.3 {
EXPLAIN QUERY PLAN SELECT a FROM t1 WHERE b>1000 AND (c>=31031 OR d IS NULL)
} {
- 0 0 0 {SEARCH TABLE t1 USING INDEX t1b (b>?) (~125000 rows)}
+ 0 0 0 {SEARCH TABLE t1 USING INDEX t1b (b>?)}
}
}
@@ -693,7 +692,7 @@ do_test where9-6.5.3 {
do_test where9-6.5.4 {
db eval {
SELECT count(*) FROM t1 UNION ALL
- SELECT a FROM t1 WHERE a%100 IN (5,31,57,82,83,84,85,86,87);
+ SELECT a FROM t1 WHERE a%100 IN (5,31,57,82,83,84,85,86,87) ORDER BY rowid;
ROLLBACK;
}
} {99 105 131 157 182 183 184 185 186 187}
@@ -769,18 +768,216 @@ do_test where9-6.7.4 {
do_test where9-6.8.1 {
catchsql {
DELETE FROM t1 INDEXED BY t1b
- WHERE (b IS NULL AND c NOT NULL AND d NOT NULL)
+ WHERE (+b IS NULL AND c NOT NULL AND d NOT NULL)
OR (b NOT NULL AND c IS NULL AND d NOT NULL)
OR (b NOT NULL AND c NOT NULL AND d IS NULL)
}
-} {1 {cannot use index: t1b}}
+} {1 {no query solution}}
do_test where9-6.8.2 {
catchsql {
UPDATE t1 INDEXED BY t1b SET a=a+100
- WHERE (b IS NULL AND c NOT NULL AND d NOT NULL)
+ WHERE (+b IS NULL AND c NOT NULL AND d NOT NULL)
OR (b NOT NULL AND c IS NULL AND d NOT NULL)
OR (b NOT NULL AND c NOT NULL AND d IS NULL)
}
-} {1 {cannot use index: t1b}}
+} {1 {no query solution}}
+ifcapable stat4||stat3 {
+ # When STAT3 is enabled, the "b NOT NULL" terms get translated
+ # into b>NULL, which can be satified by the index t1b. It is a very
+ # expensive way to do the query, but it works, and so a solution is possible.
+ do_test where9-6.8.3-stat4 {
+ catchsql {
+ UPDATE t1 INDEXED BY t1b SET a=a+100
+ WHERE (b IS NULL AND c NOT NULL AND d NOT NULL)
+ OR (b NOT NULL AND c IS NULL AND d NOT NULL)
+ OR (b NOT NULL AND c NOT NULL AND d IS NULL)
+ }
+ } {0 {}}
+ do_test where9-6.8.4-stat4 {
+ catchsql {
+ DELETE FROM t1 INDEXED BY t1b
+ WHERE (b IS NULL AND c NOT NULL AND d NOT NULL)
+ OR (b NOT NULL AND c IS NULL AND d NOT NULL)
+ OR (b NOT NULL AND c NOT NULL AND d IS NULL)
+ }
+ } {0 {}}
+} else {
+ do_test where9-6.8.3 {
+ catchsql {
+ UPDATE t1 INDEXED BY t1b SET a=a+100
+ WHERE (b IS NULL AND c NOT NULL AND d NOT NULL)
+ OR (b NOT NULL AND c IS NULL AND d NOT NULL)
+ OR (b NOT NULL AND c NOT NULL AND d IS NULL)
+ }
+ } {1 {no query solution}}
+ do_test where9-6.8.4 {
+ catchsql {
+ DELETE FROM t1 INDEXED BY t1b
+ WHERE (b IS NULL AND c NOT NULL AND d NOT NULL)
+ OR (b NOT NULL AND c IS NULL AND d NOT NULL)
+ OR (b NOT NULL AND c NOT NULL AND d IS NULL)
+ }
+ } {1 {no query solution}}
+}
+############################################################################
+# Test cases where terms inside an OR series are combined with AND terms
+# external to the OR clause. In other words, cases where
+#
+# x AND (y OR z)
+#
+# is able to use indices on x,y and x,z, or indices y,x and z,x.
+#
+do_test where9-7.0 {
+ execsql {
+ CREATE TABLE t5(a, b, c, d, e, f, g, x, y);
+ INSERT INTO t5
+ SELECT a, b, c, e, d, f, g,
+ CASE WHEN (a&1)!=0 THEN 'y' ELSE 'n' END,
+ CASE WHEN (a&2)!=0 THEN 'y' ELSE 'n' END
+ FROM t1;
+ CREATE INDEX t5xb ON t5(x, b);
+ CREATE INDEX t5xc ON t5(x, c);
+ CREATE INDEX t5xd ON t5(x, d);
+ CREATE INDEX t5xe ON t5(x, e);
+ CREATE INDEX t5xf ON t5(x, f);
+ CREATE INDEX t5xg ON t5(x, g);
+ CREATE INDEX t5yb ON t5(y, b);
+ CREATE INDEX t5yc ON t5(y, c);
+ CREATE INDEX t5yd ON t5(y, d);
+ CREATE INDEX t5ye ON t5(y, e);
+ CREATE INDEX t5yf ON t5(y, f);
+ CREATE INDEX t5yg ON t5(y, g);
+ CREATE TABLE t6(a, b, c, e, d, f, g, x, y);
+ INSERT INTO t6 SELECT * FROM t5;
+ ANALYZE t5;
+ }
+ ifcapable stat3 {
+ sqlite3 db2 test.db
+ db2 eval { DROP TABLE IF EXISTS sqlite_stat3 }
+ db2 close
+ }
+} {}
+do_test where9-7.1.1 {
+ count_steps {
+ SELECT a FROM t5 WHERE x='y' AND (b=913 OR c=27027) ORDER BY a;
+ }
+} {79 81 83 scan 0 sort 1}
+do_test where9-7.1.2 {
+ execsql {
+ SELECT a FROM t6 WHERE x='y' AND (b=913 OR c=27027) ORDER BY a;
+ }
+} {79 81 83}
+do_test where9-7.1.3 {
+ count_steps {
+ SELECT a FROM t5 WHERE x='n' AND (b=913 OR c=27027) ORDER BY a;
+ }
+} {80 scan 0 sort 1}
+do_test where9-7.1.4 {
+ execsql {
+ SELECT a FROM t6 WHERE x='n' AND (b=913 OR c=27027) ORDER BY a;
+ }
+} {80}
+do_test where9-7.2.1 {
+ count_steps {
+ SELECT a FROM t5 WHERE (x='y' OR y='y') AND b=913 ORDER BY a;
+ }
+} {83 scan 0 sort 1}
+do_test where9-7.2.2 {
+ execsql {
+ SELECT a FROM t6 WHERE (x='y' OR y='y') AND b=913 ORDER BY a;
+ }
+} {83}
+do_test where9-7.3.1 {
+ count_steps {
+ SELECT a FROM t5 WHERE (x='y' OR y='y') AND c=27027 ORDER BY a;
+ }
+} {79 81 scan 0 sort 1}
+do_test where9-7.3.2 {
+ execsql {
+ SELECT a FROM t6 WHERE (x='y' OR y='y') AND c=27027 ORDER BY a;
+ }
+} {79 81}
+
+# Fix for ticket [b7c8682cc17f32903f03a610bd0d35ffd3c1e6e4]
+# "Incorrect result from LEFT JOIN with OR in the WHERE clause"
+#
+do_test where9-8.1 {
+ db eval {
+ CREATE TABLE t81(a INTEGER PRIMARY KEY, b, c, d);
+ CREATE TABLE t82(x INTEGER PRIMARY KEY, y);
+ CREATE TABLE t83(p INTEGER PRIMARY KEY, q);
+
+ INSERT INTO t81 VALUES(2,3,4,5);
+ INSERT INTO t81 VALUES(3,4,5,6);
+ INSERT INTO t82 VALUES(2,4);
+ INSERT INTO t83 VALUES(5,55);
+
+ SELECT *
+ FROM t81 LEFT JOIN t82 ON y=b JOIN t83
+ WHERE c==p OR d==p
+ ORDER BY +a;
+ }
+} {2 3 4 5 {} {} 5 55 3 4 5 6 2 4 5 55}
+do_test where9-8.2 {
+ db eval {
+ SELECT *
+ FROM t81 LEFT JOIN (t82) ON y=b JOIN t83
+ WHERE c==p OR d==p
+ ORDER BY +a;
+ }
+} {2 3 4 5 {} {} 5 55 3 4 5 6 2 4 5 55}
+do_test where9-8.3 {
+ db eval {
+ SELECT *
+ FROM (t81) LEFT JOIN (main.t82) ON y=b JOIN t83
+ WHERE c==p OR d==p
+ ORDER BY +a;
+ }
+} {2 3 4 5 {} {} 5 55 3 4 5 6 2 4 5 55}
+
+# Fix for ticket [f2369304e47167e3e644e2f1fe9736063391d7b7]
+# Incorrect results when OR is used in the ON clause of a LEFT JOIN
+#
+do_test where9-9.1 {
+ db eval {
+ CREATE TABLE t91(x); INSERT INTO t91 VALUES(1);
+ CREATE TABLE t92(y INTEGER PRIMARY KEY,a,b);
+ INSERT INTO t92 VALUES(1,2,3);
+ SELECT 1 FROM t91 LEFT JOIN t92 ON a=2 OR b=3;
+ SELECT 2 FROM t91 LEFT JOIN t92 ON a=2 AND b=3;
+ SELECT 3 FROM t91 LEFT JOIN t92 ON (a=2 OR b=3) AND y IS NULL;
+ SELECT 4 FROM t91 LEFT JOIN t92 ON (a=2 AND b=3) AND y IS NULL;
+ CREATE TEMP TABLE x9 AS SELECT * FROM t91 LEFT JOIN t92 ON a=2 OR b=3;
+ SELECT 5 FROM x9 WHERE y IS NULL;
+ SELECT 6 FROM t91 LEFT JOIN t92 ON a=2 OR b=3 WHERE y IS NULL;
+ SELECT 7 FROM t91 LEFT JOIN t92 ON a=2 AND b=3 WHERE y IS NULL;
+ SELECT 8 FROM t91 LEFT JOIN t92 ON a=22 OR b=33 WHERE y IS NULL;
+ SELECT 9 FROM t91 LEFT JOIN t92 ON a=22 AND b=33 WHERE y IS NULL;
+ }
+} {1 2 3 4 8 9}
+
+# Fix for ticket [bc878246eafe0f52c519e29049b2fe4a99491b27]
+# Incorrect result when OR is used in a join to the right of a LEFT JOIN
+#
+do_test where9-10.1 {
+ db eval {
+ CREATE TABLE t101 (id INTEGER PRIMARY KEY);
+ INSERT INTO t101 VALUES (1);
+ SELECT * FROM t101 AS t0
+ LEFT JOIN t101 AS t1 ON t1.id BETWEEN 10 AND 20
+ JOIN t101 AS t2 ON (t2.id = t0.id OR (t2.id<>555 AND t2.id=t1.id));
+ }
+} {1 {} 1}
+do_test where9-10.2 {
+ db eval {
+ CREATE TABLE t102 (id TEXT UNIQUE NOT NULL);
+ INSERT INTO t102 VALUES ('1');
+ SELECT * FROM t102 AS t0
+ LEFT JOIN t102 AS t1 ON t1.id GLOB 'abc%'
+ JOIN t102 AS t2 ON (t2.id = t0.id OR (t2.id<>555 AND t2.id=t1.id));
+ }
+} {1 {} 1}
+
+
finish_test
diff --git a/lang/sql/sqlite/test/whereA.test b/lang/sql/sqlite/test/whereA.test
index 5d0aca59..78826b11 100644
--- a/lang/sql/sqlite/test/whereA.test
+++ b/lang/sql/sqlite/test/whereA.test
@@ -68,6 +68,12 @@ do_test whereA-1.7 {
SELECT * FROM t1;
}
} {3 4.53 {} 2 hello world 1 2 3}
+do_execsql_test whereA-1.8 {
+ SELECT * FROM t1 WHERE b=2 AND a IS NULL;
+} {}
+do_execsql_test whereA-1.9 {
+ SELECT * FROM t1 WHERE b=2 AND a IS NOT NULL;
+} {1 2 3}
do_test whereA-2.1 {
db eval {
diff --git a/lang/sql/sqlite/test/whereC.test b/lang/sql/sqlite/test/whereC.test
new file mode 100644
index 00000000..bd7fe9ad
--- /dev/null
+++ b/lang/sql/sqlite/test/whereC.test
@@ -0,0 +1,69 @@
+# 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.
+#
+#***********************************************************************
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix whereC
+
+do_execsql_test 1.0 {
+ CREATE TABLE t1(i INTEGER PRIMARY KEY, a, b INTEGER);
+
+ INSERT INTO t1 VALUES(1, 1, 1);
+ INSERT INTO t1 VALUES(2, 1, 1);
+ INSERT INTO t1 VALUES(3, 1, 2);
+ INSERT INTO t1 VALUES(4, 1, 2);
+ INSERT INTO t1 VALUES(5, 1, 2);
+ INSERT INTO t1 VALUES(6, 1, 3);
+ INSERT INTO t1 VALUES(7, 1, 3);
+
+ INSERT INTO t1 VALUES(8, 2, 1);
+ INSERT INTO t1 VALUES(9, 2, 1);
+ INSERT INTO t1 VALUES(10, 2, 2);
+ INSERT INTO t1 VALUES(11, 2, 2);
+ INSERT INTO t1 VALUES(12, 2, 2);
+ INSERT INTO t1 VALUES(13, 2, 3);
+ INSERT INTO t1 VALUES(14, 2, 3);
+
+ INSERT INTO t1 VALUES(15, 2, 1);
+ INSERT INTO t1 VALUES(16, 2, 1);
+ INSERT INTO t1 VALUES(17, 2, 2);
+ INSERT INTO t1 VALUES(18, 2, 2);
+ INSERT INTO t1 VALUES(19, 2, 2);
+ INSERT INTO t1 VALUES(20, 2, 3);
+ INSERT INTO t1 VALUES(21, 2, 3);
+
+ CREATE INDEX i1 ON t1(a, b);
+}
+
+foreach {tn sql res} {
+ 1 "SELECT i FROM t1 WHERE a=1 AND b=2 AND i>3" {4 5}
+ 2 "SELECT i FROM t1 WHERE rowid='12'" {12}
+ 3 "SELECT i FROM t1 WHERE a=1 AND b='2'" {3 4 5}
+ 4 "SELECT i FROM t1 WHERE a=1 AND b='2' AND i>'3'" {4 5}
+ 5 "SELECT i FROM t1 WHERE a=1 AND b='2' AND i<5" {3 4}
+ 6 "SELECT i FROM t1 WHERE a=2 AND b=2 AND i<12" {10 11}
+ 7 "SELECT i FROM t1 WHERE a IN(1, 2) AND b=2 AND i<11" {3 4 5 10}
+ 8 "SELECT i FROM t1 WHERE a=2 AND b=2 AND i BETWEEN 10 AND 12" {10 11 12}
+ 9 "SELECT i FROM t1 WHERE a=2 AND b=2 AND i BETWEEN 11 AND 12" {11 12}
+ 10 "SELECT i FROM t1 WHERE a=2 AND b=2 AND i BETWEEN 10 AND 11" {10 11}
+ 11 "SELECT i FROM t1 WHERE a=2 AND b=2 AND i BETWEEN 12 AND 10" {}
+ 12 "SELECT i FROM t1 WHERE a=2 AND b=2 AND i<NULL" {}
+ 13 "SELECT i FROM t1 WHERE a=2 AND b=2 AND i>=NULL" {}
+ 14 "SELECT i FROM t1 WHERE a=1 AND b='2' AND i<4.5" {3 4}
+} {
+ do_execsql_test 1.$tn.1 $sql $res
+ do_execsql_test 1.$tn.2 "$sql ORDER BY i ASC" [lsort -integer -inc $res]
+ do_execsql_test 1.$tn.3 "$sql ORDER BY i DESC" [lsort -integer -dec $res]
+}
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/whereD.test b/lang/sql/sqlite/test/whereD.test
new file mode 100644
index 00000000..eb0f8640
--- /dev/null
+++ b/lang/sql/sqlite/test/whereD.test
@@ -0,0 +1,222 @@
+# 2012 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 file is testing that an index may be used as a covering
+# index when there are OR expressions in the WHERE clause.
+#
+
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set ::testprefix whereD
+
+do_execsql_test 1.1 {
+ CREATE TABLE t(i,j,k,m,n);
+ CREATE INDEX ijk ON t(i,j,k);
+ CREATE INDEX jmn ON t(j,m,n);
+
+ INSERT INTO t VALUES(3, 3, 'three', 3, 'tres');
+ INSERT INTO t VALUES(2, 2, 'two', 2, 'dos');
+ INSERT INTO t VALUES(1, 1, 'one', 1, 'uno');
+ INSERT INTO t VALUES(4, 4, 'four', 4, 'cuatro');
+}
+
+do_execsql_test 1.2 {
+ SELECT k FROM t WHERE (i=1 AND j=1) OR (i=2 AND j=2);
+} {one two}
+do_execsql_test 1.3 {
+ SELECT k FROM t WHERE (i=1 AND j=1) OR (+i=2 AND j=2);
+} {one two}
+do_execsql_test 1.4 {
+ SELECT n FROM t WHERE (i=1 AND j=1) OR (i=2 AND j=2);
+} {uno dos}
+do_execsql_test 1.5 {
+ SELECT k, n FROM t WHERE (i=1 AND j=1) OR (i=2 AND j=2);
+} {one uno two dos}
+do_execsql_test 1.6 {
+ SELECT k FROM t WHERE (i=1 AND j=1) OR (i=2 AND j=2) OR (i=3 AND j=3);
+} {one two three}
+do_execsql_test 1.7 {
+ SELECT n FROM t WHERE (i=1 AND j=1) OR (i=2 AND j=2) OR (i=3 AND j=3);
+} {uno dos tres}
+do_execsql_test 1.8 {
+ SELECT k FROM t WHERE (i=1 AND j=1) OR (j=2 AND m=2);
+} {one two}
+do_execsql_test 1.9 {
+ SELECT k FROM t WHERE (i=1 AND j=1) OR (i=2 AND j=2) OR (j=3 AND m=3);
+} {one two three}
+do_execsql_test 1.10 {
+ SELECT n FROM t WHERE (i=1 AND j=1) OR (i=2 AND j=2) OR (j=3 AND m=3);
+} {uno dos tres}
+do_execsql_test 1.11 {
+ SELECT k FROM t WHERE (i=1 AND j=1) OR (j=2 AND m=2) OR (i=3 AND j=3);
+} {one two three}
+do_execsql_test 1.12 {
+ SELECT n FROM t WHERE (i=1 AND j=1) OR (j=2 AND m=2) OR (i=3 AND j=3);
+} {uno dos tres}
+do_execsql_test 1.13 {
+ SELECT k FROM t WHERE (j=1 AND m=1) OR (i=2 AND j=2) OR (i=3 AND j=3);
+} {one two three}
+do_execsql_test 1.14 {
+ SELECT k FROM t WHERE (i=1 AND j=1) OR (j=2 AND i=2) OR (i=3 AND j=3);
+} {one two three}
+do_execsql_test 1.15 {
+ SELECT k FROM t WHERE (i=1 AND j=2) OR (i=2 AND j=1) OR (i=3 AND j=4);
+} {}
+do_execsql_test 1.16 {
+ SELECT k FROM t WHERE (i=1 AND (j=1 or j=2)) OR (i=3 AND j=3);
+} {one three}
+
+do_execsql_test 2.0 {
+ CREATE TABLE t1(a,b,c,d);
+ CREATE INDEX t1b ON t1(b);
+ CREATE INDEX t1c ON t1(c);
+ CREATE INDEX t1d ON t1(d);
+ CREATE TABLE t2(x,y);
+ CREATE INDEX t2y ON t2(y);
+
+ INSERT INTO t1 VALUES(1,2,3,4);
+ INSERT INTO t1 VALUES(5,6,7,8);
+ INSERT INTO t2 VALUES(1,2);
+ INSERT INTO t2 VALUES(2,7);
+ INSERT INTO t2 VALUES(3,4);
+} {}
+do_execsql_test 2.1 {
+ SELECT a, x FROM t1 JOIN t2 ON +y=d OR x=7 ORDER BY a, x;
+} {1 3}
+do_execsql_test 2.2 {
+ SELECT a, x FROM t1 JOIN t2 ON y=d OR x=7 ORDER BY a, x;
+} {1 3}
+
+
+# Similar to [do_execsql_test], except that two elements are appended
+# to the result - the string "search" and the number of times test variable
+# sqlite3_search_count is incremented by running the supplied SQL. e.g.
+#
+# do_searchcount_test 1.0 { SELECT * FROM t1 } {x y search 2}
+#
+proc do_searchcount_test {tn sql res} {
+ uplevel [subst -nocommands {
+ do_test $tn {
+ set ::sqlite_search_count 0
+ concat [db eval {$sql}] search [set ::sqlite_search_count]
+ } [list $res]
+ }]
+}
+
+do_execsql_test 3.0 {
+ CREATE TABLE t3(a, b, c);
+ CREATE UNIQUE INDEX i3 ON t3(a, b);
+ INSERT INTO t3 VALUES(1, 'one', 'i');
+ INSERT INTO t3 VALUES(3, 'three', 'iii');
+ INSERT INTO t3 VALUES(6, 'six', 'vi');
+ INSERT INTO t3 VALUES(2, 'two', 'ii');
+ INSERT INTO t3 VALUES(4, 'four', 'iv');
+ INSERT INTO t3 VALUES(5, 'five', 'v');
+
+ CREATE TABLE t4(x PRIMARY KEY, y);
+ INSERT INTO t4 VALUES('a', 'one');
+ INSERT INTO t4 VALUES('b', 'two');
+}
+
+do_searchcount_test 3.1 {
+ SELECT a, b FROM t3 WHERE (a=1 AND b='one') OR (a=2 AND b='two')
+} {1 one 2 two search 2}
+
+do_searchcount_test 3.2 {
+ SELECT a, c FROM t3 WHERE (a=1 AND b='one') OR (a=2 AND b='two')
+} {1 i 2 ii search 4}
+
+do_searchcount_test 3.4.1 {
+ SELECT y FROM t4 WHERE x='a'
+} {one search 2}
+do_searchcount_test 3.4.2 {
+ SELECT a, b FROM t3 WHERE
+ (a=1 AND b=(SELECT y FROM t4 WHERE x='a'))
+ OR (a=2 AND b='two')
+} {1 one 2 two search 4}
+do_searchcount_test 3.4.3 {
+ SELECT a, b FROM t3 WHERE
+ (a=2 AND b='two')
+ OR (a=1 AND b=(SELECT y FROM t4 WHERE x='a'))
+} {2 two 1 one search 4}
+do_searchcount_test 3.4.4 {
+ SELECT a, b FROM t3 WHERE
+ (a=2 AND b=(SELECT y FROM t4 WHERE x='b'))
+ OR (a=1 AND b=(SELECT y FROM t4 WHERE x='a'))
+} {2 two 1 one search 6}
+
+do_searchcount_test 3.5.1 {
+ SELECT a, b FROM t3 WHERE (a=1 AND b='one') OR rowid=4
+} {1 one 2 two search 2}
+do_searchcount_test 3.5.2 {
+ SELECT a, c FROM t3 WHERE (a=1 AND b='one') OR rowid=4
+} {1 i 2 ii search 2}
+
+# Ticket [d02e1406a58ea02d] (2012-10-04)
+# LEFT JOIN with an OR in the ON clause causes segfault
+#
+do_test 4.1 {
+ db eval {
+ CREATE TABLE t41(a,b,c);
+ INSERT INTO t41 VALUES(1,2,3), (4,5,6);
+ CREATE TABLE t42(d,e,f);
+ INSERT INTO t42 VALUES(3,6,9), (4,8,12);
+ SELECT * FROM t41 AS x LEFT JOIN t42 AS y ON (y.d=x.c) OR (y.e=x.b);
+ }
+} {1 2 3 3 6 9 4 5 6 {} {} {}}
+do_test 4.2 {
+ db eval {
+ CREATE INDEX t42d ON t42(d);
+ CREATE INDEX t42e ON t42(e);
+ SELECT * FROM t41 AS x LEFT JOIN t42 AS y ON (y.d=x.c) OR (y.e=x.b);
+ }
+} {1 2 3 3 6 9 4 5 6 {} {} {}}
+do_test 4.3 {
+ db eval {
+ SELECT * FROM t41 AS x LEFT JOIN t42 AS y ON (y.d=x.c) OR (y.d=x.b);
+ }
+} {1 2 3 3 6 9 4 5 6 {} {} {}}
+
+# Ticket [bc1aea7b725f276177]
+# Incorrect result on LEFT JOIN with OR constraints and an ORDER BY clause.
+#
+do_execsql_test 4.4 {
+ CREATE TABLE t44(a INTEGER, b INTEGER);
+ INSERT INTO t44 VALUES(1,2);
+ INSERT INTO t44 VALUES(3,4);
+ SELECT *
+ FROM t44 AS x
+ LEFT JOIN (SELECT a AS c, b AS d FROM t44) AS y ON a=c
+ WHERE d=4 OR d IS NULL;
+} {3 4 3 4}
+do_execsql_test 4.5 {
+ SELECT *
+ FROM t44 AS x
+ LEFT JOIN (SELECT a AS c, b AS d FROM t44) AS y ON a=c
+ WHERE d=4 OR d IS NULL
+ ORDER BY a;
+} {3 4 3 4}
+do_execsql_test 4.6 {
+ CREATE TABLE t46(c INTEGER, d INTEGER);
+ INSERT INTO t46 SELECT a, b FROM t44;
+ SELECT * FROM t44 LEFT JOIN t46 ON a=c
+ WHERE d=4 OR d IS NULL;
+} {3 4 3 4}
+do_execsql_test 4.7 {
+ SELECT * FROM t44 LEFT JOIN t46 ON a=c
+ WHERE d=4 OR d IS NULL
+ ORDER BY a;
+} {3 4 3 4}
+
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/whereE.test b/lang/sql/sqlite/test/whereE.test
new file mode 100644
index 00000000..a6b8f481
--- /dev/null
+++ b/lang/sql/sqlite/test/whereE.test
@@ -0,0 +1,62 @@
+# 2012 November 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 query planner to make sure it
+# is making good planning decisions.
+#
+
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set ::testprefix whereE
+
+do_execsql_test 1.1 {
+ CREATE TABLE t1(a,b);
+ INSERT INTO t1 VALUES(1,10), (2,20), (3,30), (2,22), (3, 33);
+ 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;
+ ALTER TABLE t1 ADD COLUMN c;
+ UPDATE t1 SET c=a*rowid+10000;
+ CREATE INDEX t1ab ON t1(a,b);
+
+ CREATE TABLE t2(x,y);
+ INSERT INTO t2 VALUES(4,44),(5,55),(6,66),(7,77);
+ INSERT INTO t2 SELECT x+4, (x+4)*11 FROM t2;
+ INSERT INTO t2 SELECT x+8, (x+8)*11 FROM t2;
+ INSERT INTO t2 SELECT x+16, (x+16)*11 FROM t2;
+ INSERT INTO t2 SELECT x+32, (x+32)*11 FROM t2;
+ INSERT INTO t2 SELECT x+64, (x+32)*11 FROM t2;
+ ALTER TABLE t2 ADD COLUMN z;
+ UPDATE t2 SET z=2;
+ CREATE UNIQUE INDEX t2zx ON t2(z,x);
+
+ EXPLAIN QUERY PLAN SELECT x FROM t1, t2 WHERE a=z AND c=x;
+} {/.*SCAN TABLE t1.*SEARCH TABLE t2.*/}
+do_execsql_test 1.2 {
+ EXPLAIN QUERY PLAN SELECT x FROM t2, t1 WHERE a=z AND c=x;
+} {/.*SCAN TABLE t1.*SEARCH TABLE t2.*/}
+do_execsql_test 1.3 {
+ ANALYZE;
+ EXPLAIN QUERY PLAN SELECT x FROM t1, t2 WHERE a=z AND c=x;
+} {/.*SCAN TABLE t1.*SEARCH TABLE t2.*/}
+do_execsql_test 1.4 {
+ EXPLAIN QUERY PLAN SELECT x FROM t2, t1 WHERE a=z AND c=x;
+} {/.*SCAN TABLE t1.*SEARCH TABLE t2.*/}
+
+finish_test
diff --git a/lang/sql/sqlite/test/whereF.test b/lang/sql/sqlite/test/whereF.test
new file mode 100644
index 00000000..b9580bb1
--- /dev/null
+++ b/lang/sql/sqlite/test/whereF.test
@@ -0,0 +1,122 @@
+# 2012 November 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.
+#
+#***********************************************************************
+#
+# Test cases for query planning decisions.
+
+
+#
+# The tests in this file demonstrate the behaviour of the query planner
+# in determining the order in which joined tables are scanned.
+#
+# Assume there are two tables being joined - t1 and t2. Each has a cost
+# if it is the outer loop, and a cost if it is the inner loop. As follows:
+#
+# t1(outer) - cost of scanning t1 as the outer loop.
+# t1(inner) - cost of scanning t1 as the inner loop.
+# t2(outer) - cost of scanning t2 as the outer loop.
+# t2(inner) - cost of scanning t2 as the inner loop.
+#
+# Depending on the order in which the planner nests the scans, the total
+# cost of the join query is one of:
+#
+# t1(outer) * t2(inner)
+# t2(outer) * t1(inner)
+#
+# The tests in this file attempt to verify that the planner nests joins in
+# the correct order when the following are true:
+#
+# + (t1(outer) * t2(inner)) > (t1(inner) * t2(outer)
+# + t1(outer) < t2(outer)
+#
+# In other words, when the best overall query plan has t2 as the outer loop,
+# but when the outer loop is considered independent of the inner, t1 is the
+# most efficient choice.
+#
+# In order to make them more predictable, automatic indexes are turned off for
+# the tests in this file.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix whereF
+
+do_execsql_test 1.0 {
+ PRAGMA automatic_index = 0;
+ CREATE TABLE t1(a, b, c);
+ CREATE TABLE t2(d, e, f);
+ CREATE UNIQUE INDEX i1 ON t1(a);
+ CREATE UNIQUE INDEX i2 ON t2(d);
+} {}
+
+foreach {tn sql} {
+ 1 "SELECT * FROM t1, t2 WHERE t1.a=t2.e AND t2.d<t1.b AND t1.c!=10"
+ 2 "SELECT * FROM t2, t1 WHERE t1.a=t2.e AND t2.d<t1.b AND t1.c!=10"
+ 3 "SELECT * FROM t2 CROSS JOIN t1 WHERE t1.a=t2.e AND t2.d<t1.b AND t1.c!=10"
+} {
+ do_test 1.$tn {
+ db eval "EXPLAIN QUERY PLAN $sql"
+ } {/.*SCAN TABLE t2\y.*SEARCH TABLE t1\y.*/}
+}
+
+do_execsql_test 2.0 {
+ DROP TABLE t1;
+ DROP TABLE t2;
+ CREATE TABLE t1(a, b, c);
+ CREATE TABLE t2(d, e, f);
+
+ CREATE UNIQUE INDEX i1 ON t1(a);
+ CREATE UNIQUE INDEX i2 ON t1(b);
+ CREATE UNIQUE INDEX i3 ON t2(d);
+} {}
+
+foreach {tn sql} {
+ 1 "SELECT * FROM t1, t2 WHERE t1.a>? AND t2.d>t1.c AND t1.b=t2.e"
+ 2 "SELECT * FROM t2, t1 WHERE t1.a>? AND t2.d>t1.c AND t1.b=t2.e"
+ 3 "SELECT * FROM t2 CROSS JOIN t1 WHERE t1.a>? AND t2.d>t1.c AND t1.b=t2.e"
+} {
+ do_test 2.$tn {
+ db eval "EXPLAIN QUERY PLAN $sql"
+ } {/.*SCAN TABLE t2\y.*SEARCH TABLE t1\y.*/}
+}
+
+do_execsql_test 3.0 {
+ DROP TABLE t1;
+ DROP TABLE t2;
+ CREATE TABLE t1(a, b, c);
+ CREATE TABLE t2(d, e, f);
+
+ CREATE UNIQUE INDEX i1 ON t1(a, b);
+ CREATE INDEX i2 ON t2(d);
+} {}
+
+foreach {tn sql} {
+ 1 {SELECT t1.a, t1.b, t2.d, t2.e FROM t1, t2
+ WHERE t2.d=t1.b AND t1.a=(t2.d+1) AND t1.b = (t2.e+1)}
+
+ 2 {SELECT t1.a, t1.b, t2.d, t2.e FROM t2, t1
+ WHERE t2.d=t1.b AND t1.a=(t2.d+1) AND t1.b = (t2.e+1)}
+
+ 3 {SELECT t1.a, t1.b, t2.d, t2.e FROM t2 CROSS JOIN t1
+ WHERE t2.d=t1.b AND t1.a=(t2.d+1) AND t1.b = (t2.e+1)}
+} {
+ do_test 3.$tn {
+ db eval "EXPLAIN QUERY PLAN $sql"
+ } {/.*SCAN TABLE t2\y.*SEARCH TABLE t1\y.*/}
+}
+
+do_execsql_test 4.0 {
+ CREATE TABLE t4(a,b,c,d,e, PRIMARY KEY(a,b,c));
+ CREATE INDEX t4adc ON t4(a,d,c);
+ CREATE UNIQUE INDEX t4aebc ON t4(a,e,b,c);
+ EXPLAIN QUERY PLAN SELECT rowid FROM t4 WHERE a=? AND b=?;
+} {/a=. AND b=./}
+
+finish_test
diff --git a/lang/sql/sqlite/test/whereG.test b/lang/sql/sqlite/test/whereG.test
new file mode 100644
index 00000000..1b6a8618
--- /dev/null
+++ b/lang/sql/sqlite/test/whereG.test
@@ -0,0 +1,170 @@
+# 2013-09-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.
+#
+#***********************************************************************
+#
+# Test cases for query planning decisions and the unlikely() and
+# likelihood() functions.
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+do_execsql_test whereG-1.0 {
+ CREATE TABLE composer(
+ cid INTEGER PRIMARY KEY,
+ cname TEXT
+ );
+ CREATE TABLE album(
+ aid INTEGER PRIMARY KEY,
+ aname TEXT
+ );
+ CREATE TABLE track(
+ tid INTEGER PRIMARY KEY,
+ cid INTEGER REFERENCES composer,
+ aid INTEGER REFERENCES album,
+ title TEXT
+ );
+ CREATE INDEX track_i1 ON track(cid);
+ CREATE INDEX track_i2 ON track(aid);
+ INSERT INTO composer VALUES(1, 'W. A. Mozart');
+ INSERT INTO composer VALUES(2, 'Beethoven');
+ INSERT INTO composer VALUES(3, 'Thomas Tallis');
+ INSERT INTO composer VALUES(4, 'Joseph Hayden');
+ INSERT INTO composer VALUES(5, 'Thomas Weelkes');
+ INSERT INTO composer VALUES(6, 'J. S. Bach');
+ INSERT INTO composer VALUES(7, 'Orlando Gibbons');
+ INSERT INTO composer VALUES(8, 'Josquin des Prés');
+ INSERT INTO composer VALUES(9, 'Byrd');
+ INSERT INTO composer VALUES(10, 'Francis Poulenc');
+ INSERT INTO composer VALUES(11, 'Mendelsshon');
+ INSERT INTO composer VALUES(12, 'Zoltán Kodály');
+ INSERT INTO composer VALUES(13, 'Handel');
+ INSERT INTO album VALUES(100, 'Kodály: Missa Brevis');
+ INSERT INTO album VALUES(101, 'Messiah');
+ INSERT INTO album VALUES(102, 'Missa Brevis in D-, K.65');
+ INSERT INTO album VALUES(103, 'The complete English anthems');
+ INSERT INTO album VALUES(104, 'Mass in B Minor, BWV 232');
+ INSERT INTO track VALUES(10005, 12, 100, 'Sanctus');
+ INSERT INTO track VALUES(10007, 12, 100, 'Agnus Dei');
+ INSERT INTO track VALUES(10115, 13, 101, 'Surely He Hath Borne Our Griefs');
+ INSERT INTO track VALUES(10129, 13, 101, 'Since By Man Came Death');
+ INSERT INTO track VALUES(10206, 1, 102, 'Agnus Dei');
+ INSERT INTO track VALUES(10301, 3, 103, 'If Ye Love Me');
+ INSERT INTO track VALUES(10402, 6, 104, 'Domine Deus');
+ INSERT INTO track VALUES(10403, 6, 104, 'Qui tollis');
+} {}
+do_eqp_test whereG-1.1 {
+ SELECT DISTINCT aname
+ FROM album, composer, track
+ WHERE unlikely(cname LIKE '%bach%')
+ AND composer.cid=track.cid
+ AND album.aid=track.aid;
+} {/.*composer.*track.*album.*/}
+do_execsql_test whereG-1.2 {
+ SELECT DISTINCT aname
+ FROM album, composer, track
+ WHERE unlikely(cname LIKE '%bach%')
+ AND composer.cid=track.cid
+ AND album.aid=track.aid;
+} {{Mass in B Minor, BWV 232}}
+
+do_eqp_test whereG-1.3 {
+ SELECT DISTINCT aname
+ FROM album, composer, track
+ WHERE likelihood(cname LIKE '%bach%', 0.5)
+ AND composer.cid=track.cid
+ AND album.aid=track.aid;
+} {/.*track.*composer.*album.*/}
+do_execsql_test whereG-1.4 {
+ SELECT DISTINCT aname
+ FROM album, composer, track
+ WHERE likelihood(cname LIKE '%bach%', 0.5)
+ AND composer.cid=track.cid
+ AND album.aid=track.aid;
+} {{Mass in B Minor, BWV 232}}
+
+do_eqp_test whereG-1.5 {
+ SELECT DISTINCT aname
+ FROM album, composer, track
+ WHERE cname LIKE '%bach%'
+ AND composer.cid=track.cid
+ AND album.aid=track.aid;
+} {/.*track.*composer.*album.*/}
+do_execsql_test whereG-1.6 {
+ SELECT DISTINCT aname
+ FROM album, composer, track
+ WHERE cname LIKE '%bach%'
+ AND composer.cid=track.cid
+ AND album.aid=track.aid;
+} {{Mass in B Minor, BWV 232}}
+
+do_eqp_test whereG-1.7 {
+ SELECT DISTINCT aname
+ FROM album, composer, track
+ WHERE cname LIKE '%bach%'
+ AND unlikely(composer.cid=track.cid)
+ AND unlikely(album.aid=track.aid);
+} {/.*track.*composer.*album.*/}
+do_execsql_test whereG-1.8 {
+ SELECT DISTINCT aname
+ FROM album, composer, track
+ WHERE cname LIKE '%bach%'
+ AND unlikely(composer.cid=track.cid)
+ AND unlikely(album.aid=track.aid);
+} {{Mass in B Minor, BWV 232}}
+
+do_test whereG-2.1 {
+ catchsql {
+ SELECT DISTINCT aname
+ FROM album, composer, track
+ WHERE likelihood(cname LIKE '%bach%', -0.01)
+ AND composer.cid=track.cid
+ AND album.aid=track.aid;
+ }
+} {1 {second argument to likelihood() must be a constant between 0.0 and 1.0}}
+do_test whereG-2.2 {
+ catchsql {
+ SELECT DISTINCT aname
+ FROM album, composer, track
+ WHERE likelihood(cname LIKE '%bach%', 1.01)
+ AND composer.cid=track.cid
+ AND album.aid=track.aid;
+ }
+} {1 {second argument to likelihood() must be a constant between 0.0 and 1.0}}
+do_test whereG-2.3 {
+ catchsql {
+ SELECT DISTINCT aname
+ FROM album, composer, track
+ WHERE likelihood(cname LIKE '%bach%', track.cid)
+ AND composer.cid=track.cid
+ AND album.aid=track.aid;
+ }
+} {1 {second argument to likelihood() must be a constant between 0.0 and 1.0}}
+
+# Commuting a term of the WHERE clause should not change the query plan
+#
+do_execsql_test whereG-3.0 {
+ CREATE TABLE a(a1 PRIMARY KEY, a2);
+ CREATE TABLE b(b1 PRIMARY KEY, b2);
+} {}
+do_eqp_test whereG-3.1 {
+ SELECT * FROM a, b WHERE b1=a1 AND a2=5;
+} {/.*SCAN TABLE a.*SEARCH TABLE b USING INDEX .*b_1 .b1=..*/}
+do_eqp_test whereG-3.2 {
+ SELECT * FROM a, b WHERE a1=b1 AND a2=5;
+} {/.*SCAN TABLE a.*SEARCH TABLE b USING INDEX .*b_1 .b1=..*/}
+do_eqp_test whereG-3.3 {
+ SELECT * FROM a, b WHERE a2=5 AND b1=a1;
+} {/.*SCAN TABLE a.*SEARCH TABLE b USING INDEX .*b_1 .b1=..*/}
+do_eqp_test whereG-3.4 {
+ SELECT * FROM a, b WHERE a2=5 AND a1=b1;
+} {/.*SCAN TABLE a.*SEARCH TABLE b USING INDEX .*b_1 .b1=..*/}
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/wild001.test b/lang/sql/sqlite/test/wild001.test
new file mode 100644
index 00000000..7fe14042
--- /dev/null
+++ b/lang/sql/sqlite/test/wild001.test
@@ -0,0 +1,311 @@
+# 2013-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.
+#
+#***********************************************************************
+#
+# This is a test case from content taken "from the wild". In this
+# particular instance, the query was provided with permission by
+# Elan Feingold on 2013-06-27. His message on the SQLite mailing list
+# on that date reads:
+#
+#------------------------------------------------------------------------------
+# > Can you send (1) the schema (2) the query that is giving problems, and (3)
+# > the content of the sqlite_stat1 table after you have run ANALYZE? If you
+# > can combine all of the above into a script, that would be great!
+# >
+# > If you send (1..3) above and you give us written permission to include the
+# > query in our test suite, that would be off-the-chain terrific.
+#
+# Please find items 1..3 in this file: http://www.plexapp.com/elan/sqlite_bug.txt
+#
+# You have our permission to include the query in your test suite.
+#
+# Thanks for an amazing product.
+#-----------------------------------------------------------------------------
+#
+# This test case merely creates the schema and populates SQLITE_STAT1 and
+# SQLITE_STAT3 then runs an EXPLAIN QUERY PLAN to ensure that the right plan
+# is discovered. This test case may need to be adjusted for future revisions
+# of the query planner manage to select a better query plan. The query plan
+# shown here is known to be very fast with the original data.
+#
+# This test should work the same with and without SQLITE_ENABLE_STAT3
+#
+###############################################################################
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+ifcapable !stat3 {
+ finish_test
+ return
+}
+
+do_execsql_test wild001.01 {
+ CREATE TABLE "items" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "secid" integer, "parent_id" integer, "metadata_type" integer, "guid" varchar(255), "media_item_count" integer, "title" varchar(255), "title_sort" varchar(255) COLLATE NOCASE, "original_title" varchar(255), "studio" varchar(255), "rating" float, "rating_count" integer, "tagline" varchar(255), "summary" text, "trivia" text, "quotes" text, "content_rating" varchar(255), "content_rating_age" integer, "index" integer, "absolute_index" integer, "duration" integer, "user_thumb_url" varchar(255), "user_art_url" varchar(255), "user_banner_url" varchar(255), "user_music_url" varchar(255), "user_fields" varchar(255), "tags_genre" varchar(255), "tags_collection" varchar(255), "tags_director" varchar(255), "tags_writer" varchar(255), "tags_star" varchar(255), "originally_available_at" datetime, "available_at" datetime, "expires_at" datetime, "refreshed_at" datetime, "year" integer, "added_at" datetime, "created_at" datetime, "updated_at" datetime, "deleted_at" datetime, "tags_country" varchar(255), "extra_data" varchar(255), "hash" varchar(255));
+ CREATE INDEX "i_secid" ON "items" ("secid" );
+ CREATE INDEX "i_parent_id" ON "items" ("parent_id" );
+ CREATE INDEX "i_created_at" ON "items" ("created_at" );
+ CREATE INDEX "i_index" ON "items" ("index" );
+ CREATE INDEX "i_title" ON "items" ("title" );
+ CREATE INDEX "i_title_sort" ON "items" ("title_sort" );
+ CREATE INDEX "i_guid" ON "items" ("guid" );
+ CREATE INDEX "i_metadata_type" ON "items" ("metadata_type" );
+ CREATE INDEX "i_deleted_at" ON "items" ("deleted_at" );
+ CREATE INDEX "i_secid_ex1" ON "items" ("secid", "metadata_type", "added_at" );
+ CREATE INDEX "i_hash" ON "items" ("hash" );
+ CREATE TABLE "settings" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "account_id" integer, "guid" varchar(255), "rating" float, "view_offset" integer, "view_count" integer, "last_viewed_at" datetime, "created_at" datetime, "updated_at" datetime);
+ CREATE INDEX "s_account_id" ON "settings" ("account_id" );
+ CREATE INDEX "s_guid" ON "settings" ("guid" );
+ ANALYZE;
+ INSERT INTO sqlite_stat1 VALUES('settings','s_guid','4740 1');
+ INSERT INTO sqlite_stat1 VALUES('settings','s_account_id','4740 4740');
+ INSERT INTO sqlite_stat1 VALUES('items','i_hash','27316 2');
+ INSERT INTO sqlite_stat1 VALUES('items','i_secid_ex1','27316 6829 4553 3');
+ INSERT INTO sqlite_stat1 VALUES('items','i_deleted_at','27316 27316');
+ INSERT INTO sqlite_stat1 VALUES('items','i_metadata_type','27316 6829');
+ INSERT INTO sqlite_stat1 VALUES('items','i_guid','27316 2');
+ INSERT INTO sqlite_stat1 VALUES('items','i_title_sort','27316 2');
+ INSERT INTO sqlite_stat1 VALUES('items','i_title','27316 2');
+ INSERT INTO sqlite_stat1 VALUES('items','i_index','27316 144');
+ INSERT INTO sqlite_stat1 VALUES('items','i_created_at','27316 2');
+ INSERT INTO sqlite_stat1 VALUES('items','i_parent_id','27316 15');
+ INSERT INTO sqlite_stat1 VALUES('items','i_secid','27316 6829');
+ INSERT INTO sqlite_stat3 VALUES('settings','s_guid',1,150,150,'com.plexapp.agents.thetvdb://153021/2/9?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('settings','s_guid',1,198,198,'com.plexapp.agents.thetvdb://194031/1/10?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('settings','s_guid',1,526,526,'com.plexapp.agents.thetvdb://71256/12/92?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('settings','s_guid',1,923,923,'com.plexapp.agents.thetvdb://71256/15/16?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('settings','s_guid',1,1008,1008,'com.plexapp.agents.thetvdb://71256/15/93?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('settings','s_guid',1,1053,1053,'com.plexapp.agents.thetvdb://71256/16/21?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('settings','s_guid',1,1068,1068,'com.plexapp.agents.thetvdb://71256/16/35?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('settings','s_guid',1,1235,1235,'com.plexapp.agents.thetvdb://71256/17/44?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('settings','s_guid',1,1255,1255,'com.plexapp.agents.thetvdb://71256/17/62?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('settings','s_guid',1,1573,1573,'com.plexapp.agents.thetvdb://71663/20/9?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('settings','s_guid',1,1580,1580,'com.plexapp.agents.thetvdb://71663/21/16?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('settings','s_guid',1,2000,2000,'com.plexapp.agents.thetvdb://73141/9/8?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('settings','s_guid',1,2107,2107,'com.plexapp.agents.thetvdb://73244/6/17?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('settings','s_guid',1,2256,2256,'com.plexapp.agents.thetvdb://74845/4/7?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('settings','s_guid',1,2408,2408,'com.plexapp.agents.thetvdb://75978/2/21?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('settings','s_guid',1,2634,2634,'com.plexapp.agents.thetvdb://79126/1/1?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('settings','s_guid',1,2962,2962,'com.plexapp.agents.thetvdb://79274/3/94?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('settings','s_guid',1,3160,3160,'com.plexapp.agents.thetvdb://79274/5/129?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('settings','s_guid',1,3161,3161,'com.plexapp.agents.thetvdb://79274/5/12?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('settings','s_guid',1,3688,3688,'com.plexapp.agents.thetvdb://79274/8/62?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('settings','s_guid',1,3714,3714,'com.plexapp.agents.thetvdb://79274/8/86?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('settings','s_guid',1,4002,4002,'com.plexapp.agents.thetvdb://79590/13/17?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('settings','s_guid',1,4215,4215,'com.plexapp.agents.thetvdb://80727/3/6?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('settings','s_guid',1,4381,4381,'com.plexapp.agents.thetvdb://83462/3/24?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('settings','s_account_id',4740,0,0,1);
+ INSERT INTO sqlite_stat3 VALUES('items','i_hash',1,1879,1879,'1113f632ccd52ec8b8d7ca3d6d56da4701e48018');
+ INSERT INTO sqlite_stat3 VALUES('items','i_hash',1,2721,2721,'1936154b97bb5567163edaebc2806830ae419ccf');
+ INSERT INTO sqlite_stat3 VALUES('items','i_hash',1,3035,3035,'1c122331d4b7bfa0dc2c003ab5fb4f7152b9987a');
+ INSERT INTO sqlite_stat3 VALUES('items','i_hash',2,3393,3393,'1f81bdbc9acc3321dc592b1a109ca075731b549a');
+ INSERT INTO sqlite_stat3 VALUES('items','i_hash',1,6071,6070,'393cf7713efb4519c7a3d1d5403f0d945d15a16a');
+ INSERT INTO sqlite_stat3 VALUES('items','i_hash',1,7462,7461,'4677dd37011f8bd9ae7fbbdd3af6dcd8a5b4ab2d');
+ INSERT INTO sqlite_stat3 VALUES('items','i_hash',2,8435,8434,'4ffa339485334e81a5e12e03a63b6508d76401cf');
+ INSERT INTO sqlite_stat3 VALUES('items','i_hash',2,8716,8714,'52a093852e6599dd5004857b7ff5b5b82c7cdb25');
+ INSERT INTO sqlite_stat3 VALUES('items','i_hash',1,9107,9104,'561183e39f866d97ec728e9ff16ac4ad01466111');
+ INSERT INTO sqlite_stat3 VALUES('items','i_hash',2,10942,10939,'66e99b72e29610f49499ae09ee04a376210d1f08');
+ INSERT INTO sqlite_stat3 VALUES('items','i_hash',1,12143,12139,'71f0602427e173dc2c551535f73fdb6885fe4302');
+ INSERT INTO sqlite_stat3 VALUES('items','i_hash',2,14962,14958,'8ca8e4dfba696019830c19ab8a32c7ece9d8534b');
+ INSERT INTO sqlite_stat3 VALUES('items','i_hash',1,15179,15174,'8ebf1a5cf33f8ada1fc5853ac06ac4d7e074f825');
+ INSERT INTO sqlite_stat3 VALUES('items','i_hash',1,15375,15370,'908bc211bebdf21c79d2d2b54ebaa442ac1f5cae');
+ INSERT INTO sqlite_stat3 VALUES('items','i_hash',1,18215,18210,'ab29e4e18ec5a14fef95aa713d69e31c045a22c1');
+ INSERT INTO sqlite_stat3 VALUES('items','i_hash',1,18615,18610,'ae84c008cc0c338bf4f28d798a88575746452f6d');
+ INSERT INTO sqlite_stat3 VALUES('items','i_hash',1,18649,18644,'aec7c901353e115aa5307e94018ba7507bec3a45');
+ INSERT INTO sqlite_stat3 VALUES('items','i_hash',2,19517,19512,'b75025fbf2e9c504e3c1197ff1b69250402a31f8');
+ INSERT INTO sqlite_stat3 VALUES('items','i_hash',1,21251,21245,'c7d32f0e3a8f3a0a3dbd00833833d2ccee62f0fd');
+ INSERT INTO sqlite_stat3 VALUES('items','i_hash',2,23616,23610,'dd5ff61479a9bd4100de802515d9dcf72d46f07a');
+ INSERT INTO sqlite_stat3 VALUES('items','i_hash',1,24287,24280,'e3db00034301b7555419d4ef6f64769298d5845e');
+ INSERT INTO sqlite_stat3 VALUES('items','i_hash',1,24949,24942,'ea336abd197ecd7013854a25a4f4eb9dea7927c6');
+ INSERT INTO sqlite_stat3 VALUES('items','i_hash',1,25574,25567,'f018ea5182ec3f32768ca1c3cefbf3ad160ec20b');
+ INSERT INTO sqlite_stat3 VALUES('items','i_hash',2,26139,26132,'f53709a8d81c12cb0f4f8d58004a25dd063de67c');
+ INSERT INTO sqlite_stat3 VALUES('items','i_secid_ex1',25167,0,0,2);
+ INSERT INTO sqlite_stat3 VALUES('items','i_secid_ex1',736,25167,1,3);
+ INSERT INTO sqlite_stat3 VALUES('items','i_secid_ex1',15,25903,2,4);
+ INSERT INTO sqlite_stat3 VALUES('items','i_secid_ex1',1398,25918,3,5);
+ INSERT INTO sqlite_stat3 VALUES('items','i_deleted_at',27316,0,0,NULL);
+ INSERT INTO sqlite_stat3 VALUES('items','i_metadata_type',2149,0,0,1);
+ INSERT INTO sqlite_stat3 VALUES('items','i_metadata_type',411,2149,1,2);
+ INSERT INTO sqlite_stat3 VALUES('items','i_metadata_type',1440,2560,2,3);
+ INSERT INTO sqlite_stat3 VALUES('items','i_metadata_type',23316,4000,3,4);
+ INSERT INTO sqlite_stat3 VALUES('items','i_guid',1,215,215,'com.plexapp.agents.imdb://tt0065702?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('items','i_guid',2,711,711,'com.plexapp.agents.imdb://tt0198781?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('items','i_guid',2,987,986,'com.plexapp.agents.imdb://tt0454876?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('items','i_guid',2,1004,1002,'com.plexapp.agents.imdb://tt0464154?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('items','i_guid',2,1056,1053,'com.plexapp.agents.imdb://tt0499549?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('items','i_guid',2,1120,1116,'com.plexapp.agents.imdb://tt0903624?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('items','i_guid',2,1250,1245,'com.plexapp.agents.imdb://tt1268799?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('items','i_guid',2,1270,1264,'com.plexapp.agents.imdb://tt1320261?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('items','i_guid',2,1376,1369,'com.plexapp.agents.imdb://tt1772341?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('items','i_guid',1,3035,3027,'com.plexapp.agents.thetvdb://153021/3/14?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('items','i_guid',1,6071,6063,'com.plexapp.agents.thetvdb://71173/1/18?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('items','i_guid',1,6342,6334,'com.plexapp.agents.thetvdb://71256/13/4?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('items','i_guid',1,9107,9099,'com.plexapp.agents.thetvdb://72389/2/19?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('items','i_guid',1,11740,11732,'com.plexapp.agents.thetvdb://73893/2/13?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('items','i_guid',1,12143,12135,'com.plexapp.agents.thetvdb://73976/4/23?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('items','i_guid',1,15179,15171,'com.plexapp.agents.thetvdb://75897/16/12?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('items','i_guid',1,17408,17400,'com.plexapp.agents.thetvdb://76808/2/16?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('items','i_guid',1,17984,17976,'com.plexapp.agents.thetvdb://77068/1/16?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('items','i_guid',1,18215,18207,'com.plexapp.agents.thetvdb://77259/1/1?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('items','i_guid',1,21251,21243,'com.plexapp.agents.thetvdb://78957/8/2?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('items','i_guid',1,24287,24279,'com.plexapp.agents.thetvdb://80337/5/8?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('items','i_guid',1,25513,25505,'com.plexapp.agents.thetvdb://82226/6?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('items','i_guid',1,25548,25540,'com.plexapp.agents.thetvdb://82339/2/10?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('items','i_guid',1,26770,26762,'com.plexapp.agents.thetvdb://86901/1/3?lang=en');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title_sort',1524,0,0,'');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title_sort',2,3034,1391,'Attack of the Giant Squid');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title_sort',51,4742,2895,'Brad Sherwood');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title_sort',11,4912,2996,'Brian Williams');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title_sort',39,5847,3857,'Chip Esten');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title_sort',1,6071,4015,'Chuck Versus the DeLorean');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title_sort',12,7625,5436,'Denny Siegel');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title_sort',30,8924,6618,'Episode 1');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title_sort',29,9015,6629,'Episode 2');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title_sort',32,9082,6643,'Episode 3');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title_sort',28,9135,6654,'Episode 4');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title_sort',26,9183,6665,'Episode 5');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title_sort',27,9229,6677,'Episode 6');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title_sort',22,9266,6688,'Episode 7');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title_sort',20,9298,6699,'Episode 8');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title_sort',55,11750,8817,'Greg Proops');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title_sort',1,12143,9120,'Hardware Jungle');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title_sort',33,14712,11435,'Kathy Greenwood');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title_sort',3,15179,11840,'Last Call');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title_sort',1,18215,14601,'Nature or Nurture?');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title_sort',12,18241,14623,'Neil DeGrasse Tyson');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title_sort',68,19918,16144,'Pilot');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title_sort',7,21251,17298,'Reza Aslan');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title_sort',1,24287,20035,'Technoviking');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title',1524,0,0,'');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title',1,3035,1429,'Anderson Can''t Dance');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title',51,4782,2991,'Brad Sherwood');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title',11,4936,3079,'Brian Williams');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title',39,5694,3783,'Chip Esten');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title',1,6071,4100,'Clive Warren');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title',12,7144,5078,'Denny Siegel');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title',30,8249,6097,'Episode 1');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title',29,8340,6108,'Episode 2');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title',32,8407,6122,'Episode 3');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title',28,8460,6133,'Episode 4');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title',26,8508,6144,'Episode 5');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title',27,8554,6156,'Episode 6');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title',22,8591,6167,'Episode 7');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title',20,8623,6178,'Episode 8');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title',1,9107,6537,'Fat Albert and the Cosby Kids');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title',55,10539,7843,'Greg Proops');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title',1,12143,9276,'Iron Age Remains');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title',33,13118,10143,'Kathy Greenwood');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title',1,15179,11972,'Mink');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title',68,17411,14035,'Pilot');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title',2,18214,14727,'Reflections');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title',4,21250,17481,'The Apartment');
+ INSERT INTO sqlite_stat3 VALUES('items','i_title',1,24287,20283,'The Simpsons Already Did It');
+ INSERT INTO sqlite_stat3 VALUES('items','i_index',4315,95,2,1);
+ INSERT INTO sqlite_stat3 VALUES('items','i_index',1553,4410,3,2);
+ INSERT INTO sqlite_stat3 VALUES('items','i_index',1485,5963,4,3);
+ INSERT INTO sqlite_stat3 VALUES('items','i_index',1414,7448,5,4);
+ INSERT INTO sqlite_stat3 VALUES('items','i_index',1367,8862,6,5);
+ INSERT INTO sqlite_stat3 VALUES('items','i_index',1328,10229,7,6);
+ INSERT INTO sqlite_stat3 VALUES('items','i_index',1161,11557,8,7);
+ INSERT INTO sqlite_stat3 VALUES('items','i_index',1108,12718,9,8);
+ INSERT INTO sqlite_stat3 VALUES('items','i_index',1033,13826,10,9);
+ INSERT INTO sqlite_stat3 VALUES('items','i_index',1014,14859,11,10);
+ INSERT INTO sqlite_stat3 VALUES('items','i_index',929,15873,12,11);
+ INSERT INTO sqlite_stat3 VALUES('items','i_index',906,16802,13,12);
+ INSERT INTO sqlite_stat3 VALUES('items','i_index',844,17708,14,13);
+ INSERT INTO sqlite_stat3 VALUES('items','i_index',690,18552,15,14);
+ INSERT INTO sqlite_stat3 VALUES('items','i_index',655,19242,16,15);
+ INSERT INTO sqlite_stat3 VALUES('items','i_index',625,19897,17,16);
+ INSERT INTO sqlite_stat3 VALUES('items','i_index',579,20522,18,17);
+ INSERT INTO sqlite_stat3 VALUES('items','i_index',555,21101,19,18);
+ INSERT INTO sqlite_stat3 VALUES('items','i_index',526,21656,20,19);
+ INSERT INTO sqlite_stat3 VALUES('items','i_index',501,22182,21,20);
+ INSERT INTO sqlite_stat3 VALUES('items','i_index',459,22683,22,21);
+ INSERT INTO sqlite_stat3 VALUES('items','i_index',439,23142,23,22);
+ INSERT INTO sqlite_stat3 VALUES('items','i_index',315,23581,24,23);
+ INSERT INTO sqlite_stat3 VALUES('items','i_index',192,24177,26,25);
+ INSERT INTO sqlite_stat3 VALUES('items','i_created_at',1851,0,0,NULL);
+ INSERT INTO sqlite_stat3 VALUES('items','i_created_at',373,1857,2,'2011-10-22 14:54:39');
+ INSERT INTO sqlite_stat3 VALUES('items','i_created_at',595,2230,3,'2011-10-22 14:54:41');
+ INSERT INTO sqlite_stat3 VALUES('items','i_created_at',337,2825,4,'2011-10-22 14:54:43');
+ INSERT INTO sqlite_stat3 VALUES('items','i_created_at',361,3378,8,'2011-10-22 14:54:54');
+ INSERT INTO sqlite_stat3 VALUES('items','i_created_at',160,3739,9,'2011-10-22 14:54:56');
+ INSERT INTO sqlite_stat3 VALUES('items','i_created_at',315,4000,11,'2011-10-22 14:54:59');
+ INSERT INTO sqlite_stat3 VALUES('items','i_created_at',321,4334,13,'2011-10-22 14:55:02');
+ INSERT INTO sqlite_stat3 VALUES('items','i_created_at',1292,4723,16,'2011-10-22 14:55:06');
+ INSERT INTO sqlite_stat3 VALUES('items','i_created_at',161,6015,17,'2011-10-22 14:55:07');
+ INSERT INTO sqlite_stat3 VALUES('items','i_created_at',1,9107,2677,'2012-09-04 18:07:50');
+ INSERT INTO sqlite_stat3 VALUES('items','i_created_at',313,9717,3270,'2012-10-18 16:50:21');
+ INSERT INTO sqlite_stat3 VALUES('items','i_created_at',450,10030,3271,'2012-10-18 16:50:22');
+ INSERT INTO sqlite_stat3 VALUES('items','i_created_at',389,10668,3275,'2012-10-18 16:50:26');
+ INSERT INTO sqlite_stat3 VALUES('items','i_created_at',796,11057,3276,'2012-10-18 16:51:06');
+ INSERT INTO sqlite_stat3 VALUES('items','i_created_at',161,12041,3280,'2012-10-19 19:52:37');
+ INSERT INTO sqlite_stat3 VALUES('items','i_created_at',135,13281,4186,'2013-02-19 00:56:10');
+ INSERT INTO sqlite_stat3 VALUES('items','i_created_at',1063,13416,4187,'2013-02-19 00:56:11');
+ INSERT INTO sqlite_stat3 VALUES('items','i_created_at',797,14479,4188,'2013-02-19 00:56:13');
+ INSERT INTO sqlite_stat3 VALUES('items','i_created_at',147,15276,4189,'2013-02-19 00:56:15');
+ INSERT INTO sqlite_stat3 VALUES('items','i_created_at',346,15423,4190,'2013-02-19 00:56:16');
+ INSERT INTO sqlite_stat3 VALUES('items','i_created_at',1,18215,6436,'2013-05-05 14:09:54');
+ INSERT INTO sqlite_stat3 VALUES('items','i_created_at',2,21251,8122,'2013-05-24 15:25:45');
+ INSERT INTO sqlite_stat3 VALUES('items','i_created_at',1,24287,11116,'2013-05-26 14:17:39');
+ INSERT INTO sqlite_stat3 VALUES('items','i_parent_id',2560,0,0,NULL);
+ INSERT INTO sqlite_stat3 VALUES('items','i_parent_id',18,3022,31,2350);
+ INSERT INTO sqlite_stat3 VALUES('items','i_parent_id',10,6068,285,8150);
+ INSERT INTO sqlite_stat3 VALUES('items','i_parent_id',158,6346,315,8949);
+ INSERT INTO sqlite_stat3 VALUES('items','i_parent_id',34,9094,562,18831);
+ INSERT INTO sqlite_stat3 VALUES('items','i_parent_id',20,12139,794,22838);
+ INSERT INTO sqlite_stat3 VALUES('items','i_parent_id',134,14033,886,24739);
+ INSERT INTO sqlite_stat3 VALUES('items','i_parent_id',159,14167,887,24740);
+ INSERT INTO sqlite_stat3 VALUES('items','i_parent_id',161,14326,888,24741);
+ INSERT INTO sqlite_stat3 VALUES('items','i_parent_id',161,14487,889,24742);
+ INSERT INTO sqlite_stat3 VALUES('items','i_parent_id',124,14648,890,24743);
+ INSERT INTO sqlite_stat3 VALUES('items','i_parent_id',157,14772,891,24744);
+ INSERT INTO sqlite_stat3 VALUES('items','i_parent_id',126,15043,894,24747);
+ INSERT INTO sqlite_stat3 VALUES('items','i_parent_id',40,15169,895,24748);
+ INSERT INTO sqlite_stat3 VALUES('items','i_parent_id',161,15243,898,24753);
+ INSERT INTO sqlite_stat3 VALUES('items','i_parent_id',138,15404,899,24754);
+ INSERT INTO sqlite_stat3 VALUES('items','i_parent_id',160,15542,900,24755);
+ INSERT INTO sqlite_stat3 VALUES('items','i_parent_id',161,15702,901,24756);
+ INSERT INTO sqlite_stat3 VALUES('items','i_parent_id',161,15863,902,24757);
+ INSERT INTO sqlite_stat3 VALUES('items','i_parent_id',124,16024,903,24758);
+ INSERT INTO sqlite_stat3 VALUES('items','i_parent_id',155,16148,904,24759);
+ INSERT INTO sqlite_stat3 VALUES('items','i_parent_id',26,18208,1043,29704);
+ INSERT INTO sqlite_stat3 VALUES('items','i_parent_id',2,21251,1282,32952);
+ INSERT INTO sqlite_stat3 VALUES('items','i_parent_id',13,24279,1583,36068);
+ INSERT INTO sqlite_stat3 VALUES('items','i_secid',25167,0,0,2);
+ INSERT INTO sqlite_stat3 VALUES('items','i_secid',736,25167,1,3);
+ INSERT INTO sqlite_stat3 VALUES('items','i_secid',15,25903,2,4);
+ INSERT INTO sqlite_stat3 VALUES('items','i_secid',1398,25918,3,5);
+ ANALYZE sqlite_master;
+
+ explain query plan
+ select items.title
+ from items
+ join items as child on child.parent_id=items.id
+ join items as grandchild on grandchild.parent_id=child.id
+ join settings
+ on settings.guid=grandchild.guid
+ and settings.account_id=1
+ where items.metadata_type=2
+ and items.secid=2
+ and settings.last_viewed_at is not null
+ group by items.id
+ order by settings.last_viewed_at desc
+ limit 10;
+} [list \
+ 0 0 3 {SEARCH TABLE settings USING INDEX s_account_id (account_id=?)} \
+ 0 1 2 {SEARCH TABLE items AS grandchild USING INDEX i_guid (guid=?)} \
+ 0 2 1 {SEARCH TABLE items AS child USING INTEGER PRIMARY KEY (rowid=?)} \
+ 0 3 0 {SEARCH TABLE items USING INTEGER PRIMARY KEY (rowid=?)} \
+ 0 0 0 {USE TEMP B-TREE FOR GROUP BY} \
+ 0 0 0 {USE TEMP B-TREE FOR ORDER BY}]
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/win32heap.test b/lang/sql/sqlite/test/win32heap.test
new file mode 100644
index 00000000..b92f8040
--- /dev/null
+++ b/lang/sql/sqlite/test/win32heap.test
@@ -0,0 +1,74 @@
+# 2013 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.
+#
+#***********************************************************************
+# This file implements regression tests for SQLite library. The
+# focus of this script is recovery from transient manditory locks
+# that sometimes appear on database files due to anti-virus software.
+#
+
+if {$tcl_platform(platform)!="windows"} return
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+ifcapable !win32malloc {
+ finish_test
+ return
+}
+
+set testprefix win32heap
+
+do_test 1.1 {
+ catch {db close}
+ sqlite3_shutdown
+ sqlite3_config_heap_size 1048576
+ sqlite3_initialize
+} {SQLITE_OK}
+
+do_test 1.2 {
+ sqlite3 db test.db
+ catchsql {
+ CREATE TABLE t1(x);
+ }
+} {0 {}}
+
+do_test 1.3 {
+ catchsql {
+ INSERT INTO t1 (x) VALUES(RANDOMBLOB(1048576));
+ }
+} {1 {out of memory}}
+
+do_test 1.4 {
+ catchsql {
+ SELECT COUNT(*) FROM t1;
+ }
+} {0 0}
+
+do_test 1.5 {
+ catch {db close}
+ sqlite3_shutdown
+ sqlite3_config_heap_size 0
+ sqlite3_initialize
+} {SQLITE_OK}
+
+do_test 1.6 {
+ sqlite3 db test.db
+ catchsql {
+ INSERT INTO t1 (x) VALUES(RANDOMBLOB(1048576));
+ }
+} {0 {}}
+
+do_test 1.7 {
+ catchsql {
+ SELECT COUNT(*) FROM t1;
+ }
+} {0 1}
+
+finish_test
diff --git a/lang/sql/sqlite/test/win32lock.test b/lang/sql/sqlite/test/win32lock.test
new file mode 100644
index 00000000..72417206
--- /dev/null
+++ b/lang/sql/sqlite/test/win32lock.test
@@ -0,0 +1,134 @@
+# 2011 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. The
+# focus of this script is recovery from transient manditory locks
+# that sometimes appear on database files due to anti-virus software.
+#
+
+if {$tcl_platform(platform)!="windows"} return
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+set testprefix win32lock
+
+db close
+sqlite3_shutdown
+test_sqlite3_log xLog
+proc xLog {error_code msg} {
+ lappend ::log $msg
+}
+sqlite3 db test.db
+db eval {PRAGMA mmap_size=0}
+
+do_test win32lock-1.1 {
+ db eval {
+ PRAGMA cache_size=10;
+ CREATE TABLE t1(x,y);
+ INSERT INTO t1 VALUES(1,randomblob(100000));
+ INSERT INTO t1 VALUES(2,randomblob(50000));
+ INSERT INTO t1 VALUES(3,randomblob(25000));
+ INSERT INTO t1 VALUES(4,randomblob(12500));
+ SELECT x, length(y) FROM t1 ORDER BY rowid;
+ }
+} {1 100000 2 50000 3 25000 4 12500}
+
+unset -nocomplain delay1 rc msg
+set old_pending_byte [sqlite3_test_control_pending_byte 0x40000000]
+
+set win32_lock_ok [list]
+set win32_lock_error [list]
+set delay1 25
+while {1} {
+ lock_win32_file test.db 0 $::delay1
+ set ::log {}
+ set rc [catch {db eval {SELECT x, length(y) FROM t1 ORDER BY rowid}} msg]
+ if {$rc} {
+ lappend win32_lock_error $::delay1
+ do_test win32lock-1.2-$delay1-error {
+ set ::msg
+ } {disk I/O error}
+ } else {
+ lappend win32_lock_ok $::delay1
+ do_test win32lock-1.2-$delay1-ok {
+ set ::msg
+ } {1 100000 2 50000 3 25000 4 12500}
+ if {[info exists ::log] && $::log!=""} {
+ do_test win32lock-1.2-$delay1-log1 {
+ regsub {\d+} $::log # x
+ set x
+ } {{delayed #ms for lock/sharing conflict}}
+ }
+ }
+ if {[llength $win32_lock_ok] && [llength $win32_lock_error]} break
+ incr delay1 25
+ if {$delay1 > 12500} {
+ puts "Timed out waiting for \"ok\" and \"error\" results."
+ break
+ }
+ sqlite3_sleep 10
+}
+
+do_test win32lock-2.0 {
+ file_control_win32_av_retry db -1 -1
+} {0 10 25}
+do_test win32lock-2.1 {
+ file_control_win32_av_retry db 1 1
+} {0 1 1}
+
+#
+# NOTE: It is known that the win32lock-2.2-* tests may fail if the system is
+# experiencing heavy load (i.e. they are very timing sensitive). This is
+# primarily due to the AV retry delay being set to 1 millisecond in the
+# win32lock-2.1 test (above). While it is important to test this corner
+# case for the AV retry logic, a failure of this test should probably not
+# be interpreted as a bug in SQLite or these test cases.
+#
+set win32_lock_ok [list]
+set win32_lock_error [list]
+set delay1 1
+while {1} {
+ lock_win32_file test.db 0 $::delay1
+ set ::log {}
+ set rc [catch {db eval {SELECT x, length(y) FROM t1 ORDER BY rowid}} msg]
+ if {$rc} {
+ lappend win32_lock_error $::delay1
+ do_test win32lock-2.2-$delay1-error {
+ set ::msg
+ } {disk I/O error}
+ } else {
+ lappend win32_lock_ok $::delay1
+ do_test win32lock-2.2-$delay1-ok {
+ set ::msg
+ } {1 100000 2 50000 3 25000 4 12500}
+ if {[info exists ::log] && $::log!=""} {
+ do_test win32lock-2.2-$delay1-log1 {
+ regsub {\d+} $::log # x
+ set x
+ } {{delayed #ms for lock/sharing conflict}}
+ }
+ }
+ if {[llength $win32_lock_ok] && [llength $win32_lock_error]} break
+ incr delay1 1
+ if {$delay1 > 500} {
+ puts "Timed out waiting for \"ok\" and \"error\" results."
+ break
+ }
+ sqlite3_sleep 10
+}
+
+file_control_win32_av_retry db 10 25
+sqlite3_test_control_pending_byte $old_pending_byte
+db close
+sqlite3_shutdown
+test_sqlite3_log
+sqlite3_initialize
+finish_test
diff --git a/lang/sql/sqlite/test/win32longpath.test b/lang/sql/sqlite/test/win32longpath.test
new file mode 100644
index 00000000..9e9ed359
--- /dev/null
+++ b/lang/sql/sqlite/test/win32longpath.test
@@ -0,0 +1,110 @@
+# 2013 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 script is testing the file name handling provided
+# by the "win32-longpath" VFS.
+#
+
+if {$tcl_platform(platform)!="windows"} return
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix win32longpath
+
+do_test 1.0 {
+ file_control_vfsname db
+} win32
+
+db close
+set path [file nativename [get_pwd]]
+sqlite3 db [file join $path test.db] -vfs win32-longpath
+
+do_test 1.1 {
+ file_control_vfsname db
+} win32-longpath
+
+do_test 1.2 {
+ db eval {
+ BEGIN EXCLUSIVE;
+ CREATE TABLE t1(x);
+ INSERT INTO t1 VALUES(1);
+ INSERT INTO t1 VALUES(2);
+ INSERT INTO t1 VALUES(3);
+ INSERT INTO t1 VALUES(4);
+ SELECT x FROM t1 ORDER BY x;
+ COMMIT;
+ }
+} {1 2 3 4}
+
+set longPath(1) \\\\?\\$path\\[pid]
+make_win32_dir $longPath(1)
+
+set longPath(2) $longPath(1)\\[string repeat X 255]
+make_win32_dir $longPath(2)
+
+set longPath(3) $longPath(2)\\[string repeat Y 255]
+make_win32_dir $longPath(3)
+
+set fileName $longPath(3)\\test.db
+
+do_test 1.3 {
+ list [catch {sqlite3 db2 [string range $fileName 4 end]} msg] $msg
+} {1 {unable to open database file}}
+
+sqlite3 db3 $fileName -vfs win32-longpath
+
+do_test 1.4 {
+ db3 eval {
+ BEGIN EXCLUSIVE;
+ CREATE TABLE t1(x);
+ INSERT INTO t1 VALUES(5);
+ INSERT INTO t1 VALUES(6);
+ INSERT INTO t1 VALUES(7);
+ INSERT INTO t1 VALUES(8);
+ SELECT x FROM t1 ORDER BY x;
+ COMMIT;
+ }
+} {5 6 7 8}
+
+db3 close
+# puts " Database exists \{[exists_win32_path $fileName]\}"
+
+sqlite3 db3 $fileName -vfs win32-longpath
+
+do_test 1.5 {
+ db3 eval {
+ PRAGMA journal_mode = WAL;
+ }
+} {wal}
+
+do_test 1.6 {
+ db3 eval {
+ BEGIN EXCLUSIVE;
+ INSERT INTO t1 VALUES(9);
+ INSERT INTO t1 VALUES(10);
+ INSERT INTO t1 VALUES(11);
+ INSERT INTO t1 VALUES(12);
+ SELECT x FROM t1 ORDER BY x;
+ COMMIT;
+ }
+} {5 6 7 8 9 10 11 12}
+
+db3 close
+# puts " Database exists \{[exists_win32_path $fileName]\}"
+
+do_delete_win32_file $fileName
+# puts " Files remaining \{[find_win32_file $longPath(3)\\*]\}"
+
+do_remove_win32_dir $longPath(3)
+do_remove_win32_dir $longPath(2)
+do_remove_win32_dir $longPath(1)
+
+finish_test
diff --git a/lang/sql/sqlite/test/with1.test b/lang/sql/sqlite/test/with1.test
new file mode 100644
index 00000000..2fca1281
--- /dev/null
+++ b/lang/sql/sqlite/test/with1.test
@@ -0,0 +1,820 @@
+# 2014 January 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 WITH clause.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set ::testprefix with1
+
+ifcapable {!cte} {
+ finish_test
+ return
+}
+
+do_execsql_test 1.0 {
+ CREATE TABLE t1(x INTEGER, y INTEGER);
+ WITH x(a) AS ( SELECT * FROM t1) SELECT 10
+} {10}
+
+do_execsql_test 1.1 {
+ SELECT * FROM ( WITH x AS ( SELECT * FROM t1) SELECT 10 );
+} {10}
+
+do_execsql_test 1.2 {
+ WITH x(a) AS ( SELECT * FROM t1) INSERT INTO t1 VALUES(1,2);
+} {}
+
+do_execsql_test 1.3 {
+ WITH x(a) AS ( SELECT * FROM t1) DELETE FROM t1;
+} {}
+
+do_execsql_test 1.4 {
+ WITH x(a) AS ( SELECT * FROM t1) UPDATE t1 SET x = y;
+} {}
+
+#--------------------------------------------------------------------------
+
+do_execsql_test 2.1 {
+ DROP TABLE IF EXISTS t1;
+ CREATE TABLE t1(x);
+ INSERT INTO t1 VALUES(1);
+ INSERT INTO t1 VALUES(2);
+ WITH tmp AS ( SELECT * FROM t1 ) SELECT x FROM tmp;
+} {1 2}
+
+do_execsql_test 2.2 {
+ WITH tmp(a) AS ( SELECT * FROM t1 ) SELECT a FROM tmp;
+} {1 2}
+
+do_execsql_test 2.3 {
+ SELECT * FROM (
+ WITH tmp(a) AS ( SELECT * FROM t1 ) SELECT a FROM tmp
+ );
+} {1 2}
+
+do_execsql_test 2.4 {
+ WITH tmp1(a) AS ( SELECT * FROM t1 ),
+ tmp2(x) AS ( SELECT * FROM tmp1)
+ SELECT * FROM tmp2;
+} {1 2}
+
+do_execsql_test 2.5 {
+ WITH tmp2(x) AS ( SELECT * FROM tmp1),
+ tmp1(a) AS ( SELECT * FROM t1 )
+ SELECT * FROM tmp2;
+} {1 2}
+
+#-------------------------------------------------------------------------
+do_catchsql_test 3.1 {
+ WITH tmp2(x) AS ( SELECT * FROM tmp1 ),
+ tmp1(a) AS ( SELECT * FROM tmp2 )
+ SELECT * FROM tmp1;
+} {1 {circular reference: tmp1}}
+
+do_catchsql_test 3.2 {
+ CREATE TABLE t2(x INTEGER);
+ WITH tmp(a) AS (SELECT * FROM t1),
+ tmp(a) AS (SELECT * FROM t1)
+ SELECT * FROM tmp;
+} {1 {duplicate WITH table name: tmp}}
+
+do_execsql_test 3.3 {
+ CREATE TABLE t3(x);
+ CREATE TABLE t4(x);
+
+ INSERT INTO t3 VALUES('T3');
+ INSERT INTO t4 VALUES('T4');
+
+ WITH t3(a) AS (SELECT * FROM t4)
+ SELECT * FROM t3;
+} {T4}
+
+do_execsql_test 3.4 {
+ WITH tmp AS ( SELECT * FROM t3 ),
+ tmp2 AS ( WITH tmp AS ( SELECT * FROM t4 ) SELECT * FROM tmp )
+ SELECT * FROM tmp2;
+} {T4}
+
+do_execsql_test 3.5 {
+ WITH tmp AS ( SELECT * FROM t3 ),
+ tmp2 AS ( WITH xxxx AS ( SELECT * FROM t4 ) SELECT * FROM tmp )
+ SELECT * FROM tmp2;
+} {T3}
+
+do_catchsql_test 3.6 {
+ WITH tmp AS ( SELECT * FROM t3 ),
+ SELECT * FROM tmp;
+} {1 {near "SELECT": syntax error}}
+
+#-------------------------------------------------------------------------
+do_execsql_test 4.1 {
+ DROP TABLE IF EXISTS t1;
+ CREATE TABLE t1(x);
+ INSERT INTO t1 VALUES(1);
+ INSERT INTO t1 VALUES(2);
+ INSERT INTO t1 VALUES(3);
+ INSERT INTO t1 VALUES(4);
+
+ WITH dset AS ( SELECT 2 UNION ALL SELECT 4 )
+ DELETE FROM t1 WHERE x IN dset;
+ SELECT * FROM t1;
+} {1 3}
+
+do_execsql_test 4.2 {
+ WITH iset AS ( SELECT 2 UNION ALL SELECT 4 )
+ INSERT INTO t1 SELECT * FROM iset;
+ SELECT * FROM t1;
+} {1 3 2 4}
+
+do_execsql_test 4.3 {
+ WITH uset(a, b) AS ( SELECT 2, 8 UNION ALL SELECT 4, 9 )
+ UPDATE t1 SET x = COALESCE( (SELECT b FROM uset WHERE a=x), x );
+ SELECT * FROM t1;
+} {1 3 8 9}
+
+#-------------------------------------------------------------------------
+#
+do_execsql_test 5.1 {
+ WITH i(x) AS ( VALUES(1) UNION ALL SELECT x+1 FROM i)
+ SELECT x FROM i LIMIT 10;
+} {1 2 3 4 5 6 7 8 9 10}
+
+do_catchsql_test 5.2 {
+ WITH i(x) AS ( VALUES(1) UNION ALL SELECT x+1 FROM i ORDER BY 1)
+ SELECT x FROM i LIMIT 10;
+} {0 {1 2 3 4 5 6 7 8 9 10}}
+
+do_execsql_test 5.2.1 {
+ CREATE TABLE edge(xfrom, xto, seq, PRIMARY KEY(xfrom, xto)) WITHOUT ROWID;
+ INSERT INTO edge VALUES(0, 1, 10);
+ INSERT INTO edge VALUES(1, 2, 20);
+ INSERT INTO edge VALUES(0, 3, 30);
+ INSERT INTO edge VALUES(2, 4, 40);
+ INSERT INTO edge VALUES(3, 4, 40);
+ INSERT INTO edge VALUES(2, 5, 50);
+ INSERT INTO edge VALUES(3, 6, 60);
+ INSERT INTO edge VALUES(5, 7, 70);
+ INSERT INTO edge VALUES(3, 7, 70);
+ INSERT INTO edge VALUES(4, 8, 80);
+ INSERT INTO edge VALUES(7, 8, 80);
+ INSERT INTO edge VALUES(8, 9, 90);
+
+ WITH RECURSIVE
+ ancest(id, mtime) AS
+ (VALUES(0, 0)
+ UNION
+ SELECT edge.xto, edge.seq FROM edge, ancest
+ WHERE edge.xfrom=ancest.id
+ ORDER BY 2
+ )
+ SELECT * FROM ancest;
+} {0 0 1 10 2 20 3 30 4 40 5 50 6 60 7 70 8 80 9 90}
+do_execsql_test 5.2.2 {
+ WITH RECURSIVE
+ ancest(id, mtime) AS
+ (VALUES(0, 0)
+ UNION ALL
+ SELECT edge.xto, edge.seq FROM edge, ancest
+ WHERE edge.xfrom=ancest.id
+ ORDER BY 2
+ )
+ SELECT * FROM ancest;
+} {0 0 1 10 2 20 3 30 4 40 4 40 5 50 6 60 7 70 7 70 8 80 8 80 8 80 8 80 9 90 9 90 9 90 9 90}
+do_execsql_test 5.2.3 {
+ WITH RECURSIVE
+ ancest(id, mtime) AS
+ (VALUES(0, 0)
+ UNION ALL
+ SELECT edge.xto, edge.seq FROM edge, ancest
+ WHERE edge.xfrom=ancest.id
+ ORDER BY 2 LIMIT 4 OFFSET 2
+ )
+ SELECT * FROM ancest;
+} {2 20 3 30 4 40 4 40}
+
+do_catchsql_test 5.3 {
+ WITH i(x) AS ( VALUES(1) UNION ALL SELECT x+1 FROM i LIMIT 5)
+ SELECT x FROM i;
+} {0 {1 2 3 4 5}}
+
+do_execsql_test 5.4 {
+ WITH i(x) AS ( VALUES(1) UNION ALL SELECT (x+1)%10 FROM i)
+ SELECT x FROM i LIMIT 20;
+} {1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0}
+
+do_execsql_test 5.5 {
+ WITH i(x) AS ( VALUES(1) UNION SELECT (x+1)%10 FROM i)
+ SELECT x FROM i LIMIT 20;
+} {1 2 3 4 5 6 7 8 9 0}
+
+do_catchsql_test 5.6.1 {
+ WITH i(x, y) AS ( VALUES(1) )
+ SELECT * FROM i;
+} {1 {table i has 1 values for 2 columns}}
+
+do_catchsql_test 5.6.2 {
+ WITH i(x) AS ( VALUES(1,2) )
+ SELECT * FROM i;
+} {1 {table i has 2 values for 1 columns}}
+
+do_catchsql_test 5.6.3 {
+ CREATE TABLE t5(a, b);
+ WITH i(x) AS ( SELECT * FROM t5 )
+ SELECT * FROM i;
+} {1 {table i has 2 values for 1 columns}}
+
+do_catchsql_test 5.6.4 {
+ WITH i(x) AS ( SELECT 1, 2 UNION ALL SELECT 1 )
+ SELECT * FROM i;
+} {1 {table i has 2 values for 1 columns}}
+
+do_catchsql_test 5.6.5 {
+ WITH i(x) AS ( SELECT 1 UNION ALL SELECT 1, 2 )
+ SELECT * FROM i;
+} {1 {SELECTs to the left and right of UNION ALL do not have the same number of result columns}}
+
+do_catchsql_test 5.6.6 {
+ WITH i(x) AS ( SELECT 1 UNION ALL SELECT x+1, x*2 FROM i )
+ SELECT * FROM i;
+} {1 {SELECTs to the left and right of UNION ALL do not have the same number of result columns}}
+
+do_catchsql_test 5.6.7 {
+ WITH i(x) AS ( SELECT 1, 2 UNION SELECT x+1 FROM i )
+ SELECT * FROM i;
+} {1 {table i has 2 values for 1 columns}}
+
+#-------------------------------------------------------------------------
+#
+do_execsql_test 6.1 {
+ CREATE TABLE f(
+ id INTEGER PRIMARY KEY, parentid REFERENCES f, name TEXT
+ );
+
+ INSERT INTO f VALUES(0, NULL, '');
+ INSERT INTO f VALUES(1, 0, 'bin');
+ INSERT INTO f VALUES(2, 1, 'true');
+ INSERT INTO f VALUES(3, 1, 'false');
+ INSERT INTO f VALUES(4, 1, 'ls');
+ INSERT INTO f VALUES(5, 1, 'grep');
+ INSERT INTO f VALUES(6, 0, 'etc');
+ INSERT INTO f VALUES(7, 6, 'rc.d');
+ INSERT INTO f VALUES(8, 7, 'rc.apache');
+ INSERT INTO f VALUES(9, 7, 'rc.samba');
+ INSERT INTO f VALUES(10, 0, 'home');
+ INSERT INTO f VALUES(11, 10, 'dan');
+ INSERT INTO f VALUES(12, 11, 'public_html');
+ INSERT INTO f VALUES(13, 12, 'index.html');
+ INSERT INTO f VALUES(14, 13, 'logo.gif');
+}
+
+do_execsql_test 6.2 {
+ WITH flat(fid, fpath) AS (
+ SELECT id, '' FROM f WHERE parentid IS NULL
+ UNION ALL
+ SELECT id, fpath || '/' || name FROM f, flat WHERE parentid=fid
+ )
+ SELECT fpath FROM flat WHERE fpath!='' ORDER BY 1;
+} {
+ /bin
+ /bin/false /bin/grep /bin/ls /bin/true
+ /etc
+ /etc/rc.d
+ /etc/rc.d/rc.apache /etc/rc.d/rc.samba
+ /home
+ /home/dan
+ /home/dan/public_html
+ /home/dan/public_html/index.html
+ /home/dan/public_html/index.html/logo.gif
+}
+
+do_execsql_test 6.3 {
+ WITH flat(fid, fpath) AS (
+ SELECT id, '' FROM f WHERE parentid IS NULL
+ UNION ALL
+ SELECT id, fpath || '/' || name FROM f, flat WHERE parentid=fid
+ )
+ SELECT count(*) FROM flat;
+} {15}
+
+do_execsql_test 6.4 {
+ WITH x(i) AS (
+ SELECT 1
+ UNION ALL
+ SELECT i+1 FROM x WHERE i<10
+ )
+ SELECT count(*) FROM x
+} {10}
+
+
+#-------------------------------------------------------------------------
+
+do_execsql_test 7.1 {
+ CREATE TABLE tree(i, p);
+ INSERT INTO tree VALUES(1, NULL);
+ INSERT INTO tree VALUES(2, 1);
+ INSERT INTO tree VALUES(3, 1);
+ INSERT INTO tree VALUES(4, 2);
+ INSERT INTO tree VALUES(5, 4);
+}
+
+do_execsql_test 7.2 {
+ WITH t(id, path) AS (
+ SELECT i, '' FROM tree WHERE p IS NULL
+ UNION ALL
+ SELECT i, path || '/' || i FROM tree, t WHERE p = id
+ )
+ SELECT path FROM t;
+} {{} /2 /3 /2/4 /2/4/5}
+
+do_execsql_test 7.3 {
+ WITH t(id) AS (
+ VALUES(2)
+ UNION ALL
+ SELECT i FROM tree, t WHERE p = id
+ )
+ SELECT id FROM t;
+} {2 4 5}
+
+do_catchsql_test 7.4 {
+ WITH t(id) AS (
+ VALUES(2)
+ UNION ALL
+ SELECT i FROM tree WHERE p IN (SELECT id FROM t)
+ )
+ SELECT id FROM t;
+} {1 {recursive reference in a subquery: t}}
+
+do_catchsql_test 7.5 {
+ WITH t(id) AS (
+ VALUES(2)
+ UNION ALL
+ SELECT i FROM tree, t WHERE p = id AND p IN (SELECT id FROM t)
+ )
+ SELECT id FROM t;
+} {1 {multiple recursive references: t}}
+
+do_catchsql_test 7.6 {
+ WITH t(id) AS (
+ SELECT i FROM tree WHERE 2 IN (SELECT id FROM t)
+ UNION ALL
+ SELECT i FROM tree, t WHERE p = id
+ )
+ SELECT id FROM t;
+} {1 {circular reference: t}}
+
+# Compute the mandelbrot set using a recursive query
+#
+do_execsql_test 8.1-mandelbrot {
+ WITH RECURSIVE
+ xaxis(x) AS (VALUES(-2.0) UNION ALL SELECT x+0.05 FROM xaxis WHERE x<1.2),
+ yaxis(y) AS (VALUES(-1.0) UNION ALL SELECT y+0.1 FROM yaxis WHERE y<1.0),
+ m(iter, cx, cy, x, y) AS (
+ SELECT 0, x, y, 0.0, 0.0 FROM xaxis, yaxis
+ UNION ALL
+ SELECT iter+1, cx, cy, x*x-y*y + cx, 2.0*x*y + cy FROM m
+ WHERE (x*x + y*y) < 4.0 AND iter<28
+ ),
+ m2(iter, cx, cy) AS (
+ SELECT max(iter), cx, cy FROM m GROUP BY cx, cy
+ ),
+ a(t) AS (
+ SELECT group_concat( substr(' .+*#', 1+min(iter/7,4), 1), '')
+ FROM m2 GROUP BY cy
+ )
+ SELECT group_concat(rtrim(t),x'0a') FROM a;
+} {{ ....#
+ ..#*..
+ ..+####+.
+ .......+####.... +
+ ..##+*##########+.++++
+ .+.##################+.
+ .............+###################+.+
+ ..++..#.....*#####################+.
+ ...+#######++#######################.
+ ....+*################################.
+ #############################################...
+ ....+*################################.
+ ...+#######++#######################.
+ ..++..#.....*#####################+.
+ .............+###################+.+
+ .+.##################+.
+ ..##+*##########+.++++
+ .......+####.... +
+ ..+####+.
+ ..#*..
+ ....#
+ +.}}
+
+# Solve a sudoku puzzle using a recursive query
+#
+do_execsql_test 8.2-soduko {
+ WITH RECURSIVE
+ input(sud) AS (
+ VALUES('53..7....6..195....98....6.8...6...34..8.3..17...2...6.6....28....419..5....8..79')
+ ),
+
+ /* A table filled with digits 1..9, inclusive. */
+ digits(z, lp) AS (
+ VALUES('1', 1)
+ UNION ALL SELECT
+ CAST(lp+1 AS TEXT), lp+1 FROM digits WHERE lp<9
+ ),
+
+ /* The tricky bit. */
+ x(s, ind) AS (
+ SELECT sud, instr(sud, '.') FROM input
+ UNION ALL
+ SELECT
+ substr(s, 1, ind-1) || z || substr(s, ind+1),
+ instr( substr(s, 1, ind-1) || z || substr(s, ind+1), '.' )
+ FROM x, digits AS z
+ WHERE ind>0
+ AND NOT EXISTS (
+ SELECT 1
+ FROM digits AS lp
+ WHERE z.z = substr(s, ((ind-1)/9)*9 + lp, 1)
+ OR z.z = substr(s, ((ind-1)%9) + (lp-1)*9 + 1, 1)
+ OR z.z = substr(s, (((ind-1)/3) % 3) * 3
+ + ((ind-1)/27) * 27 + lp
+ + ((lp-1) / 3) * 6, 1)
+ )
+ )
+ SELECT s FROM x WHERE ind=0;
+} {534678912672195348198342567859761423426853791713924856961537284287419635345286179}
+
+#--------------------------------------------------------------------------
+# Some tests that use LIMIT and OFFSET in the definition of recursive CTEs.
+#
+set I [list 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20]
+proc limit_test {tn iLimit iOffset} {
+ if {$iOffset < 0} { set iOffset 0 }
+ if {$iLimit < 0 } {
+ set result [lrange $::I $iOffset end]
+ } else {
+ set result [lrange $::I $iOffset [expr $iLimit+$iOffset-1]]
+ }
+ uplevel [list do_execsql_test $tn [subst -nocommands {
+ WITH ii(a) AS (
+ VALUES(1)
+ UNION ALL
+ SELECT a+1 FROM ii WHERE a<20
+ LIMIT $iLimit OFFSET $iOffset
+ )
+ SELECT * FROM ii
+ }] $result]
+}
+
+limit_test 9.1 20 0
+limit_test 9.2 0 0
+limit_test 9.3 19 1
+limit_test 9.4 20 -1
+limit_test 9.5 5 5
+limit_test 9.6 0 -1
+limit_test 9.7 40 -1
+limit_test 9.8 -1 -1
+limit_test 9.9 -1 -1
+
+#--------------------------------------------------------------------------
+# Test the ORDER BY clause on recursive tables.
+#
+
+do_execsql_test 10.1 {
+ DROP TABLE IF EXISTS tree;
+ CREATE TABLE tree(id INTEGER PRIMARY KEY, parentid, payload);
+}
+
+proc insert_into_tree {L} {
+ db eval { DELETE FROM tree }
+ foreach key $L {
+ unset -nocomplain parentid
+ foreach seg [split $key /] {
+ if {$seg==""} continue
+ set id [db one {
+ SELECT id FROM tree WHERE parentid IS $parentid AND payload=$seg
+ }]
+ if {$id==""} {
+ db eval { INSERT INTO tree VALUES(NULL, $parentid, $seg) }
+ set parentid [db last_insert_rowid]
+ } else {
+ set parentid $id
+ }
+ }
+ }
+}
+
+insert_into_tree {
+ /a/a/a
+ /a/b/c
+ /a/b/c/d
+ /a/b/d
+}
+do_execsql_test 10.2 {
+ WITH flat(fid, p) AS (
+ SELECT id, '/' || payload FROM tree WHERE parentid IS NULL
+ UNION ALL
+ SELECT id, p || '/' || payload FROM flat, tree WHERE parentid=fid
+ )
+ SELECT p FROM flat ORDER BY p;
+} {
+ /a /a/a /a/a/a
+ /a/b /a/b/c /a/b/c/d
+ /a/b/d
+}
+
+# Scan the tree-structure currently stored in table tree. Return a list
+# of nodes visited.
+#
+proc scan_tree {bDepthFirst bReverse} {
+
+ set order "ORDER BY "
+ if {$bDepthFirst==0} { append order "2 ASC," }
+ if {$bReverse==0} {
+ append order " 3 ASC"
+ } else {
+ append order " 3 DESC"
+ }
+
+ db eval "
+ WITH flat(fid, depth, p) AS (
+ SELECT id, 1, '/' || payload FROM tree WHERE parentid IS NULL
+ UNION ALL
+ SELECT id, depth+1, p||'/'||payload FROM flat, tree WHERE parentid=fid
+ $order
+ )
+ SELECT p FROM flat;
+ "
+}
+
+insert_into_tree {
+ /a/b
+ /a/b/c
+ /a/d
+ /a/d/e
+ /a/d/f
+ /g/h
+}
+
+# Breadth first, siblings in ascending order.
+#
+do_test 10.3 {
+ scan_tree 0 0
+} [list {*}{
+ /a /g
+ /a/b /a/d /g/h
+ /a/b/c /a/d/e /a/d/f
+}]
+
+# Depth first, siblings in ascending order.
+#
+do_test 10.4 {
+ scan_tree 1 0
+} [list {*}{
+ /a /a/b /a/b/c
+ /a/d /a/d/e
+ /a/d/f
+ /g /g/h
+}]
+
+# Breadth first, siblings in descending order.
+#
+do_test 10.5 {
+ scan_tree 0 1
+} [list {*}{
+ /g /a
+ /g/h /a/d /a/b
+ /a/d/f /a/d/e /a/b/c
+}]
+
+# Depth first, siblings in ascending order.
+#
+do_test 10.6 {
+ scan_tree 1 1
+} [list {*}{
+ /g /g/h
+ /a /a/d /a/d/f
+ /a/d/e
+ /a/b /a/b/c
+}]
+
+
+# Test name resolution in ORDER BY clauses.
+#
+do_catchsql_test 10.7.1 {
+ WITH t(a) AS (
+ SELECT 1 AS b UNION ALL SELECT a+1 AS c FROM t WHERE a<5 ORDER BY a
+ )
+ SELECT * FROM t
+} {1 {1st ORDER BY term does not match any column in the result set}}
+do_execsql_test 10.7.2 {
+ WITH t(a) AS (
+ SELECT 1 AS b UNION ALL SELECT a+1 AS c FROM t WHERE a<5 ORDER BY b
+ )
+ SELECT * FROM t
+} {1 2 3 4 5}
+do_execsql_test 10.7.3 {
+ WITH t(a) AS (
+ SELECT 1 AS b UNION ALL SELECT a+1 AS c FROM t WHERE a<5 ORDER BY c
+ )
+ SELECT * FROM t
+} {1 2 3 4 5}
+
+# Test COLLATE clauses attached to ORDER BY.
+#
+insert_into_tree {
+ /a/b
+ /a/C
+ /a/d
+ /B/e
+ /B/F
+ /B/g
+ /c/h
+ /c/I
+ /c/j
+}
+
+do_execsql_test 10.8.1 {
+ WITH flat(fid, depth, p) AS (
+ SELECT id, 1, '/' || payload FROM tree WHERE parentid IS NULL
+ UNION ALL
+ SELECT id, depth+1, p||'/'||payload FROM flat, tree WHERE parentid=fid
+ ORDER BY 2, 3 COLLATE nocase
+ )
+ SELECT p FROM flat;
+} {
+ /a /B /c
+ /a/b /a/C /a/d /B/e /B/F /B/g /c/h /c/I /c/j
+}
+do_execsql_test 10.8.2 {
+ WITH flat(fid, depth, p) AS (
+ SELECT id, 1, ('/' || payload) COLLATE nocase
+ FROM tree WHERE parentid IS NULL
+ UNION ALL
+ SELECT id, depth+1, (p||'/'||payload)
+ FROM flat, tree WHERE parentid=fid
+ ORDER BY 2, 3
+ )
+ SELECT p FROM flat;
+} {
+ /a /B /c
+ /a/b /a/C /a/d /B/e /B/F /B/g /c/h /c/I /c/j
+}
+
+do_execsql_test 10.8.3 {
+ WITH flat(fid, depth, p) AS (
+ SELECT id, 1, ('/' || payload)
+ FROM tree WHERE parentid IS NULL
+ UNION ALL
+ SELECT id, depth+1, (p||'/'||payload) COLLATE nocase
+ FROM flat, tree WHERE parentid=fid
+ ORDER BY 2, 3
+ )
+ SELECT p FROM flat;
+} {
+ /a /B /c
+ /a/b /a/C /a/d /B/e /B/F /B/g /c/h /c/I /c/j
+}
+
+do_execsql_test 10.8.4.1 {
+ CREATE TABLE tst(a,b);
+ INSERT INTO tst VALUES('a', 'A');
+ INSERT INTO tst VALUES('b', 'B');
+ INSERT INTO tst VALUES('c', 'C');
+ SELECT a COLLATE nocase FROM tst UNION ALL SELECT b FROM tst ORDER BY 1;
+} {a A b B c C}
+do_execsql_test 10.8.4.2 {
+ SELECT a FROM tst UNION ALL SELECT b COLLATE nocase FROM tst ORDER BY 1;
+} {A B C a b c}
+do_execsql_test 10.8.4.3 {
+ SELECT a||'' FROM tst UNION ALL SELECT b COLLATE nocase FROM tst ORDER BY 1;
+} {a A b B c C}
+
+# Test cases to illustrate on the ORDER BY clause on a recursive query can be
+# used to control depth-first versus breath-first search in a tree.
+#
+do_execsql_test 11.1 {
+ CREATE TABLE org(
+ name TEXT PRIMARY KEY,
+ boss TEXT REFERENCES org
+ ) WITHOUT ROWID;
+ INSERT INTO org VALUES('Alice',NULL);
+ INSERT INTO org VALUES('Bob','Alice');
+ INSERT INTO org VALUES('Cindy','Alice');
+ INSERT INTO org VALUES('Dave','Bob');
+ INSERT INTO org VALUES('Emma','Bob');
+ INSERT INTO org VALUES('Fred','Cindy');
+ INSERT INTO org VALUES('Gail','Cindy');
+ INSERT INTO org VALUES('Harry','Dave');
+ INSERT INTO org VALUES('Ingrid','Dave');
+ INSERT INTO org VALUES('Jim','Emma');
+ INSERT INTO org VALUES('Kate','Emma');
+ INSERT INTO org VALUES('Lanny','Fred');
+ INSERT INTO org VALUES('Mary','Fred');
+ INSERT INTO org VALUES('Noland','Gail');
+ INSERT INTO org VALUES('Olivia','Gail');
+ -- The above are all under Alice. Add a few more records for people
+ -- not in Alice's group, just to prove that they won't be selected.
+ INSERT INTO org VALUES('Xaviar',NULL);
+ INSERT INTO org VALUES('Xia','Xaviar');
+ INSERT INTO org VALUES('Xerxes','Xaviar');
+ INSERT INTO org VALUES('Xena','Xia');
+ -- Find all members of Alice's group, breath-first order
+ WITH RECURSIVE
+ under_alice(name,level) AS (
+ VALUES('Alice','0')
+ UNION ALL
+ SELECT org.name, under_alice.level+1
+ FROM org, under_alice
+ WHERE org.boss=under_alice.name
+ ORDER BY 2
+ )
+ SELECT group_concat(substr('...............',1,level*3) || name,x'0a')
+ FROM under_alice;
+} {{Alice
+...Bob
+...Cindy
+......Dave
+......Emma
+......Fred
+......Gail
+.........Harry
+.........Ingrid
+.........Jim
+.........Kate
+.........Lanny
+.........Mary
+.........Noland
+.........Olivia}}
+
+# The previous query used "ORDER BY level" to yield a breath-first search.
+# Change that to "ORDER BY level DESC" for a depth-first search.
+#
+do_execsql_test 11.2 {
+ WITH RECURSIVE
+ under_alice(name,level) AS (
+ VALUES('Alice','0')
+ UNION ALL
+ SELECT org.name, under_alice.level+1
+ FROM org, under_alice
+ WHERE org.boss=under_alice.name
+ ORDER BY 2 DESC
+ )
+ SELECT group_concat(substr('...............',1,level*3) || name,x'0a')
+ FROM under_alice;
+} {{Alice
+...Bob
+......Dave
+.........Harry
+.........Ingrid
+......Emma
+.........Jim
+.........Kate
+...Cindy
+......Fred
+.........Lanny
+.........Mary
+......Gail
+.........Noland
+.........Olivia}}
+
+# Without an ORDER BY clause, the recursive query should use a FIFO,
+# resulting in a breath-first search.
+#
+do_execsql_test 11.3 {
+ WITH RECURSIVE
+ under_alice(name,level) AS (
+ VALUES('Alice','0')
+ UNION ALL
+ SELECT org.name, under_alice.level+1
+ FROM org, under_alice
+ WHERE org.boss=under_alice.name
+ )
+ SELECT group_concat(substr('...............',1,level*3) || name,x'0a')
+ FROM under_alice;
+} {{Alice
+...Bob
+...Cindy
+......Dave
+......Emma
+......Fred
+......Gail
+.........Harry
+.........Ingrid
+.........Jim
+.........Kate
+.........Lanny
+.........Mary
+.........Noland
+.........Olivia}}
+
+finish_test
+
diff --git a/lang/sql/sqlite/test/with2.test b/lang/sql/sqlite/test/with2.test
new file mode 100644
index 00000000..d702f8c9
--- /dev/null
+++ b/lang/sql/sqlite/test/with2.test
@@ -0,0 +1,391 @@
+# 2014 January 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 WITH clause.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set ::testprefix with2
+
+ifcapable {!cte} {
+ finish_test
+ return
+}
+
+do_execsql_test 1.0 {
+ CREATE TABLE t1(a);
+ INSERT INTO t1 VALUES(1);
+ INSERT INTO t1 VALUES(2);
+}
+
+do_execsql_test 1.1 {
+ WITH x1 AS (SELECT * FROM t1)
+ SELECT sum(a) FROM x1;
+} {3}
+
+do_execsql_test 1.2 {
+ WITH x1 AS (SELECT * FROM t1)
+ SELECT (SELECT sum(a) FROM x1);
+} {3}
+
+do_execsql_test 1.3 {
+ WITH x1 AS (SELECT * FROM t1)
+ SELECT (SELECT sum(a) FROM x1);
+} {3}
+
+do_execsql_test 1.4 {
+ CREATE TABLE t2(i);
+ INSERT INTO t2 VALUES(2);
+ INSERT INTO t2 VALUES(3);
+ INSERT INTO t2 VALUES(5);
+
+ WITH x1 AS (SELECT i FROM t2),
+ i(a) AS (
+ SELECT min(i)-1 FROM x1 UNION SELECT a+1 FROM i WHERE a<10
+ )
+ SELECT a FROM i WHERE a NOT IN x1
+} {1 4 6 7 8 9 10}
+
+do_execsql_test 1.5 {
+ WITH x1 AS (SELECT a FROM t1),
+ x2 AS (SELECT i FROM t2),
+ x3 AS (SELECT * FROM x1, x2 WHERE x1.a IN x2 AND x2.i IN x1)
+ SELECT * FROM x3
+} {2 2}
+
+do_execsql_test 1.6 {
+ CREATE TABLE t3 AS SELECT 3 AS x;
+ CREATE TABLE t4 AS SELECT 4 AS x;
+
+ WITH x1 AS (SELECT * FROM t3),
+ x2 AS (
+ WITH t3 AS (SELECT * FROM t4)
+ SELECT * FROM x1
+ )
+ SELECT * FROM x2;
+} {3}
+
+do_execsql_test 1.7 {
+ WITH x2 AS (
+ WITH t3 AS (SELECT * FROM t4)
+ SELECT * FROM t3
+ )
+ SELECT * FROM x2;
+} {4}
+
+do_execsql_test 1.8 {
+ WITH x2 AS (
+ WITH t3 AS (SELECT * FROM t4)
+ SELECT * FROM main.t3
+ )
+ SELECT * FROM x2;
+} {3}
+
+do_execsql_test 1.9 {
+ WITH x1 AS (SELECT * FROM t1)
+ SELECT (SELECT sum(a) FROM x1), (SELECT max(a) FROM x1);
+} {3 2}
+
+do_execsql_test 1.10 {
+ WITH x1 AS (SELECT * FROM t1)
+ SELECT (SELECT sum(a) FROM x1), (SELECT max(a) FROM x1), a FROM x1;
+} {3 2 1 3 2 2}
+
+do_execsql_test 1.11 {
+ WITH
+ i(x) AS (
+ WITH
+ j(x) AS ( SELECT * FROM i ),
+ i(x) AS ( SELECT * FROM t1 )
+ SELECT * FROM j
+ )
+ SELECT * FROM i;
+} {1 2}
+
+do_execsql_test 1.12 {
+ WITH r(i) AS (
+ VALUES('.')
+ UNION ALL
+ SELECT i || '.' FROM r, (
+ SELECT x FROM x INTERSECT SELECT y FROM y
+ ) WHERE length(i) < 10
+ ),
+ x(x) AS ( VALUES(1) UNION ALL VALUES(2) UNION ALL VALUES(3) ),
+ y(y) AS ( VALUES(2) UNION ALL VALUES(4) UNION ALL VALUES(6) )
+
+ SELECT * FROM r;
+} {. .. ... .... ..... ...... ....... ........ ......... ..........}
+
+do_execsql_test 1.13 {
+ WITH r(i) AS (
+ VALUES('.')
+ UNION ALL
+ SELECT i || '.' FROM r, ( SELECT x FROM x WHERE x=2 ) WHERE length(i) < 10
+ ),
+ x(x) AS ( VALUES(1) UNION ALL VALUES(2) UNION ALL VALUES(3) )
+
+ SELECT * FROM r ORDER BY length(i) DESC;
+} {.......... ......... ........ ....... ...... ..... .... ... .. .}
+
+do_execsql_test 1.14 {
+ WITH
+ t4(x) AS (
+ VALUES(4)
+ UNION ALL
+ SELECT x+1 FROM t4 WHERE x<10
+ )
+ SELECT * FROM t4;
+} {4 5 6 7 8 9 10}
+
+do_execsql_test 1.15 {
+ WITH
+ t4(x) AS (
+ VALUES(4)
+ UNION ALL
+ SELECT x+1 FROM main.t4 WHERE x<10
+ )
+ SELECT * FROM t4;
+} {4 5}
+
+do_catchsql_test 1.16 {
+ WITH
+ t4(x) AS (
+ VALUES(4)
+ UNION ALL
+ SELECT x+1 FROM t4, main.t4, t4 WHERE x<10
+ )
+ SELECT * FROM t4;
+} {1 {multiple references to recursive table: t4}}
+
+
+#---------------------------------------------------------------------------
+# Check that variables can be used in CTEs.
+#
+set ::min [expr 3]
+set ::max [expr 9]
+do_execsql_test 2.1 {
+ WITH i(x) AS (
+ VALUES($min) UNION ALL SELECT x+1 FROM i WHERE x < $max
+ )
+ SELECT * FROM i;
+} {3 4 5 6 7 8 9}
+
+do_execsql_test 2.2 {
+ WITH i(x) AS (
+ VALUES($min) UNION ALL SELECT x+1 FROM i WHERE x < $max
+ )
+ SELECT x FROM i JOIN i AS j USING (x);
+} {3 4 5 6 7 8 9}
+
+#---------------------------------------------------------------------------
+# Check that circular references are rejected.
+#
+do_catchsql_test 3.1 {
+ WITH i(x, y) AS ( VALUES(1, (SELECT x FROM i)) )
+ SELECT * FROM i;
+} {1 {circular reference: i}}
+
+do_catchsql_test 3.2 {
+ WITH
+ i(x) AS ( SELECT * FROM j ),
+ j(x) AS ( SELECT * FROM k ),
+ k(x) AS ( SELECT * FROM i )
+ SELECT * FROM i;
+} {1 {circular reference: i}}
+
+do_catchsql_test 3.3 {
+ WITH
+ i(x) AS ( SELECT * FROM (SELECT * FROM j) ),
+ j(x) AS ( SELECT * FROM (SELECT * FROM i) )
+ SELECT * FROM i;
+} {1 {circular reference: i}}
+
+do_catchsql_test 3.4 {
+ WITH
+ i(x) AS ( SELECT * FROM (SELECT * FROM j) ),
+ j(x) AS ( SELECT * FROM (SELECT * FROM i) )
+ SELECT * FROM j;
+} {1 {circular reference: j}}
+
+do_catchsql_test 3.5 {
+ WITH
+ i(x) AS (
+ WITH j(x) AS ( SELECT * FROM i )
+ SELECT * FROM j
+ )
+ SELECT * FROM i;
+} {1 {circular reference: i}}
+
+#---------------------------------------------------------------------------
+# Try empty and very long column lists.
+#
+do_catchsql_test 4.1 {
+ WITH x() AS ( SELECT 1,2,3 )
+ SELECT * FROM x;
+} {1 {near ")": syntax error}}
+
+proc genstmt {n} {
+ for {set i 1} {$i<=$n} {incr i} {
+ lappend cols "c$i"
+ lappend vals $i
+ }
+ return "
+ WITH x([join $cols ,]) AS (SELECT [join $vals ,])
+ SELECT (c$n == $n) FROM x
+ "
+}
+
+do_execsql_test 4.2 [genstmt 10] 1
+do_execsql_test 4.3 [genstmt 100] 1
+do_execsql_test 4.4 [genstmt 255] 1
+set nLimit [sqlite3_limit db SQLITE_LIMIT_COLUMN -1]
+do_execsql_test 4.5 [genstmt [expr $nLimit-1]] 1
+do_execsql_test 4.6 [genstmt $nLimit] 1
+do_catchsql_test 4.7 [genstmt [expr $nLimit+1]] {1 {too many columns in index}}
+
+#---------------------------------------------------------------------------
+# Check that adding a WITH clause to an INSERT disables the xfer
+# optimization.
+#
+proc do_xfer_test {tn bXfer sql {res {}}} {
+ set ::sqlite3_xferopt_count 0
+ uplevel [list do_test $tn [subst -nocommands {
+ set dres [db eval {$sql}]
+ list [set ::sqlite3_xferopt_count] [set dres]
+ }] [list $bXfer $res]]
+}
+
+do_execsql_test 5.1 {
+ DROP TABLE IF EXISTS t1;
+ DROP TABLE IF EXISTS t2;
+ CREATE TABLE t1(a, b);
+ CREATE TABLE t2(a, b);
+}
+
+do_xfer_test 5.2 1 { INSERT INTO t1 SELECT * FROM t2 }
+do_xfer_test 5.3 0 { INSERT INTO t1 SELECT a, b FROM t2 }
+do_xfer_test 5.4 0 { INSERT INTO t1 SELECT b, a FROM t2 }
+do_xfer_test 5.5 0 {
+ WITH x AS (SELECT a, b FROM t2) INSERT INTO t1 SELECT * FROM x
+}
+do_xfer_test 5.6 0 {
+ WITH x AS (SELECT a, b FROM t2) INSERT INTO t1 SELECT * FROM t2
+}
+do_xfer_test 5.7 0 {
+ INSERT INTO t1 WITH x AS ( SELECT * FROM t2 ) SELECT * FROM x
+}
+do_xfer_test 5.8 0 {
+ INSERT INTO t1 WITH x(a,b) AS ( SELECT * FROM t2 ) SELECT * FROM x
+}
+
+#---------------------------------------------------------------------------
+# Check that syntax (and other) errors in statements with WITH clauses
+# attached to them do not cause problems (e.g. memory leaks).
+#
+do_execsql_test 6.1 {
+ DROP TABLE IF EXISTS t1;
+ DROP TABLE IF EXISTS t2;
+ CREATE TABLE t1(a, b);
+ CREATE TABLE t2(a, b);
+}
+
+do_catchsql_test 6.2 {
+ WITH x AS (SELECT * FROM t1)
+ INSERT INTO t2 VALUES(1, 2,);
+} {1 {near ")": syntax error}}
+
+do_catchsql_test 6.3 {
+ WITH x AS (SELECT * FROM t1)
+ INSERT INTO t2 SELECT a, b, FROM t1;
+} {1 {near "FROM": syntax error}}
+
+do_catchsql_test 6.3 {
+ WITH x AS (SELECT * FROM t1)
+ INSERT INTO t2 SELECT a, b FROM abc;
+} {1 {no such table: abc}}
+
+do_catchsql_test 6.4 {
+ WITH x AS (SELECT * FROM t1)
+ INSERT INTO t2 SELECT a, b, FROM t1 a a a;
+} {1 {near "FROM": syntax error}}
+
+do_catchsql_test 6.5 {
+ WITH x AS (SELECT * FROM t1)
+ DELETE FROM t2 WHERE;
+} {1 {near ";": syntax error}}
+
+do_catchsql_test 6.6 {
+ WITH x AS (SELECT * FROM t1) DELETE FROM t2 WHERE
+} {/1 {near .* syntax error}/}
+
+do_catchsql_test 6.7 {
+ WITH x AS (SELECT * FROM t1) DELETE FROM t2 WHRE 1;
+} {/1 {near .* syntax error}/}
+
+do_catchsql_test 6.8 {
+ WITH x AS (SELECT * FROM t1) UPDATE t2 SET a = 10, b = ;
+} {/1 {near .* syntax error}/}
+
+do_catchsql_test 6.9 {
+ WITH x AS (SELECT * FROM t1) UPDATE t2 SET a = 10, b = 1 WHERE a===b;
+} {/1 {near .* syntax error}/}
+
+do_catchsql_test 6.10 {
+ WITH x(a,b) AS (
+ SELECT 1, 1
+ UNION ALL
+ SELECT a*b,a+b FROM x WHERE c=2
+ )
+ SELECT * FROM x
+} {1 {no such column: c}}
+
+#-------------------------------------------------------------------------
+# Recursive queries in IN(...) expressions.
+#
+do_execsql_test 7.1 {
+ CREATE TABLE t5(x INTEGER);
+ CREATE TABLE t6(y INTEGER);
+
+ WITH s(x) AS ( VALUES(7) UNION ALL SELECT x+7 FROM s WHERE x<49 )
+ INSERT INTO t5
+ SELECT * FROM s;
+
+ INSERT INTO t6
+ WITH s(x) AS ( VALUES(2) UNION ALL SELECT x+2 FROM s WHERE x<49 )
+ SELECT * FROM s;
+}
+
+do_execsql_test 7.2 {
+ SELECT * FROM t6 WHERE y IN (SELECT x FROM t5)
+} {14 28 42}
+
+do_execsql_test 7.3 {
+ WITH ss AS (SELECT x FROM t5)
+ SELECT * FROM t6 WHERE y IN (SELECT x FROM ss)
+} {14 28 42}
+
+do_execsql_test 7.4 {
+ WITH ss(x) AS ( VALUES(7) UNION ALL SELECT x+7 FROM ss WHERE x<49 )
+ SELECT * FROM t6 WHERE y IN (SELECT x FROM ss)
+} {14 28 42}
+
+do_execsql_test 7.5 {
+ SELECT * FROM t6 WHERE y IN (
+ WITH ss(x) AS ( VALUES(7) UNION ALL SELECT x+7 FROM ss WHERE x<49 )
+ SELECT x FROM ss
+ )
+} {14 28 42}
+
+
+
+finish_test
+
diff --git a/lang/sql/sqlite/test/withM.test b/lang/sql/sqlite/test/withM.test
new file mode 100644
index 00000000..c1650d95
--- /dev/null
+++ b/lang/sql/sqlite/test/withM.test
@@ -0,0 +1,77 @@
+# 2014 January 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 WITH clause.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+source $testdir/malloc_common.tcl
+set ::testprefix withM
+
+ifcapable {!cte} {
+ finish_test
+ return
+}
+
+do_execsql_test 1.0 {
+ CREATE TABLE t1(x INTEGER, y INTEGER);
+ INSERT INTO t1 VALUES(123, 456);
+}
+
+do_faultsim_test withM-1.1 -prep {
+ sqlite3 db test.db
+} -body {
+ execsql {
+ WITH tmp AS ( SELECT * FROM t1 )
+ SELECT * FROM tmp;
+ }
+} -test {
+ faultsim_test_result {0 {123 456}}
+ db close
+}
+
+do_faultsim_test withM-1.2 -prep {
+ sqlite3 db test.db
+} -body {
+ execsql {
+ WITH w1 AS ( SELECT * FROM t1 ),
+ w2 AS (
+ WITH w3 AS ( SELECT * FROM w1 )
+ SELECT * FROM w3
+ )
+ SELECT * FROM w2;
+ }
+} -test {
+ faultsim_test_result {0 {123 456}}
+ db close
+}
+
+do_faultsim_test withM-1.3 -prep {
+ sqlite3 db test.db
+} -body {
+ execsql {
+ WITH w1(a,b) AS (
+ SELECT 1, 1
+ UNION ALL
+ SELECT a+1, b + 2*a + 1 FROM w1
+ )
+ SELECT * FROM w1 LIMIT 5;
+ }
+} -test {
+ faultsim_test_result {0 {1 1 2 4 3 9 4 16 5 25}}
+ db close
+}
+
+finish_test
+
+
+
diff --git a/lang/sql/sqlite/test/without_rowid1.test b/lang/sql/sqlite/test/without_rowid1.test
new file mode 100644
index 00000000..1a53d26e
--- /dev/null
+++ b/lang/sql/sqlite/test/without_rowid1.test
@@ -0,0 +1,203 @@
+# 2013-10-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 WITHOUT ROWID tables.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix without_rowid1
+
+# Create and query a WITHOUT ROWID table.
+#
+do_execsql_test without_rowid1-1.0 {
+ CREATE TABLE t1(a,b,c,d, PRIMARY KEY(c,a)) WITHOUT ROWID;
+ CREATE INDEX t1bd ON t1(b, d);
+ INSERT INTO t1 VALUES('journal','sherman','ammonia','helena');
+ INSERT INTO t1 VALUES('dynamic','juliet','flipper','command');
+ INSERT INTO t1 VALUES('journal','sherman','gamma','patriot');
+ INSERT INTO t1 VALUES('arctic','sleep','ammonia','helena');
+ SELECT *, '|' FROM t1 ORDER BY c, a;
+} {arctic sleep ammonia helena | journal sherman ammonia helena | dynamic juliet flipper command | journal sherman gamma patriot |}
+
+integrity_check without_rowid1-1.0ic
+
+do_execsql_test without_rowid1-1.1 {
+ SELECT *, '|' FROM t1 ORDER BY +c, a;
+} {arctic sleep ammonia helena | journal sherman ammonia helena | dynamic juliet flipper command | journal sherman gamma patriot |}
+
+do_execsql_test without_rowid1-1.2 {
+ SELECT *, '|' FROM t1 ORDER BY c DESC, a DESC;
+} {journal sherman gamma patriot | dynamic juliet flipper command | journal sherman ammonia helena | arctic sleep ammonia helena |}
+
+do_execsql_test without_rowid1-1.11 {
+ SELECT *, '|' FROM t1 ORDER BY b, d;
+} {dynamic juliet flipper command | journal sherman ammonia helena | journal sherman gamma patriot | arctic sleep ammonia helena |}
+
+do_execsql_test without_rowid1-1.12 {
+ SELECT *, '|' FROM t1 ORDER BY +b, d;
+} {dynamic juliet flipper command | journal sherman ammonia helena | journal sherman gamma patriot | arctic sleep ammonia helena |}
+
+# Trying to insert a duplicate PRIMARY KEY fails.
+#
+do_test without_rowid1-1.21 {
+ catchsql {
+ INSERT INTO t1 VALUES('dynamic','phone','flipper','harvard');
+ }
+} {1 {UNIQUE constraint failed: t1.c, t1.a}}
+
+# REPLACE INTO works, however.
+#
+do_execsql_test without_rowid1-1.22 {
+ REPLACE INTO t1 VALUES('dynamic','phone','flipper','harvard');
+ SELECT *, '|' FROM t1 ORDER BY c, a;
+} {arctic sleep ammonia helena | journal sherman ammonia helena | dynamic phone flipper harvard | journal sherman gamma patriot |}
+
+do_execsql_test without_rowid1-1.23 {
+ SELECT *, '|' FROM t1 ORDER BY b, d;
+} {dynamic phone flipper harvard | journal sherman ammonia helena | journal sherman gamma patriot | arctic sleep ammonia helena |}
+
+# UPDATE statements.
+#
+do_execsql_test without_rowid1-1.31 {
+ UPDATE t1 SET d=3.1415926 WHERE a='journal';
+ SELECT *, '|' FROM t1 ORDER BY c, a;
+} {arctic sleep ammonia helena | journal sherman ammonia 3.1415926 | dynamic phone flipper harvard | journal sherman gamma 3.1415926 |}
+do_execsql_test without_rowid1-1.32 {
+ SELECT *, '|' FROM t1 ORDER BY b, d;
+} {dynamic phone flipper harvard | journal sherman ammonia 3.1415926 | journal sherman gamma 3.1415926 | arctic sleep ammonia helena |}
+
+do_execsql_test without_rowid1-1.35 {
+ UPDATE t1 SET a=1250 WHERE b='phone';
+ SELECT *, '|' FROM t1 ORDER BY c, a;
+} {arctic sleep ammonia helena | journal sherman ammonia 3.1415926 | 1250 phone flipper harvard | journal sherman gamma 3.1415926 |}
+integrity_check without_rowid1-1.36
+
+do_execsql_test without_rowid1-1.37 {
+ SELECT *, '|' FROM t1 ORDER BY b, d;
+} {1250 phone flipper harvard | journal sherman ammonia 3.1415926 | journal sherman gamma 3.1415926 | arctic sleep ammonia helena |}
+
+do_execsql_test without_rowid1-1.40 {
+ VACUUM;
+ SELECT *, '|' FROM t1 ORDER BY b, d;
+} {1250 phone flipper harvard | journal sherman ammonia 3.1415926 | journal sherman gamma 3.1415926 | arctic sleep ammonia helena |}
+integrity_check without_rowid1-1.41
+
+# Verify that ANALYZE works
+#
+do_execsql_test without_rowid1-1.50 {
+ ANALYZE;
+ SELECT * FROM sqlite_stat1 ORDER BY idx;
+} {t1 t1 {4 2 1} t1 t1bd {4 2 2}}
+ifcapable stat3 {
+ do_execsql_test without_rowid1-1.51 {
+ SELECT DISTINCT tbl, idx FROM sqlite_stat3 ORDER BY idx;
+ } {t1 t1 t1 t1bd}
+}
+ifcapable stat4 {
+ do_execsql_test without_rowid1-1.52 {
+ SELECT DISTINCT tbl, idx FROM sqlite_stat4 ORDER BY idx;
+ } {t1 t1 t1 t1bd}
+}
+
+#----------
+
+do_execsql_test 2.1.1 {
+ CREATE TABLE t4 (a COLLATE nocase PRIMARY KEY, b) WITHOUT ROWID;
+ INSERT INTO t4 VALUES('abc', 'def');
+ SELECT * FROM t4;
+} {abc def}
+do_execsql_test 2.1.2 {
+ UPDATE t4 SET a = 'ABC';
+ SELECT * FROM t4;
+} {ABC def}
+
+do_execsql_test 2.2.1 {
+ DROP TABLE t4;
+ CREATE TABLE t4 (b, a COLLATE nocase PRIMARY KEY) WITHOUT ROWID;
+ INSERT INTO t4(a, b) VALUES('abc', 'def');
+ SELECT * FROM t4;
+} {def abc}
+
+do_execsql_test 2.2.2 {
+ UPDATE t4 SET a = 'ABC', b = 'xyz';
+ SELECT * FROM t4;
+} {xyz ABC}
+
+do_execsql_test 2.3.1 {
+ CREATE TABLE t5 (a, b, PRIMARY KEY(b, a)) WITHOUT ROWID;
+ INSERT INTO t5(a, b) VALUES('abc', 'def');
+ UPDATE t5 SET a='abc', b='def';
+} {}
+
+do_execsql_test 2.4.1 {
+ CREATE TABLE t6 (
+ a COLLATE nocase, b, c UNIQUE, PRIMARY KEY(b, a)
+ ) WITHOUT ROWID;
+
+ INSERT INTO t6(a, b, c) VALUES('abc', 'def', 'ghi');
+ UPDATE t6 SET a='ABC', c='ghi';
+} {}
+
+do_execsql_test 2.4.2 {
+ SELECT * FROM t6 ORDER BY b, a;
+ SELECT * FROM t6 ORDER BY c;
+} {ABC def ghi ABC def ghi}
+
+#-------------------------------------------------------------------------
+# Unless the destination table is completely empty, the xfer optimization
+# is disabled for WITHOUT ROWID tables. The following tests check for
+# some problems that might occur if this were not the case.
+#
+reset_db
+do_execsql_test 3.1.1 {
+ CREATE TABLE t1(a, b, PRIMARY KEY(a)) WITHOUT ROWID;
+ CREATE UNIQUE INDEX i1 ON t1(b);
+
+ CREATE TABLE t2(a, b, PRIMARY KEY(a)) WITHOUT ROWID;
+ CREATE UNIQUE INDEX i2 ON t2(b);
+
+ INSERT INTO t1 VALUES('one', 'two');
+ INSERT INTO t2 VALUES('three', 'two');
+}
+
+do_execsql_test 3.1.2 {
+ INSERT OR REPLACE INTO t1 SELECT * FROM t2;
+ SELECT * FROM t1;
+} {three two}
+
+do_execsql_test 3.1.3 {
+ DELETE FROM t1;
+ INSERT INTO t1 SELECT * FROM t2;
+ SELECT * FROM t1;
+} {three two}
+
+do_catchsql_test 3.1.4 {
+ INSERT INTO t2 VALUES('four', 'four');
+ INSERT INTO t2 VALUES('six', 'two');
+ INSERT INTO t1 SELECT * FROM t2;
+} {1 {UNIQUE constraint failed: t2.b}}
+
+do_execsql_test 3.1.5 {
+ CREATE TABLE t3(a PRIMARY KEY);
+ CREATE TABLE t4(a PRIMARY KEY);
+
+ INSERT INTO t4 VALUES('i');
+ INSERT INTO t4 VALUES('ii');
+ INSERT INTO t4 VALUES('iii');
+
+ INSERT INTO t3 SELECT * FROM t4;
+ SELECT * FROM t3;
+} {i ii iii}
+
+finish_test
+
diff --git a/lang/sql/sqlite/test/without_rowid2.test b/lang/sql/sqlite/test/without_rowid2.test
new file mode 100644
index 00000000..5ba1a23b
--- /dev/null
+++ b/lang/sql/sqlite/test/without_rowid2.test
@@ -0,0 +1,125 @@
+# 2013-11-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 WITHOUT ROWID tables, and especially
+# FOREIGN KEY constraints.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+ifcapable {!foreignkey} {
+ finish_test
+ return
+}
+
+# Create a table and some data to work with.
+#
+do_test without_rowid2-1.0 {
+ execsql {
+ CREATE TABLE t1(
+ a INT PRIMARY KEY,
+ b INT
+ REFERENCES t1 ON DELETE CASCADE
+ REFERENCES t2,
+ c TEXT,
+ FOREIGN KEY (b,c) REFERENCES t2(x,y) ON UPDATE CASCADE
+ ) WITHOUT rowid;
+ }
+} {}
+do_test without_rowid2-1.1 {
+ execsql {
+ CREATE TABLE t2(
+ x INT PRIMARY KEY,
+ y TEXT
+ ) WITHOUT rowid;
+ }
+} {}
+do_test without_rowid2-1.2 {
+ execsql {
+ CREATE TABLE t3(
+ a INT REFERENCES t2,
+ b INT REFERENCES t1,
+ FOREIGN KEY (a,b) REFERENCES t2(x,y)
+ );
+ }
+} {}
+
+do_test without_rowid2-2.1 {
+ execsql {
+ CREATE TABLE t4(a int primary key) WITHOUT rowid;
+ 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 without_rowid2-3.1 {
+ execsql {
+ CREATE TABLE t5(a PRIMARY KEY, b, c) WITHOUT rowid;
+ 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 without_rowid2-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 without_rowid2-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 without_rowid2-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 without_rowid2-3.5 {
+ sqlite3_db_status db DBSTATUS_DEFERRED_FKS 0
+} {0 0 0}
+
+finish_test
diff --git a/lang/sql/sqlite/test/without_rowid3.test b/lang/sql/sqlite/test/without_rowid3.test
new file mode 100644
index 00000000..c4c2d6f4
--- /dev/null
+++ b/lang/sql/sqlite/test/without_rowid3.test
@@ -0,0 +1,2084 @@
+# 2013-11-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.
+#
+# This file implements tests for foreign keys on WITHOUT ROWID
+# tables.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+ifcapable {!foreignkey||!trigger} {
+ finish_test
+ return
+}
+
+#-------------------------------------------------------------------------
+# Test structure:
+#
+# without_rowid3-1.*: Simple tests to check that immediate and deferred foreign key
+# constraints work when not inside a transaction.
+#
+# without_rowid3-2.*: Tests to verify that deferred foreign keys work inside
+# explicit transactions (i.e that processing really is deferred).
+#
+# without_rowid3-3.*: Tests that a statement transaction is rolled back if an
+# immediate foreign key constraint is violated.
+#
+# without_rowid3-4.*: Test that FK actions may recurse even when recursive triggers
+# are disabled.
+#
+# without_rowid3-5.*: Check that if foreign-keys are enabled, it is not possible
+# to write to an FK column using the incremental blob API.
+#
+# without_rowid3-6.*: Test that FK processing is automatically disabled when
+# running VACUUM.
+#
+# without_rowid3-7.*: Test using an IPK as the key in the child (referencing) table.
+#
+# without_rowid3-8.*: Test that enabling/disabling foreign key support while a
+# transaction is active is not possible.
+#
+# without_rowid3-9.*: Test SET DEFAULT actions.
+#
+# without_rowid3-10.*: Test errors.
+#
+# without_rowid3-11.*: Test CASCADE actions.
+#
+# without_rowid3-12.*: Test RESTRICT actions.
+#
+# without_rowid3-13.*: Test that FK processing is performed when a row is REPLACED by
+# an UPDATE or INSERT statement.
+#
+# without_rowid3-14.*: Test the ALTER TABLE and DROP TABLE commands.
+#
+# without_rowid3-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.
+#
+# without_rowid3-16.*: Test that rows that refer to themselves may be inserted,
+# updated and deleted.
+#
+# without_rowid3-17.*: Test that the "count_changes" pragma does not interfere with
+# FK constraint processing.
+#
+# without_rowid3-18.*: Test that the authorization callback is invoked when processing
+# FK constraints.
+#
+# without_rowid3-20.*: Test that ON CONFLICT clauses specified as part of statements
+# do not affect the operation of FK constraints.
+#
+# without_rowid3-genfkey.*: Tests that were used with the shell tool .genfkey
+# command. Recycled to test the built-in implementation.
+#
+# without_rowid3-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) WITHOUT rowid;
+ CREATE TABLE t2(c REFERENCES t1(a) /D/ , d);
+
+ CREATE TABLE t3(a PRIMARY KEY, b) WITHOUT rowid;
+ CREATE TABLE t4(c REFERENCES t3 /D/, d);
+
+ CREATE TABLE t7(a, b INT PRIMARY KEY) WITHOUT rowid;
+ 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.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 without_rowid3-1.1.0 {
+ execsql [string map {/D/ {}} $FkeySimpleSchema]
+} {}
+foreach {tn zSql res} $FkeySimpleTests {
+ do_test without_rowid3-1.1.$tn.1 { catchsql $zSql } $res
+ do_test without_rowid3-1.1.$tn.2 { execsql {PRAGMA foreign_key_check(t1)} } {}
+ do_test without_rowid3-1.1.$tn.3 { execsql {PRAGMA foreign_key_check(t2)} } {}
+ do_test without_rowid3-1.1.$tn.4 { execsql {PRAGMA foreign_key_check(t3)} } {}
+ do_test without_rowid3-1.1.$tn.5 { execsql {PRAGMA foreign_key_check(t4)} } {}
+ do_test without_rowid3-1.1.$tn.6 { execsql {PRAGMA foreign_key_check(t7)} } {}
+ do_test without_rowid3-1.1.$tn.7 { execsql {PRAGMA foreign_key_check(t8)} } {}
+}
+drop_all_tables
+
+do_test without_rowid3-1.2.0 {
+ execsql [string map {/D/ {DEFERRABLE INITIALLY DEFERRED}} $FkeySimpleSchema]
+} {}
+foreach {tn zSql res} $FkeySimpleTests {
+ do_test without_rowid3-1.2.$tn { catchsql $zSql } $res
+ do_test without_rowid3-1.2.$tn.2 { execsql {PRAGMA foreign_key_check(t1)} } {}
+ do_test without_rowid3-1.2.$tn.3 { execsql {PRAGMA foreign_key_check(t2)} } {}
+ do_test without_rowid3-1.2.$tn.4 { execsql {PRAGMA foreign_key_check(t3)} } {}
+ do_test without_rowid3-1.2.$tn.5 { execsql {PRAGMA foreign_key_check(t4)} } {}
+ do_test without_rowid3-1.2.$tn.6 { execsql {PRAGMA foreign_key_check(t7)} } {}
+ do_test without_rowid3-1.2.$tn.7 { execsql {PRAGMA foreign_key_check(t8)} } {}
+}
+drop_all_tables
+
+do_test without_rowid3-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 without_rowid3-1.3.$tn { catchsql $zSql } $res
+ do_test without_rowid3-1.3.$tn.2 { execsql {PRAGMA foreign_key_check(t1)} } {}
+ do_test without_rowid3-1.3.$tn.3 { execsql {PRAGMA foreign_key_check(t2)} } {}
+ do_test without_rowid3-1.3.$tn.4 { execsql {PRAGMA foreign_key_check(t3)} } {}
+ do_test without_rowid3-1.3.$tn.5 { execsql {PRAGMA foreign_key_check(t4)} } {}
+ do_test without_rowid3-1.3.$tn.6 { execsql {PRAGMA foreign_key_check(t7)} } {}
+ do_test without_rowid3-1.3.$tn.7 { execsql {PRAGMA foreign_key_check(t8)} } {}
+}
+execsql { PRAGMA count_changes = 0 }
+drop_all_tables
+
+do_test without_rowid3-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 without_rowid3-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 without_rowid3-1.5.1 {
+ execsql {
+ CREATE TABLE i(i INT PRIMARY KEY) WITHOUT rowid;
+ 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 without_rowid3-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 without_rowid3-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 without_rowid3-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 without_rowid3-1.7.1 {
+ execsql {
+ CREATE TABLE i(i TEXT COLLATE nocase PRIMARY KEY) WITHOUT rowid;
+ 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 without_rowid3-1.7.2 {
+ execsql {
+ CREATE TABLE i(i TEXT PRIMARY KEY) WITHOUT rowid; -- 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 without_rowid3-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 without_rowid3-2.*) contains tests to check that the
+# deferred foreign key constraint logic works.
+#
+proc without_rowid3-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 without_rowid3-2.$tn [list catchsql $sql] $expected
+ if {$nocommit} {
+ do_test without_rowid3-2.${tn}c {
+ catchsql COMMIT
+ } {1 {FOREIGN KEY constraint failed}}
+ }
+}
+
+without_rowid3-2-test 1 0 {
+ CREATE TABLE node(
+ nodeid PRIMARY KEY,
+ parent REFERENCES node DEFERRABLE INITIALLY DEFERRED
+ ) WITHOUT rowid;
+ CREATE TABLE leaf(
+ cellid PRIMARY KEY,
+ parent REFERENCES node DEFERRABLE INITIALLY DEFERRED
+ ) WITHOUT rowid;
+}
+
+without_rowid3-2-test 1 0 "INSERT INTO node VALUES(1, 0)" FKV
+without_rowid3-2-test 2 0 "BEGIN"
+without_rowid3-2-test 3 1 "INSERT INTO node VALUES(1, 0)"
+without_rowid3-2-test 4 0 "UPDATE node SET parent = NULL"
+without_rowid3-2-test 5 0 "COMMIT"
+without_rowid3-2-test 6 0 "SELECT * FROM node" {1 {}}
+
+without_rowid3-2-test 7 0 "BEGIN"
+without_rowid3-2-test 8 1 "INSERT INTO leaf VALUES('a', 2)"
+without_rowid3-2-test 9 1 "INSERT INTO node VALUES(2, 0)"
+without_rowid3-2-test 10 0 "UPDATE node SET parent = 1 WHERE nodeid = 2"
+without_rowid3-2-test 11 0 "COMMIT"
+without_rowid3-2-test 12 0 "SELECT * FROM node" {1 {} 2 1}
+without_rowid3-2-test 13 0 "SELECT * FROM leaf" {a 2}
+
+without_rowid3-2-test 14 0 "BEGIN"
+without_rowid3-2-test 15 1 "DELETE FROM node WHERE nodeid = 2"
+without_rowid3-2-test 16 0 "INSERT INTO node VALUES(2, NULL)"
+without_rowid3-2-test 17 0 "COMMIT"
+without_rowid3-2-test 18 0 "SELECT * FROM node" {1 {} 2 {}}
+without_rowid3-2-test 19 0 "SELECT * FROM leaf" {a 2}
+
+without_rowid3-2-test 20 0 "BEGIN"
+without_rowid3-2-test 21 0 "INSERT INTO leaf VALUES('b', 1)"
+without_rowid3-2-test 22 0 "SAVEPOINT save"
+without_rowid3-2-test 23 0 "DELETE FROM node WHERE nodeid = 1"
+without_rowid3-2-test 24 0 "ROLLBACK TO save"
+without_rowid3-2-test 25 0 "COMMIT"
+without_rowid3-2-test 26 0 "SELECT * FROM node" {1 {} 2 {}}
+without_rowid3-2-test 27 0 "SELECT * FROM leaf" {a 2 b 1}
+
+without_rowid3-2-test 28 0 "BEGIN"
+without_rowid3-2-test 29 0 "INSERT INTO leaf VALUES('c', 1)"
+without_rowid3-2-test 30 0 "SAVEPOINT save"
+without_rowid3-2-test 31 0 "DELETE FROM node WHERE nodeid = 1"
+without_rowid3-2-test 32 1 "RELEASE save"
+without_rowid3-2-test 33 1 "DELETE FROM leaf WHERE cellid = 'b'"
+without_rowid3-2-test 34 0 "DELETE FROM leaf WHERE cellid = 'c'"
+without_rowid3-2-test 35 0 "COMMIT"
+without_rowid3-2-test 36 0 "SELECT * FROM node" {2 {}}
+without_rowid3-2-test 37 0 "SELECT * FROM leaf" {a 2}
+
+without_rowid3-2-test 38 0 "SAVEPOINT outer"
+without_rowid3-2-test 39 1 "INSERT INTO leaf VALUES('d', 3)"
+without_rowid3-2-test 40 1 "RELEASE outer" FKV
+without_rowid3-2-test 41 1 "INSERT INTO leaf VALUES('e', 3)"
+without_rowid3-2-test 42 0 "INSERT INTO node VALUES(3, 2)"
+without_rowid3-2-test 43 0 "RELEASE outer"
+
+without_rowid3-2-test 44 0 "SAVEPOINT outer"
+without_rowid3-2-test 45 1 "DELETE FROM node WHERE nodeid=3"
+without_rowid3-2-test 47 0 "INSERT INTO node VALUES(3, 2)"
+without_rowid3-2-test 48 0 "ROLLBACK TO outer"
+without_rowid3-2-test 49 0 "RELEASE outer"
+
+without_rowid3-2-test 50 0 "SAVEPOINT outer"
+without_rowid3-2-test 51 1 "INSERT INTO leaf VALUES('f', 4)"
+without_rowid3-2-test 52 1 "SAVEPOINT inner"
+without_rowid3-2-test 53 1 "INSERT INTO leaf VALUES('g', 4)"
+without_rowid3-2-test 54 1 "RELEASE outer" FKV
+without_rowid3-2-test 55 1 "ROLLBACK TO inner"
+without_rowid3-2-test 56 0 "COMMIT" FKV
+without_rowid3-2-test 57 0 "INSERT INTO node VALUES(4, NULL)"
+without_rowid3-2-test 58 0 "RELEASE outer"
+without_rowid3-2-test 59 0 "SELECT * FROM node" {2 {} 3 2 4 {}}
+without_rowid3-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.
+#
+without_rowid3-2-test 61 0 "BEGIN"
+without_rowid3-2-test 62 0 "DELETE FROM leaf"
+without_rowid3-2-test 63 0 "DELETE FROM node"
+without_rowid3-2-test 64 1 "INSERT INTO leaf VALUES('a', 1)"
+without_rowid3-2-test 65 1 "INSERT INTO leaf VALUES('b', 2)"
+without_rowid3-2-test 66 1 "INSERT INTO leaf VALUES('c', 1)"
+do_test without_rowid3-2-test-67 {
+ catchsql "INSERT INTO node SELECT parent, 3 FROM leaf"
+} {1 {UNIQUE constraint failed: node.nodeid}}
+without_rowid3-2-test 68 0 "COMMIT" FKV
+without_rowid3-2-test 69 1 "INSERT INTO node VALUES(1, NULL)"
+without_rowid3-2-test 70 0 "INSERT INTO node VALUES(2, NULL)"
+without_rowid3-2-test 71 0 "COMMIT"
+
+without_rowid3-2-test 72 0 "BEGIN"
+without_rowid3-2-test 73 1 "DELETE FROM node"
+without_rowid3-2-test 74 0 "INSERT INTO node(nodeid) SELECT DISTINCT parent FROM leaf"
+without_rowid3-2-test 75 0 "COMMIT"
+
+#-------------------------------------------------------------------------
+# Test cases without_rowid3-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.
+#
+# without_rowid3-3.1.*: Test UPDATE statements.
+# without_rowid3-3.2.*: Test DELETE statements.
+#
+drop_all_tables
+do_test without_rowid3-3.1.1 {
+ execsql {
+ CREATE TABLE ab(a PRIMARY KEY, b) WITHOUT rowid;
+ CREATE TABLE cd(
+ c PRIMARY KEY REFERENCES ab ON UPDATE CASCADE ON DELETE CASCADE,
+ d
+ ) WITHOUT rowid;
+ CREATE TABLE ef(
+ e REFERENCES cd ON UPDATE CASCADE,
+ f, CHECK (e!=5)
+ );
+ }
+} {}
+do_test without_rowid3-3.1.2 {
+ execsql {
+ INSERT INTO ab VALUES(1, 'b');
+ INSERT INTO cd VALUES(1, 'd');
+ INSERT INTO ef VALUES(1, 'e');
+ }
+} {}
+do_test without_rowid3-3.1.3 {
+ catchsql { UPDATE ab SET a = 5 }
+} {1 {CHECK constraint failed: ef}}
+do_test without_rowid3-3.1.4 {
+ execsql { SELECT * FROM ab }
+} {1 b}
+do_test without_rowid3-3.1.4 {
+ execsql BEGIN;
+ catchsql { UPDATE ab SET a = 5 }
+} {1 {CHECK constraint failed: ef}}
+do_test without_rowid3-3.1.5 {
+ execsql COMMIT;
+ execsql { SELECT * FROM ab; SELECT * FROM cd; SELECT * FROM ef }
+} {1 b 1 d 1 e}
+
+do_test without_rowid3-3.2.1 {
+ execsql BEGIN;
+ catchsql { DELETE FROM ab }
+} {1 {FOREIGN KEY constraint failed}}
+do_test without_rowid3-3.2.2 {
+ execsql COMMIT
+ execsql { SELECT * FROM ab; SELECT * FROM cd; SELECT * FROM ef }
+} {1 b 1 d 1 e}
+
+#-------------------------------------------------------------------------
+# Test cases without_rowid3-4.* test that recursive foreign key actions
+# (i.e. CASCADE) are allowed even if recursive triggers are disabled.
+#
+drop_all_tables
+do_test without_rowid3-4.1 {
+ execsql {
+ CREATE TABLE t1(
+ node PRIMARY KEY,
+ parent REFERENCES t1 ON DELETE CASCADE
+ ) WITHOUT rowid;
+ CREATE TABLE t2(node PRIMARY KEY, parent) WITHOUT rowid;
+ 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 without_rowid3-4.2 {
+ execsql { PRAGMA recursive_triggers = off }
+ execsql {
+ BEGIN;
+ DELETE FROM t1 WHERE node = 1;
+ SELECT node FROM t1;
+ }
+} {}
+do_test without_rowid3-4.3 {
+ execsql {
+ DELETE FROM t2 WHERE node = 1;
+ SELECT node FROM t2;
+ ROLLBACK;
+ }
+} {4 5 6 7}
+do_test without_rowid3-4.4 {
+ execsql { PRAGMA recursive_triggers = on }
+ execsql {
+ BEGIN;
+ DELETE FROM t1 WHERE node = 1;
+ SELECT node FROM t1;
+ }
+} {}
+do_test without_rowid3-4.3 {
+ execsql {
+ DELETE FROM t2 WHERE node = 1;
+ SELECT node FROM t2;
+ ROLLBACK;
+ }
+} {}
+
+#-------------------------------------------------------------------------
+# Test cases without_rowid3-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 without_rowid3-5.1 {
+ execsql {
+ CREATE TABLE t1(a PRIMARY KEY, b) WITHOUT rowid;
+ CREATE TABLE t2(a PRIMARY KEY, b REFERENCES t1(a)) WITHOUT rowid;
+ INSERT INTO t1 VALUES('hello', 'world');
+ INSERT INTO t2 VALUES('key', 'hello');
+ }
+ } {}
+ do_test without_rowid3-5.2 {
+ set rc [catch { set fd [db incrblob t2 b 1] } msg]
+ list $rc $msg
+ } {1 {cannot open table without rowid: t2}}
+ do_test without_rowid3-5.5 {
+ execsql { PRAGMA foreign_keys = on }
+ } {}
+}
+
+drop_all_tables
+ifcapable vacuum {
+ do_test without_rowid3-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 INT PRIMARY KEY as the child key
+# of a foreign constraint.
+#
+drop_all_tables
+do_test without_rowid3-7.1 {
+ execsql {
+ CREATE TABLE t1(a PRIMARY KEY, b) WITHOUT rowid;
+ CREATE TABLE t2(c INT PRIMARY KEY REFERENCES t1, b) WITHOUT rowid;
+ }
+} {}
+do_test without_rowid3-7.2 {
+ catchsql { INSERT INTO t2 VALUES(1, 'A'); }
+} {1 {FOREIGN KEY constraint failed}}
+do_test without_rowid3-7.3 {
+ execsql {
+ INSERT INTO t1 VALUES(1, 2);
+ INSERT INTO t1 VALUES(2, 3);
+ INSERT INTO t2 VALUES(1, 'A');
+ }
+} {}
+do_test without_rowid3-7.4 {
+ execsql { UPDATE t2 SET c = 2 }
+} {}
+do_test without_rowid3-7.5 {
+ catchsql { UPDATE t2 SET c = 3 }
+} {1 {FOREIGN KEY constraint failed}}
+do_test without_rowid3-7.6 {
+ catchsql { DELETE FROM t1 WHERE a = 2 }
+} {1 {FOREIGN KEY constraint failed}}
+do_test without_rowid3-7.7 {
+ execsql { DELETE FROM t1 WHERE a = 1 }
+} {}
+do_test without_rowid3-7.8 {
+ catchsql { UPDATE t1 SET a = 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 without_rowid3-8-test {tn zSql value} {
+ do_test without_rowid3-2.8.$tn.1 [list execsql $zSql] {}
+ do_test without_rowid3-2.8.$tn.2 { execsql "PRAGMA foreign_keys" } $value
+}
+without_rowid3-8-test 1 { PRAGMA foreign_keys = 0 } 0
+without_rowid3-8-test 2 { PRAGMA foreign_keys = 1 } 1
+without_rowid3-8-test 3 { BEGIN } 1
+without_rowid3-8-test 4 { PRAGMA foreign_keys = 0 } 1
+without_rowid3-8-test 5 { COMMIT } 1
+without_rowid3-8-test 6 { PRAGMA foreign_keys = 0 } 0
+without_rowid3-8-test 7 { BEGIN } 0
+without_rowid3-8-test 8 { PRAGMA foreign_keys = 1 } 0
+without_rowid3-8-test 9 { COMMIT } 0
+without_rowid3-8-test 10 { PRAGMA foreign_keys = 1 } 1
+without_rowid3-8-test 11 { PRAGMA foreign_keys = off } 0
+without_rowid3-8-test 12 { PRAGMA foreign_keys = on } 1
+without_rowid3-8-test 13 { PRAGMA foreign_keys = no } 0
+without_rowid3-8-test 14 { PRAGMA foreign_keys = yes } 1
+without_rowid3-8-test 15 { PRAGMA foreign_keys = false } 0
+without_rowid3-8-test 16 { PRAGMA foreign_keys = true } 1
+
+#-------------------------------------------------------------------------
+# The following tests, without_rowid3-9.*, test SET DEFAULT actions.
+#
+drop_all_tables
+do_test without_rowid3-9.1.1 {
+ execsql {
+ CREATE TABLE t1(a INT PRIMARY KEY, b) WITHOUT rowid;
+ CREATE TABLE t2(
+ c INT PRIMARY KEY,
+ d INTEGER DEFAULT 1 REFERENCES t1 ON DELETE SET DEFAULT
+ ) WITHOUT rowid;
+ DELETE FROM t1;
+ }
+} {}
+do_test without_rowid3-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 without_rowid3-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 without_rowid3-9.1.4 {
+ execsql { SELECT * FROM t1 }
+} {2 two}
+do_test without_rowid3-9.1.5 {
+ catchsql { DELETE FROM t1 }
+} {1 {FOREIGN KEY constraint failed}}
+
+do_test without_rowid3-9.2.1 {
+ execsql {
+ CREATE TABLE pp(a, b, c, PRIMARY KEY(b, c)) WITHOUT rowid;
+ 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 without_rowid3-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 without_rowid3-9.2.3 {
+ execsql {
+ DELETE FROM pp WHERE a = 4;
+ SELECT * FROM cc;
+ }
+} {{} A {} {} B {} 3 A 2 3 B 2}
+
+#-------------------------------------------------------------------------
+# The following tests, without_rowid3-10.*, test "foreign key mismatch" and
+# other errors.
+#
+set tn 0
+foreach zSql [list {
+ CREATE TABLE p(a PRIMARY KEY, b) WITHOUT rowid;
+ 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)) WITHOUT rowid;
+ 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 without_rowid3-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 without_rowid3-10.2.1 {
+ drop_all_tables
+ catchsql {
+ CREATE TABLE t1(a PRIMARY KEY, b) WITHOUT rowid;
+ CREATE TABLE t2(c, d, FOREIGN KEY(rowid) REFERENCES t1(a));
+ }
+} {1 {unknown column "rowid" in foreign key definition}}
+do_test without_rowid3-10.2.2 {
+ drop_all_tables
+ catchsql {
+ CREATE TABLE t1(a PRIMARY KEY, b) WITHOUT rowid;
+ CREATE TABLE t2(rowid, d, FOREIGN KEY(rowid) REFERENCES t1(a));
+ }
+} {0 {}}
+do_test without_rowid3-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 without_rowid3-10.2.2 {
+ drop_all_tables
+ catchsql {
+ CREATE TABLE t1(rowid PRIMARY KEY, b) WITHOUT rowid;
+ 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, without_rowid3-11.*, test CASCADE actions.
+#
+drop_all_tables
+do_test without_rowid3-11.1.1 {
+ execsql {
+ CREATE TABLE t1(a INT PRIMARY KEY, b) WITHOUT rowid;
+ CREATE TABLE t2(c, d, FOREIGN KEY(c) REFERENCES t1(a) ON UPDATE CASCADE);
+
+ INSERT INTO t1 VALUES(10, 100);
+ INSERT INTO t2 VALUES(10, 100);
+ UPDATE t1 SET a = 15;
+ SELECT * FROM t2;
+ }
+} {15 100}
+
+#-------------------------------------------------------------------------
+# The following tests, without_rowid3-12.*, test RESTRICT actions.
+#
+drop_all_tables
+do_test without_rowid3-12.1.1 {
+ execsql {
+ CREATE TABLE t1(a, b PRIMARY KEY) WITHOUT rowid;
+ 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 without_rowid3-12.1.2 {
+ execsql "BEGIN"
+ execsql "INSERT INTO t2 VALUES('two')"
+} {}
+do_test without_rowid3-12.1.3 {
+ execsql "UPDATE t1 SET b = 'four' WHERE b = 'one'"
+} {}
+do_test without_rowid3-12.1.4 {
+ catchsql "UPDATE t1 SET b = 'five' WHERE b = 'two'"
+} {1 {FOREIGN KEY constraint failed}}
+do_test without_rowid3-12.1.5 {
+ execsql "DELETE FROM t1 WHERE b = 'two'"
+} {}
+do_test without_rowid3-12.1.6 {
+ catchsql "COMMIT"
+} {1 {FOREIGN KEY constraint failed}}
+do_test without_rowid3-12.1.7 {
+ execsql {
+ INSERT INTO t1 VALUES(2, 'two');
+ COMMIT;
+ }
+} {}
+
+drop_all_tables
+do_test without_rowid3-12.2.1 {
+ execsql {
+ CREATE TABLE t1(x COLLATE NOCASE PRIMARY KEY) WITHOUT rowid;
+ 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 without_rowid3-12.2.2 {
+ execsql { DELETE FROM t1 }
+ execsql {
+ SELECT * FROM t1;
+ SELECT * FROM t2;
+ }
+} {A B a b}
+do_test without_rowid3-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 without_rowid3-12.2.4 {
+ execsql {
+ SELECT * FROM t1;
+ SELECT * FROM t2;
+ }
+} {A B a b}
+
+drop_all_tables
+do_test without_rowid3-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)
+ ) WITHOUT rowid;
+ 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 without_rowid3-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 without_rowid3-12.3.3 {
+ catchsql { INSERT INTO down(c39, c38) VALUES('yes', 'no') }
+} {1 {FOREIGN KEY constraint failed}}
+do_test without_rowid3-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 without_rowid3-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, without_rowid3-13.*, test that FK processing is performed
+# when rows are REPLACEd.
+#
+drop_all_tables
+do_test without_rowid3-13.1.1 {
+ execsql {
+ CREATE TABLE pp(a UNIQUE, b, c, PRIMARY KEY(b, c)) WITHOUT rowid;
+ 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)"
+} {
+ do_test without_rowid3-13.1.$tn.1 {
+ catchsql $stmt
+ } {1 {FOREIGN KEY constraint failed}}
+ do_test without_rowid3-13.1.$tn.2 {
+ execsql {
+ SELECT * FROM pp;
+ SELECT * FROM cc;
+ }
+ } {1 2 3 2 3 1}
+ do_test without_rowid3-13.1.$tn.3 {
+ execsql BEGIN;
+ catchsql $stmt
+ } {1 {FOREIGN KEY constraint failed}}
+ do_test without_rowid3-13.1.$tn.4 {
+ execsql {
+ COMMIT;
+ SELECT * FROM pp;
+ SELECT * FROM cc;
+ }
+ } {1 2 3 2 3 1}
+}
+
+#-------------------------------------------------------------------------
+# The following tests, without_rowid3-14.*, test that the "DROP TABLE" and "ALTER
+# TABLE" commands work as expected wrt foreign key constraints.
+#
+# without_rowid3-14.1*: ALTER TABLE ADD COLUMN
+# without_rowid3-14.2*: ALTER TABLE RENAME TABLE
+# without_rowid3-14.3*: DROP TABLE
+#
+drop_all_tables
+ifcapable altertable {
+ do_test without_rowid3-14.1.1 {
+ # Adding a column with a REFERENCES clause is not supported.
+ execsql {
+ CREATE TABLE t1(a PRIMARY KEY) WITHOUT rowid;
+ CREATE TABLE t2(a, b);
+ }
+ catchsql { ALTER TABLE t2 ADD COLUMN c REFERENCES t1 }
+ } {0 {}}
+ do_test without_rowid3-14.1.2 {
+ catchsql { ALTER TABLE t2 ADD COLUMN d DEFAULT NULL REFERENCES t1 }
+ } {0 {}}
+ do_test without_rowid3-14.1.3 {
+ catchsql { ALTER TABLE t2 ADD COLUMN e REFERENCES t1 DEFAULT NULL}
+ } {0 {}}
+ do_test without_rowid3-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 without_rowid3-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 without_rowid3-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_parent($zCreate, $zOld, $zNew)}
+ }
+ do_test without_rowid3-14.2.1.1 {
+ test_rename_parent {CREATE TABLE t1(a REFERENCES t2)} t2 t3
+ } {{CREATE TABLE t1(a REFERENCES "t3")}}
+ do_test without_rowid3-14.2.1.2 {
+ test_rename_parent {CREATE TABLE t1(a REFERENCES t2)} t4 t3
+ } {{CREATE TABLE t1(a REFERENCES t2)}}
+ do_test without_rowid3-14.2.1.3 {
+ test_rename_parent {CREATE TABLE t1(a REFERENCES "t2")} t2 t3
+ } {{CREATE TABLE t1(a REFERENCES "t3")}}
+
+ # Test ALTER TABLE RENAME TABLE a bit.
+ #
+ do_test without_rowid3-14.2.2.1 {
+ drop_all_tables
+ execsql {
+ CREATE TABLE t1(a PRIMARY KEY, b REFERENCES t1) WITHOUT rowid;
+ CREATE TABLE t2(a PRIMARY KEY, b REFERENCES t1, c REFERENCES t2)
+ WITHOUT rowid;
+ 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) WITHOUT rowid} \
+ {CREATE TABLE t2(a PRIMARY KEY, b REFERENCES t1, c REFERENCES t2)
+ WITHOUT rowid} \
+ {CREATE TABLE t3(a REFERENCES t1, b REFERENCES t2, c REFERENCES t1)} \
+ ]
+ do_test without_rowid3-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") WITHOUT rowid} \
+ {CREATE TABLE t2(a PRIMARY KEY, b REFERENCES "t4", c REFERENCES t2)
+ WITHOUT rowid} \
+ {CREATE TABLE t3(a REFERENCES "t4", b REFERENCES t2, c REFERENCES "t4")} \
+ ]
+ do_test without_rowid3-14.2.2.3 {
+ catchsql { INSERT INTO t3 VALUES(1, 2, 3) }
+ } {1 {FOREIGN KEY constraint failed}}
+ do_test without_rowid3-14.2.2.4 {
+ execsql { INSERT INTO t4 VALUES(1, NULL) }
+ } {}
+ do_test without_rowid3-14.2.2.5 {
+ catchsql { UPDATE t4 SET b = 5 }
+ } {1 {FOREIGN KEY constraint failed}}
+ do_test without_rowid3-14.2.2.6 {
+ catchsql { UPDATE t4 SET b = 1 }
+ } {0 {}}
+ do_test without_rowid3-14.2.2.7 {
+ execsql { INSERT INTO t3 VALUES(1, NULL, 1) }
+ } {}
+
+ # Repeat for TEMP tables
+ #
+ drop_all_tables
+ do_test without_rowid3-14.1tmp.1 {
+ # Adding a column with a REFERENCES clause is not supported.
+ execsql {
+ CREATE TEMP TABLE t1(a PRIMARY KEY) WITHOUT rowid;
+ CREATE TEMP TABLE t2(a, b);
+ }
+ catchsql { ALTER TABLE t2 ADD COLUMN c REFERENCES t1 }
+ } {0 {}}
+ do_test without_rowid3-14.1tmp.2 {
+ catchsql { ALTER TABLE t2 ADD COLUMN d DEFAULT NULL REFERENCES t1 }
+ } {0 {}}
+ do_test without_rowid3-14.1tmp.3 {
+ catchsql { ALTER TABLE t2 ADD COLUMN e REFERENCES t1 DEFAULT NULL}
+ } {0 {}}
+ do_test without_rowid3-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 without_rowid3-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 without_rowid3-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 sqlite_temp_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)}}
+
+ do_test without_rowid3-14.2tmp.1.1 {
+ test_rename_parent {CREATE TABLE t1(a REFERENCES t2)} t2 t3
+ } {{CREATE TABLE t1(a REFERENCES "t3")}}
+ do_test without_rowid3-14.2tmp.1.2 {
+ test_rename_parent {CREATE TABLE t1(a REFERENCES t2)} t4 t3
+ } {{CREATE TABLE t1(a REFERENCES t2)}}
+ do_test without_rowid3-14.2tmp.1.3 {
+ test_rename_parent {CREATE TABLE t1(a REFERENCES "t2")} t2 t3
+ } {{CREATE TABLE t1(a REFERENCES "t3")}}
+
+ # Test ALTER TABLE RENAME TABLE a bit.
+ #
+ do_test without_rowid3-14.2tmp.2.1 {
+ drop_all_tables
+ execsql {
+ CREATE TEMP TABLE t1(a PRIMARY KEY, b REFERENCES t1) WITHOUT rowid;
+ CREATE TEMP TABLE t2(a PRIMARY KEY, b REFERENCES t1, c REFERENCES t2)
+ WITHOUT rowid;
+ 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) WITHOUT rowid} \
+ {CREATE TABLE t2(a PRIMARY KEY, b REFERENCES t1, c REFERENCES t2)
+ WITHOUT rowid} \
+ {CREATE TABLE t3(a REFERENCES t1, b REFERENCES t2, c REFERENCES t1)} \
+ ]
+ do_test without_rowid3-14.2tmp.2.2 {
+ execsql { ALTER TABLE t1 RENAME TO t4 }
+ execsql { SELECT sql FROM sqlite_temp_master WHERE type = 'table'}
+ } [list \
+ {CREATE TABLE "t4"(a PRIMARY KEY, b REFERENCES "t4") WITHOUT rowid} \
+ {CREATE TABLE t2(a PRIMARY KEY, b REFERENCES "t4", c REFERENCES t2)
+ WITHOUT rowid} \
+ {CREATE TABLE t3(a REFERENCES "t4", b REFERENCES t2, c REFERENCES "t4")} \
+ ]
+ do_test without_rowid3-14.2tmp.2.3 {
+ catchsql { INSERT INTO t3 VALUES(1, 2, 3) }
+ } {1 {FOREIGN KEY constraint failed}}
+ do_test without_rowid3-14.2tmp.2.4 {
+ execsql { INSERT INTO t4 VALUES(1, NULL) }
+ } {}
+ do_test without_rowid3-14.2tmp.2.5 {
+ catchsql { UPDATE t4 SET b = 5 }
+ } {1 {FOREIGN KEY constraint failed}}
+ do_test without_rowid3-14.2tmp.2.6 {
+ catchsql { UPDATE t4 SET b = 1 }
+ } {0 {}}
+ do_test without_rowid3-14.2tmp.2.7 {
+ execsql { INSERT INTO t3 VALUES(1, NULL, 1) }
+ } {}
+
+ # Repeat for ATTACH-ed tables
+ #
+ drop_all_tables
+ do_test without_rowid3-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) WITHOUT rowid;
+ CREATE TABLE aux.t2(a, b);
+ }
+ catchsql { ALTER TABLE t2 ADD COLUMN c REFERENCES t1 }
+ } {0 {}}
+ do_test without_rowid3-14.1aux.2 {
+ catchsql { ALTER TABLE t2 ADD COLUMN d DEFAULT NULL REFERENCES t1 }
+ } {0 {}}
+ do_test without_rowid3-14.1aux.3 {
+ catchsql { ALTER TABLE t2 ADD COLUMN e REFERENCES t1 DEFAULT NULL}
+ } {0 {}}
+ do_test without_rowid3-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 without_rowid3-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 without_rowid3-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)}}
+
+ do_test without_rowid3-14.2aux.1.1 {
+ test_rename_parent {CREATE TABLE t1(a REFERENCES t2)} t2 t3
+ } {{CREATE TABLE t1(a REFERENCES "t3")}}
+ do_test without_rowid3-14.2aux.1.2 {
+ test_rename_parent {CREATE TABLE t1(a REFERENCES t2)} t4 t3
+ } {{CREATE TABLE t1(a REFERENCES t2)}}
+ do_test without_rowid3-14.2aux.1.3 {
+ test_rename_parent {CREATE TABLE t1(a REFERENCES "t2")} t2 t3
+ } {{CREATE TABLE t1(a REFERENCES "t3")}}
+
+ # Test ALTER TABLE RENAME TABLE a bit.
+ #
+ do_test without_rowid3-14.2aux.2.1 {
+ drop_all_tables
+ execsql {
+ CREATE TABLE aux.t1(a PRIMARY KEY, b REFERENCES t1) WITHOUT rowid;
+ CREATE TABLE aux.t2(a PRIMARY KEY, b REFERENCES t1, c REFERENCES t2)
+ WITHOUT rowid;
+ 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) WITHOUT rowid} \
+ {CREATE TABLE t2(a PRIMARY KEY, b REFERENCES t1, c REFERENCES t2)
+ WITHOUT rowid} \
+ {CREATE TABLE t3(a REFERENCES t1, b REFERENCES t2, c REFERENCES t1)} \
+ ]
+ do_test without_rowid3-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") WITHOUT rowid} \
+ {CREATE TABLE t2(a PRIMARY KEY, b REFERENCES "t4", c REFERENCES t2)
+ WITHOUT rowid} \
+ {CREATE TABLE t3(a REFERENCES "t4", b REFERENCES t2, c REFERENCES "t4")} \
+ ]
+ do_test without_rowid3-14.2aux.2.3 {
+ catchsql { INSERT INTO t3 VALUES(1, 2, 3) }
+ } {1 {FOREIGN KEY constraint failed}}
+ do_test without_rowid3-14.2aux.2.4 {
+ execsql { INSERT INTO t4 VALUES(1, NULL) }
+ } {}
+ do_test without_rowid3-14.2aux.2.5 {
+ catchsql { UPDATE t4 SET b = 5 }
+ } {1 {FOREIGN KEY constraint failed}}
+ do_test without_rowid3-14.2aux.2.6 {
+ catchsql { UPDATE t4 SET b = 1 }
+ } {0 {}}
+ do_test without_rowid3-14.2aux.2.7 {
+ execsql { INSERT INTO t3 VALUES(1, NULL, 1) }
+ } {}
+}
+
+do_test without_rowid3-2.14.3.1 {
+ drop_all_tables
+ execsql {
+ CREATE TABLE t1(a, b REFERENCES nosuchtable);
+ DROP TABLE t1;
+ }
+} {}
+do_test without_rowid3-2.14.3.2 {
+ execsql {
+ CREATE TABLE t1(a PRIMARY KEY, b) WITHOUT rowid;
+ INSERT INTO t1 VALUES('a', 1);
+ CREATE TABLE t2(x REFERENCES t1);
+ INSERT INTO t2 VALUES('a');
+ }
+} {}
+do_test without_rowid3-2.14.3.3 {
+ catchsql { DROP TABLE t1 }
+} {1 {FOREIGN KEY constraint failed}}
+do_test without_rowid3-2.14.3.4 {
+ execsql {
+ DELETE FROM t2;
+ DROP TABLE t1;
+ }
+} {}
+do_test without_rowid3-2.14.3.4 {
+ catchsql { INSERT INTO t2 VALUES('x') }
+} {1 {no such table: main.t1}}
+do_test without_rowid3-2.14.3.5 {
+ execsql {
+ CREATE TABLE t1(x PRIMARY KEY) WITHOUT rowid;
+ INSERT INTO t1 VALUES('x');
+ }
+ execsql { INSERT INTO t2 VALUES('x') }
+} {}
+do_test without_rowid3-2.14.3.6 {
+ catchsql { DROP TABLE t1 }
+} {1 {FOREIGN KEY constraint failed}}
+do_test without_rowid3-2.14.3.7 {
+ execsql {
+ DROP TABLE t2;
+ DROP TABLE t1;
+ }
+} {}
+do_test without_rowid3-2.14.3.8 {
+ execsql {
+ CREATE TABLE pp(x, y, PRIMARY KEY(x, y)) WITHOUT ROWID;
+ 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 without_rowid3-2.14.3.9 {
+ execsql { DROP TABLE cc }
+} {}
+do_test without_rowid3-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)) WITHOUT rowid;
+ INSERT INTO pp VALUES(1, 'a', 'b');
+ COMMIT;
+ }
+} {}
+do_test without_rowid3-2.14.3.11 {
+ execsql {
+ BEGIN;
+ DROP TABLE cc;
+ DROP TABLE pp;
+ COMMIT;
+ }
+} {}
+do_test without_rowid3-2.14.3.12 {
+ execsql {
+ CREATE TABLE b1(a, b);
+ CREATE TABLE b2(a, b REFERENCES b1);
+ DROP TABLE b1;
+ }
+} {}
+do_test without_rowid3-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 without_rowid3-2.14.4.1 {
+ execsql {
+ CREATE TABLE t1(x REFERENCES v);
+ CREATE VIEW v AS SELECT * FROM t1;
+ }
+} {}
+do_test without_rowid3-2.14.4.2 {
+ execsql {
+ DROP VIEW v;
+ }
+} {}
+ifcapable vtab {
+ register_echo_module db
+ do_test without_rowid3-2.14.4.3 {
+ execsql { CREATE VIRTUAL TABLE v USING echo(t1) }
+ } {}
+ do_test without_rowid3-2.14.4.2 {
+ execsql {
+ DROP TABLE v;
+ }
+ } {}
+}
+
+#-------------------------------------------------------------------------
+# The following tests, without_rowid3-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 without_rowid3-15.1.1 {
+ execsql {
+ CREATE TABLE pp(a PRIMARY KEY, b) WITHOUT rowid;
+ 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 without_rowid3-15.1.2 {
+ execsqlS { INSERT INTO pp VALUES(3, 'three') }
+} {0}
+do_test without_rowid3-15.1.3 {
+ execsql {
+ BEGIN;
+ INSERT INTO cc VALUES('see', 4); -- Violates deferred constraint
+ }
+ execsqlS { INSERT INTO pp VALUES(5, 'five') }
+} {2}
+do_test without_rowid3-15.1.4 {
+ execsql { DELETE FROM cc WHERE x = 'see' }
+ execsqlS { INSERT INTO pp VALUES(6, 'six') }
+} {0}
+do_test without_rowid3-15.1.5 {
+ execsql COMMIT
+} {}
+do_test without_rowid3-15.1.6 {
+ execsql BEGIN
+ execsqlS {
+ DELETE FROM cc WHERE x = 'neung';
+ ROLLBACK;
+ }
+} {1}
+do_test without_rowid3-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, without_rowid3-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))
+ WITHOUT rowid }
+ 2 { CREATE TABLE self(a PRIMARY KEY, b REFERENCES self(a)) WITHOUT rowid }
+ 3 { CREATE TABLE self(a UNIQUE, b INT PRIMARY KEY REFERENCES self(a))
+ WITHOUT rowid }
+} {
+ drop_all_tables
+ do_test without_rowid3-16.1.$tn.1 {
+ execsql $zSchema
+ execsql { INSERT INTO self VALUES(13, 13) }
+ } {}
+ do_test without_rowid3-16.1.$tn.2 {
+ execsql { UPDATE self SET a = 14, b = 14 }
+ } {}
+
+ do_test without_rowid3-16.1.$tn.3 {
+ catchsql { UPDATE self SET b = 15 }
+ } {1 {FOREIGN KEY constraint failed}}
+
+ do_test without_rowid3-16.1.$tn.4 {
+ catchsql { UPDATE self SET a = 15 }
+ } {1 {FOREIGN KEY constraint failed}}
+
+ do_test without_rowid3-16.1.$tn.5 {
+ catchsql { UPDATE self SET a = 15, b = 16 }
+ } {1 {FOREIGN KEY constraint failed}}
+
+ do_test without_rowid3-16.1.$tn.6 {
+ catchsql { UPDATE self SET a = 17, b = 17 }
+ } {0 {}}
+
+ do_test without_rowid3-16.1.$tn.7 {
+ execsql { DELETE FROM self }
+ } {}
+ do_test without_rowid3-16.1.$tn.8 {
+ catchsql { INSERT INTO self VALUES(20, 21) }
+ } {1 {FOREIGN KEY constraint failed}}
+}
+
+# Additional tests cases using multi-column self-referential
+# FOREIGN KEY constraints.
+#
+drop_all_tables
+do_execsql_test without_rowid3-16.4.1.1 {
+ PRAGMA foreign_keys=ON;
+ CREATE TABLE t1(a,b,c,d,e,f,
+ UNIQUE (a,b),
+ PRIMARY KEY (e,c),
+ FOREIGN KEY (d,f) REFERENCES t1(e,c)
+ ) WITHOUT rowid;
+ INSERT INTO t1 VALUES(1,2,3,5,5,3);
+ INSERT INTO t1 VALUES(2,3,4,6,6,4);
+ INSERT INTO t1 VALUES('x','y',1.5,'fizzle','fizzle',1.5);
+ SELECT *, '|' FROM t1 ORDER BY a, b;
+} {1 2 3 5 5 3 | 2 3 4 6 6 4 | x y 1.5 fizzle fizzle 1.5 |}
+
+do_execsql_test without_rowid3-16.4.1.2 {
+ UPDATE t1 SET c=99, f=99 WHERE a=1;
+ SELECT *, '|' FROM t1 ORDER BY a, b;
+} {1 2 99 5 5 99 | 2 3 4 6 6 4 | x y 1.5 fizzle fizzle 1.5 |}
+
+do_execsql_test without_rowid3-16.4.1.3 {
+ UPDATE t1 SET e=876, d=876 WHERE a=2;
+ SELECT *, '|' FROM t1 ORDER BY a, b;
+} {1 2 99 5 5 99 | 2 3 4 876 876 4 | x y 1.5 fizzle fizzle 1.5 |}
+
+do_test without_rowid3-16.4.1.4 {
+ catchsql {
+ UPDATE t1 SET c=11, e=22 WHERE a=1;
+ }
+} {1 {FOREIGN KEY constraint failed}}
+
+do_test without_rowid3-16.4.1.5 {
+ catchsql {
+ UPDATE t1 SET d=11, f=22 WHERE a=1;
+ }
+} {1 {FOREIGN KEY constraint failed}}
+
+do_execsql_test without_rowid3-16.4.1.6 {
+ DELETE FROM t1 WHERE a=1;
+ SELECT *, '|' FROM t1 ORDER BY a, b;
+} {2 3 4 876 876 4 | x y 1.5 fizzle fizzle 1.5 |}
+
+do_execsql_test without_rowid3-16.4.2.1 {
+ DROP TABLE t1;
+ CREATE TABLE t1(a,b,c,d,e,f,
+ PRIMARY KEY (a,b),
+ UNIQUE (e,c),
+ FOREIGN KEY (d,f) REFERENCES t1(e,c)
+ ) WITHOUT rowid;
+ INSERT INTO t1 VALUES(1,2,3,5,5,3);
+ INSERT INTO t1 VALUES(2,3,4,6,6,4);
+ INSERT INTO t1 VALUES('x','y',1.5,'fizzle','fizzle',1.5);
+ SELECT *, '|' FROM t1 ORDER BY a, b;
+} {1 2 3 5 5 3 | 2 3 4 6 6 4 | x y 1.5 fizzle fizzle 1.5 |}
+
+do_execsql_test without_rowid3-16.4.2.2 {
+ UPDATE t1 SET c=99, f=99 WHERE a=1;
+ SELECT *, '|' FROM t1 ORDER BY a, b;
+} {1 2 99 5 5 99 | 2 3 4 6 6 4 | x y 1.5 fizzle fizzle 1.5 |}
+
+do_execsql_test without_rowid3-16.4.2.3 {
+ UPDATE t1 SET e=876, d=876 WHERE a=2;
+ SELECT *, '|' FROM t1 ORDER BY a, b;
+} {1 2 99 5 5 99 | 2 3 4 876 876 4 | x y 1.5 fizzle fizzle 1.5 |}
+
+do_test without_rowid3-16.4.2.4 {
+ catchsql {
+ UPDATE t1 SET c=11, e=22 WHERE a=1;
+ }
+} {1 {FOREIGN KEY constraint failed}}
+
+do_test without_rowid3-16.4.2.5 {
+ catchsql {
+ UPDATE t1 SET d=11, f=22 WHERE a=1;
+ }
+} {1 {FOREIGN KEY constraint failed}}
+
+do_execsql_test without_rowid3-16.4.2.6 {
+ DELETE FROM t1 WHERE a=1;
+ SELECT *, '|' FROM t1 ORDER BY a, b;
+} {2 3 4 876 876 4 | x y 1.5 fizzle fizzle 1.5 |}
+
+
+#-------------------------------------------------------------------------
+# This next block of tests, without_rowid3-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 without_rowid3-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 without_rowid3-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 without_rowid3-17.1.2b SQLITE_CONSTRAINT_FOREIGNKEY
+ifcapable autoreset {
+ do_test without_rowid3-17.1.3 {
+ sqlite3_step $STMT
+ } {SQLITE_CONSTRAINT}
+ verify_ex_errcode without_rowid3-17.1.3b SQLITE_CONSTRAINT_FOREIGNKEY
+} else {
+ do_test without_rowid3-17.1.3 {
+ sqlite3_step $STMT
+ } {SQLITE_MISUSE}
+}
+do_test without_rowid3-17.1.4 {
+ sqlite3_finalize $STMT
+} {SQLITE_CONSTRAINT}
+verify_ex_errcode without_rowid3-17.1.4b SQLITE_CONSTRAINT_FOREIGNKEY
+do_test without_rowid3-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 without_rowid3-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 without_rowid3-17.1.7 {
+ execsql { SELECT * FROM one }
+} {1 2 3 2 3 4 3 4 5 0 0 0}
+do_test without_rowid3-17.1.8 {
+ execsql { SELECT * FROM two }
+} {1 2 3 2 3 4 3 4 5}
+do_test without_rowid3-17.1.9 {
+ execsql COMMIT
+} {}
+do_test without_rowid3-17.1.10 {
+ execsql {
+ CREATE TABLE three(
+ g, h, i,
+ FOREIGN KEY(h, i) REFERENCES one(b, c) DEFERRABLE INITIALLY DEFERRED
+ );
+ }
+} {}
+do_test without_rowid3-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 without_rowid3-17.1.12 {
+ sqlite3_column_text $STMT 0
+} {1}
+do_test without_rowid3-17.1.13 {
+ sqlite3_step $STMT
+} {SQLITE_CONSTRAINT}
+verify_ex_errcode without_rowid3-17.1.13b SQLITE_CONSTRAINT_FOREIGNKEY
+do_test without_rowid3-17.1.14 {
+ sqlite3_finalize $STMT
+} {SQLITE_CONSTRAINT}
+verify_ex_errcode without_rowid3-17.1.14b SQLITE_CONSTRAINT_FOREIGNKEY
+
+drop_all_tables
+do_test without_rowid3-17.2.1 {
+ execsql {
+ CREATE TABLE high("a'b!" PRIMARY KEY, b) WITHOUT rowid;
+ CREATE TABLE low(
+ c,
+ "d&6" REFERENCES high ON UPDATE CASCADE ON DELETE CASCADE
+ );
+ }
+} {}
+do_test without_rowid3-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 without_rowid3-17.2.3 {
+ execsql { UPDATE high SET "a'b!" = 'c' }
+} {1}
+do_test without_rowid3-17.2.4 {
+ db changes
+} {1}
+do_test without_rowid3-17.2.5 {
+ expr [db total_changes] - $nTotal
+} {2}
+do_test without_rowid3-17.2.6 {
+ execsql { SELECT * FROM high ; SELECT * FROM low }
+} {c b b c}
+do_test without_rowid3-17.2.7 {
+ execsql { DELETE FROM high }
+} {1}
+do_test without_rowid3-17.2.8 {
+ db changes
+} {1}
+do_test without_rowid3-17.2.9 {
+ expr [db total_changes] - $nTotal
+} {4}
+do_test without_rowid3-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 without_rowid3-18.1 {
+ execsql {
+ CREATE TABLE long(a, b PRIMARY KEY, c) WITHOUT rowid;
+ 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 $args ; 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 without_rowid3-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 without_rowid3-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 without_rowid3-18.4 {
+ execsql { INSERT INTO mid VALUES(1, 3, 2) }
+ set authargs
+ } {SQLITE_INSERT mid {} main {} SQLITE_READ long b main {}}
+
+ do_test without_rowid3-18.5 {
+ execsql {
+ CREATE TABLE nought(a, b PRIMARY KEY, c) WITHOUT rowid;
+ 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 without_rowid3-18.6 {
+ execsql {SELECT * FROM cross}
+ } {0 5 0}
+
+ do_test without_rowid3-18.7 {
+ execsql {
+ CREATE TABLE one(a INT PRIMARY KEY, b) WITHOUT rowid;
+ 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 without_rowid3-18.8 {
+ catchsql { INSERT INTO short VALUES(1, 3, 2) }
+ } {1 {FOREIGN KEY constraint failed}}
+ do_test without_rowid3-18.9 {
+ execsql { INSERT INTO short VALUES(1, 3, NULL) }
+ } {}
+ do_test without_rowid3-18.10 {
+ execsql { SELECT * FROM short }
+ } {1 3 2 1 3 {}}
+ do_test without_rowid3-18.11 {
+ catchsql { UPDATE short SET f = 2 WHERE f IS NULL }
+ } {1 {FOREIGN KEY constraint failed}}
+
+ db auth {}
+ unset authargs
+}
+
+
+do_test without_rowid3-19.1 {
+ execsql {
+ CREATE TABLE main(id INT PRIMARY KEY) WITHOUT rowid;
+ 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 without_rowid3-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 without_rowid3-19.2b SQLITE_CONSTRAINT_FOREIGNKEY
+do_test without_rowid3-19.3 {
+ sqlite3_reset $S
+} {SQLITE_CONSTRAINT}
+verify_ex_errcode without_rowid3-19.3b SQLITE_CONSTRAINT_FOREIGNKEY
+do_test without_rowid3-19.4 {
+ sqlite3_bind_int $S 1 1
+ sqlite3_step $S
+} {SQLITE_DONE}
+do_test without_rowid3-19.4 {
+ sqlite3_finalize $S
+} {SQLITE_OK}
+
+drop_all_tables
+do_test without_rowid3-20.1 {
+ execsql {
+ CREATE TABLE pp(a PRIMARY KEY, b) WITHOUT rowid;
+ CREATE TABLE cc(c PRIMARY KEY, d REFERENCES pp) WITHOUT rowid;
+ }
+} {}
+
+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 without_rowid3-20.2.$tn.1 {
+ catchsql "$insert INTO cc VALUES(1, 2)"
+ } {1 {FOREIGN KEY constraint failed}}
+ do_test without_rowid3-20.2.$tn.2 {
+ execsql { SELECT * FROM cc }
+ } {}
+ do_test without_rowid3-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 without_rowid3-20.2.$tn.4 {
+ execsql { COMMIT ; SELECT * FROM cc }
+ } {1 2}
+ do_test without_rowid3-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 without_rowid3-20.3.$tn.1 {
+ execsql {
+ INSERT INTO pp VALUES(2, 'two');
+ INSERT INTO cc VALUES(1, 2);
+ }
+ } {}
+ do_test without_rowid3-20.3.$tn.2 {
+ catchsql "$update pp SET a = 1"
+ } {1 {FOREIGN KEY constraint failed}}
+ do_test without_rowid3-20.3.$tn.3 {
+ execsql { SELECT * FROM pp }
+ } {2 two}
+ do_test without_rowid3-20.3.$tn.4 {
+ catchsql "$update cc SET d = 1"
+ } {1 {FOREIGN KEY constraint failed}}
+ do_test without_rowid3-20.3.$tn.5 {
+ execsql { SELECT * FROM cc }
+ } {1 2}
+ do_test without_rowid3-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 without_rowid3-20.3.$tn.7 {
+ execsql { COMMIT ; SELECT * FROM pp }
+ } {2 two 3 three}
+ do_test without_rowid3-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 without_rowid3-20.3.$tn.9 {
+ execsql { COMMIT ; SELECT * FROM cc }
+ } {1 2 2 2}
+ do_test without_rowid3-20.3.$tn.10 {
+ execsql { DELETE FROM cc ; DELETE FROM pp }
+ } {}
+}
+
+#-------------------------------------------------------------------------
+# The following block of tests, those prefixed with "without_rowid3-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 without_rowid3-genfkey.1.1 {
+ execsql {
+ CREATE TABLE t1(a INT PRIMARY KEY, b, c, UNIQUE(b, c)) WITHOUT rowid;
+ CREATE TABLE t2(e REFERENCES t1, f);
+ CREATE TABLE t3(g, h, i, FOREIGN KEY (h, i) REFERENCES t1(b, c));
+ }
+} {}
+do_test without_rowid3-genfkey.1.2 {
+ catchsql { INSERT INTO t2 VALUES(1, 2) }
+} {1 {FOREIGN KEY constraint failed}}
+do_test without_rowid3-genfkey.1.3 {
+ execsql {
+ INSERT INTO t1 VALUES(1, 2, 3);
+ INSERT INTO t2 VALUES(1, 2);
+ }
+} {}
+do_test without_rowid3-genfkey.1.4 {
+ execsql { INSERT INTO t2 VALUES(NULL, 3) }
+} {}
+do_test without_rowid3-genfkey.1.5 {
+ catchsql { UPDATE t2 SET e = 5 WHERE e IS NULL }
+} {1 {FOREIGN KEY constraint failed}}
+do_test without_rowid3-genfkey.1.6 {
+ execsql { UPDATE t2 SET e = 1 WHERE e IS NULL }
+} {}
+do_test without_rowid3-genfkey.1.7 {
+ execsql { UPDATE t2 SET e = NULL WHERE f = 3 }
+} {}
+do_test without_rowid3-genfkey.1.8 {
+ catchsql { UPDATE t1 SET a = 10 }
+} {1 {FOREIGN KEY constraint failed}}
+do_test without_rowid3-genfkey.1.9 {
+ catchsql { UPDATE t1 SET a = NULL }
+} {1 {NOT NULL constraint failed: t1.a}}
+do_test without_rowid3-genfkey.1.10 {
+ catchsql { DELETE FROM t1 }
+} {1 {FOREIGN KEY constraint failed}}
+do_test without_rowid3-genfkey.1.11 {
+ execsql { UPDATE t2 SET e = NULL }
+} {}
+do_test without_rowid3-genfkey.1.12 {
+ execsql {
+ UPDATE t1 SET a = 10;
+ DELETE FROM t1;
+ DELETE FROM t2;
+ }
+} {}
+do_test without_rowid3-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 without_rowid3-genfkey.1.14 {
+ catchsql { INSERT INTO t3 VALUES(3, 1, 4) }
+} {1 {FOREIGN KEY constraint failed}}
+do_test without_rowid3-genfkey.1.15 {
+ execsql {
+ INSERT INTO t1 VALUES(1, 1, 4);
+ INSERT INTO t3 VALUES(3, 1, 4);
+ }
+} {}
+do_test without_rowid3-genfkey.1.16 {
+ catchsql { DELETE FROM t1 }
+} {1 {FOREIGN KEY constraint failed}}
+do_test without_rowid3-genfkey.1.17 {
+ catchsql { UPDATE t1 SET b = 10}
+} {1 {FOREIGN KEY constraint failed}}
+do_test without_rowid3-genfkey.1.18 {
+ execsql { UPDATE t1 SET a = 10}
+} {}
+do_test without_rowid3-genfkey.1.19 {
+ catchsql { UPDATE t3 SET h = 'hello' WHERE i = 3}
+} {1 {FOREIGN KEY constraint failed}}
+
+drop_all_tables
+do_test without_rowid3-genfkey.2.1 {
+ execsql {
+ CREATE TABLE t1(a INT PRIMARY KEY, b, c, UNIQUE(b, c)) WITHOUT rowid;
+ 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 without_rowid3-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 without_rowid3-genfkey.2.3 {
+ execsql {
+ UPDATE t1 SET a = 2 WHERE a = 1;
+ SELECT * FROM t2;
+ }
+} {2 one 4 four}
+do_test without_rowid3-genfkey.2.4 {
+ execsql {
+ DELETE FROM t1 WHERE a = 4;
+ SELECT * FROM t2;
+ }
+} {2 one}
+
+do_test without_rowid3-genfkey.2.5 {
+ execsql {
+ INSERT INTO t3 VALUES('hello', 2, 3);
+ UPDATE t1 SET c = 2;
+ SELECT * FROM t3;
+ }
+} {hello 2 2}
+do_test without_rowid3-genfkey.2.6 {
+ execsql {
+ DELETE FROM t1;
+ SELECT * FROM t3;
+ }
+} {}
+
+drop_all_tables
+do_test without_rowid3-genfkey.3.1 {
+ execsql {
+ CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, UNIQUE(c, b)) WITHOUT rowid;
+ 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 without_rowid3-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 without_rowid3-genfkey.3.3 {
+ execsql {
+ UPDATE t1 SET a = 2 WHERE a = 1;
+ SELECT * FROM t2;
+ }
+} {{} one 4 four}
+do_test without_rowid3-genfkey.3.4 {
+ execsql {
+ DELETE FROM t1 WHERE a = 4;
+ SELECT * FROM t2;
+ }
+} {{} one {} four}
+do_test without_rowid3-genfkey.3.5 {
+ execsql {
+ INSERT INTO t3 VALUES('hello', 2, 3);
+ UPDATE t1 SET c = 2;
+ SELECT * FROM t3;
+ }
+} {hello {} {}}
+do_test without_rowid3-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 without_rowid3-dd08e5.1.1 {
+ execsql {
+ PRAGMA foreign_keys=ON;
+ CREATE TABLE tdd08(a INTEGER PRIMARY KEY, b) WITHOUT rowid;
+ 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 without_rowid3-dd08e5.1.2 {
+ catchsql {
+ DELETE FROM tdd08;
+ }
+} {1 {FOREIGN KEY constraint failed}}
+do_test without_rowid3-dd08e5.1.3 {
+ execsql {
+ SELECT * FROM tdd08;
+ }
+} {200 300}
+do_test without_rowid3-dd08e5.1.4 {
+ catchsql {
+ INSERT INTO tdd08_b VALUES(400,500,300);
+ }
+} {1 {FOREIGN KEY constraint failed}}
+do_test without_rowid3-dd08e5.1.5 {
+ catchsql {
+ UPDATE tdd08_b SET x=x+1;
+ }
+} {1 {FOREIGN KEY constraint failed}}
+do_test without_rowid3-dd08e5.1.6 {
+ catchsql {
+ UPDATE tdd08 SET a=a+1;
+ }
+} {1 {FOREIGN KEY constraint failed}}
+
+#-------------------------------------------------------------------------
+# Verify that ticket ce7c133ea6cc9ccdc1a60d80441f80b6180f5eba
+# fixed.
+#
+do_test without_rowid3-ce7c13.1.1 {
+ execsql {
+ CREATE TABLE tce71(a INTEGER PRIMARY KEY, b) WITHOUT rowid;
+ 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 without_rowid3-ce7c13.1.2 {
+ catchsql {
+ UPDATE tce71 set b = 201 where a = 100;
+ }
+} {1 {FOREIGN KEY constraint failed}}
+do_test without_rowid3-ce7c13.1.3 {
+ catchsql {
+ UPDATE tce71 set a = 101 where a = 100;
+ }
+} {1 {FOREIGN KEY constraint failed}}
+do_test without_rowid3-ce7c13.1.4 {
+ execsql {
+ CREATE TABLE tce73(a INTEGER PRIMARY KEY, b, UNIQUE(a,b)) WITHOUT rowid;
+ 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 without_rowid3-ce7c13.1.5 {
+ catchsql {
+ UPDATE tce73 set b = 201 where a = 100;
+ }
+} {1 {FOREIGN KEY constraint failed}}
+do_test without_rowid3-ce7c13.1.6 {
+ catchsql {
+ UPDATE tce73 set a = 101 where a = 100;
+ }
+} {1 {FOREIGN KEY constraint failed}}
+
+finish_test
diff --git a/lang/sql/sqlite/test/without_rowid4.test b/lang/sql/sqlite/test/without_rowid4.test
new file mode 100644
index 00000000..d8c2d69f
--- /dev/null
+++ b/lang/sql/sqlite/test/without_rowid4.test
@@ -0,0 +1,764 @@
+# 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.
+#
+#***********************************************************************
+#
+# Regression testing of FOR EACH ROW table triggers on WITHOUT ROWID
+# tables.
+#
+# 1. Trigger execution order tests.
+# These tests ensure that BEFORE and AFTER triggers are fired at the correct
+# times relative to each other and the triggering statement.
+#
+# without_rowid4-1.1.*: ON UPDATE trigger execution model.
+# without_rowid4-1.2.*: DELETE trigger execution model.
+# without_rowid4-1.3.*: INSERT trigger execution model.
+#
+# 2. Trigger program execution tests.
+# These tests ensure that trigger programs execute correctly (ie. that a
+# trigger program can correctly execute INSERT, UPDATE, DELETE * SELECT
+# statements, and combinations thereof).
+#
+# 3. Selective trigger execution
+# This tests that conditional triggers (ie. UPDATE OF triggers and triggers
+# with WHEN clauses) are fired only fired when they are supposed to be.
+#
+# without_rowid4-3.1: UPDATE OF triggers
+# without_rowid4-3.2: WHEN clause
+#
+# 4. Cascaded trigger execution
+# Tests that trigger-programs may cause other triggers to fire. Also that a
+# trigger-program is never executed recursively.
+#
+# without_rowid4-4.1: Trivial cascading trigger
+# without_rowid4-4.2: Trivial recursive trigger handling
+#
+# 5. Count changes behaviour.
+# Verify that rows altered by triggers are not included in the return value
+# of the "count changes" interface.
+#
+# 6. ON CONFLICT clause handling
+# without_rowid4-6.1[a-f]: INSERT statements
+# without_rowid4-6.2[a-f]: UPDATE statements
+#
+# 7. & 8. Triggers on views fire correctly.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+ifcapable {!trigger} {
+ 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 }
+
+# 1.
+ifcapable subquery {
+ set ii 0
+ set tbl_definitions [list \
+ {CREATE TABLE tbl (a INTEGER PRIMARY KEY, b) WITHOUT rowid;} \
+ {CREATE TABLE tbl (a, b PRIMARY KEY) WITHOUT rowid;} \
+ {CREATE TABLE tbl (a PRIMARY KEY, b) WITHOUT rowid;
+ CREATE INDEX tbl_idx ON tbl(b);} \
+ ]
+ ifcapable tempdb {
+ lappend tbl_definitions \
+ {CREATE TEMP TABLE tbl (a PRIMARY KEY, b) WITHOUT rowid;
+ CREATE INDEX tbl_idx ON tbl(b);}
+ lappend tbl_definitions \
+ {CREATE TEMP TABLE tbl (a PRIMARY KEY, b) WITHOUT rowid}
+ lappend tbl_definitions \
+ {CREATE TEMPORARY TABLE tbl (a INTEGER PRIMARY KEY, b) WITHOUT rowid;}
+ }
+ foreach tbl_defn $tbl_definitions {
+ incr ii
+ catchsql { DROP INDEX tbl_idx; }
+ catchsql {
+ DROP TABLE rlog;
+ DROP TABLE clog;
+ DROP TABLE tbl;
+ DROP TABLE other_tbl;
+ }
+
+ execsql $tbl_defn
+
+ execsql {
+ INSERT INTO tbl VALUES(1, 2);
+ INSERT INTO tbl VALUES(3, 4);
+
+ CREATE TABLE rlog (idx, old_a, old_b, db_sum_a, db_sum_b, new_a, new_b);
+ CREATE TABLE clog (idx, old_a, old_b, db_sum_a, db_sum_b, new_a, new_b);
+
+ CREATE TRIGGER before_update_row BEFORE UPDATE ON tbl FOR EACH ROW
+ BEGIN
+ INSERT INTO rlog VALUES ( (SELECT coalesce(max(idx),0) + 1 FROM rlog),
+ old.a, old.b,
+ (SELECT coalesce(sum(a),0) FROM tbl),
+ (SELECT coalesce(sum(b),0) FROM tbl),
+ new.a, new.b);
+ END;
+
+ CREATE TRIGGER after_update_row AFTER UPDATE ON tbl FOR EACH ROW
+ BEGIN
+ INSERT INTO rlog VALUES ( (SELECT coalesce(max(idx),0) + 1 FROM rlog),
+ old.a, old.b,
+ (SELECT coalesce(sum(a),0) FROM tbl),
+ (SELECT coalesce(sum(b),0) FROM tbl),
+ new.a, new.b);
+ END;
+
+ CREATE TRIGGER conditional_update_row AFTER UPDATE ON tbl FOR EACH ROW
+ WHEN old.a = 1
+ BEGIN
+ INSERT INTO clog VALUES ( (SELECT coalesce(max(idx),0) + 1 FROM clog),
+ old.a, old.b,
+ (SELECT coalesce(sum(a),0) FROM tbl),
+ (SELECT coalesce(sum(b),0) FROM tbl),
+ new.a, new.b);
+ END;
+ }
+
+ do_test without_rowid4-1.$ii.1 {
+ set r {}
+ foreach v [execsql {
+ UPDATE tbl SET a = a * 10, b = b * 10;
+ SELECT * FROM rlog ORDER BY idx;
+ SELECT * FROM clog ORDER BY idx;
+ }] {
+ lappend r [expr {int($v)}]
+ }
+ set r
+ } [list 1 1 2 4 6 10 20 \
+ 2 1 2 13 24 10 20 \
+ 3 3 4 13 24 30 40 \
+ 4 3 4 40 60 30 40 \
+ 1 1 2 13 24 10 20 ]
+
+ execsql {
+ DELETE FROM rlog;
+ DELETE FROM tbl;
+ INSERT INTO tbl VALUES (100, 100);
+ INSERT INTO tbl VALUES (300, 200);
+ CREATE TRIGGER delete_before_row BEFORE DELETE ON tbl FOR EACH ROW
+ BEGIN
+ INSERT INTO rlog VALUES ( (SELECT coalesce(max(idx),0) + 1 FROM rlog),
+ old.a, old.b,
+ (SELECT coalesce(sum(a),0) FROM tbl),
+ (SELECT coalesce(sum(b),0) FROM tbl),
+ 0, 0);
+ END;
+
+ CREATE TRIGGER delete_after_row AFTER DELETE ON tbl FOR EACH ROW
+ BEGIN
+ INSERT INTO rlog VALUES ( (SELECT coalesce(max(idx),0) + 1 FROM rlog),
+ old.a, old.b,
+ (SELECT coalesce(sum(a),0) FROM tbl),
+ (SELECT coalesce(sum(b),0) FROM tbl),
+ 0, 0);
+ END;
+ }
+ do_test without_rowid4-1.$ii.2 {
+ set r {}
+ foreach v [execsql {
+ DELETE FROM tbl;
+ SELECT * FROM rlog;
+ }] {
+ lappend r [expr {int($v)}]
+ }
+ set r
+ } [list 1 100 100 400 300 0 0 \
+ 2 100 100 300 200 0 0 \
+ 3 300 200 300 200 0 0 \
+ 4 300 200 0 0 0 0 ]
+
+ execsql {
+ DELETE FROM rlog;
+ CREATE TRIGGER insert_before_row BEFORE INSERT ON tbl FOR EACH ROW
+ BEGIN
+ INSERT INTO rlog VALUES ( (SELECT coalesce(max(idx),0) + 1 FROM rlog),
+ 0, 0,
+ (SELECT coalesce(sum(a),0) FROM tbl),
+ (SELECT coalesce(sum(b),0) FROM tbl),
+ new.a, new.b);
+ END;
+
+ CREATE TRIGGER insert_after_row AFTER INSERT ON tbl FOR EACH ROW
+ BEGIN
+ INSERT INTO rlog VALUES ( (SELECT coalesce(max(idx),0) + 1 FROM rlog),
+ 0, 0,
+ (SELECT coalesce(sum(a),0) FROM tbl),
+ (SELECT coalesce(sum(b),0) FROM tbl),
+ new.a, new.b);
+ END;
+ }
+ do_test without_rowid4-1.$ii.3 {
+ execsql {
+
+ CREATE TABLE other_tbl(a, b);
+ INSERT INTO other_tbl VALUES(1, 2);
+ INSERT INTO other_tbl VALUES(3, 4);
+ -- INSERT INTO tbl SELECT * FROM other_tbl;
+ INSERT INTO tbl VALUES(5, 6);
+ DROP TABLE other_tbl;
+
+ SELECT * FROM rlog;
+ }
+ } [list 1 0 0 0 0 5 6 \
+ 2 0 0 5 6 5 6 ]
+
+ integrity_check without_rowid4-1.$ii.4
+ }
+ catchsql {
+ DROP TABLE rlog;
+ DROP TABLE clog;
+ DROP TABLE tbl;
+ DROP TABLE other_tbl;
+ }
+}
+
+# 2.
+set ii 0
+foreach tr_program {
+ {UPDATE tbl SET b = old.b;}
+ {INSERT INTO log VALUES(new.c, 2, 3);}
+ {DELETE FROM log WHERE a = 1;}
+ {INSERT INTO tbl VALUES(500, new.b * 10, 700);
+ UPDATE tbl SET c = old.c;
+ DELETE FROM log;}
+ {INSERT INTO log select * from tbl;}
+} {
+ foreach test_varset [ list \
+ {
+ set statement {UPDATE tbl SET c = 10 WHERE a = 1;}
+ set prep {INSERT INTO tbl VALUES(1, 2, 3);}
+ set newC 10
+ set newB 2
+ set newA 1
+ set oldA 1
+ set oldB 2
+ set oldC 3
+ } \
+ {
+ set statement {DELETE FROM tbl WHERE a = 1;}
+ set prep {INSERT INTO tbl VALUES(1, 2, 3);}
+ set oldA 1
+ set oldB 2
+ set oldC 3
+ } \
+ {
+ set statement {INSERT INTO tbl VALUES(1, 2, 3);}
+ set newA 1
+ set newB 2
+ set newC 3
+ }
+ ] \
+ {
+ set statement {}
+ set prep {}
+ set newA {''}
+ set newB {''}
+ set newC {''}
+ set oldA {''}
+ set oldB {''}
+ set oldC {''}
+
+ incr ii
+
+ eval $test_varset
+
+ set statement_type [string range $statement 0 5]
+ set tr_program_fixed $tr_program
+ if {$statement_type == "DELETE"} {
+ regsub -all new\.a $tr_program_fixed {''} tr_program_fixed
+ regsub -all new\.b $tr_program_fixed {''} tr_program_fixed
+ regsub -all new\.c $tr_program_fixed {''} tr_program_fixed
+ }
+ if {$statement_type == "INSERT"} {
+ regsub -all old\.a $tr_program_fixed {''} tr_program_fixed
+ regsub -all old\.b $tr_program_fixed {''} tr_program_fixed
+ regsub -all old\.c $tr_program_fixed {''} tr_program_fixed
+ }
+
+
+ set tr_program_cooked $tr_program
+ regsub -all new\.a $tr_program_cooked $newA tr_program_cooked
+ regsub -all new\.b $tr_program_cooked $newB tr_program_cooked
+ regsub -all new\.c $tr_program_cooked $newC tr_program_cooked
+ regsub -all old\.a $tr_program_cooked $oldA tr_program_cooked
+ regsub -all old\.b $tr_program_cooked $oldB tr_program_cooked
+ regsub -all old\.c $tr_program_cooked $oldC tr_program_cooked
+
+ catchsql {
+ DROP TABLE tbl;
+ DROP TABLE log;
+ }
+
+ execsql {
+ CREATE TABLE tbl(a PRIMARY KEY, b, c) WITHOUT rowid;
+ CREATE TABLE log(a, b, c);
+ }
+
+ set query {SELECT * FROM tbl; SELECT * FROM log;}
+ set prep "$prep; INSERT INTO log VALUES(1, 2, 3);\
+ INSERT INTO log VALUES(10, 20, 30);"
+
+# Check execution of BEFORE programs:
+
+ set before_data [ execsql "$prep $tr_program_cooked $statement $query" ]
+
+ execsql "DELETE FROM tbl; DELETE FROM log; $prep";
+ execsql "CREATE TRIGGER the_trigger BEFORE [string range $statement 0 6]\
+ ON tbl BEGIN $tr_program_fixed END;"
+
+ do_test without_rowid4-2.$ii-before "execsql {$statement $query}" $before_data
+
+ execsql "DROP TRIGGER the_trigger;"
+ execsql "DELETE FROM tbl; DELETE FROM log;"
+
+# Check execution of AFTER programs
+ set after_data [ execsql "$prep $statement $tr_program_cooked $query" ]
+
+ execsql "DELETE FROM tbl; DELETE FROM log; $prep";
+ execsql "CREATE TRIGGER the_trigger AFTER [string range $statement 0 6]\
+ ON tbl BEGIN $tr_program_fixed END;"
+
+ do_test without_rowid4-2.$ii-after "execsql {$statement $query}" $after_data
+ execsql "DROP TRIGGER the_trigger;"
+
+ integrity_check without_rowid4-2.$ii-integrity
+ }
+}
+catchsql {
+ DROP TABLE tbl;
+ DROP TABLE log;
+}
+
+# 3.
+
+# without_rowid4-3.1: UPDATE OF triggers
+execsql {
+ CREATE TABLE tbl (a, b, c, d, PRIMARY KEY(a,b,c,d)) WITHOUT rowid;
+ CREATE TABLE log (a);
+ INSERT INTO log VALUES (0);
+ INSERT INTO tbl VALUES (0, 0, 0, 0);
+ INSERT INTO tbl VALUES (1, 0, 0, 0);
+ CREATE TRIGGER tbl_after_update_cd BEFORE UPDATE OF c, d ON tbl
+ BEGIN
+ UPDATE log SET a = a + 1;
+ END;
+}
+do_test without_rowid4-3.1 {
+ execsql {
+ UPDATE tbl SET b = 1, c = 10; -- 2
+ UPDATE tbl SET b = 10; -- 0
+ UPDATE tbl SET d = 4 WHERE a = 0; --1
+ UPDATE tbl SET a = 4, b = 10; --0
+ SELECT * FROM log;
+ }
+} {3}
+execsql {
+ DROP TABLE tbl;
+ DROP TABLE log;
+}
+
+# without_rowid4-3.2: WHEN clause
+set when_triggers [list {t1 BEFORE INSERT ON tbl WHEN new.a > 20}]
+ifcapable subquery {
+ lappend when_triggers \
+ {t2 BEFORE INSERT ON tbl WHEN (SELECT count(*) FROM tbl) = 0}
+}
+
+execsql {
+ CREATE TABLE tbl (a, b, c, d);
+ CREATE TABLE log (a);
+ INSERT INTO log VALUES (0);
+}
+
+foreach trig $when_triggers {
+ execsql "CREATE TRIGGER $trig BEGIN UPDATE log set a = a + 1; END;"
+}
+
+ifcapable subquery {
+ set t232 {1 0 1}
+} else {
+ set t232 {0 0 1}
+}
+do_test without_rowid4-3.2 {
+ execsql {
+
+ INSERT INTO tbl VALUES(0, 0, 0, 0); -- 1 (ifcapable subquery)
+ SELECT * FROM log;
+ UPDATE log SET a = 0;
+
+ INSERT INTO tbl VALUES(0, 0, 0, 0); -- 0
+ SELECT * FROM log;
+ UPDATE log SET a = 0;
+
+ INSERT INTO tbl VALUES(200, 0, 0, 0); -- 1
+ SELECT * FROM log;
+ UPDATE log SET a = 0;
+ }
+} $t232
+execsql {
+ DROP TABLE tbl;
+ DROP TABLE log;
+}
+integrity_check without_rowid4-3.3
+
+# Simple cascaded trigger
+execsql {
+ CREATE TABLE tblA(a, b, PRIMARY KEY(a,b)) WITHOUT rowid;
+ CREATE TABLE tblB(a, b, PRIMARY KEY(a,b)) WITHOUT rowid;
+ CREATE TABLE tblC(a, b, PRIMARY KEY(a,b)) WITHOUT rowid;
+
+ CREATE TRIGGER tr1 BEFORE INSERT ON tblA BEGIN
+ INSERT INTO tblB values(new.a, new.b);
+ END;
+
+ CREATE TRIGGER tr2 BEFORE INSERT ON tblB BEGIN
+ INSERT INTO tblC values(new.a, new.b);
+ END;
+}
+do_test without_rowid4-4.1 {
+ execsql {
+ INSERT INTO tblA values(1, 2);
+ SELECT * FROM tblA;
+ SELECT * FROM tblB;
+ SELECT * FROM tblC;
+ }
+} {1 2 1 2 1 2}
+execsql {
+ DROP TABLE tblA;
+ DROP TABLE tblB;
+ DROP TABLE tblC;
+}
+
+# Simple recursive trigger
+execsql {
+ CREATE TABLE tbl(a, b, c, PRIMARY KEY(c,a,b)) WITHOUT rowid;
+ CREATE TRIGGER tbl_trig BEFORE INSERT ON tbl
+ BEGIN
+ INSERT INTO tbl VALUES (new.a, new.b, new.c+1);
+ END;
+}
+do_test without_rowid4-4.2 {
+ execsql {
+ INSERT INTO tbl VALUES (1, 2, 3);
+ select * from tbl;
+ }
+} {1 2 3 1 2 4}
+execsql {
+ DROP TABLE tbl;
+}
+
+# 5.
+execsql {
+ CREATE TABLE tbl(a, b, c, PRIMARY KEY(c,a,b)) WITHOUT rowid;
+ CREATE TRIGGER tbl_trig BEFORE INSERT ON tbl
+ BEGIN
+ INSERT INTO tbl VALUES (1, 2, 3);
+ INSERT INTO tbl VALUES (2, 2, 3);
+ UPDATE tbl set b = 10 WHERE a = 1;
+ DELETE FROM tbl WHERE a = 1;
+ DELETE FROM tbl;
+ END;
+}
+do_test without_rowid4-5 {
+ execsql {
+ INSERT INTO tbl VALUES(100, 200, 300);
+ }
+ db changes
+} {1}
+execsql {
+ DROP TABLE tbl;
+}
+
+ifcapable conflict {
+ # Handling of ON CONFLICT by INSERT statements inside triggers
+ execsql {
+ CREATE TABLE tbl (a PRIMARY KEY, b, c) WITHOUT rowid;
+ CREATE TRIGGER ai_tbl AFTER INSERT ON tbl BEGIN
+ INSERT OR IGNORE INTO tbl values (new.a, 0, 0);
+ END;
+ }
+ do_test without_rowid4-6.1a {
+ execsql {
+ BEGIN;
+ INSERT INTO tbl values (1, 2, 3);
+ SELECT * from tbl;
+ }
+ } {1 2 3}
+ do_test without_rowid4-6.1b {
+ catchsql {
+ INSERT OR ABORT INTO tbl values (2, 2, 3);
+ }
+ } {1 {UNIQUE constraint failed: tbl.a}}
+ do_test without_rowid4-6.1c {
+ execsql {
+ SELECT * from tbl;
+ }
+ } {1 2 3}
+ do_test without_rowid4-6.1d {
+ catchsql {
+ INSERT OR FAIL INTO tbl values (2, 2, 3);
+ }
+ } {1 {UNIQUE constraint failed: tbl.a}}
+ do_test without_rowid4-6.1e {
+ execsql {
+ SELECT * from tbl;
+ }
+ } {1 2 3 2 2 3}
+ do_test without_rowid4-6.1f {
+ execsql {
+ INSERT OR REPLACE INTO tbl values (2, 2, 3);
+ SELECT * from tbl;
+ }
+ } {1 2 3 2 0 0}
+ do_test without_rowid4-6.1g {
+ catchsql {
+ INSERT OR ROLLBACK INTO tbl values (3, 2, 3);
+ }
+ } {1 {UNIQUE constraint failed: tbl.a}}
+ do_test without_rowid4-6.1h {
+ execsql {
+ SELECT * from tbl;
+ }
+ } {}
+ execsql {DELETE FROM tbl}
+
+
+ # Handling of ON CONFLICT by UPDATE statements inside triggers
+ execsql {
+ INSERT INTO tbl values (4, 2, 3);
+ INSERT INTO tbl values (6, 3, 4);
+ CREATE TRIGGER au_tbl AFTER UPDATE ON tbl BEGIN
+ UPDATE OR IGNORE tbl SET a = new.a, c = 10;
+ END;
+ }
+ do_test without_rowid4-6.2a {
+ execsql {
+ BEGIN;
+ UPDATE tbl SET a = 1 WHERE a = 4;
+ SELECT * from tbl;
+ }
+ } {1 2 10 6 3 4}
+ do_test without_rowid4-6.2b {
+ catchsql {
+ UPDATE OR ABORT tbl SET a = 4 WHERE a = 1;
+ }
+ } {1 {UNIQUE constraint failed: tbl.a}}
+ do_test without_rowid4-6.2c {
+ execsql {
+ SELECT * from tbl;
+ }
+ } {1 2 10 6 3 4}
+ do_test without_rowid4-6.2d {
+ catchsql {
+ UPDATE OR FAIL tbl SET a = 4 WHERE a = 1;
+ }
+ } {1 {UNIQUE constraint failed: tbl.a}}
+ do_test without_rowid4-6.2e {
+ execsql {
+ SELECT * from tbl;
+ }
+ } {4 2 10 6 3 4}
+ do_test without_rowid4-6.2f.1 {
+ execsql {
+ UPDATE OR REPLACE tbl SET a = 1 WHERE a = 4;
+ SELECT * from tbl;
+ }
+ } {1 3 10}
+ do_test without_rowid4-6.2f.2 {
+ execsql {
+ INSERT INTO tbl VALUES (2, 3, 4);
+ SELECT * FROM tbl;
+ }
+ } {1 3 10 2 3 4}
+ do_test without_rowid4-6.2g {
+ catchsql {
+ UPDATE OR ROLLBACK tbl SET a = 4 WHERE a = 1;
+ }
+ } {1 {UNIQUE constraint failed: tbl.a}}
+ do_test without_rowid4-6.2h {
+ execsql {
+ SELECT * from tbl;
+ }
+ } {4 2 3 6 3 4}
+ execsql {
+ DROP TABLE tbl;
+ }
+} ; # ifcapable conflict
+
+# 7. Triggers on views
+ifcapable view {
+
+do_test without_rowid4-7.1 {
+ execsql {
+ CREATE TABLE ab(a, b, PRIMARY KEY(a,b)) WITHOUT rowid;
+ CREATE TABLE cd(c, d, PRIMARY KEY(c,d)) WITHOUT rowid;
+ INSERT INTO ab VALUES (1, 2);
+ INSERT INTO ab VALUES (0, 0);
+ INSERT INTO cd VALUES (3, 4);
+
+ CREATE TABLE tlog(ii INTEGER PRIMARY KEY,
+ olda, oldb, oldc, oldd, newa, newb, newc, newd);
+
+ CREATE VIEW abcd AS SELECT a, b, c, d FROM ab, cd;
+
+ CREATE TRIGGER before_update INSTEAD OF UPDATE ON abcd BEGIN
+ INSERT INTO tlog VALUES(NULL,
+ old.a, old.b, old.c, old.d, new.a, new.b, new.c, new.d);
+ END;
+ CREATE TRIGGER after_update INSTEAD OF UPDATE ON abcd BEGIN
+ INSERT INTO tlog VALUES(NULL,
+ old.a, old.b, old.c, old.d, new.a, new.b, new.c, new.d);
+ END;
+
+ CREATE TRIGGER before_delete INSTEAD OF DELETE ON abcd BEGIN
+ INSERT INTO tlog VALUES(NULL,
+ old.a, old.b, old.c, old.d, 0, 0, 0, 0);
+ END;
+ CREATE TRIGGER after_delete INSTEAD OF DELETE ON abcd BEGIN
+ INSERT INTO tlog VALUES(NULL,
+ old.a, old.b, old.c, old.d, 0, 0, 0, 0);
+ END;
+
+ CREATE TRIGGER before_insert INSTEAD OF INSERT ON abcd BEGIN
+ INSERT INTO tlog VALUES(NULL,
+ 0, 0, 0, 0, new.a, new.b, new.c, new.d);
+ END;
+ CREATE TRIGGER after_insert INSTEAD OF INSERT ON abcd BEGIN
+ INSERT INTO tlog VALUES(NULL,
+ 0, 0, 0, 0, new.a, new.b, new.c, new.d);
+ END;
+ }
+} {};
+
+do_test without_rowid4-7.2 {
+ execsql {
+ UPDATE abcd SET a = 100, b = 5*5 WHERE a = 1;
+ DELETE FROM abcd WHERE a = 1;
+ INSERT INTO abcd VALUES(10, 20, 30, 40);
+ SELECT * FROM tlog;
+ }
+} [ list 1 1 2 3 4 100 25 3 4 \
+ 2 1 2 3 4 100 25 3 4 \
+ 3 1 2 3 4 0 0 0 0 \
+ 4 1 2 3 4 0 0 0 0 \
+ 5 0 0 0 0 10 20 30 40 \
+ 6 0 0 0 0 10 20 30 40 ]
+
+do_test without_rowid4-7.3 {
+ execsql {
+ DELETE FROM tlog;
+ INSERT INTO abcd VALUES(10, 20, 30, 40);
+ UPDATE abcd SET a = 100, b = 5*5 WHERE a = 1;
+ DELETE FROM abcd WHERE a = 1;
+ SELECT * FROM tlog;
+ }
+} [ list \
+ 1 0 0 0 0 10 20 30 40 \
+ 2 0 0 0 0 10 20 30 40 \
+ 3 1 2 3 4 100 25 3 4 \
+ 4 1 2 3 4 100 25 3 4 \
+ 5 1 2 3 4 0 0 0 0 \
+ 6 1 2 3 4 0 0 0 0 \
+]
+do_test without_rowid4-7.4 {
+ execsql {
+ DELETE FROM tlog;
+ DELETE FROM abcd WHERE a = 1;
+ INSERT INTO abcd VALUES(10, 20, 30, 40);
+ UPDATE abcd SET a = 100, b = 5*5 WHERE a = 1;
+ SELECT * FROM tlog;
+ }
+} [ list \
+ 1 1 2 3 4 0 0 0 0 \
+ 2 1 2 3 4 0 0 0 0 \
+ 3 0 0 0 0 10 20 30 40 \
+ 4 0 0 0 0 10 20 30 40 \
+ 5 1 2 3 4 100 25 3 4 \
+ 6 1 2 3 4 100 25 3 4 \
+]
+
+do_test without_rowid4-8.1 {
+ execsql {
+ CREATE TABLE t1(a,b,c, PRIMARY KEY(a,b,c)) WITHOUT rowid;
+ INSERT INTO t1 VALUES(1,2,3);
+ CREATE VIEW v1 AS
+ SELECT a+b AS x, b+c AS y, a+c AS z FROM t1;
+ SELECT * FROM v1;
+ }
+} {3 5 4}
+do_test without_rowid4-8.2 {
+ execsql {
+ CREATE TABLE v1log(a,b,c,d,e,f);
+ CREATE TRIGGER r1 INSTEAD OF DELETE ON v1 BEGIN
+ INSERT INTO v1log VALUES(OLD.x,NULL,OLD.y,NULL,OLD.z,NULL);
+ END;
+ DELETE FROM v1 WHERE x=1;
+ SELECT * FROM v1log;
+ }
+} {}
+do_test without_rowid4-8.3 {
+ execsql {
+ DELETE FROM v1 WHERE x=3;
+ SELECT * FROM v1log;
+ }
+} {3 {} 5 {} 4 {}}
+do_test without_rowid4-8.4 {
+ execsql {
+ INSERT INTO t1 VALUES(4,5,6);
+ DELETE FROM v1log;
+ DELETE FROM v1 WHERE y=11;
+ SELECT * FROM v1log;
+ }
+} {9 {} 11 {} 10 {}}
+do_test without_rowid4-8.5 {
+ execsql {
+ CREATE TRIGGER r2 INSTEAD OF INSERT ON v1 BEGIN
+ INSERT INTO v1log VALUES(NULL,NEW.x,NULL,NEW.y,NULL,NEW.z);
+ END;
+ DELETE FROM v1log;
+ INSERT INTO v1 VALUES(1,2,3);
+ SELECT * FROM v1log;
+ }
+} {{} 1 {} 2 {} 3}
+do_test without_rowid4-8.6 {
+ execsql {
+ CREATE TRIGGER r3 INSTEAD OF UPDATE ON v1 BEGIN
+ INSERT INTO v1log VALUES(OLD.x,NEW.x,OLD.y,NEW.y,OLD.z,NEW.z);
+ END;
+ DELETE FROM v1log;
+ UPDATE v1 SET x=x+100, y=y+200, z=z+300;
+ SELECT * FROM v1log;
+ }
+} {3 103 5 205 4 304 9 109 11 211 10 310}
+
+# At one point the following was causing a segfault.
+do_test without_rowid4-9.1 {
+ execsql {
+ CREATE TABLE t3(a TEXT, b TEXT);
+ CREATE VIEW v3 AS SELECT t3.a FROM t3;
+ CREATE TRIGGER trig1 INSTEAD OF DELETE ON v3 BEGIN
+ SELECT 1;
+ END;
+ DELETE FROM v3 WHERE a = 1;
+ }
+} {}
+
+} ;# ifcapable view
+
+integrity_check without_rowid4-9.9
+
+finish_test
diff --git a/lang/sql/sqlite/test/without_rowid5.test b/lang/sql/sqlite/test/without_rowid5.test
new file mode 100644
index 00000000..45e047be
--- /dev/null
+++ b/lang/sql/sqlite/test/without_rowid5.test
@@ -0,0 +1,201 @@
+# 2013-11-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.
+#
+#***********************************************************************
+#
+# Requirements testing for WITHOUT ROWID tables.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+
+# EVIDENCE-OF: R-36924-43758 By default, every row in SQLite has a
+# special column, usually called the "rowid", that uniquely identifies
+# that row within the table.
+#
+# EVIDENCE-OF: R-32341-39358 However if the phrase "WITHOUT ROWID" is
+# added to the end of a CREATE TABLE statement, then the special "rowid"
+# column is omitted.
+#
+do_execsql_test without_rowid5-1.1 {
+ CREATE TABLE t1(a PRIMARY KEY,b,c);
+ CREATE TABLE t1w(a PRIMARY KEY,b,c) WITHOUT ROWID;
+ INSERT INTO t1 VALUES(1565,681,1148),(1429,1190,1619),(425,358,1306);
+ INSERT INTO t1w SELECT a,b,c FROM t1;
+ SELECT rowid, _rowid_, oid FROM t1 ORDER BY a DESC;
+} {1 1 1 2 2 2 3 3 3}
+do_catchsql_test without_rowid5-1.2 {
+ SELECT rowid FROM t1w;
+} {1 {no such column: rowid}}
+do_catchsql_test without_rowid5-1.3 {
+ SELECT _rowid_ FROM t1w;
+} {1 {no such column: _rowid_}}
+do_catchsql_test without_rowid5-1.4 {
+ SELECT oid FROM t1w;
+} {1 {no such column: oid}}
+
+# EVIDENCE-OF: R-00217-01605 To create a WITHOUT ROWID table, simply add
+# the keywords "WITHOUT ROWID" to the end of the CREATE TABLE statement.
+# For example: CREATE TABLE IF NOT EXISTS wordcount( word TEXT PRIMARY
+# KEY, cnt INTEGER ) WITHOUT ROWID;
+#
+do_execsql_test without_rowid5-2.1 {
+ CREATE TABLE IF NOT EXISTS wordcount(
+ word TEXT PRIMARY KEY,
+ cnt INTEGER
+ ) WITHOUT ROWID;
+ INSERT INTO wordcount VALUES('one',1);
+} {}
+do_catchsql_test without_rowid5-2.2 {
+ SELECT rowid FROM wordcount;
+} {1 {no such column: rowid}}
+
+# EVIDENCE-OF: R-24770-17719 As with all SQL syntax, the case of the
+# keywords does not matter. One can write "WITHOUT rowid" or "without
+# rowid" or "WiThOuT rOwId" and it will mean the same thing.
+#
+do_execsql_test without_rowid5-2.3 {
+ CREATE TABLE IF NOT EXISTS wordcount_b(
+ word TEXT PRIMARY KEY,
+ cnt INTEGER
+ ) WITHOUT rowid;
+ INSERT INTO wordcount_b VALUES('one',1);
+} {}
+do_catchsql_test without_rowid5-2.4 {
+ SELECT rowid FROM wordcount_b;
+} {1 {no such column: rowid}}
+do_execsql_test without_rowid5-2.5 {
+ CREATE TABLE IF NOT EXISTS wordcount_c(
+ word TEXT PRIMARY KEY,
+ cnt INTEGER
+ ) without rowid;
+ INSERT INTO wordcount_c VALUES('one',1);
+} {}
+do_catchsql_test without_rowid5-2.6 {
+ SELECT rowid FROM wordcount_c;
+} {1 {no such column: rowid}}
+do_execsql_test without_rowid5-2.7 {
+ CREATE TABLE IF NOT EXISTS wordcount_d(
+ word TEXT PRIMARY KEY,
+ cnt INTEGER
+ ) WITHOUT rowid;
+ INSERT INTO wordcount_d VALUES('one',1);
+} {}
+do_catchsql_test without_rowid5-2.8 {
+ SELECT rowid FROM wordcount_d;
+} {1 {no such column: rowid}}
+
+# EVIDENCE-OF: R-01418-51310 However, only "rowid" works as the keyword
+# in the CREATE TABLE statement.
+#
+do_catchsql_test without_rowid5-3.1 {
+ CREATE TABLE IF NOT EXISTS error1(
+ word TEXT PRIMARY KEY,
+ cnt INTEGER
+ ) WITHOUT _rowid_;
+} {1 {unknown table option: _rowid_}}
+do_catchsql_test without_rowid5-3.2 {
+ CREATE TABLE IF NOT EXISTS error2(
+ word TEXT PRIMARY KEY,
+ cnt INTEGER
+ ) WITHOUT oid;
+} {1 {unknown table option: oid}}
+
+# EVIDENCE-OF: R-58033-17334 An error is raised if a CREATE TABLE
+# statement with the WITHOUT ROWID clause lacks a PRIMARY KEY.
+#
+# EVIDENCE-OF: R-63443-09418 Every WITHOUT ROWID table must have a
+# PRIMARY KEY.
+#
+# EVIDENCE-OF: R-27966-31616 An attempt to create a WITHOUT ROWID table
+# without a PRIMARY KEY results in an error.
+#
+do_catchsql_test without_rowid5-4.1 {
+ CREATE TABLE IF NOT EXISTS error3(
+ word TEXT UNIQUE,
+ cnt INTEGER
+ ) WITHOUT ROWID;
+} {1 {PRIMARY KEY missing on table error3}}
+
+# EVIDENCE-OF: R-48230-36247 The special behaviors associated "INTEGER
+# PRIMARY KEY" do not apply on WITHOUT ROWID tables.
+#
+do_execsql_test without_rowid5-5.1 {
+ CREATE TABLE ipk(key INTEGER PRIMARY KEY, val TEXT) WITHOUT ROWID;
+ INSERT INTO ipk VALUES('rival','bonus'); -- ok to insert non-integer key
+ SELECT * FROM ipk;
+} {rival bonus}
+do_catchsql_test without_rowid5-5.2 {
+ INSERT INTO ipk VALUES(NULL,'sample'); -- no automatic generation of keys
+} {1 {NOT NULL constraint failed: ipk.key}}
+
+# EVIDENCE-OF: R-33142-02092 AUTOINCREMENT does not work on WITHOUT
+# ROWID tables.
+#
+# EVIDENCE-OF: R-53084-07740 An error is raised if the "AUTOINCREMENT"
+# keyword is used in the CREATE TABLE statement for a WITHOUT ROWID
+# table.
+#
+do_catchsql_test without_rowid5-5.3 {
+ CREATE TABLE ipk2(key INTEGER PRIMARY KEY AUTOINCREMENT, val TEXT)WITHOUT ROWID;
+} {1 {AUTOINCREMENT not allowed on WITHOUT ROWID tables}}
+
+# EVIDENCE-OF: R-27831-00579 NOT NULL is enforced on every column of the
+# PRIMARY KEY in a WITHOUT ROWID table.
+#
+# EVIDENCE-OF: R-29781-51289 So, ordinary rowid tables in SQLite violate
+# the SQL standard and allow NULL values in PRIMARY KEY fields.
+#
+# EVIDENCE-OF: R-27472-62612 But WITHOUT ROWID tables do follow the
+# standard and will throw an error on any attempt to insert a NULL into
+# a PRIMARY KEY column.
+#
+do_execsql_test without_rowid5-5.4 {
+ CREATE TABLE nn(a, b, c, d, e, PRIMARY KEY(c,a,e));
+ CREATE TABLE nnw(a, b, c, d, e, PRIMARY KEY(c,a,e)) WITHOUT ROWID;
+ INSERT INTO nn VALUES(1,2,3,4,5);
+ INSERT INTO nnw VALUES(1,2,3,4,5);
+} {}
+do_execsql_test without_rowid5-5.5 {
+ INSERT INTO nn VALUES(NULL, 3,4,5,6);
+ INSERT INTO nn VALUES(3,4,NULL,7,8);
+ INSERT INTO nn VALUES(4,5,6,7,NULL);
+ SELECT count(*) FROM nn;
+} {4}
+do_catchsql_test without_rowid5-5.6 {
+ INSERT INTO nnw VALUES(NULL, 3,4,5,6);
+} {1 {NOT NULL constraint failed: nnw.a}}
+do_catchsql_test without_rowid5-5.7 {
+ INSERT INTO nnw VALUES(3,4,NULL,7,8)
+} {1 {NOT NULL constraint failed: nnw.c}}
+do_catchsql_test without_rowid5-5.8 {
+ INSERT INTO nnw VALUES(4,5,6,7,NULL)
+} {1 {NOT NULL constraint failed: nnw.e}}
+do_execsql_test without_rowid5-5.9 {
+ SELECT count(*) FROM nnw;
+} {1}
+
+# EVIDENCE-OF: R-12643-30541 The incremental blob I/O mechanism does not
+# work for WITHOUT ROWID tables.
+#
+# EVIDENCE-OF: R-25760-33257 The sqlite3_blob_open() interface will fail
+# for a WITHOUT ROWID table.
+#
+do_execsql_test without_rowid5-6.1 {
+ CREATE TABLE b1(a INTEGER PRIMARY KEY, b BLOB) WITHOUT ROWID;
+ INSERT INTO b1 VALUES(1,x'0102030405060708090a0b0c0d0e0f');
+} {}
+do_test without_rowid5-6.2 {
+ set rc [catch {db incrblob b1 b 1} msg]
+ lappend rc $msg
+} {1 {cannot open table without rowid: b1}}
+
+
+finish_test
diff --git a/lang/sql/sqlite/test/wordcount.c b/lang/sql/sqlite/test/wordcount.c
new file mode 100644
index 00000000..cf63e983
--- /dev/null
+++ b/lang/sql/sqlite/test/wordcount.c
@@ -0,0 +1,545 @@
+/*
+** This C program extracts all "words" from an input document and adds them
+** to an SQLite database. A "word" is any contiguous sequence of alphabetic
+** characters. All digits, punctuation, and whitespace characters are
+** word separators. The database stores a single entry for each distinct
+** word together with a count of the number of occurrences of that word.
+** A fresh database is created automatically on each run.
+**
+** wordcount DATABASE INPUTFILE
+**
+** The INPUTFILE name can be omitted, in which case input it taken from
+** standard input.
+**
+** Option:
+**
+** --without-rowid Use a WITHOUT ROWID table to store the words.
+** --insert Use INSERT mode (the default)
+** --replace Use REPLACE mode
+** --select Use SELECT mode
+** --update Use UPDATE mode
+** --delete Use DELETE mode
+** --query Use QUERY mode
+** --nocase Add the NOCASE collating sequence to the words.
+** --trace Enable sqlite3_trace() output.
+** --summary Show summary information on the collected data.
+** --stats Show sqlite3_status() results at the end.
+** --pagesize NNN Use a page size of NNN
+** --cachesize NNN Use a cache size of NNN
+** --commit NNN Commit after every NNN operations
+** --nosync Use PRAGMA synchronous=OFF
+** --journal MMMM Use PRAGMA journal_mode=MMMM
+** --timer Time the operation of this program
+**
+** Modes:
+**
+** Insert mode means:
+** (1) INSERT OR IGNORE INTO wordcount VALUES($new,1)
+** (2) UPDATE wordcount SET cnt=cnt+1 WHERE word=$new -- if (1) is a noop
+**
+** Update mode means:
+** (1) INSERT OR IGNORE INTO wordcount VALUES($new,0)
+** (2) UPDATE wordcount SET cnt=cnt+1 WHERE word=$new
+**
+** Replace mode means:
+** (1) REPLACE INTO wordcount
+** VALUES($new,ifnull((SELECT cnt FROM wordcount WHERE word=$new),0)+1);
+**
+** Select mode means:
+** (1) SELECT 1 FROM wordcount WHERE word=$new
+** (2) INSERT INTO wordcount VALUES($new,1) -- if (1) returns nothing
+** (3) UPDATE wordcount SET cnt=cnt+1 WHERE word=$new --if (1) return TRUE
+**
+** Delete mode means:
+** (1) DELETE FROM wordcount WHERE word=$new
+**
+** Query mode means:
+** (1) SELECT cnt FROM wordcount WHERE word=$new
+**
+** Note that delete mode and query mode are only useful for preexisting
+** databases. The wordcount table is created using IF NOT EXISTS so this
+** utility can be run multiple times on the same database file. The
+** --without-rowid, --nocase, and --pagesize parameters are only effective
+** when creating a new database and are harmless no-ops on preexisting
+** databases.
+**
+******************************************************************************
+**
+** Compile as follows:
+**
+** gcc -I. wordcount.c sqlite3.c -ldl -lpthreads
+**
+** Or:
+**
+** gcc -I. -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION \
+** wordcount.c sqlite3.c
+*/
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include "sqlite3.h"
+
+/* Return the current wall-clock time */
+static sqlite3_int64 realTime(void){
+ static sqlite3_vfs *clockVfs = 0;
+ sqlite3_int64 t;
+ if( clockVfs==0 ) clockVfs = sqlite3_vfs_find(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;
+}
+
+/* Print an error message and exit */
+static void fatal_error(const char *zMsg, ...){
+ va_list ap;
+ va_start(ap, zMsg);
+ vfprintf(stderr, zMsg, ap);
+ va_end(ap);
+ exit(1);
+}
+
+/* The sqlite3_trace() callback function */
+static void traceCallback(void *NotUsed, const char *zSql){
+ printf("%s;\n", zSql);
+}
+
+/* An sqlite3_exec() callback that prints results on standard output,
+** each column separated by a single space. */
+static int printResult(void *NotUsed, int nArg, char **azArg, char **azNm){
+ int i;
+ printf("--");
+ for(i=0; i<nArg; i++){
+ printf(" %s", azArg[i] ? azArg[i] : "(null)");
+ }
+ printf("\n");
+ return 0;
+}
+
+
+/*
+** Add one character to a hash
+*/
+static void addCharToHash(unsigned int *a, unsigned char x){
+ if( a[0]<4 ){
+ a[1] = (a[1]<<8) | x;
+ a[0]++;
+ }else{
+ a[2] = (a[2]<<8) | x;
+ a[0]++;
+ if( a[0]==8 ){
+ a[3] += a[1] + a[4];
+ a[4] += a[2] + a[3];
+ a[0] = a[1] = a[2] = 0;
+ }
+ }
+}
+
+/*
+** Compute the final hash value.
+*/
+static void finalHash(unsigned int *a, char *z){
+ a[3] += a[1] + a[4] + a[0];
+ a[4] += a[2] + a[3];
+ sqlite3_snprintf(17, z, "%08x%08x", a[3], a[4]);
+}
+
+
+/*
+** Implementation of a checksum() aggregate SQL function
+*/
+static void checksumStep(
+ sqlite3_context *context,
+ int argc,
+ sqlite3_value **argv
+){
+ const unsigned char *zVal;
+ int nVal, i, j;
+ unsigned int *a;
+ a = (unsigned*)sqlite3_aggregate_context(context, sizeof(unsigned int)*5);
+
+ if( a ){
+ for(i=0; i<argc; i++){
+ nVal = sqlite3_value_bytes(argv[i]);
+ zVal = (const unsigned char*)sqlite3_value_text(argv[i]);
+ if( zVal ) for(j=0; j<nVal; j++) addCharToHash(a, zVal[j]);
+ addCharToHash(a, '|');
+ }
+ addCharToHash(a, '\n');
+ }
+}
+static void checksumFinalize(sqlite3_context *context){
+ unsigned int *a;
+ char zResult[24];
+ a = sqlite3_aggregate_context(context, 0);
+ if( a ){
+ finalHash(a, zResult);
+ sqlite3_result_text(context, zResult, -1, SQLITE_TRANSIENT);
+ }
+}
+
+
+/* Define operating modes */
+#define MODE_INSERT 0
+#define MODE_REPLACE 1
+#define MODE_SELECT 2
+#define MODE_UPDATE 3
+#define MODE_DELETE 4
+#define MODE_QUERY 5
+
+int main(int argc, char **argv){
+ const char *zFileToRead = 0; /* Input file. NULL for stdin */
+ const char *zDbName = 0; /* Name of the database file to create */
+ int useWithoutRowid = 0; /* True for --without-rowid */
+ int iMode = MODE_INSERT; /* One of MODE_xxxxx */
+ int useNocase = 0; /* True for --nocase */
+ int doTrace = 0; /* True for --trace */
+ int showStats = 0; /* True for --stats */
+ int showSummary = 0; /* True for --summary */
+ int showTimer = 0; /* True for --timer */
+ int cacheSize = 0; /* Desired cache size. 0 means default */
+ int pageSize = 0; /* Desired page size. 0 means default */
+ int commitInterval = 0; /* How often to commit. 0 means never */
+ int noSync = 0; /* True for --nosync */
+ const char *zJMode = 0; /* Journal mode */
+ int nOp = 0; /* Operation counter */
+ int i, j; /* Loop counters */
+ sqlite3 *db; /* The SQLite database connection */
+ char *zSql; /* Constructed SQL statement */
+ sqlite3_stmt *pInsert = 0; /* The INSERT statement */
+ sqlite3_stmt *pUpdate = 0; /* The UPDATE statement */
+ sqlite3_stmt *pSelect = 0; /* The SELECT statement */
+ sqlite3_stmt *pDelete = 0; /* The DELETE statement */
+ FILE *in; /* The open input file */
+ int rc; /* Return code from an SQLite interface */
+ int iCur, iHiwtr; /* Statistics values, current and "highwater" */
+ sqlite3_int64 sumCnt = 0; /* Sum in QUERY mode */
+ sqlite3_int64 startTime;
+ char zInput[2000]; /* A single line of input */
+
+ /* Process command-line arguments */
+ for(i=1; i<argc; i++){
+ const char *z = argv[i];
+ if( z[0]=='-' ){
+ do{ z++; }while( z[0]=='-' );
+ if( strcmp(z,"without-rowid")==0 ){
+ useWithoutRowid = 1;
+ }else if( strcmp(z,"replace")==0 ){
+ iMode = MODE_REPLACE;
+ }else if( strcmp(z,"select")==0 ){
+ iMode = MODE_SELECT;
+ }else if( strcmp(z,"insert")==0 ){
+ iMode = MODE_INSERT;
+ }else if( strcmp(z,"update")==0 ){
+ iMode = MODE_UPDATE;
+ }else if( strcmp(z,"delete")==0 ){
+ iMode = MODE_DELETE;
+ }else if( strcmp(z,"query")==0 ){
+ iMode = MODE_QUERY;
+ }else if( strcmp(z,"nocase")==0 ){
+ useNocase = 1;
+ }else if( strcmp(z,"trace")==0 ){
+ doTrace = 1;
+ }else if( strcmp(z,"nosync")==0 ){
+ noSync = 1;
+ }else if( strcmp(z,"stats")==0 ){
+ showStats = 1;
+ }else if( strcmp(z,"summary")==0 ){
+ showSummary = 1;
+ }else if( strcmp(z,"timer")==0 ){
+ showTimer = i;
+ }else if( strcmp(z,"cachesize")==0 && i<argc-1 ){
+ i++;
+ cacheSize = atoi(argv[i]);
+ }else if( strcmp(z,"pagesize")==0 && i<argc-1 ){
+ i++;
+ pageSize = atoi(argv[i]);
+ }else if( strcmp(z,"commit")==0 && i<argc-1 ){
+ i++;
+ commitInterval = atoi(argv[i]);
+ }else if( strcmp(z,"journal")==0 && i<argc-1 ){
+ zJMode = argv[++i];
+ }else{
+ fatal_error("unknown option: %s\n", argv[i]);
+ }
+ }else if( zDbName==0 ){
+ zDbName = argv[i];
+ }else if( zFileToRead==0 ){
+ zFileToRead = argv[i];
+ }else{
+ fatal_error("surplus argument: %s\n", argv[i]);
+ }
+ }
+ if( zDbName==0 ){
+ fatal_error("Usage: %s [--options] DATABASE [INPUTFILE]\n", argv[0]);
+ }
+ startTime = realTime();
+
+ /* Open the database and the input file */
+ if( sqlite3_open(zDbName, &db) ){
+ fatal_error("Cannot open database file: %s\n", zDbName);
+ }
+ if( zFileToRead ){
+ in = fopen(zFileToRead, "rb");
+ if( in==0 ){
+ fatal_error("Could not open input file \"%s\"\n", zFileToRead);
+ }
+ }else{
+ in = stdin;
+ }
+
+ /* Set database connection options */
+ if( doTrace ) sqlite3_trace(db, traceCallback, 0);
+ if( pageSize ){
+ zSql = sqlite3_mprintf("PRAGMA page_size=%d", pageSize);
+ sqlite3_exec(db, zSql, 0, 0, 0);
+ sqlite3_free(zSql);
+ }
+ if( cacheSize ){
+ zSql = sqlite3_mprintf("PRAGMA cache_size=%d", cacheSize);
+ sqlite3_exec(db, zSql, 0, 0, 0);
+ sqlite3_free(zSql);
+ }
+ if( noSync ) sqlite3_exec(db, "PRAGMA synchronous=OFF", 0, 0, 0);
+ if( zJMode ){
+ zSql = sqlite3_mprintf("PRAGMA journal_mode=%s", zJMode);
+ sqlite3_exec(db, zSql, 0, 0, 0);
+ sqlite3_free(zSql);
+ }
+
+
+ /* Construct the "wordcount" table into which to put the words */
+ if( sqlite3_exec(db, "BEGIN IMMEDIATE", 0, 0, 0) ){
+ fatal_error("Could not start a transaction\n");
+ }
+ zSql = sqlite3_mprintf(
+ "CREATE TABLE IF NOT EXISTS wordcount(\n"
+ " word TEXT PRIMARY KEY COLLATE %s,\n"
+ " cnt INTEGER\n"
+ ")%s",
+ useNocase ? "nocase" : "binary",
+ useWithoutRowid ? " WITHOUT ROWID" : ""
+ );
+ if( zSql==0 ) fatal_error("out of memory\n");
+ rc = sqlite3_exec(db, zSql, 0, 0, 0);
+ if( rc ) fatal_error("Could not create the wordcount table: %s.\n",
+ sqlite3_errmsg(db));
+ sqlite3_free(zSql);
+
+ /* Prepare SQL statements that will be needed */
+ if( iMode==MODE_QUERY ){
+ rc = sqlite3_prepare_v2(db,
+ "SELECT cnt FROM wordcount WHERE word=?1",
+ -1, &pSelect, 0);
+ if( rc ) fatal_error("Could not prepare the SELECT statement: %s\n",
+ sqlite3_errmsg(db));
+ }
+ if( iMode==MODE_SELECT ){
+ rc = sqlite3_prepare_v2(db,
+ "SELECT 1 FROM wordcount WHERE word=?1",
+ -1, &pSelect, 0);
+ if( rc ) fatal_error("Could not prepare the SELECT statement: %s\n",
+ sqlite3_errmsg(db));
+ rc = sqlite3_prepare_v2(db,
+ "INSERT INTO wordcount(word,cnt) VALUES(?1,1)",
+ -1, &pInsert, 0);
+ if( rc ) fatal_error("Could not prepare the INSERT statement: %s\n",
+ sqlite3_errmsg(db));
+ }
+ if( iMode==MODE_SELECT || iMode==MODE_UPDATE || iMode==MODE_INSERT ){
+ rc = sqlite3_prepare_v2(db,
+ "UPDATE wordcount SET cnt=cnt+1 WHERE word=?1",
+ -1, &pUpdate, 0);
+ if( rc ) fatal_error("Could not prepare the UPDATE statement: %s\n",
+ sqlite3_errmsg(db));
+ }
+ if( iMode==MODE_INSERT ){
+ rc = sqlite3_prepare_v2(db,
+ "INSERT OR IGNORE INTO wordcount(word,cnt) VALUES(?1,1)",
+ -1, &pInsert, 0);
+ if( rc ) fatal_error("Could not prepare the INSERT statement: %s\n",
+ sqlite3_errmsg(db));
+ }
+ if( iMode==MODE_UPDATE ){
+ rc = sqlite3_prepare_v2(db,
+ "INSERT OR IGNORE INTO wordcount(word,cnt) VALUES(?1,0)",
+ -1, &pInsert, 0);
+ if( rc ) fatal_error("Could not prepare the INSERT statement: %s\n",
+ sqlite3_errmsg(db));
+ }
+ if( iMode==MODE_REPLACE ){
+ rc = sqlite3_prepare_v2(db,
+ "REPLACE INTO wordcount(word,cnt)"
+ "VALUES(?1,coalesce((SELECT cnt FROM wordcount WHERE word=?1),0)+1)",
+ -1, &pInsert, 0);
+ if( rc ) fatal_error("Could not prepare the REPLACE statement: %s\n",
+ sqlite3_errmsg(db));
+ }
+ if( iMode==MODE_DELETE ){
+ rc = sqlite3_prepare_v2(db,
+ "DELETE FROM wordcount WHERE word=?1",
+ -1, &pDelete, 0);
+ if( rc ) fatal_error("Could not prepare the DELETE statement: %s\n",
+ sqlite3_errmsg(db));
+ }
+
+ /* Process the input file */
+ while( fgets(zInput, sizeof(zInput), in) ){
+ for(i=0; zInput[i]; i++){
+ if( !isalpha(zInput[i]) ) continue;
+ for(j=i+1; isalpha(zInput[j]); j++){}
+
+ /* Found a new word at zInput[i] that is j-i bytes long.
+ ** Process it into the wordcount table. */
+ if( iMode==MODE_DELETE ){
+ sqlite3_bind_text(pDelete, 1, zInput+i, j-i, SQLITE_STATIC);
+ if( sqlite3_step(pDelete)!=SQLITE_DONE ){
+ fatal_error("DELETE failed: %s\n", sqlite3_errmsg(db));
+ }
+ sqlite3_reset(pDelete);
+ }else if( iMode==MODE_SELECT ){
+ sqlite3_bind_text(pSelect, 1, zInput+i, j-i, SQLITE_STATIC);
+ rc = sqlite3_step(pSelect);
+ sqlite3_reset(pSelect);
+ if( rc==SQLITE_ROW ){
+ sqlite3_bind_text(pUpdate, 1, zInput+i, j-i, SQLITE_STATIC);
+ if( sqlite3_step(pUpdate)!=SQLITE_DONE ){
+ fatal_error("UPDATE failed: %s\n", sqlite3_errmsg(db));
+ }
+ sqlite3_reset(pUpdate);
+ }else if( rc==SQLITE_DONE ){
+ sqlite3_bind_text(pInsert, 1, zInput+i, j-i, SQLITE_STATIC);
+ if( sqlite3_step(pInsert)!=SQLITE_DONE ){
+ fatal_error("Insert failed: %s\n", sqlite3_errmsg(db));
+ }
+ sqlite3_reset(pInsert);
+ }else{
+ fatal_error("SELECT failed: %s\n", sqlite3_errmsg(db));
+ }
+ }else if( iMode==MODE_QUERY ){
+ sqlite3_bind_text(pSelect, 1, zInput+i, j-i, SQLITE_STATIC);
+ if( sqlite3_step(pSelect)==SQLITE_ROW ){
+ sumCnt += sqlite3_column_int64(pSelect, 0);
+ }
+ sqlite3_reset(pSelect);
+ }else{
+ sqlite3_bind_text(pInsert, 1, zInput+i, j-i, SQLITE_STATIC);
+ if( sqlite3_step(pInsert)!=SQLITE_DONE ){
+ fatal_error("INSERT failed: %s\n", sqlite3_errmsg(db));
+ }
+ sqlite3_reset(pInsert);
+ if( iMode==MODE_UPDATE
+ || (iMode==MODE_INSERT && sqlite3_changes(db)==0)
+ ){
+ sqlite3_bind_text(pUpdate, 1, zInput+i, j-i, SQLITE_STATIC);
+ if( sqlite3_step(pUpdate)!=SQLITE_DONE ){
+ fatal_error("UPDATE failed: %s\n", sqlite3_errmsg(db));
+ }
+ sqlite3_reset(pUpdate);
+ }
+ }
+ i = j-1;
+
+ /* Increment the operation counter. Do a COMMIT if it is time. */
+ nOp++;
+ if( commitInterval>0 && (nOp%commitInterval)==0 ){
+ sqlite3_exec(db, "COMMIT; BEGIN IMMEDIATE", 0, 0, 0);
+ }
+ }
+ }
+ sqlite3_exec(db, "COMMIT", 0, 0, 0);
+ if( zFileToRead ) fclose(in);
+ sqlite3_finalize(pInsert);
+ sqlite3_finalize(pUpdate);
+ sqlite3_finalize(pSelect);
+ sqlite3_finalize(pDelete);
+
+ if( iMode==MODE_QUERY ){
+ printf("sum of cnt: %lld\n", sumCnt);
+ rc = sqlite3_prepare_v2(db,"SELECT sum(cnt*cnt) FROM wordcount", -1,
+ &pSelect, 0);
+ if( rc==SQLITE_OK && sqlite3_step(pSelect)==SQLITE_ROW ){
+ printf("double-check: %lld\n", sqlite3_column_int64(pSelect, 0));
+ }
+ sqlite3_finalize(pSelect);
+ }
+
+
+ if( showTimer ){
+ sqlite3_int64 elapseTime = realTime() - startTime;
+ fprintf(stderr, "%3d.%03d wordcount", (int)(elapseTime/1000),
+ (int)(elapseTime%1000));
+ for(i=1; i<argc; i++) if( i!=showTimer ) fprintf(stderr, " %s", argv[i]);
+ fprintf(stderr, "\n");
+ }
+
+ if( showSummary ){
+ sqlite3_create_function(db, "checksum", -1, SQLITE_UTF8, 0,
+ 0, checksumStep, checksumFinalize);
+ sqlite3_exec(db,
+ "SELECT 'count(*): ', count(*) FROM wordcount;\n"
+ "SELECT 'sum(cnt): ', sum(cnt) FROM wordcount;\n"
+ "SELECT 'max(cnt): ', max(cnt) FROM wordcount;\n"
+ "SELECT 'avg(cnt): ', avg(cnt) FROM wordcount;\n"
+ "SELECT 'sum(cnt=1):', sum(cnt=1) FROM wordcount;\n"
+ "SELECT 'top 10: ', group_concat(word, ', ') FROM "
+ "(SELECT word FROM wordcount ORDER BY cnt DESC, word LIMIT 10);\n"
+ "SELECT 'checksum: ', checksum(word, cnt) FROM "
+ "(SELECT word, cnt FROM wordcount ORDER BY word);\n"
+ "PRAGMA integrity_check;\n",
+ printResult, 0, 0);
+ }
+
+ /* Database connection statistics printed after both prepared statements
+ ** have been finalized */
+ if( showStats ){
+ sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_USED, &iCur, &iHiwtr, 0);
+ printf("-- Lookaside Slots Used: %d (max %d)\n", iCur,iHiwtr);
+ sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_HIT, &iCur, &iHiwtr, 0);
+ printf("-- Successful lookasides: %d\n", iHiwtr);
+ sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE, &iCur,&iHiwtr,0);
+ printf("-- Lookaside size faults: %d\n", iHiwtr);
+ sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL, &iCur,&iHiwtr,0);
+ printf("-- Lookaside OOM faults: %d\n", iHiwtr);
+ sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_USED, &iCur, &iHiwtr, 0);
+ printf("-- Pager Heap Usage: %d bytes\n", iCur);
+ sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_HIT, &iCur, &iHiwtr, 1);
+ printf("-- Page cache hits: %d\n", iCur);
+ sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_MISS, &iCur, &iHiwtr, 1);
+ printf("-- Page cache misses: %d\n", iCur);
+ sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_WRITE, &iCur, &iHiwtr, 1);
+ printf("-- Page cache writes: %d\n", iCur);
+ sqlite3_db_status(db, SQLITE_DBSTATUS_SCHEMA_USED, &iCur, &iHiwtr, 0);
+ printf("-- Schema Heap Usage: %d bytes\n", iCur);
+ sqlite3_db_status(db, SQLITE_DBSTATUS_STMT_USED, &iCur, &iHiwtr, 0);
+ printf("-- Statement Heap Usage: %d bytes\n", iCur);
+ }
+
+ sqlite3_close(db);
+
+ /* Global memory usage statistics printed after the database connection
+ ** has closed. Memory usage should be zero at this point. */
+ if( showStats ){
+ sqlite3_status(SQLITE_STATUS_MEMORY_USED, &iCur, &iHiwtr, 0);
+ printf("-- Memory Used (bytes): %d (max %d)\n", iCur,iHiwtr);
+ sqlite3_status(SQLITE_STATUS_MALLOC_COUNT, &iCur, &iHiwtr, 0);
+ printf("-- Outstanding Allocations: %d (max %d)\n", iCur,iHiwtr);
+ sqlite3_status(SQLITE_STATUS_PAGECACHE_OVERFLOW, &iCur, &iHiwtr, 0);
+ printf("-- Pcache Overflow Bytes: %d (max %d)\n", iCur,iHiwtr);
+ sqlite3_status(SQLITE_STATUS_SCRATCH_OVERFLOW, &iCur, &iHiwtr, 0);
+ printf("-- Scratch Overflow Bytes: %d (max %d)\n", iCur,iHiwtr);
+ sqlite3_status(SQLITE_STATUS_MALLOC_SIZE, &iCur, &iHiwtr, 0);
+ printf("-- Largest Allocation: %d bytes\n",iHiwtr);
+ sqlite3_status(SQLITE_STATUS_PAGECACHE_SIZE, &iCur, &iHiwtr, 0);
+ printf("-- Largest Pcache Allocation: %d bytes\n",iHiwtr);
+ sqlite3_status(SQLITE_STATUS_SCRATCH_SIZE, &iCur, &iHiwtr, 0);
+ printf("-- Largest Scratch Allocation: %d bytes\n", iHiwtr);
+ }
+ return 0;
+}
diff --git a/lang/sql/sqlite/test/zerodamage.test b/lang/sql/sqlite/test/zerodamage.test
new file mode 100644
index 00000000..de5088b5
--- /dev/null
+++ b/lang/sql/sqlite/test/zerodamage.test
@@ -0,0 +1,121 @@
+# 2011 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 tests of the SQLITE_IOCAP_POWERSAFE_OVERWRITE property
+# and the SQLITE_FCNTL_POWERSAFE_OVERWRITE file-control for manipulating it.
+#
+# The name of this file comes from the fact that we used to call the
+# POWERSAFE_OVERWRITE property ZERO_DAMAGE.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix zerodamage
+
+ifcapable !vtab {
+ finish_test
+ return
+}
+
+# POWERSAFE_OVERWRITE defaults to true
+#
+do_test zerodamage-1.0 {
+ file_control_powersafe_overwrite db -1
+} {0 1}
+
+# Check the ability to turn zero-damage on and off.
+#
+do_test zerodamage-1.1 {
+ file_control_powersafe_overwrite db 0
+ file_control_powersafe_overwrite db -1
+} {0 0}
+do_test zerodamage-1.2 {
+ file_control_powersafe_overwrite db 1
+ file_control_powersafe_overwrite db -1
+} {0 1}
+
+# Run a transaction with zero-damage on, a small page size and a much larger
+# sectorsize. Verify that the maximum journal size is small - that the
+# rollback journal is not being padded.
+#
+do_test zerodamage-2.0 {
+ db close
+ testvfs tv -default 1
+ tv sectorsize 8192
+ sqlite3 db file:test.db?psow=TRUE -uri 1
+ unset -nocomplain ::max_journal_size
+ set ::max_journal_size 0
+ proc xDeleteCallback {method file args} {
+ set sz [file size $file]
+ if {$sz>$::max_journal_size} {set ::max_journal_size $sz}
+ }
+ tv filter xDelete
+ tv script xDeleteCallback
+ load_static_extension db wholenumber
+ db eval {
+ PRAGMA page_size=1024;
+ PRAGMA journal_mode=DELETE;
+ PRAGMA cache_size=5;
+ CREATE VIRTUAL TABLE nums USING wholenumber;
+ CREATE TABLE t1(x, y);
+ INSERT INTO t1 SELECT value, randomblob(100) FROM nums
+ WHERE value BETWEEN 1 AND 400;
+ }
+ set ::max_journal_size 0
+ db eval {
+ UPDATE t1 SET y=randomblob(50) WHERE x=123;
+ }
+ concat [file_control_powersafe_overwrite db -1] [set ::max_journal_size]
+} {0 1 2576}
+
+# Repeat the previous step with zero-damage turned off. This time the
+# maximum rollback journal size should be much larger.
+#
+do_test zerodamage-2.1 {
+ set ::max_journal_size 0
+ db close
+ sqlite3 db file:test.db?psow=FALSE -uri 1
+ db eval {
+ UPDATE t1 SET y=randomblob(50) WHERE x=124;
+ }
+ concat [file_control_powersafe_overwrite db -1] [set ::max_journal_size]
+} {0 0 24704}
+
+ifcapable wal {
+ # Run a WAL-mode transaction with POWERSAFE_OVERWRITE on to verify that the
+ # WAL file does not get too big.
+ #
+ do_test zerodamage-3.0 {
+ db eval {
+ PRAGMA journal_mode=WAL;
+ }
+ db close
+ sqlite3 db file:test.db?psow=TRUE -uri 1
+ db eval {
+ UPDATE t1 SET y=randomblob(50) WHERE x=124;
+ }
+ file size test.db-wal
+ } {1080}
+
+ # Repeat the previous with POWERSAFE_OVERWRITE off. Verify that the WAL file
+ # is padded.
+ #
+ do_test zerodamage-3.1 {
+ db close
+ sqlite3 db file:test.db?psow=FALSE -uri 1
+ db eval {
+ UPDATE t1 SET y=randomblob(50) WHERE x=124;
+ }
+ file size test.db-wal
+ } {8416}
+}
+
+finish_test