diff options
author | dan <dan@noemail.net> | 2015-07-31 15:13:29 +0000 |
---|---|---|
committer | dan <dan@noemail.net> | 2015-07-31 15:13:29 +0000 |
commit | dd688e797025c3cc8070e868905c1fa1db357c8b (patch) | |
tree | 8b1d2157c4114a24d4515a73201e4e9e64147bfe /tool/sqldiff.c | |
parent | 79e2347fdf389fc0100e973dcfcaba0e84edbe56 (diff) | |
download | sqlite-dd688e797025c3cc8070e868905c1fa1db357c8b.tar.gz sqlite-dd688e797025c3cc8070e868905c1fa1db357c8b.zip |
Fix a problem causing [sqldiff --rbu] to fail on tables for which all columns are part of the PRIMARY KEY.
FossilOrigin-Name: 93449e7046d60cad020ca439ded82e759c2e3cd9
Diffstat (limited to 'tool/sqldiff.c')
-rw-r--r-- | tool/sqldiff.c | 52 |
1 files changed, 29 insertions, 23 deletions
diff --git a/tool/sqldiff.c b/tool/sqldiff.c index 1102a89fc..f5edd6014 100644 --- a/tool/sqldiff.c +++ b/tool/sqldiff.c @@ -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 "); |