e_insert.test 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. # 2010 September 18
  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. #
  12. # The majority of this file implements tests to verify that the "testable
  13. # statements" in the lang_insert.html document are correct.
  14. #
  15. # Also, it contains tests to verify the statements in (the very short)
  16. # lang_replace.html.
  17. #
  18. set testdir [file dirname $argv0]
  19. source $testdir/tester.tcl
  20. ifcapable !compound {
  21. finish_test
  22. return
  23. }
  24. # Organization of tests:
  25. #
  26. # e_insert-0.*: Test the syntax diagram.
  27. #
  28. # e_insert-1.*: Test statements of the form "INSERT ... VALUES(...)".
  29. #
  30. # e_insert-2.*: Test statements of the form "INSERT ... SELECT ...".
  31. #
  32. # e_insert-3.*: Test statements of the form "INSERT ... DEFAULT VALUES".
  33. #
  34. # e_insert-4.*: Test statements regarding the conflict clause.
  35. #
  36. # e_insert-5.*: Test that the qualified table name and "DEFAULT VALUES"
  37. # syntaxes do not work in trigger bodies.
  38. #
  39. do_execsql_test e_insert-0.0 {
  40. CREATE TABLE a1(a, b);
  41. CREATE TABLE a2(a, b, c DEFAULT 'xyz');
  42. CREATE TABLE a3(x DEFAULT 1.0, y DEFAULT 'string', z);
  43. CREATE TABLE a4(c UNIQUE, d);
  44. } {}
  45. proc do_insert_tests {args} {
  46. uplevel do_select_tests $args
  47. }
  48. # -- syntax diagram insert-stmt
  49. #
  50. do_insert_tests e_insert-0 {
  51. 1 "INSERT INTO a1 DEFAULT VALUES" {}
  52. 2 "INSERT INTO main.a1 DEFAULT VALUES" {}
  53. 3 "INSERT OR ROLLBACK INTO main.a1 DEFAULT VALUES" {}
  54. 4 "INSERT OR ROLLBACK INTO a1 DEFAULT VALUES" {}
  55. 5 "INSERT OR ABORT INTO main.a1 DEFAULT VALUES" {}
  56. 6 "INSERT OR ABORT INTO a1 DEFAULT VALUES" {}
  57. 7 "INSERT OR REPLACE INTO main.a1 DEFAULT VALUES" {}
  58. 8 "INSERT OR REPLACE INTO a1 DEFAULT VALUES" {}
  59. 9 "INSERT OR FAIL INTO main.a1 DEFAULT VALUES" {}
  60. 10 "INSERT OR FAIL INTO a1 DEFAULT VALUES" {}
  61. 11 "INSERT OR FAIL INTO main.a1 DEFAULT VALUES" {}
  62. 12 "INSERT OR IGNORE INTO a1 DEFAULT VALUES" {}
  63. 13 "REPLACE INTO a1 DEFAULT VALUES" {}
  64. 14 "REPLACE INTO main.a1 DEFAULT VALUES" {}
  65. 15 "INSERT INTO a1 VALUES(1, 2)" {}
  66. 16 "INSERT INTO main.a1 VALUES(1, 2)" {}
  67. 17 "INSERT OR ROLLBACK INTO main.a1 VALUES(1, 2)" {}
  68. 18 "INSERT OR ROLLBACK INTO a1 VALUES(1, 2)" {}
  69. 19 "INSERT OR ABORT INTO main.a1 VALUES(1, 2)" {}
  70. 20 "INSERT OR ABORT INTO a1 VALUES(1, 2)" {}
  71. 21 "INSERT OR REPLACE INTO main.a1 VALUES(1, 2)" {}
  72. 22 "INSERT OR REPLACE INTO a1 VALUES(1, 2)" {}
  73. 23 "INSERT OR FAIL INTO main.a1 VALUES(1, 2)" {}
  74. 24 "INSERT OR FAIL INTO a1 VALUES(1, 2)" {}
  75. 25 "INSERT OR FAIL INTO main.a1 VALUES(1, 2)" {}
  76. 26 "INSERT OR IGNORE INTO a1 VALUES(1, 2)" {}
  77. 27 "REPLACE INTO a1 VALUES(1, 2)" {}
  78. 28 "REPLACE INTO main.a1 VALUES(1, 2)" {}
  79. 29 "INSERT INTO a1 (b, a) VALUES(1, 2)" {}
  80. 30 "INSERT INTO main.a1 (b, a) VALUES(1, 2)" {}
  81. 31 "INSERT OR ROLLBACK INTO main.a1 (b, a) VALUES(1, 2)" {}
  82. 32 "INSERT OR ROLLBACK INTO a1 (b, a) VALUES(1, 2)" {}
  83. 33 "INSERT OR ABORT INTO main.a1 (b, a) VALUES(1, 2)" {}
  84. 34 "INSERT OR ABORT INTO a1 (b, a) VALUES(1, 2)" {}
  85. 35 "INSERT OR REPLACE INTO main.a1 (b, a) VALUES(1, 2)" {}
  86. 36 "INSERT OR REPLACE INTO a1 (b, a) VALUES(1, 2)" {}
  87. 37 "INSERT OR FAIL INTO main.a1 (b, a) VALUES(1, 2)" {}
  88. 38 "INSERT OR FAIL INTO a1 (b, a) VALUES(1, 2)" {}
  89. 39 "INSERT OR FAIL INTO main.a1 (b, a) VALUES(1, 2)" {}
  90. 40 "INSERT OR IGNORE INTO a1 (b, a) VALUES(1, 2)" {}
  91. 41 "REPLACE INTO a1 (b, a) VALUES(1, 2)" {}
  92. 42 "REPLACE INTO main.a1 (b, a) VALUES(1, 2)" {}
  93. 43 "INSERT INTO a1 SELECT c, b FROM a2" {}
  94. 44 "INSERT INTO main.a1 SELECT c, b FROM a2" {}
  95. 45 "INSERT OR ROLLBACK INTO main.a1 SELECT c, b FROM a2" {}
  96. 46 "INSERT OR ROLLBACK INTO a1 SELECT c, b FROM a2" {}
  97. 47 "INSERT OR ABORT INTO main.a1 SELECT c, b FROM a2" {}
  98. 48 "INSERT OR ABORT INTO a1 SELECT c, b FROM a2" {}
  99. 49 "INSERT OR REPLACE INTO main.a1 SELECT c, b FROM a2" {}
  100. 50 "INSERT OR REPLACE INTO a1 SELECT c, b FROM a2" {}
  101. 51 "INSERT OR FAIL INTO main.a1 SELECT c, b FROM a2" {}
  102. 52 "INSERT OR FAIL INTO a1 SELECT c, b FROM a2" {}
  103. 53 "INSERT OR FAIL INTO main.a1 SELECT c, b FROM a2" {}
  104. 54 "INSERT OR IGNORE INTO a1 SELECT c, b FROM a2" {}
  105. 55 "REPLACE INTO a1 SELECT c, b FROM a2" {}
  106. 56 "REPLACE INTO main.a1 SELECT c, b FROM a2" {}
  107. 57 "INSERT INTO a1 (b, a) SELECT c, b FROM a2" {}
  108. 58 "INSERT INTO main.a1 (b, a) SELECT c, b FROM a2" {}
  109. 59 "INSERT OR ROLLBACK INTO main.a1 (b, a) SELECT c, b FROM a2" {}
  110. 60 "INSERT OR ROLLBACK INTO a1 (b, a) SELECT c, b FROM a2" {}
  111. 61 "INSERT OR ABORT INTO main.a1 (b, a) SELECT c, b FROM a2" {}
  112. 62 "INSERT OR ABORT INTO a1 (b, a) SELECT c, b FROM a2" {}
  113. 63 "INSERT OR REPLACE INTO main.a1 (b, a) SELECT c, b FROM a2" {}
  114. 64 "INSERT OR REPLACE INTO a1 (b, a) SELECT c, b FROM a2" {}
  115. 65 "INSERT OR FAIL INTO main.a1 (b, a) SELECT c, b FROM a2" {}
  116. 66 "INSERT OR FAIL INTO a1 (b, a) SELECT c, b FROM a2" {}
  117. 67 "INSERT OR FAIL INTO main.a1 (b, a) SELECT c, b FROM a2" {}
  118. 68 "INSERT OR IGNORE INTO a1 (b, a) SELECT c, b FROM a2" {}
  119. 69 "REPLACE INTO a1 (b, a) SELECT c, b FROM a2" {}
  120. 70 "REPLACE INTO main.a1 (b, a) SELECT c, b FROM a2" {}
  121. 71 "INSERT INTO a1 (b, a) VALUES(1, 2),(3,4)" {}
  122. 72 "INSERT INTO main.a1 (b, a) VALUES(1, 2),(3,4)" {}
  123. 73 "INSERT OR ROLLBACK INTO main.a1 (b, a) VALUES(1, 2),(3,4)" {}
  124. 74 "INSERT OR ROLLBACK INTO a1 (b, a) VALUES(1, 2),(3,4)" {}
  125. 75 "INSERT OR ABORT INTO main.a1 (b, a) VALUES(1, 2),(3,4)" {}
  126. 76 "INSERT OR ABORT INTO a1 (b, a) VALUES(1, 2),(3,4)" {}
  127. 77 "INSERT OR REPLACE INTO main.a1 (b, a) VALUES(1, 2),(3,4)" {}
  128. 78 "INSERT OR REPLACE INTO a1 (b, a) VALUES(1, 2),(3,4)" {}
  129. 79 "INSERT OR FAIL INTO main.a1 (b, a) VALUES(1, 2),(3,4)" {}
  130. 80 "INSERT OR FAIL INTO a1 (b, a) VALUES(1, 2),(3,4)" {}
  131. 81 "INSERT OR FAIL INTO main.a1 (b, a) VALUES(1, 2),(3,4)" {}
  132. 82 "INSERT OR IGNORE INTO a1 (b, a) VALUES(1, 2),(3,4)" {}
  133. 83 "REPLACE INTO a1 (b, a) VALUES(1, 2),(3,4)" {}
  134. 84 "REPLACE INTO main.a1 (b, a) VALUES(1, 2),(3,4)" {}
  135. }
  136. delete_all_data
  137. # EVIDENCE-OF: R-21490-41092 The first form (with the "VALUES" keyword)
  138. # creates one or more new rows in an existing table.
  139. #
  140. do_insert_tests e_insert-1.1 {
  141. 0 "SELECT count(*) FROM a2" {0}
  142. 1a "INSERT INTO a2 VALUES(1, 2, 3)" {}
  143. 1b "SELECT count(*) FROM a2" {1}
  144. 2a "INSERT INTO a2(a, b) VALUES(1, 2)" {}
  145. 2b "SELECT count(*) FROM a2" {2}
  146. 3a "INSERT INTO a2(a) VALUES(3),(4)" {}
  147. 3b "SELECT count(*) FROM a2" {4}
  148. }
  149. # EVIDENCE-OF: R-53616-44976 If no column-list is specified then the
  150. # number of values inserted into each row must be the same as the number
  151. # of columns in the table.
  152. #
  153. # A test in the block above verifies that if the VALUES list has the
  154. # correct number of columns (for table a2, 3 columns) works. So these
  155. # tests just show that other values cause an error.
  156. #
  157. do_insert_tests e_insert-1.2 -error {
  158. table %s has %d columns but %d values were supplied
  159. } {
  160. 1 "INSERT INTO a2 VALUES(1)" {a2 3 1}
  161. 2 "INSERT INTO a2 VALUES(1,2)" {a2 3 2}
  162. 3 "INSERT INTO a2 VALUES(1,2,3,4)" {a2 3 4}
  163. 4 "INSERT INTO a2 VALUES(1,2,3,4,5)" {a2 3 5}
  164. }
  165. # EVIDENCE-OF: R-34231-22576 In this case the result of evaluating the
  166. # left-most expression in each term of the VALUES list is inserted into
  167. # the left-most column of the each new row, and forth for each
  168. # subsequent expression.
  169. #
  170. delete_all_data
  171. do_insert_tests e_insert-1.3 {
  172. 1a "INSERT INTO a2 VALUES(1, 2, 3)" {}
  173. 1b "SELECT * FROM a2 WHERE oid=last_insert_rowid()" {1 2 3}
  174. 2a "INSERT INTO a2 VALUES('abc', NULL, 3*3+1)" {}
  175. 2b "SELECT * FROM a2 WHERE oid=last_insert_rowid()" {abc {} 10}
  176. 3a "INSERT INTO a2 VALUES((SELECT count(*) FROM a2), 'x', 'y')" {}
  177. 3b "SELECT * FROM a2 WHERE oid=last_insert_rowid()" {2 x y}
  178. }
  179. # EVIDENCE-OF: R-09234-17933 If a column-list is specified, then the
  180. # number of values in each term of the VALUE list must match the number
  181. # of specified columns.
  182. #
  183. do_insert_tests e_insert-1.4 -error {
  184. %d values for %d columns
  185. } {
  186. 1 "INSERT INTO a2(a, b, c) VALUES(1)" {1 3}
  187. 2 "INSERT INTO a2(a, b, c) VALUES(1,2)" {2 3}
  188. 3 "INSERT INTO a2(a, b, c) VALUES(1,2,3,4)" {4 3}
  189. 4 "INSERT INTO a2(a, b, c) VALUES(1,2,3,4,5)" {5 3}
  190. 5 "INSERT INTO a2(c, a) VALUES(1)" {1 2}
  191. 6 "INSERT INTO a2(c, a) VALUES(1,2,3)" {3 2}
  192. 7 "INSERT INTO a2(c, a) VALUES(1,2,3,4)" {4 2}
  193. 8 "INSERT INTO a2(c, a) VALUES(1,2,3,4,5)" {5 2}
  194. }
  195. # EVIDENCE-OF: R-07016-26442 Each of the named columns of the new row is
  196. # populated with the results of evaluating the corresponding VALUES
  197. # expression.
  198. #
  199. # EVIDENCE-OF: R-12183-43719 Table columns that do not appear in the
  200. # column list are populated with the default column value (specified as
  201. # part of the CREATE TABLE statement), or with NULL if no default value
  202. # is specified.
  203. #
  204. delete_all_data
  205. do_insert_tests e_insert-1.5 {
  206. 1a "INSERT INTO a2(b, c) VALUES('b', 'c')" {}
  207. 1b "SELECT * FROM a2" {{} b c}
  208. 2a "INSERT INTO a2(a, b) VALUES('a', 'b')" {}
  209. 2b "SELECT * FROM a2" {{} b c a b xyz}
  210. }
  211. # EVIDENCE-OF: R-52173-30215 A new entry is inserted into the table for
  212. # each row of data returned by executing the SELECT statement.
  213. #
  214. delete_all_data
  215. do_insert_tests e_insert-2.1 {
  216. 0 "SELECT count(*) FROM a1" {0}
  217. 1a "SELECT count(*) FROM (SELECT 1, 2)" {1}
  218. 1b "INSERT INTO a1 SELECT 1, 2" {}
  219. 1c "SELECT count(*) FROM a1" {1}
  220. 2a "SELECT count(*) FROM (SELECT b, a FROM a1)" {1}
  221. 2b "INSERT INTO a1 SELECT b, a FROM a1" {}
  222. 2c "SELECT count(*) FROM a1" {2}
  223. 3a "SELECT count(*) FROM (SELECT b, a FROM a1)" {2}
  224. 3b "INSERT INTO a1 SELECT b, a FROM a1" {}
  225. 3c "SELECT count(*) FROM a1" {4}
  226. 4a "SELECT count(*) FROM (SELECT b, a FROM a1)" {4}
  227. 4b "INSERT INTO a1 SELECT b, a FROM a1" {}
  228. 4c "SELECT count(*) FROM a1" {8}
  229. 4a "SELECT count(*) FROM (SELECT min(b), min(a) FROM a1)" {1}
  230. 4b "INSERT INTO a1 SELECT min(b), min(a) FROM a1" {}
  231. 4c "SELECT count(*) FROM a1" {9}
  232. }
  233. # EVIDENCE-OF: R-63614-47421 If a column-list is specified, the number
  234. # of columns in the result of the SELECT must be the same as the number
  235. # of items in the column-list.
  236. #
  237. do_insert_tests e_insert-2.2 -error {
  238. %d values for %d columns
  239. } {
  240. 1 "INSERT INTO a3(x, y) SELECT a, b, c FROM a2" {3 2}
  241. 2 "INSERT INTO a3(x, y) SELECT * FROM a2" {3 2}
  242. 3 "INSERT INTO a3(x, y) SELECT * FROM a2 CROSS JOIN a1" {5 2}
  243. 4 "INSERT INTO a3(x, y) SELECT * FROM a2 NATURAL JOIN a1" {3 2}
  244. 5 "INSERT INTO a3(x, y) SELECT a2.a FROM a2,a1" {1 2}
  245. 6 "INSERT INTO a3(z) SELECT a, b, c FROM a2" {3 1}
  246. 7 "INSERT INTO a3(z) SELECT * FROM a2" {3 1}
  247. 8 "INSERT INTO a3(z) SELECT * FROM a2 CROSS JOIN a1" {5 1}
  248. 9 "INSERT INTO a3(z) SELECT * FROM a2 NATURAL JOIN a1" {3 1}
  249. 10 "INSERT INTO a3(z) SELECT a1.* FROM a2,a1" {2 1}
  250. }
  251. # EVIDENCE-OF: R-58951-07798 Otherwise, if no column-list is specified,
  252. # the number of columns in the result of the SELECT must be the same as
  253. # the number of columns in the table.
  254. #
  255. do_insert_tests e_insert-2.3 -error {
  256. table %s has %d columns but %d values were supplied
  257. } {
  258. 1 "INSERT INTO a1 SELECT a, b, c FROM a2" {a1 2 3}
  259. 2 "INSERT INTO a1 SELECT * FROM a2" {a1 2 3}
  260. 3 "INSERT INTO a1 SELECT * FROM a2 CROSS JOIN a1" {a1 2 5}
  261. 4 "INSERT INTO a1 SELECT * FROM a2 NATURAL JOIN a1" {a1 2 3}
  262. 5 "INSERT INTO a1 SELECT a2.a FROM a2,a1" {a1 2 1}
  263. }
  264. # EVIDENCE-OF: R-31074-37730 Any SELECT statement, including compound
  265. # SELECTs and SELECT statements with ORDER BY and/or LIMIT clauses, may
  266. # be used in an INSERT statement of this form.
  267. #
  268. delete_all_data
  269. do_execsql_test e_insert-2.3.0 {
  270. INSERT INTO a1 VALUES('x', 'y');
  271. } {}
  272. do_insert_tests e_insert-2.3 {
  273. 1 "INSERT INTO a1 SELECT a,b FROM a1 UNION SELECT b,a FROM a1 ORDER BY 1" {}
  274. 2 "INSERT INTO a1(b, a) SELECT * FROM a1 LIMIT 1" {}
  275. 3 "INSERT INTO a1 SELECT 'a'||a, 'b'||b FROM a1 LIMIT 2 OFFSET 1" {}
  276. 4 "INSERT INTO a1 SELECT * FROM a1 ORDER BY b, a" {}
  277. S "SELECT * FROM a1" {
  278. x y
  279. x y y x
  280. y x
  281. ax by ay bx
  282. ay bx ax by y x y x x y x y
  283. }
  284. }
  285. # EVIDENCE-OF: R-25149-22012 The INSERT ... DEFAULT VALUES statement
  286. # inserts a single new row into the named table.
  287. #
  288. delete_all_data
  289. do_insert_tests e_insert-3.1 {
  290. 1 "SELECT count(*) FROM a3" {0}
  291. 2a "INSERT INTO a3 DEFAULT VALUES" {}
  292. 2b "SELECT count(*) FROM a3" {1}
  293. }
  294. # EVIDENCE-OF: R-18927-01951 Each column of the new row is populated
  295. # with its default value, or with a NULL if no default value is
  296. # specified as part of the column definition in the CREATE TABLE
  297. # statement.
  298. #
  299. delete_all_data
  300. do_insert_tests e_insert-3.2 {
  301. 1.1 "INSERT INTO a3 DEFAULT VALUES" {}
  302. 1.2 "SELECT * FROM a3" {1.0 string {}}
  303. 2.1 "INSERT INTO a3 DEFAULT VALUES" {}
  304. 2.2 "SELECT * FROM a3" {1.0 string {} 1.0 string {}}
  305. 3.1 "INSERT INTO a2 DEFAULT VALUES" {}
  306. 3.2 "SELECT * FROM a2" {{} {} xyz}
  307. 4.1 "INSERT INTO a2 DEFAULT VALUES" {}
  308. 4.2 "SELECT * FROM a2" {{} {} xyz {} {} xyz}
  309. 5.1 "INSERT INTO a1 DEFAULT VALUES" {}
  310. 5.2 "SELECT * FROM a1" {{} {}}
  311. 6.1 "INSERT INTO a1 DEFAULT VALUES" {}
  312. 6.2 "SELECT * FROM a1" {{} {} {} {}}
  313. }
  314. # EVIDENCE-OF: R-46928-50290 The optional conflict-clause allows the
  315. # specification of an alternative constraint conflict resolution
  316. # algorithm to use during this one INSERT command.
  317. #
  318. # EVIDENCE-OF: R-23110-47146 the parser allows the use of the single
  319. # keyword REPLACE as an alias for "INSERT OR REPLACE".
  320. #
  321. # The two requirements above are tested by e_select-4.1.* and
  322. # e_select-4.2.*, respectively.
  323. #
  324. # EVIDENCE-OF: R-03421-22330 The REPLACE command is an alias for the
  325. # "INSERT OR REPLACE" variant of the INSERT command.
  326. #
  327. # This is a dup of R-23110-47146. Therefore it is also verified
  328. # by e_select-4.2.*. This requirement is the only one from
  329. # lang_replace.html.
  330. #
  331. do_execsql_test e_insert-4.1.0 {
  332. INSERT INTO a4 VALUES(1, 'a');
  333. INSERT INTO a4 VALUES(2, 'a');
  334. INSERT INTO a4 VALUES(3, 'a');
  335. } {}
  336. foreach {tn sql error ac data } {
  337. 1.1 "INSERT INTO a4 VALUES(2,'b')" {column c is not unique} 1 {1 a 2 a 3 a}
  338. 1.2 "INSERT OR REPLACE INTO a4 VALUES(2, 'b')" {} 1 {1 a 3 a 2 b}
  339. 1.3 "INSERT OR IGNORE INTO a4 VALUES(3, 'c')" {} 1 {1 a 3 a 2 b}
  340. 1.4 "BEGIN" {} 0 {1 a 3 a 2 b}
  341. 1.5 "INSERT INTO a4 VALUES(1, 'd')" {column c is not unique} 0 {1 a 3 a 2 b}
  342. 1.6 "INSERT OR ABORT INTO a4 VALUES(1, 'd')"
  343. {column c is not unique} 0 {1 a 3 a 2 b}
  344. 1.7 "INSERT OR ROLLBACK INTO a4 VALUES(1, 'd')"
  345. {column c is not unique} 1 {1 a 3 a 2 b}
  346. 1.8 "INSERT INTO a4 SELECT 4, 'e' UNION ALL SELECT 3, 'e'"
  347. {column c is not unique} 1 {1 a 3 a 2 b}
  348. 1.9 "INSERT OR FAIL INTO a4 SELECT 4, 'e' UNION ALL SELECT 3, 'e'"
  349. {column c is not unique} 1 {1 a 3 a 2 b 4 e}
  350. 2.1 "INSERT INTO a4 VALUES(2,'f')"
  351. {column c is not unique} 1 {1 a 3 a 2 b 4 e}
  352. 2.2 "REPLACE INTO a4 VALUES(2, 'f')" {} 1 {1 a 3 a 4 e 2 f}
  353. } {
  354. do_catchsql_test e_insert-4.1.$tn.1 $sql [list [expr {$error!=""}] $error]
  355. do_execsql_test e_insert-4.1.$tn.2 {SELECT * FROM a4} [list {*}$data]
  356. do_test e_insert-4.1.$tn.3 {sqlite3_get_autocommit db} $ac
  357. }
  358. # EVIDENCE-OF: R-64196-02418 The optional "database-name." prefix on the
  359. # table-name is support for top-level INSERT statements only.
  360. #
  361. # EVIDENCE-OF: R-05731-00924 The table name must be unqualified for
  362. # INSERT statements that occur within CREATE TRIGGER statements.
  363. #
  364. set err {1 {qualified table names are not allowed on INSERT, UPDATE, and DELETE statements within triggers}}
  365. do_catchsql_test e_insert-5.1.1 {
  366. CREATE TRIGGER AFTER UPDATE ON a1 BEGIN
  367. INSERT INTO main.a4 VALUES(new.a, new.b);
  368. END;
  369. } $err
  370. do_catchsql_test e_insert-5.1.2 {
  371. CREATE TEMP TABLE IF NOT EXISTS tmptable(a, b);
  372. CREATE TRIGGER AFTER DELETE ON a3 BEGIN
  373. INSERT INTO temp.tmptable VALUES(1, 2);
  374. END;
  375. } $err
  376. # EVIDENCE-OF: R-15888-36326 Similarly, the "DEFAULT VALUES" form of the
  377. # INSERT statement is supported for top-level INSERT statements only and
  378. # not for INSERT statements within triggers.
  379. #
  380. do_catchsql_test e_insert-5.2.1 {
  381. CREATE TRIGGER AFTER UPDATE ON a1 BEGIN
  382. INSERT INTO a4 DEFAULT VALUES;
  383. END;
  384. } {1 {near "DEFAULT": syntax error}}
  385. delete_all_data
  386. finish_test