mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-07 02:42:48 +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:
@@ -789,8 +789,10 @@ static void getRbudiffQuery(
|
||||
/* Deleted rows: */
|
||||
strPrintf(pSql, "\nUNION ALL\nSELECT ");
|
||||
strPrintfArray(pSql, ", ", "%s", azCol, nPK);
|
||||
strPrintf(pSql, ", ");
|
||||
strPrintfArray(pSql, ", ", "NULL", &azCol[nPK], -1);
|
||||
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,29 +800,33 @@ static void getRbudiffQuery(
|
||||
strPrintfArray(pSql, " AND ", "(n.%Q IS o.%Q)", azCol, nPK);
|
||||
strPrintf(pSql, "\n) ");
|
||||
|
||||
/* Updated rows: */
|
||||
strPrintf(pSql, "\nUNION ALL\nSELECT ");
|
||||
strPrintfArray(pSql, ", ", "n.%s", azCol, nPK);
|
||||
strPrintf(pSql, ",\n");
|
||||
strPrintfArray(pSql, " ,\n",
|
||||
" CASE WHEN n.%s IS o.%s THEN NULL ELSE n.%s END", &azCol[nPK], -1
|
||||
);
|
||||
|
||||
if( bOtaRowid==0 ){
|
||||
strPrintf(pSql, ", '");
|
||||
strPrintfArray(pSql, "", ".", azCol, nPK);
|
||||
strPrintf(pSql, "' ||\n");
|
||||
}else{
|
||||
/* 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");
|
||||
}
|
||||
strPrintfArray(pSql, " ||\n",
|
||||
" CASE WHEN n.%s IS o.%s THEN '.' ELSE 'x' END", &azCol[nPK], -1
|
||||
);
|
||||
strPrintf(pSql, "\nAS ota_control");
|
||||
strPrintfArray(pSql, " ,\n",
|
||||
" CASE WHEN n.%s IS o.%s THEN NULL ELSE n.%s END", &azCol[nPK], -1
|
||||
);
|
||||
|
||||
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%%'");
|
||||
if( bOtaRowid==0 ){
|
||||
strPrintf(pSql, ", '");
|
||||
strPrintfArray(pSql, "", ".", azCol, nPK);
|
||||
strPrintf(pSql, "' ||\n");
|
||||
}else{
|
||||
strPrintf(pSql, ",\n");
|
||||
}
|
||||
strPrintfArray(pSql, " ||\n",
|
||||
" CASE WHEN n.%s IS o.%s THEN '.' ELSE 'x' END", &azCol[nPK], -1
|
||||
);
|
||||
strPrintf(pSql, "\nAS ota_control");
|
||||
|
||||
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