Mercurial > hg > syntilista
comparison src/main.cpp @ 179:a2f11e6665d6
Add some comments.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 02 Oct 2017 13:39:58 +0300 |
parents | 2155e05bf61c |
children | ee5479079238 |
comparison
equal
deleted
inserted
replaced
178:2155e05bf61c | 179:a2f11e6665d6 |
---|---|
1041 // | 1041 // |
1042 // Add one transaction to given person id | 1042 // Add one transaction to given person id |
1043 // | 1043 // |
1044 int SyntilistaMainWindow::addTransaction(qint64 id, double value, SLPersonInfo &info) | 1044 int SyntilistaMainWindow::addTransaction(qint64 id, double value, SLPersonInfo &info) |
1045 { | 1045 { |
1046 // Sanity check: Check if the given person ID exists | |
1046 if (!slGetPersonInfo(id, info)) | 1047 if (!slGetPersonInfo(id, info)) |
1047 return -1; | 1048 return -1; |
1048 | 1049 |
1049 QSqlDatabase::database().transaction(); | 1050 QSqlDatabase::database().transaction(); |
1050 | 1051 |
1052 // Add transaction entry | |
1051 QSqlQuery query; | 1053 QSqlQuery query; |
1052 query.prepare("INSERT INTO transactions (person,value,added) VALUES (?,?,?)"); | 1054 query.prepare("INSERT INTO transactions (person,value,added) VALUES (?,?,?)"); |
1053 query.addBindValue(id); | 1055 query.addBindValue(id); |
1054 query.addBindValue(value); | 1056 query.addBindValue(value); |
1055 query.addBindValue(QDateTime::currentDateTimeUtc()); | 1057 query.addBindValue(QDateTime::currentDateTimeUtc()); |
1058 { | 1060 { |
1059 QSqlDatabase::database().rollback(); | 1061 QSqlDatabase::database().rollback(); |
1060 return -2; | 1062 return -2; |
1061 } | 1063 } |
1062 | 1064 |
1065 // Update person record timestamp | |
1063 query.prepare("UPDATE people SET updated=? WHERE id=?"); | 1066 query.prepare("UPDATE people SET updated=? WHERE id=?"); |
1064 query.addBindValue(QDateTime::currentDateTimeUtc()); | 1067 query.addBindValue(QDateTime::currentDateTimeUtc()); |
1065 query.addBindValue(id); | 1068 query.addBindValue(id); |
1066 query.exec(); | 1069 query.exec(); |
1067 if (!slCheckAndReportSQLError("addTransaction update timestamp", query.lastError(), true)) | 1070 if (!slCheckAndReportSQLError("addTransaction update timestamp", query.lastError(), true)) |