main.test 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. # 2001 September 15
  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 exercising the code in main.c.
  13. #
  14. # $Id: main.test,v 1.11 2002/05/15 14:17:45 drh Exp $
  15. set testdir [file dirname $argv0]
  16. source $testdir/tester.tcl
  17. # Tests of the sqlite_complete() function.
  18. #
  19. do_test main-1.1 {
  20. db complete {This is a test}
  21. } {0}
  22. do_test main-1.2 {
  23. db complete {
  24. }
  25. } {0}
  26. do_test main-1.3 {
  27. db complete {
  28. -- a comment ;
  29. }
  30. } {0}
  31. do_test main-1.4 {
  32. db complete {
  33. -- a comment ;
  34. ;
  35. }
  36. } {1}
  37. do_test main-1.5 {
  38. db complete {DROP TABLE 'xyz;}
  39. } {0}
  40. do_test main-1.6 {
  41. db complete {DROP TABLE 'xyz';}
  42. } {1}
  43. do_test main-1.7 {
  44. db complete {DROP TABLE "xyz;}
  45. } {0}
  46. do_test main-1.8 {
  47. db complete {DROP TABLE "xyz';}
  48. } {0}
  49. do_test main-1.9 {
  50. db complete {DROP TABLE "xyz";}
  51. } {1}
  52. do_test main-1.10 {
  53. db complete {DROP TABLE xyz; hi}
  54. } {0}
  55. do_test main-1.11 {
  56. db complete {DROP TABLE xyz; }
  57. } {1}
  58. do_test main-1.12 {
  59. db complete {DROP TABLE xyz; -- hi }
  60. } {1}
  61. do_test main-1.13 {
  62. db complete {DROP TABLE xyz; -- hi
  63. }
  64. } {1}
  65. do_test main-1.14 {
  66. db complete {SELECT a-b FROM t1; }
  67. } {1}
  68. do_test main-1.15 {
  69. db complete {SELECT a-b FROM t1 }
  70. } {0}
  71. do_test main-1.16 {
  72. db complete {
  73. CREATE TABLE abc(x,y);
  74. }
  75. } {1}
  76. do_test main-1.17 {
  77. db complete {
  78. CREATE TRIGGER xyz AFTER DELETE abc BEGIN UPDATE pqr;
  79. }
  80. } {0}
  81. do_test main-1.18 {
  82. db complete {
  83. CREATE TRIGGER xyz AFTER DELETE abc BEGIN UPDATE pqr; END;
  84. }
  85. } {1}
  86. do_test main-1.19 {
  87. db complete {
  88. CREATE TRIGGER xyz AFTER DELETE abc BEGIN
  89. UPDATE pqr;
  90. unknown command;
  91. }
  92. } {0}
  93. do_test main-1.20 {
  94. db complete {
  95. CREATE TRIGGER xyz AFTER DELETE backend BEGIN
  96. UPDATE pqr;
  97. }
  98. } {0}
  99. do_test main-1.21 {
  100. db complete {
  101. CREATE TRIGGER xyz AFTER DELETE end BEGIN
  102. SELECT a, b FROM end;
  103. }
  104. } {0}
  105. do_test main-1.22 {
  106. db complete {
  107. CREATE TRIGGER xyz AFTER DELETE end BEGIN
  108. SELECT a, b FROM end;
  109. END;
  110. }
  111. } {1}
  112. do_test main-1.23 {
  113. db complete {
  114. CREATE TRIGGER xyz AFTER DELETE end BEGIN
  115. SELECT a, b FROM end;
  116. END;
  117. SELECT a, b FROM end;
  118. }
  119. } {1}
  120. do_test main-1.24 {
  121. db complete {
  122. CREATE TRIGGER xyz AFTER DELETE [;end;] BEGIN
  123. UPDATE pqr;
  124. }
  125. } {0}
  126. do_test main-1.25 {
  127. db complete {
  128. CREATE TRIGGER xyz AFTER DELETE backend BEGIN
  129. UPDATE pqr SET a=[;end;];;;
  130. }
  131. } {0}
  132. do_test main-1.26 {
  133. db complete {
  134. CREATE -- a comment
  135. TRIGGER xyz AFTER DELETE backend BEGIN
  136. UPDATE pqr SET a=5;
  137. }
  138. } {0}
  139. do_test main-1.27 {
  140. db complete {
  141. CREATE -- a comment
  142. TRIGGERX xyz AFTER DELETE backend BEGIN
  143. UPDATE pqr SET a=5;
  144. }
  145. } {1}
  146. do_test main-1.28 {
  147. db complete {
  148. CREATE TEMP TRIGGER xyz AFTER DELETE backend BEGIN
  149. UPDATE pqr SET a=5;
  150. }
  151. } {1}
  152. do_test main-1.29 {
  153. db complete {
  154. CREATE TRIGGER xyz AFTER DELETE backend BEGIN
  155. UPDATE pqr SET a=5;
  156. EXPLAIN select * from xyz;
  157. }
  158. } {0}
  159. # Try to open a database with a corrupt database file.
  160. #
  161. do_test main-2.0 {
  162. catch {db close}
  163. file delete -force test.db
  164. set fd [open test.db w]
  165. puts $fd hi!
  166. close $fd
  167. set v [catch {sqlite db test.db} msg]
  168. if {$v} {lappend v $msg} {lappend v {}}
  169. } {0 {}}
  170. # Here are some tests for tokenize.c.
  171. #
  172. do_test main-3.1 {
  173. catch {db close}
  174. foreach f [glob -nocomplain testdb/*] {file delete -force $f}
  175. file delete -force testdb
  176. sqlite db testdb
  177. set v [catch {execsql {SELECT * from T1 where x!!5}} msg]
  178. lappend v $msg
  179. } {1 {unrecognized token: "!!"}}
  180. do_test main-3.2 {
  181. catch {db close}
  182. foreach f [glob -nocomplain testdb/*] {file delete -force $f}
  183. file delete -force testdb
  184. sqlite db testdb
  185. set v [catch {execsql {SELECT * from T1 where @x}} msg]
  186. lappend v $msg
  187. } {1 {unrecognized token: "@"}}
  188. do_test main-3.3 {
  189. catch {db close}
  190. foreach f [glob -nocomplain testdb/*] {file delete -force $f}
  191. file delete -force testdb
  192. sqlite db testdb
  193. execsql {
  194. create table T1(X REAL);
  195. insert into T1 values(.5);
  196. insert into T1 values(0.5e2);
  197. insert into T1 values(0.5e-002);
  198. insert into T1 values(5e-002);
  199. insert into T1 values(-5.0e-2);
  200. insert into T1 values(-5.1e-2);
  201. insert into T1 values(.5e2);
  202. insert into T1 values(.5E+02);
  203. insert into T1 values(5E+02);
  204. insert into T1 values(5.E+03);
  205. select x*10 from T1 order by x*5;
  206. }
  207. } {-0.51 -0.5 0.05 0.5 5 500 500 500 5000 50000}
  208. do_test main-3.4 {
  209. set v [catch {execsql {create bogus}} msg]
  210. lappend v $msg
  211. } {1 {near "bogus": syntax error}}
  212. do_test main-3.5 {
  213. set v [catch {execsql {create}} msg]
  214. lappend v $msg
  215. } {1 {near "create": syntax error}}
  216. finish_test