Commit 03012f54 authored by Cristian Oneț's avatar Cristian Oneț
Browse files

Fix a crash in reports using the mysql storage backend.

This crash was caused by the fact that the report, after requesting
the transaction list, did not check that the transactions are inside
the requested date interval. Since the date is used to compute an
index in a columns list a date outside the requested interval would
cause an invalid index to be computed and causing the crash.

Now the report performs a validity check of the date after filtering
the transactions.

Also fixed the SQL backend implementation to properly filter by dates
even if an empty split filter is provided. Also added a testcase for
this scenario.

BUG: 312676
(cherry picked from commit cad7ecbc)
parent a313812d
......@@ -1249,6 +1249,21 @@ void MyMoneyDatabaseMgrTest::testTransactionList()
QVERIFY(list.count() == 2);
QVERIFY(list.at(0).id() == "T000000000000000002");
QVERIFY(list.at(1).id() == "T000000000000000001");
// test the date filtering while split filtering is active but with an empty filter
filter.clear();
filter.addPayee(QString());
filter.setDateFilter(QDate(2002, 5, 10), QDate(2002, 5, 10));
list = m->transactionList(filter);
QVERIFY(list.count() == 1);
QVERIFY(list.at(0).id() == "T000000000000000001");
filter.clear();
filter.addAccount(QString());
filter.setDateFilter(QDate(2002, 5, 9), QDate(2002, 5, 9));
list = m->transactionList(filter);
QVERIFY(list.count() == 1);
QVERIFY(list.at(0).id() == "T000000000000000002");
}
void MyMoneyDatabaseMgrTest::testAddPayee()
......
......@@ -3210,10 +3210,10 @@ const QMap<QString, MyMoneyTransaction> MyMoneyStorageSql::fetchTransactions(con
whereClause.append(')');
cbc++;
}
// if the split filter is active, but the where clause is empty
// if the split filter is active, but the where clause and the date filter is empty
// it means we already have all the transactions for the specified filter
// in memory, so just exit
if ((splitFilterActive) && (whereClause.isEmpty())) {
if ((splitFilterActive) && (whereClause.isEmpty()) && (!txFilterActive)) {
qDebug("all transactions already in storage");
return fetchTransactions();
}
......
......@@ -244,10 +244,14 @@ void PivotTable::init(void)
QList<MyMoneyTransaction>::const_iterator it_transaction = transactions.constBegin();
int colofs = columnValue(m_beginDate) - 1;
while (it_transaction != transactions.constEnd()) {
QDate postdate = (*it_transaction).postDate();
int column = columnValue(postdate) - colofs;
MyMoneyTransaction tx = (*it_transaction);
QDate postdate = tx.postDate();
if (postdate < m_beginDate) {
qDebug("MyMoneyFile::transactionList returned a transaction that is outside the date filter, skipping it");
++it_transaction;
continue;
}
int column = columnValue(postdate) - colofs;
// check if we need to call the autocalculation routine
if (tx.isLoanPayment() && tx.hasAutoCalcSplit() && (tx.value("kmm-schedule-id").length() > 0)) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment