vtabC.test 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. # 2008 April 10
  2. #
  3. # The author disclaims copyright to this source code. In place of
  4. # a legal notice, here is a blessing:
  5. #
  6. # May you do good and not evil.
  7. # May you find forgiveness for yourself and forgive others.
  8. # May you share freely, never taking more than you give.
  9. #
  10. #***********************************************************************
  11. # This file implements regression tests for SQLite library. The
  12. # focus of this file is is verifying that the xUpdate, xSync, xCommit
  13. # and xRollback methods are only invoked after an xBegin or xCreate.
  14. # Ticket #3083.
  15. #
  16. # $Id: vtabC.test,v 1.2 2009/04/07 14:14:23 danielk1977 Exp $
  17. set testdir [file dirname $argv0]
  18. source $testdir/tester.tcl
  19. ifcapable !vtab {
  20. finish_test
  21. return
  22. }
  23. ifcapable !trigger { finish_test ; return }
  24. # N will be the number of virtual tables we have defined.
  25. #
  26. unset -nocomplain N
  27. for {set N 1} {$N<=20} {incr N} {
  28. db close
  29. forcedelete test.db test.db-journal
  30. sqlite3 db test.db
  31. register_echo_module [sqlite3_connection_pointer db]
  32. # Create $N tables and $N virtual tables to echo them.
  33. #
  34. unset -nocomplain tablist
  35. set tablist {}
  36. do_test vtabC-1.$N.1 {
  37. for {set i 1} {$i<=$::N} {incr i} {
  38. execsql "CREATE TABLE t${i}(x)"
  39. execsql "CREATE VIRTUAL TABLE vt$i USING echo(t$i)"
  40. lappend ::tablist t$i vt$i
  41. }
  42. execsql {SELECT count(*) FROM sqlite_master}
  43. } [expr {$N*2}]
  44. do_test vtabC-1.$N.2 {
  45. execsql {SELECT name FROM sqlite_master}
  46. } $tablist
  47. # Create a table m and add triggers to make changes on all
  48. # of the virtual tables when m is changed.
  49. #
  50. do_test vtabC-1.$N.3 {
  51. execsql {CREATE TABLE m(a)}
  52. set sql "CREATE TRIGGER rins AFTER INSERT ON m BEGIN\n"
  53. for {set i 1} {$i<=$::N} {incr i} {
  54. append sql " INSERT INTO vt$i VALUES(NEW.a+$i);\n"
  55. }
  56. append sql "END;"
  57. execsql $sql
  58. execsql {SELECT count(*) FROM sqlite_master}
  59. } [expr {$N*2+2}]
  60. do_test vtabC-1.$N.4 {
  61. execsql {
  62. INSERT INTO m VALUES(1000);
  63. SELECT * FROM m;
  64. }
  65. } {1000}
  66. for {set j 1} {$j<=$::N} {incr j} {
  67. do_test vtabC-1.$N.5.$j {
  68. execsql "SELECT * FROM t$::j"
  69. } [expr {$j+1000}]
  70. do_test vtabC-1.$N.6.$j {
  71. execsql "SELECT * FROM vt$::j"
  72. } [expr {$j+1000}]
  73. }
  74. do_test vtabC-1.$N.7 {
  75. set sql "CREATE TRIGGER rins2 BEFORE INSERT ON m BEGIN\n"
  76. for {set i 1} {$i<=$::N} {incr i} {
  77. append sql " INSERT INTO vt$i VALUES(NEW.a+$i*100);\n"
  78. }
  79. for {set i 1} {$i<=$::N} {incr i} {
  80. append sql " INSERT INTO vt$i VALUES(NEW.a+$i*10000);\n"
  81. }
  82. append sql "END;"
  83. execsql $sql
  84. execsql {SELECT count(*) FROM sqlite_master}
  85. } [expr {$N*2+3}]
  86. do_test vtabC-1.$N.8 {
  87. execsql {
  88. INSERT INTO m VALUES(9000000);
  89. SELECT * FROM m;
  90. }
  91. } {1000 9000000}
  92. unset -nocomplain res
  93. for {set j 1} {$j<=$::N} {incr j} {
  94. set res [expr {$j+1000}]
  95. lappend res [expr {$j*100+9000000}]
  96. lappend res [expr {$j*10000+9000000}]
  97. lappend res [expr {$j+9000000}]
  98. do_test vtabC-1.$N.9.$j {
  99. execsql "SELECT * FROM t$::j"
  100. } $res
  101. do_test vtabC-1.$N.10.$j {
  102. execsql "SELECT * FROM vt$::j"
  103. } $res
  104. }
  105. }
  106. unset -nocomplain res N i j
  107. finish_test