1
0

vtabA.test 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. # 2007 June 26
  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 'hidden' virtual table columns.
  13. #
  14. # $Id: vtabA.test,v 1.2 2008/07/12 14:52:21 drh Exp $
  15. set testdir [file dirname $argv0]
  16. source $testdir/tester.tcl
  17. ifcapable !vtab {
  18. finish_test
  19. return
  20. }
  21. proc get_decltype {table col} {
  22. set STMT [sqlite3_prepare $::DB "SELECT $col FROM $table" -1 TAIL]
  23. set decltype [sqlite3_column_decltype $STMT 0]
  24. sqlite3_finalize $STMT
  25. set decltype
  26. }
  27. proc get_collist {table} {
  28. set ret [list]
  29. db eval "PRAGMA table_info($table)" { lappend ret $name }
  30. set ret
  31. }
  32. # Register the echo module
  33. register_echo_module [sqlite3_connection_pointer db]
  34. # Create a virtual table with a 'hidden' column (column b).
  35. #
  36. do_test vtabA-1.1 {
  37. execsql { CREATE TABLE t1(a, b HIDDEN VARCHAR, c INTEGER) }
  38. } {}
  39. do_test vtabA-1.2 {
  40. execsql { CREATE VIRTUAL TABLE t1e USING echo(t1) }
  41. } {}
  42. # Test that the hidden column is not listed by [PRAGMA table_info].
  43. #
  44. do_test vtabA-1.3 {
  45. execsql { PRAGMA table_info(t1e) }
  46. } [list \
  47. 0 a {} 0 {} 0 \
  48. 1 c INTEGER 0 {} 0 \
  49. ]
  50. # Test that the hidden column is not require in the default column
  51. # list for an INSERT statement.
  52. #
  53. do_test vtabA-1.4 {
  54. catchsql {
  55. INSERT INTO t1e VALUES('value a', 'value c');
  56. }
  57. } {0 {}}
  58. do_test vtabA-1.5 {
  59. execsql {
  60. SELECT a, b, c FROM t1e;
  61. }
  62. } {{value a} {} {value c}}
  63. do_test vtabA-1.6 {
  64. execsql {
  65. SELECT * FROM t1e;
  66. }
  67. } {{value a} {value c}}
  68. # Test that the expansion of a '*' expression in the result set of
  69. # a SELECT does not include the hidden column.
  70. #
  71. do_test vtabA-1.7 {
  72. execsql {
  73. INSERT INTO t1e SELECT * FROM t1e;
  74. }
  75. } {}
  76. do_test vtabA-1.8 {
  77. execsql {
  78. SELECT * FROM t1e;
  79. }
  80. } {{value a} {value c} {value a} {value c}}
  81. # Test that the declaration type of the hidden column does not include
  82. # the token "HIDDEN".
  83. #
  84. do_test vtabA-1.9 {
  85. get_decltype t1e b
  86. } {VARCHAR}
  87. do_test vtabA-1.10 {
  88. get_collist t1e
  89. } {a c}
  90. #----------------------------------------------------------------------
  91. # These tests vtabA-2.* concentrate on testing that the HIDDEN token
  92. # is detected and handled correctly in various declarations.
  93. #
  94. proc analyse_parse {columns decltype_list} {
  95. db eval { DROP TABLE IF EXISTS t1e; }
  96. db eval { DROP TABLE IF EXISTS t1; }
  97. db eval " CREATE TABLE t1 $columns "
  98. db eval { CREATE VIRTUAL TABLE t1e USING echo(t1) }
  99. set ret [list [get_collist t1e]]
  100. foreach c $decltype_list {
  101. lappend ret [get_decltype t1e $c]
  102. }
  103. set ret
  104. }
  105. do_test vtabA-2.1 {
  106. analyse_parse {(a text, b integer hidden, c hidden)} {a b c}
  107. } {a text integer {}}
  108. do_test vtabA-2.2 {
  109. analyse_parse {(a hidden , b integerhidden, c hidden1)} {a b c}
  110. } {{b c} {} integerhidden hidden1}
  111. do_test vtabA-2.3 {
  112. analyse_parse {(a HiDden, b HIDDEN, c hidden)} {a b c}
  113. } {{} {} {} {}}
  114. do_test vtabA-2.4 {
  115. analyse_parse {(a whatelse can i hidden test, b HIDDEN hidden)} {a b}
  116. } {{} {whatelse can i test} hidden}
  117. # Ticket [d2f02d37f52bfe23e421f2c60fbb8586ac76ff01]:
  118. # assertion failure on an UPDATE involving two virtual tables.
  119. #
  120. do_test vtabA-3.1 {
  121. db eval {
  122. DROP TABLE IF EXISTS t1;
  123. DROP TABLE IF EXISTS t2;
  124. CREATE TABLE t1(a,b);
  125. INSERT INTO t1 VALUES(1,2);
  126. CREATE TABLE t2(x,y);
  127. INSERT INTO t2 VALUES(3,4);
  128. CREATE VIRTUAL TABLE vt1 USING echo(t1);
  129. CREATE VIRTUAL TABLE vt2 USING echo(t2);
  130. UPDATE vt2 SET x=(SELECT a FROM vt1 WHERE b=2) WHERE y=4;
  131. SELECT * FROM t2;
  132. }
  133. } {1 4}
  134. finish_test