1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

Fix the error message returned by sqlite3session_diff() for tables with no PRIMARY KEY.

FossilOrigin-Name: 4d34a3d40da210bebb2a2e6dff094f9a39c92798
This commit is contained in:
dan
2015-04-23 15:03:14 +00:00
parent dd009f839c
commit 4cc923e3e3
5 changed files with 49 additions and 10 deletions

View File

@ -184,5 +184,36 @@ do_execsql_test 3.0 {
}
do_empty_diff_test 3.1
#-------------------------------------------------------------------------
# Test some error cases:
#
# 1) schema mismatches between the two dbs, and
# 2) tables with no primary keys.
#
reset_db
forcedelete test.db2
do_execsql_test 4.0 {
ATTACH 'test.db2' AS ixua;
CREATE TABLE ixua.t1(a, b, c);
CREATE TABLE main.t1(a, b, c);
CREATE TABLE ixua.t2(a PRIMARY KEY, b, c);
CREATE TABLE main.t2(a PRIMARY KEY, b, x);
}
do_test 4.1 {
sqlite3session S db main
S attach t1
list [catch { S diff ixua t1 } msg] $msg
} {1 {table has no primary key}}
do_test 4.2 {
S attach t2
list [catch { S diff ixua t2 } msg] $msg
} {1 {table schemas do not match}}
S delete
finish_test

View File

@ -1473,18 +1473,21 @@ int sqlite3session_diff(
/* Check the table schemas match */
if( rc==SQLITE_OK ){
int bHasPk = 0;
int nCol; /* Columns in zFrom.zTbl */
u8 *abPK;
const char **azCol = 0;
rc = sessionTableInfo(db, zFrom, zTbl, &nCol, 0, &azCol, &abPK);
if( rc==SQLITE_OK ){
int bMismatch = 0;
if( pTo->nCol!=nCol || memcmp(pTo->abPK, abPK, nCol) ){
if( pTo->nCol!=nCol ){
bMismatch = 1;
}else{
int i;
for(i=0; i<nCol; i++){
if( pTo->abPK[i]!=abPK[i] ) bMismatch = 1;
if( sqlite3_stricmp(azCol[i], pTo->azCol[i]) ) bMismatch = 1;
if( abPK[i] ) bHasPk = 1;
}
}
@ -1492,6 +1495,10 @@ int sqlite3session_diff(
*pzErrMsg = sqlite3_mprintf("table schemas do not match");
rc = SQLITE_ERROR;
}
if( bHasPk==0 ){
*pzErrMsg = sqlite3_mprintf("table has no primary key");
rc = SQLITE_ERROR;
}
}
sqlite3_free(azCol);
}

View File

@ -228,6 +228,7 @@ static int test_session_cmd(
assert( rc!=SQLITE_OK || zErr==0 );
if( zErr ){
Tcl_AppendResult(interp, zErr, 0);
sqlite3_free(zErr);
return TCL_ERROR;
}
if( rc ){

View File

@ -1,5 +1,5 @@
C Fix\sa\sperformance\sproblem\sin\ssqlite3session_diff().
D 2015-04-23T14:40:17.627
C Fix\sthe\serror\smessage\sreturned\sby\ssqlite3session_diff()\sfor\stables\swith\sno\sPRIMARY\sKEY.
D 2015-04-23T15:03:14.997
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 7599f0c96df628cd543884b1b2f2a2fbffd00079
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -158,12 +158,12 @@ F ext/session/session9.test 5409d90d8141881d08285ed1c2c0d8d10fb92069
F ext/session/sessionA.test 1feeab0b8e03527f08f2f1defb442da25480138f
F ext/session/sessionB.test 06961b7c3641151f5d23088250ecad132501113c
F ext/session/sessionC.test 3982f8577b0744c5ce3aaef7cfeb5bd903f17fe4
F ext/session/sessionD.test 197781b4823fbf0003a21da0e4360b37d0e0a81f
F ext/session/sessionD.test bdc20e2384bf92b5719b9e41ad3b18cd9188cf26
F ext/session/session_common.tcl 9de0451b6a47218fc16b9ed8876b6238a0a3d88d
F ext/session/sessionfault.test bef044d0952c0d62c31c8d2400be72c8684545cc
F ext/session/sqlite3session.c de11ba62d7bf5b9a5d732411550771d4ee6b412a
F ext/session/sqlite3session.c 0b26c45c0c3c0b2afaae9bd69ae1e80a6b8e9b5a
F ext/session/sqlite3session.h d9ebd8d4c5791aafdf18165575c7f2223c09279b
F ext/session/test_session.c 037fc25340a918eb2195972fed439d7adf7b5db9
F ext/session/test_session.c 67a049635d910c55917f23d067575ab5432d4546
F ext/userauth/sqlite3userauth.h 19cb6f0e31316d0ee4afdfb7a85ef9da3333a220
F ext/userauth/user-auth.txt e6641021a9210364665fe625d067617d03f27b04
F ext/userauth/userauth.c 5fa3bdb492f481bbc1709fc83c91ebd13460c69e
@ -1271,7 +1271,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P 4e5f17d189eb0578a544c21fc150f9e2ee3428e3
R bb0c0c482394af2863743ccd1d1a9362
P ea400eca314d81761fe5c0e329b906c045f0dfe4
R 57c462c26b9985ec1f9daf86d6b971a1
U dan
Z ee0bd6bc3557d1b9872d331b62e53091
Z dd15ced7dcdddbd36a44e0c8439b0673

View File

@ -1 +1 @@
ea400eca314d81761fe5c0e329b906c045f0dfe4
4d34a3d40da210bebb2a2e6dff094f9a39c92798