]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Omit the TEMP keyword from the schema of TEMP tables created using
authordrh <drh@noemail.net>
Mon, 2 Feb 2009 18:03:21 +0000 (18:03 +0000)
committerdrh <drh@noemail.net>
Mon, 2 Feb 2009 18:03:21 +0000 (18:03 +0000)
CREATE TEMP TABLE AS SELECT .....  Ticket #3630. (CVS 6232)

FossilOrigin-Name: 3b0a25548c4c15c86aadcd9a6c3af0adafb85c17

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

index 5986bf2af4168392757e7f4de965181daa65d654..a7668f3312faf53f6c8eec963ae77109eb33c57e 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Minor\ssimplifications\sto\sSQL\sfunction\simplementations.\s(CVS\s6231)
-D 2009-02-02T17:30:00
+C Omit\sthe\sTEMP\skeyword\sfrom\sthe\sschema\sof\sTEMP\stables\screated\susing\nCREATE\sTEMP\sTABLE\sAS\sSELECT\s.....\s\sTicket\s#3630.\s(CVS\s6232)
+D 2009-02-02T18:03:22
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in 3871d308188cefcb7c5ab20da4c7b6aad023bc52
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -106,7 +106,7 @@ F src/btmutex.c 63c5cc4ad5715690767ffcb741e185d7bc35ec1a
 F src/btree.c dfbbfc396fdd8cbc29754864a97c4df484b78870
 F src/btree.h 07359623fa24748709dd61212a32364a6adc6b56
 F src/btreeInt.h 44bcbfe387ba99a3a9f2527bd12fa1bb8bc574b3
-F src/build.c c8bf5dcef4d5889bc57eecdb8b3dba178e5e06a8
+F src/build.c 691354249a4a56ff09e370a13092e70ac1160f3c
 F src/callback.c 5f10bca853e59a2c272bbfd5b720303f8b69e520
 F src/complete.c cb14e06dbe79dee031031f0d9e686ff306afe07c
 F src/date.c 870770dde3fb56772ab247dfb6a6eda44d16cfbc
@@ -214,6 +214,7 @@ F test/all.test 14165b3e32715b700b5f0cbf8f6e3833dda0be45
 F test/alter.test 6353aae6839e486c9b7d8f73b1f4a1e98e57332c
 F test/alter2.test dd55146e812622c8fc51fd2216bcd8dca8880752
 F test/alter3.test 25b95a136708f22b87184fa6a4309eea03d65153
+F test/alter4.test 9386ffd1e9c7245f43eca412b2058d747509cc1f
 F test/altermalloc.test e81ac9657ed25c6c5bb09bebfa5a047cd8e4acfc
 F test/analyze.test ad5329098fe4de4a96852231d53e3e9e6283ad4b
 F test/async.test 0ed384c12d556ce38a4fe21fd41cda7e6dbf55be
@@ -614,6 +615,7 @@ F test/tkt3541.test 5dc257bde9bc833ab9cc6844bf170b998dbb950a
 F test/tkt3554.test 0463fea3650ac18d3694a8f39e6e25cddc1ac1fc
 F test/tkt3581.test 1966b7193f1e3f14951cce8c66907ae69454e9a3
 F test/tkt35xx.test 53bca895091e968126a858ee7da186f59f328994
+F test/tkt3630.test 929f64852103054125200bc825c316d5f75d42f7
 F test/tokenize.test ce430a7aed48fc98301611429595883fdfcab5d7
 F test/trace.test 951cd0f5f571e7f36bf7bfe04be70f90fb16fb00
 F test/trans.test b3f0c696ddf8c3f113fd2edf49318b2bf431c99a
@@ -693,7 +695,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
-P 5fc125d362df4b8525c7e1ab34a14f505756af24
-R b7f789dd91f22c5545aa187a43c65833
+P 92e5c27f20f150c1777c1b91d35207ade961319d
+R ea477193cacfc00fd0ed1607f173f41d
 U drh
-Z 4951ab79196ed7bd6ab94577ec125524
+Z d6cd04b7b570fe870dc266c2d4bae7bf
index 1599e813ead9eeef2185c68105b104a40cf9532f..493147f1958c8cd848bf86530985bcdaf617c0e7 100644 (file)
@@ -1 +1 @@
-92e5c27f20f150c1777c1b91d35207ade961319d
\ No newline at end of file
+3b0a25548c4c15c86aadcd9a6c3af0adafb85c17
\ No newline at end of file
index 27ded7ebb08293822798f926294e9f8b415c0342..acf602fb185e2c03c6adf65ab944052caa1a0d76 100644 (file)
@@ -22,7 +22,7 @@
 **     COMMIT
 **     ROLLBACK
 **
-** $Id: build.c,v 1.512 2009/01/20 16:53:40 danielk1977 Exp $
+** $Id: build.c,v 1.513 2009/02/02 18:03:22 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -1386,8 +1386,7 @@ static char *createTableStmt(sqlite3 *db, Table *p, int isTemp){
     db->mallocFailed = 1;
     return 0;
   }
-  sqlite3_snprintf(n, zStmt,
-                  !OMIT_TEMPDB&&isTemp ? "CREATE TEMP TABLE ":"CREATE TABLE ");
+  sqlite3_snprintf(n, zStmt, "CREATE TABLE ");
   k = sqlite3Strlen30(zStmt);
   identPut(zStmt, &k, p->zName);
   zStmt[k++] = '(';
diff --git a/test/alter4.test b/test/alter4.test
new file mode 100644 (file)
index 0000000..992e0db
--- /dev/null
@@ -0,0 +1,397 @@
+# 2009 February 2
+#
+# 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 script is testing that SQLite can handle a subtle 
+# file format change that may be used in the future to implement
+# "ALTER TABLE ... ADD COLUMN".
+#
+# $Id: alter4.test,v 1.1 2009/02/02 18:03:22 drh Exp $
+#
+
+set testdir [file dirname $argv0]
+
+source $testdir/tester.tcl
+
+# If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
+ifcapable !altertable {
+  finish_test
+  return
+}
+
+# Determine if there is a codec available on this test.
+#
+if {[catch {sqlite3 -has_codec} r] || $r} {
+  set has_codec 1
+} else {
+  set has_codec 0
+}
+
+
+# Test Organisation:
+# ------------------
+#
+# alter4-1.*: Test that ALTER TABLE correctly modifies the CREATE TABLE sql.
+# alter4-2.*: Test error messages.
+# alter4-3.*: Test adding columns with default value NULL.
+# alter4-4.*: Test adding columns with default values other than NULL.
+# alter4-5.*: Test adding columns to tables in ATTACHed databases.
+# alter4-6.*: Test that temp triggers are not accidentally dropped.
+# alter4-7.*: Test that VACUUM resets the file-format.
+#
+
+# This procedure returns the value of the file-format in file 'test.db'.
+# 
+proc get_file_format {{fname test.db}} {
+  return [hexio_get_int [hexio_read $fname 44 4]]
+}
+
+do_test alter4-1.1 {
+  execsql {
+    CREATE TEMP TABLE abc(a, b, c);
+    SELECT sql FROM sqlite_temp_master;
+  }
+} {{CREATE TABLE abc(a, b, c)}}
+do_test alter4-1.2 {
+  execsql {ALTER TABLE abc ADD d INTEGER;}
+  execsql {
+    SELECT sql FROM sqlite_temp_master;
+  }
+} {{CREATE TABLE abc(a, b, c, d INTEGER)}}
+do_test alter4-1.3 {
+  execsql {ALTER TABLE abc ADD e}
+  execsql {
+    SELECT sql FROM sqlite_temp_master;
+  }
+} {{CREATE TABLE abc(a, b, c, d INTEGER, e)}}
+do_test alter4-1.4 {
+  execsql {
+    CREATE TABLE temp.t1(a, b);
+    ALTER TABLE t1 ADD c;
+    SELECT sql FROM sqlite_temp_master WHERE tbl_name = 't1';
+  }
+} {{CREATE TABLE t1(a, b, c)}}
+do_test alter4-1.5 {
+  execsql {
+    ALTER TABLE t1 ADD d CHECK (a>d);
+    SELECT sql FROM sqlite_temp_master WHERE tbl_name = 't1';
+  }
+} {{CREATE TABLE t1(a, b, c, d CHECK (a>d))}}
+ifcapable foreignkey {
+  do_test alter4-1.6 {
+    execsql {
+      CREATE TEMP TABLE t2(a, b, UNIQUE(a, b));
+      ALTER TABLE t2 ADD c REFERENCES t1(c)  ;
+      SELECT sql FROM sqlite_temp_master
+       WHERE tbl_name = 't2' AND type = 'table';
+    }
+  } {{CREATE TABLE t2(a, b, c REFERENCES t1(c), UNIQUE(a, b))}}
+}
+do_test alter4-1.7 {
+  execsql {
+    CREATE TEMPORARY TABLE t3(a, b, UNIQUE(a, b));
+    ALTER TABLE t3 ADD COLUMN c VARCHAR(10, 20);
+    SELECT sql FROM sqlite_temp_master
+     WHERE tbl_name = 't3' AND type = 'table';
+  }
+} {{CREATE TABLE t3(a, b, c VARCHAR(10, 20), UNIQUE(a, b))}}
+do_test alter4-1.99 {
+  catchsql {
+    # May not exist if foriegn-keys are omitted at compile time.
+    DROP TABLE t2; 
+  }
+  execsql {
+    DROP TABLE abc; 
+    DROP TABLE t1; 
+    DROP TABLE t3; 
+  }
+} {}
+
+do_test alter4-2.1 {
+  execsql {
+    CREATE TABLE temp.t1(a, b);
+  }
+  catchsql {
+    ALTER TABLE t1 ADD c PRIMARY KEY;
+  }
+} {1 {Cannot add a PRIMARY KEY column}}
+do_test alter4-2.2 {
+  catchsql {
+    ALTER TABLE t1 ADD c UNIQUE
+  }
+} {1 {Cannot add a UNIQUE column}}
+do_test alter4-2.3 {
+  catchsql {
+    ALTER TABLE t1 ADD b VARCHAR(10)
+  }
+} {1 {duplicate column name: b}}
+do_test alter4-2.3 {
+  catchsql {
+    ALTER TABLE t1 ADD c NOT NULL;
+  }
+} {1 {Cannot add a NOT NULL column with default value NULL}}
+do_test alter4-2.4 {
+  catchsql {
+    ALTER TABLE t1 ADD c NOT NULL DEFAULT 10;
+  }
+} {0 {}}
+ifcapable view {
+  do_test alter4-2.5 {
+    execsql {
+      CREATE TEMPORARY VIEW v1 AS SELECT * FROM t1;
+    }
+    catchsql {
+      alter table v1 add column d;
+    }
+  } {1 {Cannot add a column to a view}}
+}
+do_test alter4-2.6 {
+  catchsql {
+    alter table t1 add column d DEFAULT CURRENT_TIME;
+  }
+} {1 {Cannot add a column with non-constant default}}
+do_test alter4-2.99 {
+  execsql {
+    DROP TABLE t1;
+  }
+} {}
+
+do_test alter4-3.1 {
+  execsql {
+    CREATE TEMP TABLE t1(a, b);
+    INSERT INTO t1 VALUES(1, 100);
+    INSERT INTO t1 VALUES(2, 300);
+    SELECT * FROM t1;
+  }
+} {1 100 2 300}
+do_test alter4-3.1 {
+  execsql {
+    PRAGMA schema_version = 10;
+  }
+} {}
+do_test alter4-3.2 {
+  execsql {
+    ALTER TABLE t1 ADD c;
+    SELECT * FROM t1;
+  }
+} {1 100 {} 2 300 {}}
+if {!$has_codec} {
+  do_test alter4-3.3 {
+    get_file_format
+  } {3}
+}
+ifcapable schema_version {
+  do_test alter4-3.4 {
+    execsql {
+      PRAGMA schema_version;
+    }
+  } {10}
+}
+
+do_test alter4-4.1 {
+  db close
+  file delete -force test.db
+  set ::DB [sqlite3 db test.db]
+  execsql {
+    CREATE TEMP TABLE t1(a, b);
+    INSERT INTO t1 VALUES(1, 100);
+    INSERT INTO t1 VALUES(2, 300);
+    SELECT * FROM t1;
+  }
+} {1 100 2 300}
+do_test alter4-4.1 {
+  execsql {
+    PRAGMA schema_version = 20;
+  }
+} {}
+do_test alter4-4.2 {
+  execsql {
+    ALTER TABLE t1 ADD c DEFAULT 'hello world';
+    SELECT * FROM t1;
+  }
+} {1 100 {hello world} 2 300 {hello world}}
+if {!$has_codec} {
+  do_test alter4-4.3 {
+    get_file_format
+  } {3}
+}
+ifcapable schema_version {
+  do_test alter4-4.4 {
+    execsql {
+      PRAGMA schema_version;
+    }
+  } {20}
+}
+do_test alter4-4.99 {
+  execsql {
+    DROP TABLE t1;
+  }
+} {}
+
+ifcapable attach {
+  do_test alter4-5.1 {
+    file delete -force test2.db
+    file delete -force test2.db-journal
+    execsql {
+      CREATE TEMP TABLE t1(a, b);
+      INSERT INTO t1 VALUES(1, 'one');
+      INSERT INTO t1 VALUES(2, 'two');
+      ATTACH 'test2.db' AS aux;
+      CREATE TABLE aux.t1 AS SELECT * FROM t1;
+      PRAGMA aux.schema_version = 30;
+      SELECT sql FROM aux.sqlite_master;
+    } 
+  } {{CREATE TABLE t1(a,b)}}
+  do_test alter4-5.2 {
+    execsql {
+      ALTER TABLE aux.t1 ADD COLUMN c VARCHAR(128);
+      SELECT sql FROM aux.sqlite_master;
+    }
+  } {{CREATE TABLE t1(a,b, c VARCHAR(128))}}
+  do_test alter4-5.3 {
+    execsql {
+      SELECT * FROM aux.t1;
+    }
+  } {1 one {} 2 two {}}
+  ifcapable schema_version {
+    do_test alter4-5.4 {
+      execsql {
+        PRAGMA aux.schema_version;
+      }
+    } {31}
+  }
+  if {!$has_codec} {
+    do_test alter4-5.5 {
+      list [get_file_format test2.db] [get_file_format]
+    } {2 3}
+  }
+  do_test alter4-5.6 {
+    execsql {
+      ALTER TABLE aux.t1 ADD COLUMN d DEFAULT 1000;
+      SELECT sql FROM aux.sqlite_master;
+    }
+  } {{CREATE TABLE t1(a,b, c VARCHAR(128), d DEFAULT 1000)}}
+  do_test alter4-5.7 {
+    execsql {
+      SELECT * FROM aux.t1;
+    }
+  } {1 one {} 1000 2 two {} 1000}
+  ifcapable schema_version {
+    do_test alter4-5.8 {
+      execsql {
+        PRAGMA aux.schema_version;
+      }
+    } {32}
+  }
+  do_test alter4-5.9 {
+    execsql {
+      SELECT * FROM t1;
+    }
+  } {1 one 2 two}
+  do_test alter4-5.99 {
+    execsql {
+      DROP TABLE aux.t1;
+      DROP TABLE t1;
+    }
+  } {}
+}
+
+#----------------------------------------------------------------
+# Test that the table schema is correctly reloaded when a column
+# is added to a table.
+#
+ifcapable trigger&&tempdb {
+  do_test alter4-6.1 {
+    execsql {
+      CREATE TEMP TABLE t1(a, b);
+      CREATE TEMP TABLE log(trig, a, b);
+
+      CREATE TRIGGER t1_a AFTER INSERT ON t1 BEGIN
+        INSERT INTO log VALUES('a', new.a, new.b);
+      END;
+      CREATE TEMP TRIGGER t1_b AFTER INSERT ON t1 BEGIN
+        INSERT INTO log VALUES('b', new.a, new.b);
+      END;
+  
+      INSERT INTO t1 VALUES(1, 2);
+      SELECT * FROM log;
+    }
+  } {b 1 2 a 1 2}
+  do_test alter4-6.2 {
+    execsql {
+      ALTER TABLE t1 ADD COLUMN c DEFAULT 'c';
+      INSERT INTO t1(a, b) VALUES(3, 4);
+      SELECT * FROM log;
+    }
+  } {b 1 2 a 1 2 b 3 4 a 3 4}
+}
+
+if {!$has_codec} {
+  ifcapable vacuum {
+    do_test alter4-7.1 {
+      execsql {
+        VACUUM;
+      }
+      get_file_format
+    } {1}
+    do_test alter4-7.2 {
+      execsql {
+        CREATE TEMP TABLE abc(a, b, c);
+        ALTER TABLE abc ADD d DEFAULT NULL;
+      }
+      get_file_format
+    } {2}
+    do_test alter4-7.3 {
+      execsql {
+        ALTER TABLE abc ADD e DEFAULT 10;
+      }
+      get_file_format
+    } {3}
+    do_test alter4-7.4 {
+      execsql {
+        ALTER TABLE abc ADD f DEFAULT NULL;
+      }
+      get_file_format
+    } {3}
+    do_test alter4-7.5 {
+      execsql {
+        VACUUM;
+      }
+      get_file_format
+    } {1}
+  }
+}
+
+# Ticket #1183 - Make sure adding columns to large tables does not cause
+# memory corruption (as was the case before this bug was fixed).
+do_test alter4-8.1 {
+  execsql {
+    CREATE TEMP TABLE t4(c1);
+  }
+} {}
+set ::sql ""
+do_test alter4-8.2 {
+  set cols c1
+  for {set i 2} {$i < 100} {incr i} {
+    execsql "
+      ALTER TABLE t4 ADD c$i
+    "
+    lappend cols c$i
+  }
+  set ::sql "CREATE TABLE t4([join $cols {, }])"
+  list 
+} {}
+do_test alter4-8.2 {
+  execsql {
+    SELECT sql FROM sqlite_temp_master WHERE name = 't4';
+  }
+} [list $::sql]
+
+finish_test
diff --git a/test/tkt3630.test b/test/tkt3630.test
new file mode 100644 (file)
index 0000000..b329c48
--- /dev/null
@@ -0,0 +1,47 @@
+# 2009 February 2
+#
+# 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 checks to make sure the "TEMP" or "TEMPORARY" keyword is
+# omitted from the schema of a table that is created using that
+# keyword.  Ticket #3630.
+#
+# $Id: tkt3630.test,v 1.1 2009/02/02 18:03:22 drh Exp $
+#
+
+set testdir [file dirname $argv0]
+
+source $testdir/tester.tcl
+
+do_test tkt3630-1 {
+  db eval {
+    CREATE TEMP TABLE temp1(a,b,c);
+    SELECT * FROM sqlite_temp_master WHERE sql GLOB '*TEMP*';
+  }
+} {}
+do_test tkt3630-2 {
+  db eval {
+    CREATE TABLE main1(a,b,c);
+    CREATE TEMP TABLE temp2 AS SELECT * FROM main1;
+    SELECT * FROM sqlite_temp_master WHERE sql GLOB '*TEMP*';
+  }
+} {}
+
+ifcapable altertable {
+  do_test tkt3630-3 {
+    db eval {
+      ALTER TABLE temp2 ADD COLUMN d;
+      ALTER TABLE temp2 RENAME TO temp2rn;
+      SELECT name FROM sqlite_temp_master WHERE name LIKE 'temp2%';
+    }
+  } {temp2rn}
+}
+
+finish_test