CoolFace
Modelpublic

AryaWu/sqlite

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
make-where7.tcl121 linesDownload Raw Back to test
1#!/usr/bin/tclsh2#3# Run this script to generate randomized test cases for the where7.test4# script.  The output will need to be manually copied and pasted into5# the where7.test script.6#7puts "do_test where7-2.1 \173"8puts "  db eval \173"9puts "    CREATE TABLE t2(a INTEGER PRIMARY KEY,b,c,d,e,f,g);"10set NA 10011for {set a 1} {$a<=$NA} {incr a} {12  set b [expr {$a*11}]13  set div3 [expr {int(($a+2)/3)}]14  set c [expr {$div3*1001}]15  set d [expr {$a*1.001}]16  set e [expr {$div3*100.1}]17  set x [expr {$a%26}]18  set f [string range {abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz} \19           $x [expr {$x+8}]]20  set div5 [expr {int(($a+7)/5)}]21  set x [expr {$div5%26}]22  set g [string range {zyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcba} \23           $x [expr {$x+6}]]24  puts "    INSERT INTO t2 VALUES($a,$b,$c,$d,$e,'$f','$g');"25  lappend fidx($f) $a26  lappend gidx($g) $a27  set gof($a) $g28  set fof($a) $f29 30  set expr "a=$a"31  set term($expr) $a32  set expr "((a BETWEEN [expr {$a-1}] AND [expr {$a+1}]) AND a!=$a)"33  set x {}34  if {$a>1} {set x [expr {$a-1}]}35  if {$a<$NA} {lappend x [expr {$a+1}]}36  set term($expr) $x37  set expr "b=$b"38  set term($expr) $a39  set expr "b=[expr {$a*11+3}]"40  set term($expr) {}41  set expr "c=$c"42  lappend term($expr) $a43  set expr "(d>=$a.0 AND d<[expr {$a+1.0}] AND d NOT NULL)"44  lappend term($expr) $a45  set expr "f='$f'"46  lappend term($expr) $a47  set expr \48     "(f GLOB '?[string range $f 1 4]*' AND f GLOB '[string range $f 0 3]*')"49  lappend term($expr) $a50  set expr "(g='$g' AND f GLOB '[string range $f 0 4]*')"51  lappend term($expr) $a52}53puts "    CREATE INDEX t2b ON t2(b);"54puts "    CREATE INDEX t2c ON t2(c);"55puts "    CREATE INDEX t2d ON t2(d);"56puts "    CREATE INDEX t2e ON t2(e);"57puts "    CREATE INDEX t2f ON t2(f);"58puts "    CREATE INDEX t2g ON t2(g);"59puts "    CREATE TABLE t3(a INTEGER PRIMARY KEY,b,c,d,e,f,g);"60puts "    INSERT INTO t3 SELECT * FROM t2;"61puts "    CREATE INDEX t3b ON t3(b,c);"62puts "    CREATE INDEX t3c ON t3(c,e);"63puts "    CREATE INDEX t3d ON t3(d,g);"64puts "    CREATE INDEX t3e ON t3(e,f,g);"65puts "    CREATE INDEX t3f ON t3(f,b,d,c);"66puts "    CREATE INDEX t3g ON t3(g,f);"67 68puts "  \175"69puts "\175 {}"70 71set term(b<0) {}72set term(1000000<b) {}73set term(c<=10) {}74set term(c>=[expr {int(($NA+2)/3)*1001+1}]) {}75set term(d<0.0) {}76set term(d>1e10) {}77set expr {e IS NULL}78set term($expr) {}79set expr {f IS NULL}80set term($expr) {}81set expr {g IS NULL}82set term($expr) {}83 84set NT 100085set termlist [array names term]86set nterm [llength $termlist]87for {set i 2} {$i<=$NT+1} {incr i} {88  set n [expr {int(rand()*10)+2}]89  set w {}90  unset -nocomplain r91  for {set j 0} {$j<$n} {incr j} {92    set k [expr {int(rand()*$nterm)}]93    set t [lindex $termlist $k]94    lappend w $t95    foreach a $term($t) {96      set r($a) 197    }98  }99  if {[info exists seen($w)]} {100    incr i -1101    continue102  }103  set seen($w) 1104  set result [lsort -int [array names r]]105  puts "do_test where7-2.$i.1 \173"106  puts "  count_steps_sort \173"107  puts "     SELECT a FROM t2"108  set wc [join $w "\n         OR "]109  puts "      WHERE $wc"110  puts "  \175"111  puts "\175 {$result scan 0 sort 0}"112  puts "do_test where7-2.$i.2 \173"113  puts "  count_steps_sort \173"114  puts "     SELECT a FROM t3"115  set wc [join $w "\n         OR "]116  puts "      WHERE $wc"117  puts "  \175"118  puts "\175 {$result scan 0 sort 0}"119}120puts "finish_test"121