blob: bfccaa9b84b17db4fbdd3badb20a439c458a4063 [file] [log] [blame]
drh82286fd2008-04-28 17:12:10 +00001# 2008 April 27
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# Ticket #3080
13#
14# Make sure that application-defined functions are able to recursively
15# invoke SQL statements that create and drop virtual tables.
16#
drhad4a4b82008-11-05 16:37:34 +000017# $Id: tkt3080.test,v 1.2 2008/11/05 16:37:35 drh Exp $
drh82286fd2008-04-28 17:12:10 +000018#
19
20set testdir [file dirname $argv0]
21source $testdir/tester.tcl
22
23do_test tkt3080.1 {
24 db function execsql execsql
25 db eval {
26 SELECT execsql('CREATE TABLE t1(x)');
27 }
28 execsql {SELECT name FROM sqlite_master}
29} {t1}
30do_test tkt3080.2 {
31 db eval {
32 INSERT INTO t1 VALUES('CREATE TABLE t2(y);');
33 SELECT execsql(x) FROM t1;
34 }
35 db eval {
36 SELECT name FROM sqlite_master;
37 }
38} {t1 t2}
39do_test tkt3080.3 {
40 execsql {
41 INSERT INTO t1 VALUES('CREATE TABLE t3(z); DROP TABLE t3;');
42 }
43 catchsql {
44 SELECT execsql(x) FROM t1 WHERE rowid=2;
45 }
46} {1 {database table is locked}}
47do_test tkt3080.4 {
48 db eval {
49 SELECT name FROM sqlite_master;
50 }
drhad4a4b82008-11-05 16:37:34 +000051} {t1 t2 t3}
drh82286fd2008-04-28 17:12:10 +000052
53ifcapable vtab {
54 register_echo_module [sqlite3_connection_pointer db]
55 do_test tkt3080.10 {
56 set sql {
57 CREATE VIRTUAL TABLE t4 USING echo(t2);
58 INSERT INTO t4 VALUES(123);
59 DROP TABLE t4;
60 }
61 execsql {
62 DELETE FROM t1;
63 INSERT INTO t1 VALUES($sql);
64 }
65 db eval {
66 SELECT execsql(x) FROM t1
67 }
68 execsql {SELECT name FROM sqlite_master}
drhad4a4b82008-11-05 16:37:34 +000069 } {t1 t2 t3}
drh82286fd2008-04-28 17:12:10 +000070 do_test tkt3080.11 {
71 execsql {SELECT * FROM t2}
72 } {123}
73}
74
75
76
77finish_test