]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add test file e_dropview.test.
authordan <dan@noemail.net>
Tue, 30 Nov 2010 12:12:24 +0000 (12:12 +0000)
committerdan <dan@noemail.net>
Tue, 30 Nov 2010 12:12:24 +0000 (12:12 +0000)
FossilOrigin-Name: 6197822cc8310fd7e1d7151683833e8b39fe631a

manifest
manifest.uuid
test/e_droptrigger.test
test/e_dropview.test [new file with mode: 0644]

index 7d2f9c4108e29c39855bec0416ee66212eefbde1..9e728b7c049fd2145454d9fecbcb528e38cb9360 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sa\swarning\sin\sos_unix.c.
-D 2010-11-29T18:36:23
+C Add\stest\sfile\se_dropview.test.
+D 2010-11-30T12:12:25
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 4547616ad2286053af6ccccefa242dc925e49bf0
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -354,7 +354,8 @@ F test/diskfull.test 0cede7ef9d8f415d9d3944005c76be7589bb5ebb
 F test/distinctagg.test 1a6ef9c87a58669438fc771450d7a72577417376
 F test/e_createtable.test b8f5286879315d5b7f4cc5ead1afda4846f0c0bb
 F test/e_delete.test 55d868b647acc091c261a10b9b0cb0ab660a6acb
-F test/e_droptrigger.test 0b96c0df9b6390c728d9e15ff046419b678ddf44
+F test/e_droptrigger.test ddd4b28ed8a3d81bd5153fa0ab7559529a2ca03a
+F test/e_dropview.test b347bab30fc8de67b131594b3cd6f3d3bdaa753d
 F test/e_expr.test 4e004d1f5187d4bbc9ca3d55660a8d164dd59f4e
 F test/e_fkey.test 38039b840ab19331000b0f0eb1d82baa7208a67a
 F test/e_fts3.test 75bb0aee26384ef586165e21018a17f7cd843469
@@ -890,7 +891,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P 0a3cba95a14ae7a24b2d268567a02d651ab278dc
-R e401f90ddb8266a3429b5e6c7d3e2f82
+P ee8dc8c87ed15b76ba437df23e1d7b1b7fa30296
+R 4a3bff37fc4c660278f60fbda77a6338
 U dan
-Z bef9d0b466eb5f68fca05b419b07c81c
+Z 27edb6190ff4f86a8a8a1f3444932c26
index 4f9f6df5e85a51d4063a1f5fbb4f98665e90d900..2f572f9cafea8bb1e428cf1b0d3d1f8a3fa0a0f0 100644 (file)
@@ -1 +1 @@
-ee8dc8c87ed15b76ba437df23e1d7b1b7fa30296
\ No newline at end of file
+6197822cc8310fd7e1d7151683833e8b39fe631a
\ No newline at end of file
index d84fc6ad2dd93e65ec1f135322253709c48af51f..0c1483176c679497d79734386e0b81e408769623 100644 (file)
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
-set ::testprefix e_createtable
+set ::testprefix e_droptrigger
 
 ifcapable !trigger { finish_test ; return }
 
-proc do_droptable_tests {nm args} {
+proc do_droptrigger_tests {nm args} {
   uplevel do_select_tests [list e_createtable-$nm] $args
 }
 
@@ -71,7 +71,7 @@ proc droptrigger_reopen_db {{event INSERT}} {
 
 # EVIDENCE-OF: R-52650-16855 -- syntax diagram drop-trigger-stmt
 #
-do_droptable_tests 1.1 -repair {
+do_droptrigger_tests 1.1 -repair {
   droptrigger_reopen_db
 } -tclquery {
   list_all_triggers 
diff --git a/test/e_dropview.test b/test/e_dropview.test
new file mode 100644 (file)
index 0000000..447e5c3
--- /dev/null
@@ -0,0 +1,192 @@
+# 2010 November 30
+#
+# The author disclaims copyright to this source code.  In place of
+# a legal notice, here is a blessing:
+#
+#    May you do good and not evil.
+#    May you find forgiveness for yourself and forgive others.
+#    May you share freely, never taking more than you give.
+#
+#***********************************************************************
+#
+# This file implements tests to verify that the "testable statements" in 
+# the lang_dropview.html document are correct.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set ::testprefix e_dropview
+
+proc dropview_reopen_db {} {
+  db close
+  forcedelete test.db test.db2
+  sqlite3 db test.db
+
+  db eval {
+    ATTACH 'test.db2' AS aux;
+    CREATE TABLE t1(a, b); 
+    INSERT INTO t1 VALUES('a main', 'b main');
+    CREATE VIEW v1 AS SELECT * FROM t1;
+    CREATE VIEW v2 AS SELECT * FROM t1;
+
+    CREATE TEMP TABLE t1(a, b);
+    INSERT INTO temp.t1 VALUES('a temp', 'b temp');
+    CREATE VIEW temp.v1 AS SELECT * FROM t1;
+
+    CREATE TABLE aux.t1(a, b);
+    INSERT INTO aux.t1 VALUES('a aux', 'b aux');
+    CREATE VIEW aux.v1 AS SELECT * FROM t1;
+    CREATE VIEW aux.v2 AS SELECT * FROM t1;
+    CREATE VIEW aux.v3 AS SELECT * FROM t1;
+  }
+}
+
+proc list_all_views {{db db}} {
+  set res [list]
+  $db eval { PRAGMA database_list } {
+    set tbl "$name.sqlite_master"
+    if {$name == "temp"} { set tbl sqlite_temp_master }
+
+    set sql "SELECT '$name.' || name FROM $tbl WHERE type = 'view'"
+    lappend res {*}[$db eval $sql]
+  }
+  set res
+}
+
+proc list_all_data {{db db}} {
+  set res [list]
+  $db eval { PRAGMA database_list } {
+    set tbl "$name.sqlite_master"
+    if {$name == "temp"} { set tbl sqlite_temp_master }
+
+    db eval "SELECT '$name.' || name AS x FROM $tbl WHERE type = 'table'" {
+      lappend res [list $x [db eval "SELECT * FROM $x"]]
+    }
+  }
+  set res
+}
+
+proc do_dropview_tests {nm args} {
+  uplevel do_select_tests $nm $args
+}
+
+# EVIDENCE-OF: R-21739-51207 -- syntax diagram drop-view-stmt
+#
+# All paths in the syntax diagram for DROP VIEW are tested by tests 1.*.
+#
+do_dropview_tests 1 -repair {
+  dropview_reopen_db
+} -tclquery {
+  list_all_views
+} {
+  1   "DROP VIEW v1"                  {main.v1 main.v2 aux.v1 aux.v2 aux.v3}
+  2   "DROP VIEW v2"                  {main.v1 temp.v1 aux.v1 aux.v2 aux.v3}
+  3   "DROP VIEW main.v1"             {main.v2 temp.v1 aux.v1 aux.v2 aux.v3}
+  4   "DROP VIEW main.v2"             {main.v1 temp.v1 aux.v1 aux.v2 aux.v3}
+  5   "DROP VIEW IF EXISTS v1"        {main.v1 main.v2 aux.v1 aux.v2 aux.v3}
+  6   "DROP VIEW IF EXISTS v2"        {main.v1 temp.v1 aux.v1 aux.v2 aux.v3}
+  7   "DROP VIEW IF EXISTS main.v1"   {main.v2 temp.v1 aux.v1 aux.v2 aux.v3}
+  8   "DROP VIEW IF EXISTS main.v2"   {main.v1 temp.v1 aux.v1 aux.v2 aux.v3}
+}
+
+# EVIDENCE-OF: R-27002-52307 The DROP VIEW statement removes a view
+# created by the CREATE VIEW statement.
+#
+dropview_reopen_db
+do_execsql_test 2.1 {
+  CREATE VIEW "new view" AS SELECT * FROM t1 AS x, t1 AS y;
+  SELECT * FROM "new view";
+} {{a main} {b main} {a main} {b main}}
+do_execsql_test 2.2 {;
+  SELECT * FROM sqlite_master WHERE name = 'new view';
+} {
+  view {new view} {new view} 0 
+  {CREATE VIEW "new view" AS SELECT * FROM t1 AS x, t1 AS y}
+}
+do_execsql_test 2.3 {
+  DROP VIEW "new view";
+  SELECT * FROM sqlite_master WHERE name = 'new view';
+} {}
+do_catchsql_test 2.4 {
+  SELECT * FROM "new view"
+} {1 {no such table: new view}}
+
+# EVIDENCE-OF: R-00359-41639 The view definition is removed from the
+# database schema, but no actual data in the underlying base tables is
+# modified.
+#
+#     For each view in the database, check that it can be queried. Then drop
+#     it. Check that it can no longer be queried and is no longer listed
+#     in any schema table. Then check that the contents of the db tables have 
+#     not changed
+#
+set databasedata [list_all_data]
+
+do_execsql_test  3.1.0 { SELECT * FROM temp.v1 } {{a temp} {b temp}}
+do_execsql_test  3.1.1 { DROP VIEW temp.v1 } {}
+do_catchsql_test 3.1.2 { SELECT * FROM temp.v1 } {1 {no such table: temp.v1}}
+do_test          3.1.3 { list_all_views } {main.v1 main.v2 aux.v1 aux.v2 aux.v3}
+do_test          3.1.4 { list_all_data  } $databasedata
+
+do_execsql_test  3.2.0 { SELECT * FROM v1 } {{a main} {b main}}
+do_execsql_test  3.2.1 { DROP VIEW v1 } {}
+do_catchsql_test 3.2.2 { SELECT * FROM main.v1 } {1 {no such table: main.v1}}
+do_test          3.2.3 { list_all_views } {main.v2 aux.v1 aux.v2 aux.v3}
+do_test          3.2.4 { list_all_data  } $databasedata
+
+do_execsql_test  3.3.0 { SELECT * FROM v2 } {{a main} {b main}}
+do_execsql_test  3.3.1 { DROP VIEW v2 } {}
+do_catchsql_test 3.3.2 { SELECT * FROM main.v2 } {1 {no such table: main.v2}}
+do_test          3.3.3 { list_all_views } {aux.v1 aux.v2 aux.v3}
+do_test          3.3.4 { list_all_data  } $databasedata
+
+do_execsql_test  3.4.0 { SELECT * FROM v1 } {{a aux} {b aux}}
+do_execsql_test  3.4.1 { DROP VIEW v1 } {}
+do_catchsql_test 3.4.2 { SELECT * FROM v1 } {1 {no such table: v1}}
+do_test          3.4.3 { list_all_views } {aux.v2 aux.v3}
+do_test          3.4.4 { list_all_data  } $databasedata
+
+do_execsql_test  3.4.0 { SELECT * FROM aux.v2 } {{a aux} {b aux}}
+do_execsql_test  3.4.1 { DROP VIEW aux.v2 } {}
+do_catchsql_test 3.4.2 { SELECT * FROM aux.v2 } {1 {no such table: aux.v2}}
+do_test          3.4.3 { list_all_views } {aux.v3}
+do_test          3.4.4 { list_all_data  } $databasedata
+
+do_execsql_test  3.5.0 { SELECT * FROM v3 } {{a aux} {b aux}}
+do_execsql_test  3.5.1 { DROP VIEW v3 } {}
+do_catchsql_test 3.5.2 { SELECT * FROM v3 } {1 {no such table: v3}}
+do_test          3.5.3 { list_all_views } {}
+do_test          3.5.4 { list_all_data  } $databasedata
+
+# EVIDENCE-OF: R-25558-37487 If the specified view cannot be found and
+# the IF EXISTS clause is not present, it is an error.
+#
+do_dropview_tests 4 -repair {
+  dropview_reopen_db 
+} -errorformat {
+  no such view: %s
+} {
+  1   "DROP VIEW xx"                  xx
+  2   "DROP VIEW main.xx"             main.xx
+  3   "DROP VIEW temp.v2"             temp.v2
+}
+
+# EVIDENCE-OF: R-07490-32536 If the specified view cannot be found and
+# an IF EXISTS clause is present in the DROP VIEW statement, then the
+# statement is a no-op.
+#
+do_dropview_tests 5 -repair {
+  dropview_reopen_db
+} -tclquery {
+  list_all_views
+  expr {[list_all_views] == "main.v1 main.v2 temp.v1 aux.v1 aux.v2 aux.v3"}
+} {
+  1    "DROP VIEW IF EXISTS xx"       1
+  2    "DROP VIEW IF EXISTS main.xx"  1
+  3    "DROP VIEW IF EXISTS temp.v2"  1
+}
+
+
+
+
+finish_test