From b2359e126756320eecc0b9ac3d400e7ea70840c6 Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Fri, 17 Nov 2017 05:50:00 -0500 Subject: [PATCH] Fixup account transactions to work for both Postgres and MySQL --- internal/handlers/transactions.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/handlers/transactions.go b/internal/handlers/transactions.go index d1b729b..a6adc8e 100644 --- a/internal/handlers/transactions.go +++ b/internal/handlers/transactions.go @@ -623,7 +623,7 @@ func GetAccountTransactions(tx *Tx, user *User, accountid int64, sort string, pa var sqlsort, balanceLimitOffset string var balanceLimitOffsetArg uint64 if sort == "date-asc" { - sqlsort = " ORDER BY transactions.Date ASC" + sqlsort = " ORDER BY transactions.Date ASC, transactions.TransactionId ASC" balanceLimitOffset = " LIMIT ?" balanceLimitOffsetArg = page * limit } else if sort == "date-desc" { @@ -631,7 +631,7 @@ func GetAccountTransactions(tx *Tx, user *User, accountid int64, sort string, pa if err != nil { return nil, err } - sqlsort = " ORDER BY transactions.Date DESC" + sqlsort = " ORDER BY transactions.Date DESC, transactions.TransactionId DESC" balanceLimitOffset = fmt.Sprintf(" LIMIT %d OFFSET ?", numSplits) balanceLimitOffsetArg = (page + 1) * limit } @@ -676,7 +676,7 @@ func GetAccountTransactions(tx *Tx, user *User, accountid int64, sort string, pa // Sum all the splits for all transaction splits for this account that // occurred before the page we're returning var amounts []string - sql = "SELECT s.Amount FROM splits AS s INNER JOIN (SELECT DISTINCT transactions.TransactionId FROM transactions INNER JOIN splits ON transactions.TransactionId = splits.TransactionId WHERE transactions.UserId=? AND splits.AccountId=?" + sqlsort + balanceLimitOffset + ") as t ON s.TransactionId = t.TransactionId WHERE s.AccountId=?" + sql = "SELECT s.Amount FROM splits AS s INNER JOIN (SELECT DISTINCT transactions.Date, transactions.TransactionId FROM transactions INNER JOIN splits ON transactions.TransactionId = splits.TransactionId WHERE transactions.UserId=? AND splits.AccountId=?" + sqlsort + balanceLimitOffset + ") as t ON s.TransactionId = t.TransactionId WHERE s.AccountId=?" _, err = tx.Select(&amounts, sql, user.UserId, accountid, balanceLimitOffsetArg, accountid) if err != nil { return nil, err