mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-08 14:02:16 +03:00
Fix a problem causing [sqldiff --rbu] to fail on tables for which all columns are part of the PRIMARY KEY.
FossilOrigin-Name: 93449e7046d60cad020ca439ded82e759c2e3cd9
This commit is contained in:
@@ -53,17 +53,21 @@ proc apply_rbudiff {sql target} {
|
||||
}
|
||||
|
||||
proc rbudiff_cksum {db1} {
|
||||
set txt ""
|
||||
|
||||
sqlite3 dbtmp $db1
|
||||
set txt [dbtmp eval {
|
||||
SELECT a || '.' || b || '.' || c FROM t1 ORDER BY 1;
|
||||
SELECT a || '.' || b || '.' || c FROM t2 ORDER BY 1;
|
||||
}]
|
||||
foreach tbl [dbtmp eval {SELECT name FROM sqlite_master WHERE type='table'}] {
|
||||
append txt [dbtmp eval \
|
||||
"SELECT a || '.' || b || '.' || c FROM $tbl ORDER BY 1"
|
||||
]
|
||||
}
|
||||
dbtmp close
|
||||
|
||||
md5 $txt
|
||||
}
|
||||
|
||||
sqlite3 db test.db
|
||||
do_execsql_test 1.0 {
|
||||
foreach {tn init mod} {
|
||||
1 {
|
||||
CREATE TABLE t1(a PRIMARY KEY, b, c);
|
||||
INSERT INTO t1 VALUES(1, 2, 3);
|
||||
INSERT INTO t1 VALUES(4, 5, 6);
|
||||
@@ -71,14 +75,7 @@ do_execsql_test 1.0 {
|
||||
CREATE TABLE t2(a, b, c, PRIMARY KEY(b, c));
|
||||
INSERT INTO t2 VALUES(1, 2, 3);
|
||||
INSERT INTO t2 VALUES(4, 5, 6);
|
||||
}
|
||||
|
||||
db close
|
||||
forcedelete test.db2
|
||||
forcecopy test.db test.db2
|
||||
|
||||
sqlite3 db test.db
|
||||
do_execsql_test 1.1 {
|
||||
} {
|
||||
INSERT INTO t1 VALUES(7, 8, 9);
|
||||
DELETE FROM t1 WHERE a=4;
|
||||
UPDATE t1 SET c = 11 WHERE a = 1;
|
||||
@@ -87,14 +84,46 @@ do_execsql_test 1.1 {
|
||||
DELETE FROM t2 WHERE a=4;
|
||||
UPDATE t2 SET c = 11 WHERE a = 1;
|
||||
}
|
||||
|
||||
2 {
|
||||
CREATE TABLE t1(a, b, c, PRIMARY KEY(a, b, c));
|
||||
INSERT INTO t1 VALUES('u', 'v', 'w');
|
||||
INSERT INTO t1 VALUES('x', 'y', 'z');
|
||||
} {
|
||||
DELETE FROM t1 WHERE a='u';
|
||||
INSERT INTO t1 VALUES('a', 'b', 'c');
|
||||
}
|
||||
|
||||
} {
|
||||
|
||||
catch { db close }
|
||||
|
||||
forcedelete test.db test.db2
|
||||
sqlite3 db test.db
|
||||
db eval "$init"
|
||||
sqlite3 db test.db2
|
||||
db eval "$init ; $mod"
|
||||
db close
|
||||
|
||||
do_test 1.2 {
|
||||
do_test 1.$tn.2 {
|
||||
set sql [get_rbudiff_sql test.db test.db2]
|
||||
apply_rbudiff $sql test.db
|
||||
} {SQLITE_DONE}
|
||||
do_test 1.$tn.3 { rbudiff_cksum test.db } [rbudiff_cksum test.db2]
|
||||
|
||||
do_test 1.3 { rbudiff_cksum test.db } [rbudiff_cksum test.db2]
|
||||
forcedelete test.db test.db2
|
||||
sqlite3 db test.db
|
||||
db eval "$init ; $mod"
|
||||
sqlite3 db test.db2
|
||||
db eval "$init"
|
||||
db close
|
||||
|
||||
do_test 1.$tn.4 {
|
||||
set sql [get_rbudiff_sql test.db test.db2]
|
||||
apply_rbudiff $sql test.db
|
||||
} {SQLITE_DONE}
|
||||
do_test 1.$tn.5 { rbudiff_cksum test.db } [rbudiff_cksum test.db2]
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
||||
|
14
manifest
14
manifest
@@ -1,5 +1,5 @@
|
||||
C Fix\sa\sbug\sin\sthe\sfts5\sporter\stokenizer\spreventing\sit\sfrom\spassing\sxCreate()\sarguments\sthrough\sto\sits\sparent\stokenizer.
|
||||
D 2015-07-31T14:43:02.175
|
||||
C Fix\sa\sproblem\scausing\s[sqldiff\s--rbu]\sto\sfail\son\stables\sfor\swhich\sall\scolumns\sare\spart\sof\sthe\sPRIMARY\sKEY.
|
||||
D 2015-07-31T15:13:29.192
|
||||
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
||||
F Makefile.in 4de3ef40c8b3b75c0c55ff4242a43c8ce1ad90ee
|
||||
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
||||
@@ -215,7 +215,7 @@ F ext/rbu/rbu8.test 3bbf2c35d71a843c463efe93946f14ad10c3ede0
|
||||
F ext/rbu/rbu9.test 0806d1772c9f4981774ff028de6656e4183082af
|
||||
F ext/rbu/rbuA.test c1a7b3e2d926b8f8448bb3b4ae787e314ee4b2b3
|
||||
F ext/rbu/rbucrash.test 8d2ed5d4b05fef6c00c2a6b5f7ead71fa172a695
|
||||
F ext/rbu/rbudiff.test deba11b97a41163e39de49d7455eb6429d0bd510
|
||||
F ext/rbu/rbudiff.test fbc3aa567927ac0141d4fe2d92c182e39a7b761f
|
||||
F ext/rbu/rbufault.test cc0be8d5d392d98b0c2d6a51be377ea989250a89
|
||||
F ext/rbu/rbufault2.test 9a7f19edd6ea35c4c9f807d8a3db0a03a5670c06
|
||||
F ext/rbu/rbufts.test 17db7d968b3d073788bcba044c498d09e830726b
|
||||
@@ -1357,7 +1357,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
||||
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
|
||||
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
|
||||
F tool/split-sqlite3c.tcl d9be87f1c340285a3e081eb19b4a247981ed290c
|
||||
F tool/sqldiff.c 7ed3a042126755e87266c3e1dbbce39a20455a1f
|
||||
F tool/sqldiff.c 664fbb0e99c0feea42512aaab544b635892b1813
|
||||
F tool/stack_usage.tcl f8e71b92cdb099a147dad572375595eae55eca43
|
||||
F tool/symbols-mingw.sh 4dbcea7e74768305384c9fd2ed2b41bbf9f0414d
|
||||
F tool/symbols.sh fec58532668296d7c7dc48be9c87f75ccdb5814f
|
||||
@@ -1368,7 +1368,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
|
||||
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
|
||||
F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b
|
||||
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
|
||||
P 098bea26da4533d9ad97a85687cca56fb0d764a4
|
||||
R 8a1feb7aa96f289823fcad1b81aa7445
|
||||
P c3c672af97edf2ae5d793f6fa47364370aa4f4ec
|
||||
R b15a02058aabdd16b9a14979e1d956cd
|
||||
U dan
|
||||
Z c5878e3f2569723ede9a1179817f20fd
|
||||
Z f7d27995d6acc03880e556f3a3ff2a8c
|
||||
|
@@ -1 +1 @@
|
||||
c3c672af97edf2ae5d793f6fa47364370aa4f4ec
|
||||
93449e7046d60cad020ca439ded82e759c2e3cd9
|
@@ -789,8 +789,10 @@ static void getRbudiffQuery(
|
||||
/* Deleted rows: */
|
||||
strPrintf(pSql, "\nUNION ALL\nSELECT ");
|
||||
strPrintfArray(pSql, ", ", "%s", azCol, nPK);
|
||||
if( azCol[nPK] ){
|
||||
strPrintf(pSql, ", ");
|
||||
strPrintfArray(pSql, ", ", "NULL", &azCol[nPK], -1);
|
||||
}
|
||||
strPrintf(pSql, ", 1"); /* Set ota_control to 1 for a delete */
|
||||
strPrintf(pSql, " FROM main.%Q AS n WHERE NOT EXISTS (\n", zTab);
|
||||
strPrintf(pSql, " SELECT 1 FROM ", zTab);
|
||||
@@ -798,7 +800,10 @@ static void getRbudiffQuery(
|
||||
strPrintfArray(pSql, " AND ", "(n.%Q IS o.%Q)", azCol, nPK);
|
||||
strPrintf(pSql, "\n) ");
|
||||
|
||||
/* Updated rows: */
|
||||
/* Updated rows. If all table columns are part of the primary key, there
|
||||
** can be no updates. In this case this part of the compound SELECT can
|
||||
** be omitted altogether. */
|
||||
if( azCol[nPK] ){
|
||||
strPrintf(pSql, "\nUNION ALL\nSELECT ");
|
||||
strPrintfArray(pSql, ", ", "n.%s", azCol, nPK);
|
||||
strPrintf(pSql, ",\n");
|
||||
@@ -821,6 +826,7 @@ static void getRbudiffQuery(
|
||||
strPrintf(pSql, "\nFROM main.%Q AS o, aux.%Q AS n\nWHERE ", zTab, zTab);
|
||||
strPrintfArray(pSql, " AND ", "(n.%Q IS o.%Q)", azCol, nPK);
|
||||
strPrintf(pSql, " AND ota_control LIKE '%%x%%'");
|
||||
}
|
||||
|
||||
/* Now add an ORDER BY clause to sort everything by PK. */
|
||||
strPrintf(pSql, "\nORDER BY ");
|
||||
|
Reference in New Issue
Block a user