]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add an OP_VerifyCookie instruction to "CREATE XXX IF NOT EXISTS" commands. This way...
authordan <dan@noemail.net>
Sat, 9 Apr 2011 15:39:02 +0000 (15:39 +0000)
committerdan <dan@noemail.net>
Sat, 9 Apr 2011 15:39:02 +0000 (15:39 +0000)
FossilOrigin-Name: b9dbd9936191666c3fc9889e938344a82cc03aeb

manifest
manifest.uuid
src/build.c
src/trigger.c
test/exists.test [new file with mode: 0644]

index 79217168e82f20cc8eff0d19a7ebc726ea114450..7b7d0cd93d39706f32ee1deccf52869029277108 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C If\sthe\skeyword\s"unordered"\sappears\sat\sthe\send\sof\sthe\sSQLITE_STAT1.STAT\s\ncolumn\sfor\san\sindex,\sthen\suse\sthat\sindex\sfor\sequality\slookups\sonly,\snever\s\nfor\srange\squeries\sor\ssorting.\s\sThis\sfeature\sis\scurrently\sundocumented\sand\nmy\schange\sor\sbe\sremoved\sin\sa\sfuture\srelease.
-D 2011-04-09T03:20:59.281
+C Add\san\sOP_VerifyCookie\sinstruction\sto\s"CREATE\sXXX\sIF\sNOT\sEXISTS"\scommands.\sThis\sway,\sif\sthe\sspecified\sdatabase\sobject\sexisted\swhen\sthe\sstatement\swas\scompiled\sbut\sremoved\sfrom\sthe\sdatabase\sbefore\ssqlite3_step()\swas\scalled,\sthe\sstatement\sstill\sworks\sas\sexpected\s(and\screates\sthe\sobject).
+D 2011-04-09T15:39:02.585
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 7a4d9524721d40ef9ee26f93f9bd6a51dba106f2
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -124,7 +124,7 @@ F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7
 F src/btree.c 6a9164af8a2ef4612ee30b253635a9bd8e5e1b1b
 F src/btree.h 11753dd46597a20702bca8746cb4caa4486a82b5
 F src/btreeInt.h 67978c014fa4f7cc874032dd3aacadd8db656bc3
-F src/build.c b7c993274ee2a029937b0bc4815bdef80b330017
+F src/build.c 84d4a8030d38c8f8cea6bbfa3b9a9e92932b0d03
 F src/callback.c 0425c6320730e6d3981acfb9202c1bed9016ad1a
 F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac
 F src/ctime.c 7deec4534f3b5a0c3b4a4cbadf809d321f64f9c4
@@ -230,7 +230,7 @@ F src/test_vfstrace.c 2265c9895f350c8d3c39b079998fbe7481505cc1
 F src/test_wholenumber.c 6129adfbe7c7444f2e60cc785927f3aa74e12290
 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9
 F src/tokenize.c 604607d6813e9551cf5189d899e0a25c12681080
-F src/trigger.c d5bc8b9ffa2b54569ce635084765c6e41aa9d174
+F src/trigger.c c31aeb3c33e8cef9029e83f5fd9111ef644ca6b9
 F src/update.c 81911be16ece3c3e7716aa18565b4814ec41f8b9
 F src/utf.c d83650c3ea08f7407bd9d0839d9885241c209c60
 F src/util.c cd997077bad039efc0597eb027c929658f93c018
@@ -388,6 +388,7 @@ F test/eval.test bc269c365ba877554948441e91ad5373f9f91be3
 F test/exclusive.test 53e1841b422e554cecf0160f937c473d6d0e3062
 F test/exclusive2.test 343d55130c12c67b8bf10407acec043a6c26c86b
 F test/exec.test e949714dc127eaa5ecc7d723efec1ec27118fdd7
+F test/exists.test 5e14325e4b2ea28709ff82d8d2605a129b5aec72
 F test/expr.test 19e8ac40313e2282a47b586d11c4892040990d3a
 F test/fallocate.test 43dc34b8c24be6baffadc3b4401ee15710ce83c6
 F test/filectrl.test 97003734290887566e01dded09dc9e99cb937e9e
@@ -926,7 +927,7 @@ F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/split-sqlite3c.tcl d9be87f1c340285a3e081eb19b4a247981ed290c
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P 927e955b93e869727c55b784401de3ea07bee257 3b964155f611c437d53d44feafa22f531942b1b4
-R 8f730b36ea51ef307e60876151b20fbc
-U drh
-Z ad8576a5ee09c7cb93d286363cb1b8eb
+P 8a42e236701c8afd9ada7d4568712a21690ea087
+R 962a8a84c94502671291e1b24e5febe9
+U dan
+Z a74ebc24c62ba84a876e128dc1be558a
index 822c3cbb9ebbc3571ae394474f5ee41df46f014f..09892107355e36f858ef684d465b5f48aab5b6f5 100644 (file)
@@ -1 +1 @@
-8a42e236701c8afd9ada7d4568712a21690ea087
\ No newline at end of file
+b9dbd9936191666c3fc9889e938344a82cc03aeb
\ No newline at end of file
index 8ab07c857c267bb879d66e0e0f3456ff55ec12df..2d1d8dc6a322917e3f8ed19a5a8224cd70e88e99 100644 (file)
@@ -813,6 +813,9 @@ void sqlite3StartTable(
     if( pTable ){
       if( !noErr ){
         sqlite3ErrorMsg(pParse, "table %T already exists", pName);
+      }else{
+        assert( !db->init.busy );
+        sqlite3CodeVerifySchema(pParse, iDb);
       }
       goto begin_table_error;
     }
@@ -2518,6 +2521,9 @@ Index *sqlite3CreateIndex(
     if( sqlite3FindIndex(db, zName, pDb->zName)!=0 ){
       if( !ifNotExist ){
         sqlite3ErrorMsg(pParse, "index %s already exists", zName);
+      }else{
+        assert( !db->init.busy );
+        sqlite3CodeVerifySchema(pParse, iDb);
       }
       goto exit_create_index;
     }
index 8a050eac50cb139ee45acd2ae5cf7c6c8032bc5d..8952ad59a1f9bfccd31343604a81cd33a3b65137 100644 (file)
@@ -171,6 +171,9 @@ void sqlite3BeginTrigger(
                       zName, sqlite3Strlen30(zName)) ){
     if( !noErr ){
       sqlite3ErrorMsg(pParse, "trigger %T already exists", pName);
+    }else{
+      assert( !db->init.busy );
+      sqlite3CodeVerifySchema(pParse, iDb);
     }
     goto trigger_cleanup;
   }
diff --git a/test/exists.test b/test/exists.test
new file mode 100644 (file)
index 0000000..05914d3
--- /dev/null
@@ -0,0 +1,76 @@
+# 2011 April 9
+#
+# 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 regression tests for SQLite library.  The
+# focus of this file is testing the various schema modification statements
+# that feature "IF EXISTS" or "IF NOT EXISTS" clauses.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+source $testdir/lock_common.tcl
+
+set testprefix exists
+
+do_multiclient_test tn {
+
+  # TABLE objects.
+  #
+  do_test $tn.1.1 {
+    sql2 { CREATE TABLE t1(x) }
+    sql1 { CREATE TABLE IF NOT EXISTS t1(a, b) }
+    sql2 { DROP TABLE t1 }
+    sql1 { CREATE TABLE IF NOT EXISTS t1(a, b) }
+    sql2 { SELECT name FROM sqlite_master WHERE type = 'table' }
+  } {t1}
+
+  do_test $tn.1.2 {
+    sql2 { CREATE TABLE t2(x) }
+    sql1 { CREATE TABLE IF NOT EXISTS t2 AS SELECT * FROM t1 }
+    sql2 { DROP TABLE t2 }
+    sql1 { CREATE TABLE IF NOT EXISTS t2 AS SELECT * FROM t1 }
+    sql2 { SELECT name FROM sqlite_master WHERE type = 'table' }
+  } {t1 t2}
+
+
+  # INDEX objects.
+  #
+  do_test $tn.2 {
+    sql2 { CREATE INDEX i1 ON t1(a) }
+    sql1 { CREATE INDEX IF NOT EXISTS i1 ON t1(a, b) }
+    sql2 { DROP INDEX i1 }
+    sql1 { CREATE INDEX IF NOT EXISTS i1 ON t1(a, b) }
+    sql2 { SELECT name FROM sqlite_master WHERE type = 'index' }
+  } {i1}
+
+  # VIEW objects.
+  #
+  do_test $tn.3 {
+    sql2 { CREATE VIEW v1 AS SELECT * FROM t1 }
+    sql1 { CREATE VIEW IF NOT EXISTS v1 AS SELECT * FROM t1 }
+    sql2 { DROP VIEW v1 }
+    sql1 { CREATE VIEW IF NOT EXISTS v1 AS SELECT * FROM t1 }
+    sql2 { SELECT name FROM sqlite_master WHERE type = 'view' }
+  } {v1}
+
+  # TRIGGER objects.
+  #
+  do_test $tn.4 {
+    sql2 { CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN SELECT 1; END }
+sql1 { CREATE TRIGGER IF NOT EXISTS tr1 AFTER INSERT ON t1 BEGIN SELECT 1; END }
+    sql2 { DROP TRIGGER tr1 }
+sql1 { CREATE TRIGGER IF NOT EXISTS tr1 AFTER INSERT ON t1 BEGIN SELECT 1; END }
+    sql2 { SELECT name FROM sqlite_master WHERE type = 'trigger' }
+  } {tr1}
+
+}
+
+
+finish_test