Skip to content

Commit db4c848

Browse files
committed
delete empty transactions
1 parent 032b9b7 commit db4c848

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

app/src/org/gnucash/android/db/AccountsDbAdapter.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,9 @@ public boolean destructiveDeleteAccount(long rowId){
279279
}
280280
}
281281
}
282+
// TODO: with "ON DELETE CASCADE", the first two delete will not be necessary.
283+
// deleteRecord(AccountEntry.TABLE_NAME, rowId); will delete related
284+
// transactions and splits
282285
//delete splits in this account
283286
mDb.delete(SplitEntry.TABLE_NAME,
284287
SplitEntry.COLUMN_TRANSACTION_UID + " IN ( SELECT DISTINCT "
@@ -287,6 +290,14 @@ public boolean destructiveDeleteAccount(long rowId){
287290
+ AccountEntry.TABLE_NAME + "_" + AccountEntry.COLUMN_UID
288291
+ " = ? )",
289292
new String[]{getAccountUID(rowId)});
293+
// delete empty transactions
294+
// trans_split_acct is an inner joint, empty transactions will
295+
// not be selected in this view
296+
mDb.delete(TransactionEntry.TABLE_NAME,
297+
TransactionEntry.COLUMN_UID + " NOT IN ( SELECT DISTINCT "
298+
+ TransactionEntry.TABLE_NAME + "_" + TransactionEntry.COLUMN_UID
299+
+ " FROM trans_split_acct",
300+
null);
290301
deleteRecord(AccountEntry.TABLE_NAME, rowId);
291302
mDb.setTransactionSuccessful();
292303
return true;

0 commit comments

Comments
 (0)