Update the sqlite_sequence table when a table is renamed with ALTER_TABLE. (CVS 2114)

FossilOrigin-Name: 6e971868808e3c3f77fa521de626f1510ba9644a
This commit is contained in:
danielk1977 2004-11-19 08:02:14 +00:00
parent 4d36b81ea0
commit aacd732b11
4 changed files with 53 additions and 17 deletions

View File

@ -1,5 +1,5 @@
C When\sdropping\sa\stable,\supdate\sthe\ssqlite_sequence\stable\sfirst,\sas\sauto-vacuum\smode\smay\sneed\sto\smove\ssqlite_sequence\swhen\sthe\sbtree\stable\sis\sdropped.\s(CVS\s2113)
D 2004-11-19T07:07:31
C Update\sthe\ssqlite_sequence\stable\swhen\sa\stable\sis\srenamed\swith\sALTER_TABLE.\s(CVS\s2114)
D 2004-11-19T08:02:14
F Makefile.in e747bb5ba34ccbdd81f79dcf1b2b33c02817c21d
F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457
F README a01693e454a00cc117967e3f9fdab2d4d52e9bc1
@ -31,7 +31,7 @@ F src/attach.c e49d09dad9f5f9fb10b4b0c1be5a70ae4c45e689
F src/auth.c 3b81f2a42f48a62c2c9c9b0eda31a157c681edea
F src/btree.c 49b09718cd988d1c7c981b03e94679bc10b5f711
F src/btree.h 861e40b759a195ba63819740e484390012cf81ab
F src/build.c 27897ee30d914e503cc948370858ed54c940d4bf
F src/build.c 81422cd1c6a61a4d84fe438638fc3fec8d6c78cb
F src/date.c 65536e7ea04fdde6e0551264fca15966966e171f
F src/delete.c be9d039b819f4a5d0fdfaeceace139ba189ef819
F src/expr.c 4ee3e47358c92a919062255b14057a7a8f641e01
@ -83,7 +83,7 @@ F src/vdbeaux.c c6da55e0096e141211f918837eca98e0be6400b4
F src/vdbemem.c 5876c8abf4374fef671f4fd8dc333ef3fc95a2f0
F src/where.c 4d28167e450255372b45abf1bc8cd5f0e9264d7b
F test/all.test 929bfa932b55e75c96fe2203f7650ba451c1862c
F test/alter.test 627f1c24c80b842b02b94ce7416e9b2498a790eb
F test/alter.test 6337578f49c9dd4e429e5998ea361758b0400255
F test/attach.test e305dd59a375e37c658c6d401f19f8a95880bf9a
F test/attach2.test 399128a7b3b209a339a8dbf53ca2ed42eb982d1a
F test/attach3.test 8a0309e284cf9aa1d7d6cc444989031881f7a21c
@ -259,7 +259,7 @@ F www/tclsqlite.tcl 560ecd6a916b320e59f2917317398f3d59b7cc25
F www/vdbe.tcl 095f106d93875c94b47367384ebc870517431618
F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0
F www/whentouse.tcl fdacb0ba2d39831e8a6240d05a490026ad4c4e4c
P 1fd8e835a3656799c23f4ef6ea1311fecf5a15cb
R f7502d84d016bfe7e59d6b1281918ee0
P 0514107bff970ab1e5ce96c8b1fa13dcbf75cb71
R ee4ef14e815e9448c083988d455f742c
U danielk1977
Z aee34b960e1efd640d84c3f0d865dd8b
Z 9d9ed74db73894f86a8bcc71876d5ed3

View File

@ -1 +1 @@
0514107bff970ab1e5ce96c8b1fa13dcbf75cb71
6e971868808e3c3f77fa521de626f1510ba9644a

View File

@ -22,7 +22,7 @@
** COMMIT
** ROLLBACK
**
** $Id: build.c,v 1.282 2004/11/19 07:07:31 danielk1977 Exp $
** $Id: build.c,v 1.283 2004/11/19 08:02:14 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@ -2996,10 +2996,21 @@ void sqlite3AlterRenameTable(
"'sqlite_autoindex_' || %Q || substr(name, %d+18,10) "
"ELSE name END "
"WHERE tbl_name=%Q AND type IN ('table', 'index', 'trigger');",
db->aDb[iDb].zName, SCHEMA_TABLE(iDb), zName, zName, zName, zName,
zDb, SCHEMA_TABLE(iDb), zName, zName, zName, zName,
zName, strlen(pTab->zName), pTab->zName
);
#ifndef SQLITE_OMIT_AUTOINCREMENT
/* If the sqlite_sequence table exists in this database, then update
** it with the new table name.
*/
if( sqlite3FindTable(db, "sqlite_sequence", zDb) ){
sqlite3NestedParse(pParse,
"UPDATE %Q.sqlite_sequence set name = %Q WHERE name = %Q",
zDb, zName, pTab->zName);
}
#endif
#ifndef SQLITE_OMIT_TRIGGER
/* If there are TEMP triggers on this table, modify the sqlite_temp_master
** table. Don't do this if the table being ALTERed is itself located in

View File

@ -8,7 +8,7 @@
# This file implements regression tests for SQLite library. The
# focus of this script is testing the ALTER TABLE statement.
#
# $Id: alter.test,v 1.4 2004/11/19 05:14:56 danielk1977 Exp $
# $Id: alter.test,v 1.5 2004/11/19 08:02:14 danielk1977 Exp $
#
set testdir [file dirname $argv0]
@ -33,6 +33,7 @@ ifcapable !altertable {
# "CREATE TABLE abc (a, b, c);"
# alter-2.*: Test error conditions and messages.
# alter-3.*: Test ALTER TABLE on tables that have TRIGGERs attached to them.
# alter-4.*: Test ALTER TABLE on tables that have AUTOINCREMENT fields.
#
# Create some tables to rename. Be sure to include some TEMP tables
@ -255,12 +256,8 @@ do_test alter-2.3 {
}
} {1 {there is already another table or index with this name: i3}}
# If this compilation does not include triggers, omit the remainder
# of this file.
ifcapable !trigger {
finish_test
return
}
# If this compilation does not include triggers, omit the alter-3.* tests.
ifcapable trigger {
#-----------------------------------------------------------------------
# Tests alter-3.* test ALTER TABLE on tables that have triggers.
@ -452,4 +449,32 @@ do_test alter-3.3.7 {
}
} {}
} ;# ifcapable trigger
# If the build does not include AUTOINCREMENT fields, omit alter-4.*.
ifcapable autoinc {
do_test alter-4.1 {
execsql {
CREATE TABLE tbl1(a INTEGER PRIMARY KEY AUTOINCREMENT);
INSERT INTO tbl1 VALUES(10);
}
} {}
do_test alter-4.2 {
execsql {
INSERT INTO tbl1 VALUES(NULL);
SELECT a FROM tbl1;
}
} {10 11}
do_test alter-4.3 {
execsql {
ALTER TABLE tbl1 RENAME TO tbl2;
DELETE FROM tbl2;
INSERT INTO tbl2 VALUES(NULL);
SELECT a FROM tbl2;
}
} {12}
} ;# ifcapable autoinc
finish_test