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

Improve the error messages returned by sqlite3session_diff().

FossilOrigin-Name: a3217cdb75fd305705856f6504f8816c2b6b0a10907725cb74d025a5c4e369b8
This commit is contained in:
dan
2025-04-10 16:48:04 +00:00
parent 08122e96fe
commit da00cc101c
5 changed files with 85 additions and 21 deletions

View File

@ -2229,17 +2229,43 @@ int sqlite3session_diff(
if( rc==SQLITE_OK ){
int bHasPk = 0;
int bMismatch = 0;
int nCol; /* Columns in zFrom.zTbl */
int nCol = 0; /* Columns in zFrom.zTbl */
int bRowid = 0;
u8 *abPK;
u8 *abPK = 0;
const char **azCol = 0;
rc = sessionTableInfo(0, db, zFrom, zTbl,
&nCol, 0, 0, &azCol, 0, 0, &abPK,
pSession->bImplicitPK ? &bRowid : 0
);
char *zDbExists = 0;
/* Check that database zFrom is attached. */
zDbExists = sqlite3_mprintf("SELECT * FROM %Q.sqlite_schema", zFrom);
if( zDbExists==0 ){
rc = SQLITE_NOMEM;
}else{
sqlite3_stmt *pDbExists = 0;
rc = sqlite3_prepare_v2(db, zDbExists, -1, &pDbExists, 0);
if( rc==SQLITE_ERROR ){
rc = SQLITE_OK;
nCol = -1;
}
sqlite3_finalize(pDbExists);
sqlite3_free(zDbExists);
}
if( rc==SQLITE_OK && nCol==0 ){
rc = sessionTableInfo(0, db, zFrom, zTbl,
&nCol, 0, 0, &azCol, 0, 0, &abPK,
pSession->bImplicitPK ? &bRowid : 0
);
}
if( rc==SQLITE_OK ){
if( pTo->nCol!=nCol ){
bMismatch = 1;
if( nCol<=0 ){
rc = SQLITE_SCHEMA;
if( pzErrMsg ){
*pzErrMsg = sqlite3_mprintf("no such table: %s.%s", zFrom, zTbl);
}
}else{
bMismatch = 1;
}
}else{
int i;
for(i=0; i<nCol; i++){