os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/vtabC.test
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/vtabC.test	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,114 @@
     1.4 +# 2008 April 10
     1.5 +#
     1.6 +# The author disclaims copyright to this source code.  In place of
     1.7 +# a legal notice, here is a blessing:
     1.8 +#
     1.9 +#    May you do good and not evil.
    1.10 +#    May you find forgiveness for yourself and forgive others.
    1.11 +#    May you share freely, never taking more than you give.
    1.12 +#
    1.13 +#***********************************************************************
    1.14 +# This file implements regression tests for SQLite library.  The
    1.15 +# focus of this file is is verifying that the xUpdate, xSync, xCommit
    1.16 +# and xRollback methods are only invoked after an xBegin or xCreate.
    1.17 +# Ticket #3083.
    1.18 +#
    1.19 +# $Id: vtabC.test,v 1.1 2008/04/28 20:27:54 drh Exp $
    1.20 +
    1.21 +set testdir [file dirname $argv0]
    1.22 +source $testdir/tester.tcl
    1.23 +
    1.24 +ifcapable !vtab {
    1.25 +  finish_test
    1.26 +  return
    1.27 +}
    1.28 +
    1.29 +
    1.30 +# N will be the number of virtual tables we have defined.
    1.31 +#
    1.32 +unset -nocomplain N
    1.33 +for {set N 1} {$N<=20} {incr N} {
    1.34 +  db close
    1.35 +  file delete -force test.db test.db-journal
    1.36 +  sqlite3 db test.db
    1.37 +  register_echo_module [sqlite3_connection_pointer db]
    1.38 +
    1.39 +  # Create $N tables and $N virtual tables to echo them.
    1.40 +  #
    1.41 +  unset -nocomplain tablist
    1.42 +  set tablist {}
    1.43 +  do_test vtabC-1.$N.1 {
    1.44 +    for {set i 1} {$i<=$::N} {incr i} {
    1.45 +      execsql "CREATE TABLE t${i}(x)"
    1.46 +      execsql "CREATE VIRTUAL TABLE vt$i USING echo(t$i)"
    1.47 +      lappend ::tablist t$i vt$i
    1.48 +    }
    1.49 +    execsql {SELECT count(*) FROM sqlite_master}
    1.50 +  } [expr {$N*2}]
    1.51 +  do_test vtabC-1.$N.2 {
    1.52 +    execsql {SELECT name FROM sqlite_master}
    1.53 +  } $tablist
    1.54 +
    1.55 +  # Create a table m and add triggers to make changes on all
    1.56 +  # of the virtual tables when m is changed.
    1.57 +  #
    1.58 +  do_test vtabC-1.$N.3 {
    1.59 +    execsql {CREATE TABLE m(a)}
    1.60 +    set sql "CREATE TRIGGER rins AFTER INSERT ON m BEGIN\n"
    1.61 +    for {set i 1} {$i<=$::N} {incr i} {
    1.62 +      append sql "  INSERT INTO vt$i VALUES(NEW.a+$i);\n"
    1.63 +    }
    1.64 +    append sql "END;"
    1.65 +    execsql $sql
    1.66 +    execsql {SELECT count(*) FROM sqlite_master}
    1.67 +  } [expr {$N*2+2}]
    1.68 +  do_test vtabC-1.$N.4 {
    1.69 +    execsql {
    1.70 +      INSERT INTO m VALUES(1000);
    1.71 +      SELECT * FROM m;
    1.72 +    }
    1.73 +  } {1000}
    1.74 +  for {set j 1} {$j<=$::N} {incr j} {
    1.75 +    do_test vtabC-1.$N.5.$j {
    1.76 +      execsql "SELECT * FROM t$::j"
    1.77 +    } [expr {$j+1000}]
    1.78 +    do_test vtabC-1.$N.6.$j {
    1.79 +      execsql "SELECT * FROM vt$::j"
    1.80 +    } [expr {$j+1000}]
    1.81 +  }
    1.82 +  do_test vtabC-1.$N.7 {
    1.83 +    set sql "CREATE TRIGGER rins2 BEFORE INSERT ON m BEGIN\n"
    1.84 +    for {set i 1} {$i<=$::N} {incr i} {
    1.85 +      append sql "  INSERT INTO vt$i VALUES(NEW.a+$i*100);\n"
    1.86 +    }
    1.87 +    for {set i 1} {$i<=$::N} {incr i} {
    1.88 +      append sql "  INSERT INTO vt$i VALUES(NEW.a+$i*10000);\n"
    1.89 +    }
    1.90 +    append sql "END;"
    1.91 +    execsql $sql
    1.92 +    execsql {SELECT count(*) FROM sqlite_master}
    1.93 +  } [expr {$N*2+3}]
    1.94 +  do_test vtabC-1.$N.8 {
    1.95 +    execsql {
    1.96 +      INSERT INTO m VALUES(9000000);
    1.97 +      SELECT * FROM m;
    1.98 +    }
    1.99 +  } {1000 9000000}
   1.100 +  unset -nocomplain res
   1.101 +  for {set j 1} {$j<=$::N} {incr j} {
   1.102 +    set res [expr {$j+1000}]
   1.103 +    lappend res [expr {$j*100+9000000}]
   1.104 +    lappend res [expr {$j*10000+9000000}]
   1.105 +    lappend res [expr {$j+9000000}]
   1.106 +    do_test vtabC-1.$N.9.$j {
   1.107 +      execsql "SELECT * FROM t$::j"
   1.108 +    } $res
   1.109 +    do_test vtabC-1.$N.10.$j {
   1.110 +      execsql "SELECT * FROM vt$::j"
   1.111 +    } $res
   1.112 +  }
   1.113 +}
   1.114 +unset -nocomplain res N i j
   1.115 +
   1.116 +
   1.117 +finish_test