vtab5.test 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. # 2006 June 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.
  12. #
  13. # $Id: vtab5.test,v 1.8 2008/07/12 14:52:21 drh Exp $
  14. set testdir [file dirname $argv0]
  15. source $testdir/tester.tcl
  16. ifcapable !vtab {
  17. finish_test
  18. return
  19. }
  20. # The following tests - vtab5-1.* - ensure that an INSERT, DELETE or UPDATE
  21. # statement can be executed immediately after a CREATE or schema reload. The
  22. # point here is testing that the parser always calls xConnect() before the
  23. # schema of a virtual table is used.
  24. #
  25. register_echo_module [sqlite3_connection_pointer db]
  26. do_test vtab5-1.1 {
  27. execsql {
  28. CREATE TABLE treal(a VARCHAR(16), b INTEGER, c FLOAT);
  29. INSERT INTO treal VALUES('a', 'b', 'c');
  30. CREATE VIRTUAL TABLE techo USING echo(treal);
  31. }
  32. } {}
  33. do_test vtab5.1.2 {
  34. execsql {
  35. SELECT * FROM techo;
  36. }
  37. } {a b c}
  38. do_test vtab5.1.3 {
  39. db close
  40. sqlite3 db test.db
  41. register_echo_module [sqlite3_connection_pointer db]
  42. execsql {
  43. INSERT INTO techo VALUES('c', 'd', 'e');
  44. SELECT * FROM techo;
  45. }
  46. } {a b c c d e}
  47. do_test vtab5.1.4 {
  48. db close
  49. sqlite3 db test.db
  50. register_echo_module [sqlite3_connection_pointer db]
  51. execsql {
  52. UPDATE techo SET a = 10;
  53. SELECT * FROM techo;
  54. }
  55. } {10 b c 10 d e}
  56. do_test vtab5.1.5 {
  57. db close
  58. sqlite3 db test.db
  59. register_echo_module [sqlite3_connection_pointer db]
  60. execsql {
  61. DELETE FROM techo WHERE b > 'c';
  62. SELECT * FROM techo;
  63. }
  64. } {10 b c}
  65. do_test vtab5.1.X {
  66. execsql {
  67. DROP TABLE techo;
  68. DROP TABLE treal;
  69. }
  70. } {}
  71. # The following tests - vtab5-2.* - ensure that collation sequences
  72. # assigned to virtual table columns via the "CREATE TABLE" statement
  73. # passed to sqlite3_declare_vtab() are used correctly.
  74. #
  75. do_test vtab5.2.1 {
  76. execsql {
  77. CREATE TABLE strings(str COLLATE NOCASE);
  78. INSERT INTO strings VALUES('abc1');
  79. INSERT INTO strings VALUES('Abc3');
  80. INSERT INTO strings VALUES('ABc2');
  81. INSERT INTO strings VALUES('aBc4');
  82. SELECT str FROM strings ORDER BY 1;
  83. }
  84. } {abc1 ABc2 Abc3 aBc4}
  85. do_test vtab5.2.2 {
  86. execsql {
  87. CREATE VIRTUAL TABLE echo_strings USING echo(strings);
  88. SELECT str FROM echo_strings ORDER BY 1;
  89. }
  90. } {abc1 ABc2 Abc3 aBc4}
  91. do_test vtab5.2.3 {
  92. execsql {
  93. SELECT str||'' FROM echo_strings ORDER BY 1;
  94. }
  95. } {ABc2 Abc3 aBc4 abc1}
  96. # Test that it is impossible to create a triggger on a virtual table.
  97. #
  98. ifcapable trigger {
  99. do_test vtab5.3.1 {
  100. catchsql {
  101. CREATE TRIGGER trig INSTEAD OF INSERT ON echo_strings BEGIN
  102. SELECT 1, 2, 3;
  103. END;
  104. }
  105. } {1 {cannot create triggers on virtual tables}}
  106. do_test vtab5.3.2 {
  107. catchsql {
  108. CREATE TRIGGER trig AFTER INSERT ON echo_strings BEGIN
  109. SELECT 1, 2, 3;
  110. END;
  111. }
  112. } {1 {cannot create triggers on virtual tables}}
  113. do_test vtab5.3.2 {
  114. catchsql {
  115. CREATE TRIGGER trig BEFORE INSERT ON echo_strings BEGIN
  116. SELECT 1, 2, 3;
  117. END;
  118. }
  119. } {1 {cannot create triggers on virtual tables}}
  120. }
  121. # Test that it is impossible to create an index on a virtual table.
  122. #
  123. do_test vtab5.4.1 {
  124. catchsql {
  125. CREATE INDEX echo_strings_i ON echo_strings(str);
  126. }
  127. } {1 {virtual tables may not be indexed}}
  128. # Test that it is impossible to add a column to a virtual table.
  129. #
  130. ifcapable altertable {
  131. do_test vtab5.4.2 {
  132. catchsql {
  133. ALTER TABLE echo_strings ADD COLUMN col2;
  134. }
  135. } {1 {virtual tables may not be altered}}
  136. }
  137. # Test that it is impossible to rename a virtual table.
  138. # UPDATE: It is now possible.
  139. #
  140. # do_test vtab5.4.3 {
  141. # catchsql {
  142. # ALTER TABLE echo_strings RENAME TO echo_strings2;
  143. # }
  144. # } {1 {virtual tables may not be altered}}
  145. finish_test