mirror of https://github.com/sqlite/sqlite
Fix a problem involving session objects and attached databases.
FossilOrigin-Name: ad91d30073a8faa7eb064dd2e1cc4d2297d7b3f8
This commit is contained in:
parent
1f34f8cc71
commit
d7fb7d24c6
|
@ -34,9 +34,10 @@ proc do_common_sql {sql} {
|
|||
}
|
||||
proc xConflict args { return "OMIT" }
|
||||
|
||||
proc do_then_apply_sql {sql} {
|
||||
sqlite3session S db main
|
||||
db eval {SELECT name FROM sqlite_master WHERE type = 'table'} {
|
||||
proc do_then_apply_sql {sql {dbname main}} {
|
||||
|
||||
sqlite3session S db $dbname
|
||||
db eval "SELECT name FROM $dbname.sqlite_master WHERE type = 'table'" {
|
||||
S attach $name
|
||||
}
|
||||
|
||||
|
@ -171,10 +172,96 @@ foreach {tn sql} {
|
|||
ROLLBACK;
|
||||
}
|
||||
} {
|
||||
if {$tn==9} breakpoint
|
||||
do_then_apply_sql $sql
|
||||
do_test $tn { compare_db db db2 } {}
|
||||
do_test 1.$tn { compare_db db db2 } {}
|
||||
}
|
||||
|
||||
# The following block of tests is similar to the last, except that the
|
||||
# session object is recording changes made to an attached database. The
|
||||
# main database contains a table of the same name as the table being
|
||||
# modified within the attached db.
|
||||
#
|
||||
test_reset
|
||||
forcedelete test.db3
|
||||
sqlite3 db3 test.db3
|
||||
do_test 2.0 {
|
||||
execsql {
|
||||
ATTACH 'test.db3' AS 'aux';
|
||||
CREATE TABLE t1(a, b PRIMARY KEY);
|
||||
CREATE TABLE t2(x, y, z);
|
||||
CREATE TABLE t3(a);
|
||||
|
||||
CREATE TABLE aux.t1(a PRIMARY KEY, b);
|
||||
CREATE TABLE aux.t2(a, b INTEGER PRIMARY KEY);
|
||||
CREATE TABLE aux.t3(a, b, c, PRIMARY KEY(a, b));
|
||||
}
|
||||
execsql {
|
||||
CREATE TABLE t1(a PRIMARY KEY, b);
|
||||
CREATE TABLE t2(a, b INTEGER PRIMARY KEY);
|
||||
CREATE TABLE t3(a, b, c, PRIMARY KEY(a, b));
|
||||
} db2
|
||||
} {}
|
||||
|
||||
foreach {tn sql} {
|
||||
1 { INSERT INTO aux.t1 VALUES(1, 2) }
|
||||
|
||||
2 {
|
||||
INSERT INTO aux.t2 VALUES(1, NULL);
|
||||
INSERT INTO aux.t2 VALUES(2, NULL);
|
||||
INSERT INTO aux.t2 VALUES(3, NULL);
|
||||
DELETE FROM aux.t2 WHERE a = 2;
|
||||
INSERT INTO aux.t2 VALUES(4, NULL);
|
||||
UPDATE aux.t2 SET b=0 WHERE b=1;
|
||||
}
|
||||
|
||||
3 { INSERT INTO aux.t3 SELECT *, NULL FROM aux.t2 }
|
||||
|
||||
4 {
|
||||
INSERT INTO aux.t3 SELECT a||a, b||b, NULL FROM aux.t3;
|
||||
DELETE FROM aux.t3 WHERE rowid%2;
|
||||
}
|
||||
|
||||
5 { UPDATE aux.t3 SET c = a||b }
|
||||
|
||||
6 { UPDATE aux.t1 SET a = 32 }
|
||||
|
||||
7 {
|
||||
INSERT INTO aux.t1 SELECT randomblob(32), randomblob(32) FROM aux.t1;
|
||||
INSERT INTO aux.t1 SELECT randomblob(32), randomblob(32) FROM aux.t1;
|
||||
INSERT INTO aux.t1 SELECT randomblob(32), randomblob(32) FROM aux.t1;
|
||||
INSERT INTO aux.t1 SELECT randomblob(32), randomblob(32) FROM aux.t1;
|
||||
INSERT INTO aux.t1 SELECT randomblob(32), randomblob(32) FROM aux.t1;
|
||||
INSERT INTO aux.t1 SELECT randomblob(32), randomblob(32) FROM aux.t1;
|
||||
INSERT INTO aux.t1 SELECT randomblob(32), randomblob(32) FROM aux.t1;
|
||||
INSERT INTO aux.t1 SELECT randomblob(32), randomblob(32) FROM aux.t1;
|
||||
INSERT INTO aux.t1 SELECT randomblob(32), randomblob(32) FROM aux.t1;
|
||||
INSERT INTO aux.t1 SELECT randomblob(32), randomblob(32) FROM aux.t1;
|
||||
INSERT INTO aux.t1 SELECT randomblob(32), randomblob(32) FROM aux.t1;
|
||||
DELETE FROM aux.t1 WHERE (rowid%3)==0;
|
||||
}
|
||||
|
||||
8 {
|
||||
BEGIN;
|
||||
INSERT INTO aux.t1 SELECT randomblob(32), randomblob(32) FROM aux.t1;
|
||||
ROLLBACK;
|
||||
}
|
||||
9 {
|
||||
BEGIN;
|
||||
UPDATE aux.t1 SET b = 'xxx';
|
||||
ROLLBACK;
|
||||
}
|
||||
10 {
|
||||
BEGIN;
|
||||
DELETE FROM aux.t1 WHERE 1;
|
||||
ROLLBACK;
|
||||
}
|
||||
} {
|
||||
do_then_apply_sql $sql aux
|
||||
do_test 2.$tn { compare_db db3 db2 } {}
|
||||
}
|
||||
|
||||
|
||||
catch {db3 close}
|
||||
|
||||
finish_test
|
||||
|
||||
|
|
|
@ -1191,6 +1191,7 @@ static void sessionAppendUpdate(
|
|||
|
||||
static int sessionSelectStmt(
|
||||
sqlite3 *db, /* Database handle */
|
||||
const char *zDb, /* Database name */
|
||||
const char *zTab, /* Table name */
|
||||
int nCol,
|
||||
const char **azCol,
|
||||
|
@ -1203,6 +1204,8 @@ static int sessionSelectStmt(
|
|||
SessionBuffer buf = {0, 0, 0};
|
||||
|
||||
sessionAppendStr(&buf, "SELECT * FROM ", &rc);
|
||||
sessionAppendIdent(&buf, zDb, &rc);
|
||||
sessionAppendStr(&buf, ".", &rc);
|
||||
sessionAppendIdent(&buf, zTab, &rc);
|
||||
sessionAppendStr(&buf, " WHERE ", &rc);
|
||||
for(i=0; i<nCol; i++){
|
||||
|
@ -1313,6 +1316,7 @@ int sqlite3session_changeset(
|
|||
|
||||
for(pTab=pSession->pTable; rc==SQLITE_OK && pTab; pTab=pTab->pNext){
|
||||
if( pTab->nEntry ){
|
||||
const char *zName = pTab->zName;
|
||||
int nCol = pTab->nCol; /* Local copy of member variable */
|
||||
u8 *abPK = pTab->abPK; /* Local copy of member variable */
|
||||
int i; /* Used to iterate through hash buckets */
|
||||
|
@ -1323,11 +1327,12 @@ int sqlite3session_changeset(
|
|||
/* Write a table header */
|
||||
sessionAppendByte(&buf, 'T', &rc);
|
||||
sessionAppendVarint(&buf, nCol, &rc);
|
||||
sessionAppendBlob(&buf, (u8 *)pTab->zName, strlen(pTab->zName)+1, &rc);
|
||||
sessionAppendBlob(&buf, (u8 *)zName, strlen(zName)+1, &rc);
|
||||
|
||||
/* Build and compile a statement to execute: */
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sessionSelectStmt(db, pTab->zName, nCol, pTab->azCol, abPK, &pSel);
|
||||
rc = sessionSelectStmt(
|
||||
db, pSession->zDb, zName, nCol, pTab->azCol, abPK, &pSel);
|
||||
}
|
||||
|
||||
if( rc==SQLITE_OK && nCol!=sqlite3_column_count(pSel) ){
|
||||
|
@ -1942,7 +1947,8 @@ static int sessionSelectRow(
|
|||
const char *zTab, /* Table name */
|
||||
SessionApplyCtx *p /* Session changeset-apply context */
|
||||
){
|
||||
return sessionSelectStmt(db, zTab, p->nCol, p->azCol, p->abPK, &p->pSelect);
|
||||
return sessionSelectStmt(
|
||||
db, "main", zTab, p->nCol, p->azCol, p->abPK, &p->pSelect);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
14
manifest
14
manifest
|
@ -1,5 +1,5 @@
|
|||
C Fix\sa\sbug\sin\schangeset\sgeneration\scode.
|
||||
D 2011-03-19T18:46:16
|
||||
C Fix\sa\sproblem\sinvolving\ssession\sobjects\sand\sattached\sdatabases.
|
||||
D 2011-03-19T19:19:26
|
||||
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
||||
F Makefile.in 27701a1653595a1f2187dc61c8117e00a6c1d50f
|
||||
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
||||
|
@ -100,8 +100,8 @@ F ext/rtree/sqlite3rtree.h 1af0899c63a688e272d69d8e746f24e76f10a3f0
|
|||
F ext/rtree/tkt3363.test 142ab96eded44a3615ec79fba98c7bde7d0f96de
|
||||
F ext/rtree/viewrtree.tcl eea6224b3553599ae665b239bd827e182b466024
|
||||
F ext/session/session1.test 3f982c74ee4ba97069917cc35aae25b4ed858e6a
|
||||
F ext/session/session2.test 09cbe57d949a315c68fb59822314990fd0e2af33
|
||||
F ext/session/sqlite3session.c 4cb15010040b093e452e6de52e8b5a9161032ebf
|
||||
F ext/session/session2.test 96ff08995ab9935d1992ac554a240052883a0ebc
|
||||
F ext/session/sqlite3session.c d211ce2e95483dfc144494f6c67879d85dddabfa
|
||||
F ext/session/sqlite3session.h 9551c002efd5fde07c52994c6b592308e0df2d6a
|
||||
F ext/session/test_session.c 2559ef68e421c7fb83e2c19ef08a17343b70d535
|
||||
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895
|
||||
|
@ -921,7 +921,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
|||
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
|
||||
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
|
||||
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
|
||||
P c4436a936ab302aec3b7f41a4552f69ad5815744
|
||||
R 633c4c2a52a8f04fd2ba1fea02dc8ad5
|
||||
P 825df75ba453c853953e17ec29653e11c46f92bb
|
||||
R 1e82a0bf18f9b8bb4d549f268721a5ef
|
||||
U dan
|
||||
Z 046a676deaa5ff1f82305a84f859a0a7
|
||||
Z 935cff1eff2f640f29c72314cdd47105
|
||||
|
|
|
@ -1 +1 @@
|
|||
825df75ba453c853953e17ec29653e11c46f92bb
|
||||
ad91d30073a8faa7eb064dd2e1cc4d2297d7b3f8
|
Loading…
Reference in New Issue