]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
When a CREATE TABLE ... AS SELECT statement fails, make sure the table name
authordrh <drh@noemail.net>
Sat, 1 Feb 2003 13:53:28 +0000 (13:53 +0000)
committerdrh <drh@noemail.net>
Sat, 1 Feb 2003 13:53:28 +0000 (13:53 +0000)
is removed from the internal hash tables.  Ticket #238. (CVS 858)

FossilOrigin-Name: 65264780c553e8a00ec7a40cf76b89a11b245faf

manifest
manifest.uuid
src/build.c
test/misc1.test

index 611cbb1ed729d56855db2db7638c5abf9ba1e7a9..d1228f5c105a2e2fb208833983cbf4415162d34b 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C The\ssqlite_exec()\sfunction\snow\sreturns\sSQLITE_AUTH\swhen\sauthorization\sfails.\nTicket\s#231.\s(CVS\s857)
-D 2003-01-31T17:21:50
+C When\sa\sCREATE\sTABLE\s...\sAS\sSELECT\sstatement\sfails,\smake\ssure\sthe\stable\sname\nis\sremoved\sfrom\sthe\sinternal\shash\stables.\s\sTicket\s#238.\s(CVS\s858)
+D 2003-02-01T13:53:28
 F Makefile.in 6606854b1512f185b8e8c779b8d7fc2750463d64
 F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@@ -21,7 +21,7 @@ F sqlite.1 83f4a9d37bdf2b7ef079a82d54eaf2e3509ee6ea
 F src/auth.c f37bfc9451b8c1fa52f34adff474560018892729
 F src/btree.c 668402ca441592d85da521309625bd1bcc6f010e
 F src/btree.h 17710339f7a8f46e3c7d6d0d4648ef19c584ffda
-F src/build.c 6e0310086b8e2deef74f0d4fb3297c4e8fcf6222
+F src/build.c f13728865b6de5eb1ecc61827d334dc881ca1fb5
 F src/delete.c cbd499f3f9297504c42e328af89bef1a2113d04c
 F src/encode.c faf03741efe921755ec371cf4a6984536de00042
 F src/expr.c bd690b3a6174e97a0f16800e78c8aeae749a4e71
@@ -85,7 +85,7 @@ F test/main.test c66b564554b770ee7fdbf6a66c0cd90329bc2c85
 F test/malloc.test 7ba32a9ebd3aeed52ae4aaa6d42ca37e444536fd
 F test/memleak.test b4f59aa44488793b00feff2011d77d0f05b22468
 F test/minmax.test 29bc5727c3e4c792d5c4745833dd4b505905819e
-F test/misc1.test 6d61d1282f2d1f1c184f50e0373d9ffc7d42f744
+F test/misc1.test 2876987a723b4053db081069007cd6aadf80b62b
 F test/misuse.test a3aa2b18a97e4c409a1fcaff5151a4dd804a0162
 F test/notnull.test 7a08117a71e74b0321aaa937dbeb41a09d6eb1d0
 F test/null.test 5c2b57307e4b6178aae825eb65ddbee01e76b0fd
@@ -155,7 +155,7 @@ F www/speed.tcl 4d463e2aea41f688ed320a937f93ff885be918c3
 F www/sqlite.tcl ae3dcfb077e53833b59d4fcc94d8a12c50a44098
 F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331
 F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218
-P 187d9c405891e543fc706f8ddb41f3966a842214
-R e72cd3d7f826c0bad837a962239e2bd9
+P d93c1aeb544a5b1056424945eb43854213b30e50
+R b5d305d3382423fe9540f0b4e0c64173
 U drh
-Z 1c620db2c2b284ab3836973fab10f6c5
+Z cd3aa5a5b1d7b6dd053874302f832e4b
index 79d2a1a139e5a5e28f1a2f6112e7b6c40122dd5c..845cc0f697585e68e0acc3538d2d1373dc67796f 100644 (file)
@@ -1 +1 @@
-d93c1aeb544a5b1056424945eb43854213b30e50
\ No newline at end of file
+65264780c553e8a00ec7a40cf76b89a11b245faf
\ No newline at end of file
index 4e7bf7400b917b855b031fa15d566f98b8d9a013..ade09f24fb43658b06edea7727e91ddca7faf179 100644 (file)
@@ -25,7 +25,7 @@
 **     ROLLBACK
 **     PRAGMA
 **
-** $Id: build.c,v 1.127 2003/01/29 18:46:52 drh Exp $
+** $Id: build.c,v 1.128 2003/02/01 13:53:28 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -820,27 +820,6 @@ void sqliteEndTable(Parse *pParse, Token *pEnd, Select *pSelect){
   p = pParse->pNewTable;
   if( p==0 ) return;
 
-  /* Add the table to the in-memory representation of the database.
-  */
-  assert( pParse->nameClash==0 || pParse->initFlag==1 );
-  if( pParse->explain==0 && pParse->nameClash==0 ){
-    Table *pOld;
-    FKey *pFKey;
-    pOld = sqliteHashInsert(&db->tblHash, p->zName, strlen(p->zName)+1, p);
-    if( pOld ){
-      assert( p==pOld );  /* Malloc must have failed inside HashInsert() */
-      return;
-    }
-    for(pFKey=p->pFKey; pFKey; pFKey=pFKey->pNextFrom){
-      int nTo = strlen(pFKey->zTo) + 1;
-      pFKey->pNextTo = sqliteHashFind(&db->aFKey, pFKey->zTo, nTo);
-      sqliteHashInsert(&db->aFKey, pFKey->zTo, nTo, pFKey);
-    }
-    pParse->pNewTable = 0;
-    db->nTable++;
-    db->flags |= SQLITE_InternChanges;
-  }
-
   /* If the table is generated from a SELECT, then construct the
   ** list of columns and the text of the table.
   */
@@ -924,6 +903,27 @@ void sqliteEndTable(Parse *pParse, Token *pEnd, Select *pSelect){
     }
     sqliteEndWriteOperation(pParse);
   }
+
+  /* Add the table to the in-memory representation of the database.
+  */
+  assert( pParse->nameClash==0 || pParse->initFlag==1 );
+  if( pParse->explain==0 && pParse->nameClash==0 && pParse->nErr==0 ){
+    Table *pOld;
+    FKey *pFKey;
+    pOld = sqliteHashInsert(&db->tblHash, p->zName, strlen(p->zName)+1, p);
+    if( pOld ){
+      assert( p==pOld );  /* Malloc must have failed inside HashInsert() */
+      return;
+    }
+    for(pFKey=p->pFKey; pFKey; pFKey=pFKey->pNextFrom){
+      int nTo = strlen(pFKey->zTo) + 1;
+      pFKey->pNextTo = sqliteHashFind(&db->aFKey, pFKey->zTo, nTo);
+      sqliteHashInsert(&db->aFKey, pFKey->zTo, nTo, pFKey);
+    }
+    pParse->pNewTable = 0;
+    db->nTable++;
+    db->flags |= SQLITE_InternChanges;
+  }
 }
 
 /*
index d365df8c69c586420d23cb49ed49dac3555d1f28..e6063f608542299608db0c1906348f0aecad7263 100644 (file)
@@ -13,7 +13,7 @@
 # This file implements tests for miscellanous features that were
 # left out of other test files.
 #
-# $Id: misc1.test,v 1.19 2003/01/29 18:46:54 drh Exp $
+# $Id: misc1.test,v 1.20 2003/02/01 13:53:28 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -464,5 +464,20 @@ do_test misc1-14.3 {
   file exists ./test.db-journal
 } {0}
 
+# A failed create table should not leave the table in the internal
+# data structures.  Ticket #238.
+#
+do_test misc1-15.1 {
+  catchsql {
+    CREATE TABLE t10 AS SELECT c1;
+  }
+} {1 {no such column: c1}}
+do_test misc1-15.2 {
+  catchsql {
+    CREATE TABLE t10 AS SELECT 1;
+  }
+  # The bug in ticket #238 causes the statement above to fail with
+  # the error "table t10 alread exists"
+} {0 {}}
 
 finish_test