Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/plugins/sql/mymoneystoragesql_p.h
Context not available. | |||||
123 | } else { | 123 | } else { | ||
---|---|---|---|---|---|
124 | try{ | 124 | try{ | ||
125 | m_db.endCommitUnit(m_name); | 125 | m_db.endCommitUnit(m_name); | ||
126 | } catch(MyMoneyException&) { | 126 | } catch (const MyMoneyException &) { | ||
127 | try { | 127 | try { | ||
128 | m_db.cancelCommitUnit(m_name); | 128 | m_db.cancelCommitUnit(m_name); | ||
129 | } catch (const MyMoneyException & e) { | 129 | } catch (const MyMoneyException &e) { | ||
130 | qDebug() << e.what(); | 130 | qDebug() << e.what(); | ||
131 | } | 131 | } | ||
132 | } | 132 | } | ||
Context not available. | |||||
184 | #define GETDATETIME(a) getDateTime(GETSTRING(a)) | 184 | #define GETDATETIME(a) getDateTime(GETSTRING(a)) | ||
185 | #define GETINT(a) query.value(a).toInt() | 185 | #define GETINT(a) query.value(a).toInt() | ||
186 | #define GETULL(a) query.value(a).toULongLong() | 186 | #define GETULL(a) query.value(a).toULongLong() | ||
187 | #define MYMONEYEXCEPTIONSQL(exceptionMessage) MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, exceptionMessage)) | ||||
188 | #define MYMONEYEXCEPTIONSQL_D(exceptionMessage) MYMONEYEXCEPTION(d->buildError(query, Q_FUNC_INFO, exceptionMessage)) | ||||
187 | 189 | | |||
188 | class MyMoneyStorageSqlPrivate | 190 | class MyMoneyStorageSqlPrivate | ||
189 | { | 191 | { | ||
Context not available. | |||||
248 | QSqlQuery query(*q); | 250 | QSqlQuery query(*q); | ||
249 | 251 | | |||
250 | if (!query.exec(m_driver->highestNumberFromIdString(tableName, tableField, prefixLength)) || !query.next()) | 252 | if (!query.exec(m_driver->highestNumberFromIdString(tableName, tableField, prefixLength)) || !query.next()) | ||
251 | throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, QString("retrieving highest ID number"))); // krazy:exclude=crashy | 253 | throw MYMONEYEXCEPTIONSQL("retrieving highest ID number"); | ||
252 | 254 | | |||
253 | return query.value(0).toULongLong(); | 255 | return query.value(0).toULongLong(); | ||
254 | } | 256 | } | ||
Context not available. | |||||
275 | QList<QString> dbList; | 277 | QList<QString> dbList; | ||
276 | QSqlQuery query(*q); | 278 | QSqlQuery query(*q); | ||
277 | query.prepare("SELECT id FROM kmmInstitutions;"); | 279 | query.prepare("SELECT id FROM kmmInstitutions;"); | ||
278 | if (!query.exec()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, "building Institution list")); // krazy:exclude=crashy | 280 | if (!query.exec()) throw MYMONEYEXCEPTIONSQL("building Institution list"); // krazy:exclude=crashy | ||
279 | while (query.next()) dbList.append(query.value(0).toString()); | 281 | while (query.next()) dbList.append(query.value(0).toString()); | ||
280 | 282 | | |||
281 | const QList<MyMoneyInstitution> list = m_storage->institutionList(); | 283 | const QList<MyMoneyInstitution> list = m_storage->institutionList(); | ||
Context not available. | |||||
308 | } | 310 | } | ||
309 | query.prepare("DELETE FROM kmmInstitutions WHERE id = :id"); | 311 | query.prepare("DELETE FROM kmmInstitutions WHERE id = :id"); | ||
310 | query.bindValue(":id", deleteList); | 312 | query.bindValue(":id", deleteList); | ||
311 | if (!query.execBatch()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, "deleting Institution")); | 313 | if (!query.execBatch()) throw MYMONEYEXCEPTIONSQL("deleting Institution"); | ||
312 | 314 | | |||
313 | deleteKeyValuePairs("OFXSETTINGS", deleteList); | 315 | deleteKeyValuePairs("OFXSETTINGS", deleteList); | ||
314 | } | 316 | } | ||
Context not available. | |||||
322 | QSqlQuery query(*q); | 324 | QSqlQuery query(*q); | ||
323 | query.prepare("SELECT id FROM kmmPayees;"); | 325 | query.prepare("SELECT id FROM kmmPayees;"); | ||
324 | if (!query.exec()) | 326 | if (!query.exec()) | ||
325 | throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, "building Payee list")); // krazy:exclude=crashy | 327 | throw MYMONEYEXCEPTIONSQL("building Payee list"); // krazy:exclude=crashy | ||
326 | 328 | | |||
327 | QList<QString> dbList; | 329 | QList<QString> dbList; | ||
328 | dbList.reserve(query.numRowsAffected()); | 330 | dbList.reserve(query.numRowsAffected()); | ||
Context not available. | |||||
359 | QList<QString> dbList; | 361 | QList<QString> dbList; | ||
360 | QSqlQuery query(*q); | 362 | QSqlQuery query(*q); | ||
361 | query.prepare("SELECT id FROM kmmTags;"); | 363 | query.prepare("SELECT id FROM kmmTags;"); | ||
362 | if (!query.exec()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, "building Tag list")); // krazy:exclude=crashy | 364 | if (!query.exec()) throw MYMONEYEXCEPTIONSQL("building Tag list"); // krazy:exclude=crashy | ||
363 | while (query.next()) dbList.append(query.value(0).toString()); | 365 | while (query.next()) dbList.append(query.value(0).toString()); | ||
364 | 366 | | |||
365 | QList<MyMoneyTag> list = m_storage->tagList(); | 367 | QList<MyMoneyTag> list = m_storage->tagList(); | ||
Context not available. | |||||
385 | } | 387 | } | ||
386 | query.prepare(m_db.m_tables["kmmTags"].deleteString()); | 388 | query.prepare(m_db.m_tables["kmmTags"].deleteString()); | ||
387 | query.bindValue(":id", deleteList); | 389 | query.bindValue(":id", deleteList); | ||
388 | if (!query.execBatch()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, "deleting Tag")); | 390 | if (!query.execBatch()) throw MYMONEYEXCEPTIONSQL("deleting Tag"); | ||
389 | m_tags -= query.numRowsAffected(); | 391 | m_tags -= query.numRowsAffected(); | ||
390 | } | 392 | } | ||
391 | } | 393 | } | ||
Context not available. | |||||
397 | QList<QString> dbList; | 399 | QList<QString> dbList; | ||
398 | QSqlQuery query(*q); | 400 | QSqlQuery query(*q); | ||
399 | query.prepare("SELECT id FROM kmmAccounts;"); | 401 | query.prepare("SELECT id FROM kmmAccounts;"); | ||
400 | if (!query.exec()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, "building Account list")); // krazy:exclude=crashy | 402 | if (!query.exec()) throw MYMONEYEXCEPTIONSQL("building Account list"); // krazy:exclude=crashy | ||
401 | while (query.next()) dbList.append(query.value(0).toString()); | 403 | while (query.next()) dbList.append(query.value(0).toString()); | ||
402 | 404 | | |||
403 | QList<MyMoneyAccount> list; | 405 | QList<MyMoneyAccount> list; | ||
Context not available. | |||||
489 | } | 491 | } | ||
490 | } | 492 | } | ||
491 | query.bindValue(":id", kvpList); | 493 | query.bindValue(":id", kvpList); | ||
492 | if (!query.execBatch()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, "deleting Account")); | 494 | if (!query.execBatch()) throw MYMONEYEXCEPTIONSQL("deleting Account"); | ||
493 | 495 | | |||
494 | deleteKeyValuePairs("ACCOUNT", kvpList); | 496 | deleteKeyValuePairs("ACCOUNT", kvpList); | ||
495 | deleteKeyValuePairs("ONLINEBANKING", kvpList); | 497 | deleteKeyValuePairs("ONLINEBANKING", kvpList); | ||
Context not available. | |||||
503 | QList<QString> dbList; | 505 | QList<QString> dbList; | ||
504 | QSqlQuery query(*q); | 506 | QSqlQuery query(*q); | ||
505 | query.prepare("SELECT id FROM kmmTransactions WHERE txType = 'N';"); | 507 | query.prepare("SELECT id FROM kmmTransactions WHERE txType = 'N';"); | ||
506 | if (!query.exec()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, "building Transaction list")); // krazy:exclude=crashy | 508 | if (!query.exec()) throw MYMONEYEXCEPTIONSQL("building Transaction list"); // krazy:exclude=crashy | ||
507 | while (query.next()) dbList.append(query.value(0).toString()); | 509 | while (query.next()) dbList.append(query.value(0).toString()); | ||
508 | 510 | | |||
509 | MyMoneyTransactionFilter filter; | 511 | MyMoneyTransactionFilter filter; | ||
Context not available. | |||||
538 | QList<QString> dbList; | 540 | QList<QString> dbList; | ||
539 | QSqlQuery query(*q); | 541 | QSqlQuery query(*q); | ||
540 | query.prepare("SELECT id FROM kmmSchedules;"); | 542 | query.prepare("SELECT id FROM kmmSchedules;"); | ||
541 | if (!query.exec()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, "building Schedule list")); // krazy:exclude=crashy | 543 | if (!query.exec()) throw MYMONEYEXCEPTIONSQL("building Schedule list"); // krazy:exclude=crashy | ||
542 | while (query.next()) dbList.append(query.value(0).toString()); | 544 | while (query.next()) dbList.append(query.value(0).toString()); | ||
543 | 545 | | |||
544 | const auto list = m_storage->scheduleList(QString(), Schedule::Type::Any, Schedule::Occurrence::Any, Schedule::PaymentType::Any, | 546 | const auto list = m_storage->scheduleList(QString(), Schedule::Type::Any, Schedule::Occurrence::Any, Schedule::PaymentType::Any, | ||
Context not available. | |||||
576 | QSqlQuery query(*q); | 578 | QSqlQuery query(*q); | ||
577 | QSqlQuery query2(*q); | 579 | QSqlQuery query2(*q); | ||
578 | query.prepare("SELECT id FROM kmmSecurities;"); | 580 | query.prepare("SELECT id FROM kmmSecurities;"); | ||
579 | if (!query.exec()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, "building security list")); // krazy:exclude=crashy | 581 | if (!query.exec()) throw MYMONEYEXCEPTIONSQL("building security list"); // krazy:exclude=crashy | ||
580 | while (query.next()) dbList.append(query.value(0).toString()); | 582 | while (query.next()) dbList.append(query.value(0).toString()); | ||
581 | 583 | | |||
582 | const QList<MyMoneySecurity> securityList = m_storage->securityList(); | 584 | const QList<MyMoneySecurity> securityList = m_storage->securityList(); | ||
Context not available. | |||||
603 | query.prepare("DELETE FROM kmmSecurities WHERE id = :id"); | 605 | query.prepare("DELETE FROM kmmSecurities WHERE id = :id"); | ||
604 | query2.prepare("DELETE FROM kmmPrices WHERE fromId = :id OR toId = :id"); | 606 | query2.prepare("DELETE FROM kmmPrices WHERE fromId = :id OR toId = :id"); | ||
605 | query.bindValue(":id", idList); | 607 | query.bindValue(":id", idList); | ||
606 | if (!query.execBatch()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, "deleting Security")); | 608 | if (!query.execBatch()) throw MYMONEYEXCEPTIONSQL("deleting Security"); | ||
607 | 609 | | |||
608 | query2.bindValue(":fromId", idList); | 610 | query2.bindValue(":fromId", idList); | ||
609 | query2.bindValue(":toId", idList); | 611 | query2.bindValue(":toId", idList); | ||
610 | if (!query2.execBatch()) throw MYMONEYEXCEPTION(buildError(query2, Q_FUNC_INFO, "deleting Security")); | 612 | if (!query2.execBatch()) throw MYMONEYEXCEPTIONSQL("deleting Security"); | ||
611 | 613 | | |||
612 | deleteKeyValuePairs("SECURITY", idList); | 614 | deleteKeyValuePairs("SECURITY", idList); | ||
613 | } | 615 | } | ||
Context not available. | |||||
620 | // easiest way is to delete all and re-insert | 622 | // easiest way is to delete all and re-insert | ||
621 | QSqlQuery query(*q); | 623 | QSqlQuery query(*q); | ||
622 | query.prepare("DELETE FROM kmmPrices"); | 624 | query.prepare("DELETE FROM kmmPrices"); | ||
623 | if (!query.exec()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, QString("deleting Prices"))); // krazy:exclude=crashy | 625 | if (!query.exec()) throw MYMONEYEXCEPTIONSQL("deleting Prices"); // krazy:exclude=crashy | ||
624 | m_prices = 0; | 626 | m_prices = 0; | ||
625 | 627 | | |||
626 | const MyMoneyPriceList list = m_storage->priceList(); | 628 | const MyMoneyPriceList list = m_storage->priceList(); | ||
Context not available. | |||||
639 | QSqlQuery query(*q); | 641 | QSqlQuery query(*q); | ||
640 | QSqlQuery query2(*q); | 642 | QSqlQuery query2(*q); | ||
641 | query.prepare("SELECT ISOCode FROM kmmCurrencies;"); | 643 | query.prepare("SELECT ISOCode FROM kmmCurrencies;"); | ||
642 | if (!query.exec()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, "building Currency list")); // krazy:exclude=crashy | 644 | if (!query.exec()) throw MYMONEYEXCEPTIONSQL("building Currency list"); // krazy:exclude=crashy | ||
643 | while (query.next()) dbList.append(query.value(0).toString()); | 645 | while (query.next()) dbList.append(query.value(0).toString()); | ||
644 | 646 | | |||
645 | const QList<MyMoneySecurity> currencyList = m_storage->currencyList(); | 647 | const QList<MyMoneySecurity> currencyList = m_storage->currencyList(); | ||
Context not available. | |||||
665 | } | 667 | } | ||
666 | 668 | | |||
667 | query.bindValue(":ISOCode", isoCodeList); | 669 | query.bindValue(":ISOCode", isoCodeList); | ||
668 | if (!query.execBatch()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, "deleting Currency")); | 670 | if (!query.execBatch()) throw MYMONEYEXCEPTIONSQL("deleting Currency"); | ||
669 | } | 671 | } | ||
670 | } | 672 | } | ||
671 | 673 | | |||
Context not available. | |||||
683 | QSqlQuery query(*q); | 685 | QSqlQuery query(*q); | ||
684 | query.prepare("SELECT count(*) FROM kmmFileInfo;"); | 686 | query.prepare("SELECT count(*) FROM kmmFileInfo;"); | ||
685 | if (!query.exec() || !query.next()) | 687 | if (!query.exec() || !query.next()) | ||
686 | throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, "checking fileinfo")); // krazy:exclude=crashy | 688 | throw MYMONEYEXCEPTIONSQL("checking fileinfo"); // krazy:exclude=crashy | ||
687 | 689 | | |||
688 | if (query.value(0).toInt() == 0) { | 690 | if (query.value(0).toInt() == 0) { | ||
689 | // Cannot use "INSERT INTO kmmFileInfo DEFAULT VALUES;" because it is not supported by MySQL | 691 | // Cannot use "INSERT INTO kmmFileInfo DEFAULT VALUES;" because it is not supported by MySQL | ||
690 | query.prepare(QLatin1String("INSERT INTO kmmFileInfo (version) VALUES (null);")); | 692 | query.prepare(QLatin1String("INSERT INTO kmmFileInfo (version) VALUES (null);")); | ||
691 | if (!query.exec()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, "inserting fileinfo")); // krazy:exclude=crashy | 693 | if (!query.exec()) throw MYMONEYEXCEPTIONSQL("inserting fileinfo"); // krazy:exclude=crashy | ||
692 | } | 694 | } | ||
693 | 695 | | |||
694 | query.prepare(QLatin1String( | 696 | query.prepare(QLatin1String( | ||
Context not available. | |||||
790 | query.bindValue(":budgets", (unsigned long long) m_budgets); | 792 | query.bindValue(":budgets", (unsigned long long) m_budgets); | ||
791 | 793 | | |||
792 | if (!query.exec()) | 794 | if (!query.exec()) | ||
793 | throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, QString("writing FileInfo"))); // krazy:exclude=crashy | 795 | throw MYMONEYEXCEPTIONSQL("writing FileInfo"); // krazy:exclude=crashy | ||
794 | } | 796 | } | ||
795 | 797 | | |||
796 | void writeReports() | 798 | void writeReports() | ||
Context not available. | |||||
801 | QSqlQuery query(*q); | 803 | QSqlQuery query(*q); | ||
802 | QSqlQuery query2(*q); | 804 | QSqlQuery query2(*q); | ||
803 | query.prepare("SELECT id FROM kmmReportConfig;"); | 805 | query.prepare("SELECT id FROM kmmReportConfig;"); | ||
804 | if (!query.exec()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, "building Report list")); // krazy:exclude=crashy | 806 | if (!query.exec()) throw MYMONEYEXCEPTIONSQL("building Report list"); // krazy:exclude=crashy | ||
805 | while (query.next()) dbList.append(query.value(0).toString()); | 807 | while (query.next()) dbList.append(query.value(0).toString()); | ||
806 | 808 | | |||
807 | QList<MyMoneyReport> list = m_storage->reportList(); | 809 | QList<MyMoneyReport> list = m_storage->reportList(); | ||
Context not available. | |||||
827 | } | 829 | } | ||
828 | 830 | | |||
829 | query.bindValue(":id", idList); | 831 | query.bindValue(":id", idList); | ||
830 | if (!query.execBatch()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, "deleting Report")); | 832 | if (!query.execBatch()) throw MYMONEYEXCEPTIONSQL("deleting Report"); | ||
831 | } | 833 | } | ||
832 | } | 834 | } | ||
833 | 835 | | |||
Context not available. | |||||
840 | QSqlQuery query2(*q); | 842 | QSqlQuery query2(*q); | ||
841 | query.prepare("SELECT name FROM kmmBudgetConfig;"); | 843 | query.prepare("SELECT name FROM kmmBudgetConfig;"); | ||
842 | if (!query.exec()) | 844 | if (!query.exec()) | ||
843 | throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, "building Budget list")); // krazy:exclude=crashy | 845 | throw MYMONEYEXCEPTIONSQL("building Budget list"); // krazy:exclude=crashy | ||
844 | while (query.next()) | 846 | while (query.next()) | ||
845 | dbList.append(query.value(0).toString()); | 847 | dbList.append(query.value(0).toString()); | ||
846 | 848 | | |||
Context not available. | |||||
868 | 870 | | |||
869 | query.bindValue(":name", idList); | 871 | query.bindValue(":name", idList); | ||
870 | if (!query.execBatch()) | 872 | if (!query.execBatch()) | ||
871 | throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, "deleting Budget")); | 873 | throw MYMONEYEXCEPTIONSQL("deleting Budget"); | ||
872 | } | 874 | } | ||
873 | } | 875 | } | ||
874 | 876 | | |||
Context not available. | |||||
877 | Q_Q(MyMoneyStorageSql); | 879 | Q_Q(MyMoneyStorageSql); | ||
878 | QSqlQuery query(*q); | 880 | QSqlQuery query(*q); | ||
879 | if (!query.exec("DELETE FROM kmmOnlineJobs;")) | 881 | if (!query.exec("DELETE FROM kmmOnlineJobs;")) | ||
880 | throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, QLatin1String("Clean kmmOnlineJobs table"))); | 882 | throw MYMONEYEXCEPTIONSQL("Clean kmmOnlineJobs table"); | ||
881 | 883 | | |||
882 | const QList<onlineJob> jobs(m_storage->onlineJobList()); | 884 | const QList<onlineJob> jobs(m_storage->onlineJobList()); | ||
883 | signalProgress(0, jobs.count(), i18n("Inserting online jobs.")); | 885 | signalProgress(0, jobs.count(), i18n("Inserting online jobs.")); | ||
Context not available. | |||||
887 | foreach (const onlineJob& job, jobs) { | 889 | foreach (const onlineJob& job, jobs) { | ||
888 | try { | 890 | try { | ||
889 | q->addOnlineJob(job); | 891 | q->addOnlineJob(job); | ||
890 | } catch (MyMoneyException& e) { | 892 | } catch (const MyMoneyException &e) { | ||
891 | // Do not save e as this may point to an inherited class | 893 | // Do not save e as this may point to an inherited class | ||
892 | failedJobs.append(QPair<onlineJob, QString>(job, e.what())); | 894 | failedJobs.append(QPair<onlineJob, QString>(job, e.what())); | ||
893 | qDebug() << "Failed to save onlineJob" << job.id() << "Reson:" << e.what(); | 895 | qDebug() << "Failed to save onlineJob" << job.id() << "Reson:" << e.what(); | ||
Context not available. | |||||
898 | 900 | | |||
899 | if (!failedJobs.isEmpty()) { | 901 | if (!failedJobs.isEmpty()) { | ||
900 | /** @todo Improve error message */ | 902 | /** @todo Improve error message */ | ||
901 | throw MYMONEYEXCEPTION(i18np("Could not save one onlineJob.", "Could not save %1 onlineJobs.", failedJobs.count())); | 903 | throw MYMONEYEXCEPTION_CSTRING("Could not save onlineJob."); | ||
902 | } | 904 | } | ||
903 | } | 905 | } | ||
904 | /** @} */ | 906 | /** @} */ | ||
Context not available. | |||||
943 | query.bindValue(":telephone", telephoneList); | 945 | query.bindValue(":telephone", telephoneList); | ||
944 | 946 | | |||
945 | if (!query.execBatch()) | 947 | if (!query.execBatch()) | ||
946 | throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, QString("writing Institution"))); | 948 | throw MYMONEYEXCEPTIONSQL("writing Institution"); | ||
947 | writeKeyValuePairs("OFXSETTINGS", idList, kvpPairsList); | 949 | writeKeyValuePairs("OFXSETTINGS", idList, kvpPairsList); | ||
948 | // Set m_hiIdInstitutions to 0 to force recalculation the next time it is requested | 950 | // Set m_hiIdInstitutions to 0 to force recalculation the next time it is requested | ||
949 | m_hiIdInstitutions = 0; | 951 | m_hiIdInstitutions = 0; | ||
Context not available. | |||||
978 | 980 | | |||
979 | query.bindValue(":matchKeys", matchKeys); | 981 | query.bindValue(":matchKeys", matchKeys); | ||
980 | if (!query.exec()) // krazy:exclude=crashy | 982 | if (!query.exec()) // krazy:exclude=crashy | ||
981 | throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, QString("writing Payee"))); // krazy:exclude=crashy | 983 | throw MYMONEYEXCEPTIONSQL("writing Payee"); // krazy:exclude=crashy | ||
982 | 984 | | |||
983 | if (!isUserInfo) | 985 | if (!isUserInfo) | ||
984 | m_hiIdPayees = 0; | 986 | m_hiIdPayees = 0; | ||
Context not available. | |||||
992 | if (ta.isClosed()) query.bindValue(":closed", "Y"); | 994 | if (ta.isClosed()) query.bindValue(":closed", "Y"); | ||
993 | else query.bindValue(":closed", "N"); | 995 | else query.bindValue(":closed", "N"); | ||
994 | query.bindValue(":notes", ta.notes()); | 996 | query.bindValue(":notes", ta.notes()); | ||
995 | if (!query.exec()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, QString("writing Tag"))); // krazy:exclude=crashy | 997 | if (!query.exec()) throw MYMONEYEXCEPTIONSQL("writing Tag"); // krazy:exclude=crashy | ||
996 | m_hiIdTags = 0; | 998 | m_hiIdTags = 0; | ||
997 | } | 999 | } | ||
998 | 1000 | | |||
Context not available. | |||||
1083 | query.bindValue(":transactionCount", transactionCountList); | 1085 | query.bindValue(":transactionCount", transactionCountList); | ||
1084 | 1086 | | |||
1085 | if (!query.execBatch()) | 1087 | if (!query.execBatch()) | ||
1086 | throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, QString("writing Account"))); | 1088 | throw MYMONEYEXCEPTIONSQL("writing Account"); | ||
1087 | 1089 | | |||
1088 | //Add in Key-Value Pairs for accounts. | 1090 | //Add in Key-Value Pairs for accounts. | ||
1089 | writeKeyValuePairs("ACCOUNT", idList, pairs); | 1091 | writeKeyValuePairs("ACCOUNT", idList, pairs); | ||
Context not available. | |||||
1102 | query.bindValue(":bankId", tx.bankID()); | 1104 | query.bindValue(":bankId", tx.bankID()); | ||
1103 | 1105 | | |||
1104 | if (!query.exec()) // krazy:exclude=crashy | 1106 | if (!query.exec()) // krazy:exclude=crashy | ||
1105 | throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, QString("writing Transaction"))); // krazy:exclude=crashy | 1107 | throw MYMONEYEXCEPTIONSQL("writing Transaction"); // krazy:exclude=crashy | ||
1106 | 1108 | | |||
1107 | m_txPostDate = tx.postDate(); // FIXME: TEMP till Tom puts date in split object | 1109 | m_txPostDate = tx.postDate(); // FIXME: TEMP till Tom puts date in split object | ||
1108 | QList<MyMoneySplit> splitList = tx.splits(); | 1110 | QList<MyMoneySplit> splitList = tx.splits(); | ||
Context not available. | |||||
1130 | QSqlQuery query(*q); | 1132 | QSqlQuery query(*q); | ||
1131 | query.prepare("SELECT splitId FROM kmmSplits where transactionId = :id;"); | 1133 | query.prepare("SELECT splitId FROM kmmSplits where transactionId = :id;"); | ||
1132 | query.bindValue(":id", txId); | 1134 | query.bindValue(":id", txId); | ||
1133 | if (!query.exec()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, "building Split list")); // krazy:exclude=crashy | 1135 | if (!query.exec()) throw MYMONEYEXCEPTIONSQL("building Split list"); // krazy:exclude=crashy | ||
1134 | while (query.next()) dbList.append(query.value(0).toUInt()); | 1136 | while (query.next()) dbList.append(query.value(0).toUInt()); | ||
1135 | 1137 | | |||
1136 | QSqlQuery query2(*q); | 1138 | QSqlQuery query2(*q); | ||
Context not available. | |||||
1171 | } | 1173 | } | ||
1172 | query.bindValue(":txId", txIdList.toList()); | 1174 | query.bindValue(":txId", txIdList.toList()); | ||
1173 | query.bindValue(":splitId", splitIdList); | 1175 | query.bindValue(":splitId", splitIdList); | ||
1174 | if (!query.execBatch()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, "deleting Splits")); | 1176 | if (!query.execBatch()) throw MYMONEYEXCEPTIONSQL("deleting Splits"); | ||
1175 | } | 1177 | } | ||
1176 | } | 1178 | } | ||
1177 | 1179 | | |||
Context not available. | |||||
1201 | query.bindValue(":tagId", tagIdList); | 1203 | query.bindValue(":tagId", tagIdList); | ||
1202 | query.bindValue(":splitId", splitIdList_TagSplits); | 1204 | query.bindValue(":splitId", splitIdList_TagSplits); | ||
1203 | query.bindValue(":transactionId", txIdList); | 1205 | query.bindValue(":transactionId", txIdList); | ||
1204 | if (!query.execBatch()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, QString("writing tagSplits"))); | 1206 | if (!query.execBatch()) throw MYMONEYEXCEPTIONSQL("writing tagSplits"); | ||
1205 | } | 1207 | } | ||
1206 | 1208 | | |||
1207 | void writeSplitList | 1209 | void writeSplitList | ||
Context not available. | |||||
1298 | query.bindValue(":checkNumber", checkNumberList); | 1300 | query.bindValue(":checkNumber", checkNumberList); | ||
1299 | query.bindValue(":postDate", postDateList); | 1301 | query.bindValue(":postDate", postDateList); | ||
1300 | query.bindValue(":bankId", bankIdList); | 1302 | query.bindValue(":bankId", bankIdList); | ||
1301 | if (!query.execBatch()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, QString("writing Split"))); | 1303 | if (!query.execBatch()) throw MYMONEYEXCEPTIONSQL("writing Split"); | ||
1302 | deleteKeyValuePairs("SPLIT", kvpIdList); | 1304 | deleteKeyValuePairs("SPLIT", kvpIdList); | ||
1303 | writeKeyValuePairs("SPLIT", kvpIdList, kvpPairsList); | 1305 | writeKeyValuePairs("SPLIT", kvpIdList, kvpPairsList); | ||
1304 | } | 1306 | } | ||
Context not available. | |||||
1335 | query.bindValue(":nextPaymentDue", sch.nextDueDate().toString(Qt::ISODate)); | 1337 | query.bindValue(":nextPaymentDue", sch.nextDueDate().toString(Qt::ISODate)); | ||
1336 | query.bindValue(":weekendOption", (int)sch.weekendOption()); | 1338 | query.bindValue(":weekendOption", (int)sch.weekendOption()); | ||
1337 | query.bindValue(":weekendOptionString", MyMoneySchedule::weekendOptionToString(sch.weekendOption())); | 1339 | query.bindValue(":weekendOptionString", MyMoneySchedule::weekendOptionToString(sch.weekendOption())); | ||
1338 | if (!query.exec()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, QString("writing Schedules"))); // krazy:exclude=crashy | 1340 | if (!query.exec()) throw MYMONEYEXCEPTIONSQL("writing Schedules"); // krazy:exclude=crashy | ||
1339 | 1341 | | |||
1340 | //store the payment history for this scheduled task. | 1342 | //store the payment history for this scheduled task. | ||
1341 | //easiest way is to delete all and re-insert; it's not a high use table | 1343 | //easiest way is to delete all and re-insert; it's not a high use table | ||
1342 | query.prepare("DELETE FROM kmmSchedulePaymentHistory WHERE schedId = :id;"); | 1344 | query.prepare("DELETE FROM kmmSchedulePaymentHistory WHERE schedId = :id;"); | ||
1343 | query.bindValue(":id", sch.id()); | 1345 | query.bindValue(":id", sch.id()); | ||
1344 | if (!query.exec()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, QString("deleting Schedule Payment History"))); // krazy:exclude=crashy | 1346 | if (!query.exec()) throw MYMONEYEXCEPTIONSQL("deleting Schedule Payment History"); // krazy:exclude=crashy | ||
1345 | 1347 | | |||
1346 | query.prepare(m_db.m_tables["kmmSchedulePaymentHistory"].insertString()); | 1348 | query.prepare(m_db.m_tables["kmmSchedulePaymentHistory"].insertString()); | ||
1347 | foreach (const QDate& it, sch.recordedPayments()) { | 1349 | foreach (const QDate& it, sch.recordedPayments()) { | ||
1348 | query.bindValue(":schedId", sch.id()); | 1350 | query.bindValue(":schedId", sch.id()); | ||
1349 | query.bindValue(":payDate", it.toString(Qt::ISODate)); | 1351 | query.bindValue(":payDate", it.toString(Qt::ISODate)); | ||
1350 | if (!query.exec()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, QString("writing Schedule Payment History"))); // krazy:exclude=crashy | 1352 | if (!query.exec()) throw MYMONEYEXCEPTIONSQL("writing Schedule Payment History"); // krazy:exclude=crashy | ||
1351 | } | 1353 | } | ||
1352 | 1354 | | |||
1353 | //store the transaction data for this task. | 1355 | //store the transaction data for this task. | ||
Context not available. | |||||
1377 | query.bindValue(":pricePrecision", security.pricePrecision()); | 1379 | query.bindValue(":pricePrecision", security.pricePrecision()); | ||
1378 | query.bindValue(":tradingCurrency", security.tradingCurrency()); | 1380 | query.bindValue(":tradingCurrency", security.tradingCurrency()); | ||
1379 | query.bindValue(":tradingMarket", security.tradingMarket()); | 1381 | query.bindValue(":tradingMarket", security.tradingMarket()); | ||
1380 | if (!query.exec()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, QString("writing Securities"))); // krazy:exclude=crashy | 1382 | if (!query.exec()) throw MYMONEYEXCEPTIONSQL("writing Securities"); // krazy:exclude=crashy | ||
1381 | 1383 | | |||
1382 | //Add in Key-Value Pairs for security | 1384 | //Add in Key-Value Pairs for security | ||
1383 | QVariantList idList; | 1385 | QVariantList idList; | ||
Context not available. | |||||
1408 | query.bindValue(":price", p.rate(QString()).toString()); | 1410 | query.bindValue(":price", p.rate(QString()).toString()); | ||
1409 | query.bindValue(":priceFormatted", p.rate(QString()).formatMoney("", 2)); | 1411 | query.bindValue(":priceFormatted", p.rate(QString()).formatMoney("", 2)); | ||
1410 | query.bindValue(":priceSource", p.source()); | 1412 | query.bindValue(":priceSource", p.source()); | ||
1411 | if (!query.exec()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, QString("writing Prices"))); // krazy:exclude=crashy | 1413 | if (!query.exec()) throw MYMONEYEXCEPTIONSQL("writing Prices"); // krazy:exclude=crashy | ||
1412 | } | 1414 | } | ||
1413 | 1415 | | |||
1414 | void writeCurrency(const MyMoneySecurity& currency, QSqlQuery& query) | 1416 | void writeCurrency(const MyMoneySecurity& currency, QSqlQuery& query) | ||
Context not available. | |||||
1433 | query.bindValue(":smallestCashFraction", currency.smallestCashFraction()); | 1435 | query.bindValue(":smallestCashFraction", currency.smallestCashFraction()); | ||
1434 | query.bindValue(":smallestAccountFraction", currency.smallestAccountFraction()); | 1436 | query.bindValue(":smallestAccountFraction", currency.smallestAccountFraction()); | ||
1435 | query.bindValue(":pricePrecision", currency.pricePrecision()); | 1437 | query.bindValue(":pricePrecision", currency.pricePrecision()); | ||
1436 | if (!query.exec()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, QString("writing Currencies"))); // krazy:exclude=crashy | 1438 | if (!query.exec()) throw MYMONEYEXCEPTIONSQL("writing Currencies"); // krazy:exclude=crashy | ||
1437 | } | 1439 | } | ||
1438 | 1440 | | |||
1439 | void writeReport(const MyMoneyReport& rep, QSqlQuery& query) | 1441 | void writeReport(const MyMoneyReport& rep, QSqlQuery& query) | ||
Context not available. | |||||
1445 | query.bindValue(":id", rep.id()); | 1447 | query.bindValue(":id", rep.id()); | ||
1446 | query.bindValue(":name", rep.name()); | 1448 | query.bindValue(":name", rep.name()); | ||
1447 | query.bindValue(":XML", d.toString()); | 1449 | query.bindValue(":XML", d.toString()); | ||
1448 | if (!query.exec()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, QString("writing Reports"))); // krazy:exclude=crashy | 1450 | if (!query.exec()) throw MYMONEYEXCEPTIONSQL("writing Reports"); // krazy:exclude=crashy | ||
1449 | } | 1451 | } | ||
1450 | 1452 | | |||
1451 | void writeBudget(const MyMoneyBudget& bud, QSqlQuery& query) | 1453 | void writeBudget(const MyMoneyBudget& bud, QSqlQuery& query) | ||
Context not available. | |||||
1459 | query.bindValue(":start", bud.budgetStart()); | 1461 | query.bindValue(":start", bud.budgetStart()); | ||
1460 | query.bindValue(":XML", d.toString()); | 1462 | query.bindValue(":XML", d.toString()); | ||
1461 | if (!query.exec()) // krazy:exclude=crashy | 1463 | if (!query.exec()) // krazy:exclude=crashy | ||
1462 | throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, QString("writing Budgets"))); // krazy:exclude=crashy | 1464 | throw MYMONEYEXCEPTIONSQL("writing Budgets"); // krazy:exclude=crashy | ||
1463 | } | 1465 | } | ||
1464 | 1466 | | |||
1465 | void writeKeyValuePairs(const QString& kvpType, const QVariantList& kvpId, const QList<QMap<QString, QString> >& pairs) | 1467 | void writeKeyValuePairs(const QString& kvpType, const QVariantList& kvpId, const QList<QMap<QString, QString> >& pairs) | ||
Context not available. | |||||
1491 | query.bindValue(":kvpId", id); | 1493 | query.bindValue(":kvpId", id); | ||
1492 | query.bindValue(":kvpKey", key); | 1494 | query.bindValue(":kvpKey", key); | ||
1493 | query.bindValue(":kvpData", value); | 1495 | query.bindValue(":kvpData", value); | ||
1494 | if (!query.execBatch()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, QString("writing KVP"))); | 1496 | if (!query.execBatch()) throw MYMONEYEXCEPTIONSQL("writing KVP"); | ||
1495 | m_kvps += pairCount; | 1497 | m_kvps += pairCount; | ||
1496 | } | 1498 | } | ||
1497 | 1499 | | |||
Context not available. | |||||
1520 | query.bindValue(":type", pid.iid()); | 1522 | query.bindValue(":type", pid.iid()); | ||
1521 | if (!query.exec()) { // krazy:exclude=crashy | 1523 | if (!query.exec()) { // krazy:exclude=crashy | ||
1522 | qWarning() << buildError(query, Q_FUNC_INFO, QString("modifying payeeIdentifier")); | 1524 | qWarning() << buildError(query, Q_FUNC_INFO, QString("modifying payeeIdentifier")); | ||
1523 | throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, QString("modifying payeeIdentifier"))); // krazy:exclude=crashy | 1525 | throw MYMONEYEXCEPTIONSQL("modifying payeeIdentifier"); // krazy:exclude=crashy | ||
1524 | } | 1526 | } | ||
1525 | } | 1527 | } | ||
1526 | /** @} */ | 1528 | /** @} */ | ||
Context not available. | |||||
1560 | ); | 1562 | ); | ||
1561 | 1563 | | |||
1562 | if (!query.exec()) | 1564 | if (!query.exec()) | ||
1563 | throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, QString("reading FileInfo"))); // krazy:exclude=crashy | 1565 | throw MYMONEYEXCEPTIONSQL("reading FileInfo"); // krazy:exclude=crashy | ||
1564 | if (!query.next()) | 1566 | if (!query.next()) | ||
1565 | throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, QString("retrieving FileInfo"))); | 1567 | throw MYMONEYEXCEPTIONSQL("retrieving FileInfo"); | ||
1566 | 1568 | | |||
1567 | QSqlRecord rec = query.record(); | 1569 | QSqlRecord rec = query.record(); | ||
1568 | m_storage->setCreationDate(GETDATE(rec.indexOf("created"))); | 1570 | m_storage->setCreationDate(GETDATE(rec.indexOf("created"))); | ||
Context not available. | |||||
1657 | query1.prepare("SELECT tagId from kmmTagSplits where splitId = :id and transactionId = :transactionId"); | 1659 | query1.prepare("SELECT tagId from kmmTagSplits where splitId = :id and transactionId = :transactionId"); | ||
1658 | query1.bindValue(":id", GETSTRING(splitIdCol)); | 1660 | query1.bindValue(":id", GETSTRING(splitIdCol)); | ||
1659 | query1.bindValue(":transactionId", GETSTRING(transactionIdCol)); | 1661 | query1.bindValue(":transactionId", GETSTRING(transactionIdCol)); | ||
1660 | if (!query1.exec()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, QString("reading tagId in Split"))); // krazy:exclude=crashy | 1662 | if (!query1.exec()) throw MYMONEYEXCEPTIONSQL("reading tagId in Split"); // krazy:exclude=crashy | ||
1661 | while (query1.next()) | 1663 | while (query1.next()) | ||
1662 | tagIdList << query1.value(0).toString(); | 1664 | tagIdList << query1.value(0).toString(); | ||
1663 | 1665 | | |||
Context not available. | |||||
1687 | query.prepare("SELECT kvpKey, kvpData from kmmKeyValuePairs where kvpType = :type and kvpId = :id;"); | 1689 | query.prepare("SELECT kvpKey, kvpData from kmmKeyValuePairs where kvpType = :type and kvpId = :id;"); | ||
1688 | query.bindValue(":type", kvpType); | 1690 | query.bindValue(":type", kvpType); | ||
1689 | query.bindValue(":id", kvpId); | 1691 | query.bindValue(":id", kvpId); | ||
1690 | if (!query.exec()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, QString("reading Kvp for %1 %2").arg(kvpType) // krazy:exclude=crashy | 1692 | if (!query.exec()) throw MYMONEYEXCEPTIONSQL(QString::fromLatin1("reading Kvp for %1 %2").arg(kvpType) // krazy:exclude=crashy | ||
1691 | .arg(kvpId))); | 1693 | .arg(kvpId)); | ||
1692 | while (query.next()) list.setValue(query.value(0).toString(), query.value(1).toString()); | 1694 | while (query.next()) list.setValue(query.value(0).toString(), query.value(1).toString()); | ||
1693 | return (list); | 1695 | return (list); | ||
1694 | } | 1696 | } | ||
Context not available. | |||||
1709 | 1711 | | |||
1710 | query.prepare(sQuery); | 1712 | query.prepare(sQuery); | ||
1711 | query.bindValue(":type", kvpType); | 1713 | query.bindValue(":type", kvpType); | ||
1712 | if (!query.exec()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, QString("reading Kvp List for %1").arg(kvpType))); // krazy:exclude=crashy | 1714 | if (!query.exec()) throw MYMONEYEXCEPTIONSQL(QString::fromLatin1("reading Kvp List for %1").arg(kvpType)); // krazy:exclude=crashy | ||
1713 | 1715 | | |||
1714 | // Reserve enough space for all values. | 1716 | // Reserve enough space for all values. | ||
1715 | retval.reserve(kvpIdList.size()); | 1717 | retval.reserve(kvpIdList.size()); | ||
Context not available. | |||||
1807 | idList << id; | 1809 | idList << id; | ||
1808 | query.prepare("DELETE FROM kmmSplits WHERE transactionId = :transactionId;"); | 1810 | query.prepare("DELETE FROM kmmSplits WHERE transactionId = :transactionId;"); | ||
1809 | query.bindValue(":transactionId", idList); | 1811 | query.bindValue(":transactionId", idList); | ||
1810 | if (!query.execBatch()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, "deleting Splits")); | 1812 | if (!query.execBatch()) throw MYMONEYEXCEPTIONSQL("deleting Splits"); | ||
1811 | 1813 | | |||
1812 | query.prepare("DELETE FROM kmmKeyValuePairs WHERE kvpType = 'SPLIT' " | 1814 | query.prepare("DELETE FROM kmmKeyValuePairs WHERE kvpType = 'SPLIT' " | ||
1813 | "AND kvpId LIKE '?%'"); | 1815 | "AND kvpId LIKE '?%'"); | ||
1814 | query.bindValue(1, idList); | 1816 | query.bindValue(1, idList); | ||
1815 | if (!query.execBatch()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, "deleting Splits KVP")); | 1817 | if (!query.execBatch()) throw MYMONEYEXCEPTIONSQL("deleting Splits KVP"); | ||
1816 | 1818 | | |||
1817 | m_splits -= query.numRowsAffected(); | 1819 | m_splits -= query.numRowsAffected(); | ||
1818 | deleteKeyValuePairs("TRANSACTION", idList); | 1820 | deleteKeyValuePairs("TRANSACTION", idList); | ||
1819 | query.prepare(m_db.m_tables["kmmTransactions"].deleteString()); | 1821 | query.prepare(m_db.m_tables["kmmTransactions"].deleteString()); | ||
1820 | query.bindValue(":id", idList); | 1822 | query.bindValue(":id", idList); | ||
1821 | if (!query.execBatch()) | 1823 | if (!query.execBatch()) | ||
1822 | throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, "deleting Transaction")); | 1824 | throw MYMONEYEXCEPTIONSQL("deleting Transaction"); | ||
1823 | } | 1825 | } | ||
1824 | 1826 | | |||
1825 | void deleteTagSplitsList(const QString& txId, const QList<int>& splitIdList) | 1827 | void deleteTagSplitsList(const QString& txId, const QList<int>& splitIdList) | ||
Context not available. | |||||
1838 | query.prepare("DELETE FROM kmmTagSplits WHERE transactionId = :transactionId AND splitId = :splitId"); | 1840 | query.prepare("DELETE FROM kmmTagSplits WHERE transactionId = :transactionId AND splitId = :splitId"); | ||
1839 | query.bindValue(":splitId", iList); | 1841 | query.bindValue(":splitId", iList); | ||
1840 | query.bindValue(":transactionId", transactionIdList); | 1842 | query.bindValue(":transactionId", transactionIdList); | ||
1841 | if (!query.execBatch()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, QString("deleting tagSplits"))); | 1843 | if (!query.execBatch()) throw MYMONEYEXCEPTIONSQL("deleting tagSplits"); | ||
1842 | } | 1844 | } | ||
1843 | 1845 | | |||
1844 | void deleteSchedule(const QString& id) | 1846 | void deleteSchedule(const QString& id) | ||
Context not available. | |||||
1848 | QSqlQuery query(*q); | 1850 | QSqlQuery query(*q); | ||
1849 | query.prepare("DELETE FROM kmmSchedulePaymentHistory WHERE schedId = :id"); | 1851 | query.prepare("DELETE FROM kmmSchedulePaymentHistory WHERE schedId = :id"); | ||
1850 | query.bindValue(":id", id); | 1852 | query.bindValue(":id", id); | ||
1851 | if (!query.exec()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, "deleting Schedule Payment History")); // krazy:exclude=crashy | 1853 | if (!query.exec()) throw MYMONEYEXCEPTIONSQL("deleting Schedule Payment History"); // krazy:exclude=crashy | ||
1852 | query.prepare(m_db.m_tables["kmmSchedules"].deleteString()); | 1854 | query.prepare(m_db.m_tables["kmmSchedules"].deleteString()); | ||
1853 | query.bindValue(":id", id); | 1855 | query.bindValue(":id", id); | ||
1854 | if (!query.exec()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, "deleting Schedule")); // krazy:exclude=crashy | 1856 | if (!query.exec()) throw MYMONEYEXCEPTIONSQL("deleting Schedule"); // krazy:exclude=crashy | ||
1855 | //FIXME: enable when schedules have KVPs. | 1857 | //FIXME: enable when schedules have KVPs. | ||
1856 | //deleteKeyValuePairs("SCHEDULE", id); | 1858 | //deleteKeyValuePairs("SCHEDULE", id); | ||
1857 | } | 1859 | } | ||
Context not available. | |||||
1872 | for (int i = 0; i < idList.size(); ++i) { | 1874 | for (int i = 0; i < idList.size(); ++i) { | ||
1873 | idString.append(idList[i].toString() + ' '); | 1875 | idString.append(idList[i].toString() + ' '); | ||
1874 | } | 1876 | } | ||
1875 | throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, QString("deleting kvp for %1 %2").arg(kvpType).arg(idString))); | 1877 | throw MYMONEYEXCEPTIONSQL(QString::fromLatin1("deleting kvp for %1 %2").arg(kvpType).arg(idString)); | ||
1876 | } | 1878 | } | ||
1877 | m_kvps -= query.numRowsAffected(); | 1879 | m_kvps -= query.numRowsAffected(); | ||
1878 | } | 1880 | } | ||
Context not available. | |||||
1990 | maindb.setUserName(url.userName()); | 1992 | maindb.setUserName(url.userName()); | ||
1991 | maindb.setPassword(url.password()); | 1993 | maindb.setPassword(url.password()); | ||
1992 | if (!maindb.open()) { | 1994 | if (!maindb.open()) { | ||
1993 | throw MYMONEYEXCEPTION(QString("opening database %1 in function %2") | 1995 | throw MYMONEYEXCEPTION(QString::fromLatin1("opening database %1 in function %2") | ||
1994 | .arg(maindb.databaseName()).arg(Q_FUNC_INFO)); | 1996 | .arg(maindb.databaseName()).arg(Q_FUNC_INFO)); | ||
1995 | } else { | 1997 | } else { | ||
1996 | QSqlQuery qm(maindb); | 1998 | QSqlQuery qm(maindb); | ||
1997 | QString qs = m_driver->createDbString(dbName) + ';'; | 1999 | QString qs = m_driver->createDbString(dbName) + ';'; | ||
Context not available. | |||||
2063 | for (QMap<QString, MyMoneyDbView>::ConstIterator tt = m_db.viewBegin(); tt != m_db.viewEnd(); ++tt) { | 2065 | for (QMap<QString, MyMoneyDbView>::ConstIterator tt = m_db.viewBegin(); tt != m_db.viewEnd(); ++tt) { | ||
2064 | if (lowerTables.contains(tt.key().toLower())) { | 2066 | if (lowerTables.contains(tt.key().toLower())) { | ||
2065 | if (!query.exec("DROP VIEW " + tt.value().name() + ';')) // krazy:exclude=crashy | 2067 | if (!query.exec("DROP VIEW " + tt.value().name() + ';')) // krazy:exclude=crashy | ||
2066 | throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, QString("dropping view %1").arg(tt.key()))); | 2068 | throw MYMONEYEXCEPTIONSQL(QString::fromLatin1("dropping view %1").arg(tt.key())); | ||
2067 | } | 2069 | } | ||
2068 | } | 2070 | } | ||
2069 | 2071 | | |||
Context not available. | |||||
2131 | for (QMap<QString, MyMoneyDbView>::ConstIterator tt = m_db.viewBegin(); tt != m_db.viewEnd(); ++tt) { | 2133 | for (QMap<QString, MyMoneyDbView>::ConstIterator tt = m_db.viewBegin(); tt != m_db.viewEnd(); ++tt) { | ||
2132 | if (!lowerTables.contains(tt.key().toLower())) { | 2134 | if (!lowerTables.contains(tt.key().toLower())) { | ||
2133 | if (!query.exec(tt.value().createString())) // krazy:exclude=crashy | 2135 | if (!query.exec(tt.value().createString())) // krazy:exclude=crashy | ||
2134 | throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, | 2136 | throw MYMONEYEXCEPTIONSQL(QString::fromLatin1("creating view %1").arg(tt.key())); | ||
2135 | QString("creating view %1").arg(tt.key()))); | | |||
2136 | } | 2137 | } | ||
2137 | } | 2138 | } | ||
2138 | 2139 | | |||
Context not available. | |||||
2502 | QSqlQuery query(*q); | 2503 | QSqlQuery query(*q); | ||
2503 | for (QMap<QString, MyMoneyDbView>::ConstIterator tt = m_db.viewBegin(); tt != m_db.viewEnd(); ++tt) { | 2504 | for (QMap<QString, MyMoneyDbView>::ConstIterator tt = m_db.viewBegin(); tt != m_db.viewEnd(); ++tt) { | ||
2504 | if (!lowerTables.contains(tt.key().toLower())) { | 2505 | if (!lowerTables.contains(tt.key().toLower())) { | ||
2505 | if (!query.exec(tt.value().createString())) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, QString("creating view %1").arg(tt.key()))); | 2506 | if (!query.exec(tt.value().createString())) throw MYMONEYEXCEPTIONSQL(QString::fromLatin1("creating view %1").arg(tt.key())); | ||
2506 | } | 2507 | } | ||
2507 | } | 2508 | } | ||
2508 | 2509 | | |||
Context not available. | |||||
2514 | query.bindValue(0, m_dbVersion); | 2515 | query.bindValue(0, m_dbVersion); | ||
2515 | query.bindValue(1, m_storage->fileFixVersion()); | 2516 | query.bindValue(1, m_storage->fileFixVersion()); | ||
2516 | if (!query.exec()) | 2517 | if (!query.exec()) | ||
2517 | throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, QString("Saving database version"))); | 2518 | throw MYMONEYEXCEPTIONSQL(QString::fromLatin1("Saving database version")); | ||
2518 | } | 2519 | } | ||
2519 | 2520 | | |||
2520 | return upgradeDb(); | 2521 | return upgradeDb(); | ||
Context not available. | |||||
2527 | QStringList ql = t.generateCreateSQL(m_driver, version).split('\n', QString::SkipEmptyParts); | 2528 | QStringList ql = t.generateCreateSQL(m_driver, version).split('\n', QString::SkipEmptyParts); | ||
2528 | QSqlQuery query(*q); | 2529 | QSqlQuery query(*q); | ||
2529 | foreach (const QString& i, ql) { | 2530 | foreach (const QString& i, ql) { | ||
2530 | if (!query.exec(i)) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, QString("creating table/index %1").arg(t.name()))); | 2531 | if (!query.exec(i)) throw MYMONEYEXCEPTIONSQL(QString::fromLatin1("creating table/index %1").arg(t.name())); | ||
2531 | } | 2532 | } | ||
2532 | } | 2533 | } | ||
2533 | 2534 | | |||
Context not available. | |||||
2584 | QSqlQuery query(*q); | 2585 | QSqlQuery query(*q); | ||
2585 | while (it != m_db.tableEnd()) { | 2586 | while (it != m_db.tableEnd()) { | ||
2586 | query.prepare(QString("DELETE from %1;").arg(it.key())); | 2587 | query.prepare(QString("DELETE from %1;").arg(it.key())); | ||
2587 | if (!query.exec()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, QString("cleaning database"))); // krazy:exclude=crashy | 2588 | if (!query.exec()) throw MYMONEYEXCEPTIONSQL("cleaning database"); // krazy:exclude=crashy | ||
2588 | ++it; | 2589 | ++it; | ||
2589 | } | 2590 | } | ||
2590 | } | 2591 | } | ||
Context not available. | |||||
2598 | QSqlQuery query(*q); | 2599 | QSqlQuery query(*q); | ||
2599 | while ((tt != m_db.tableEnd()) && (recordCount == 0)) { | 2600 | while ((tt != m_db.tableEnd()) && (recordCount == 0)) { | ||
2600 | query.prepare(QString("select count(*) from %1;").arg((*tt).name())); | 2601 | query.prepare(QString("select count(*) from %1;").arg((*tt).name())); | ||
2601 | if (!query.exec()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, "getting record count")); // krazy:exclude=crashy | 2602 | if (!query.exec()) throw MYMONEYEXCEPTIONSQL("getting record count"); // krazy:exclude=crashy | ||
2602 | if (!query.next()) throw MYMONEYEXCEPTION(buildError(query, Q_FUNC_INFO, "retrieving record count")); | 2603 | if (!query.next()) throw MYMONEYEXCEPTIONSQL("retrieving record count"); | ||
2603 | recordCount += query.value(0).toInt(); | 2604 | recordCount += query.value(0).toInt(); | ||
2604 | ++tt; | 2605 | ++tt; | ||
2605 | } | 2606 | } | ||
Context not available. | |||||
2658 | ); | 2659 | ); | ||
2659 | 2660 | | |||
2660 | if (plugin == 0) | 2661 | if (plugin == 0) | ||
2661 | throw MYMONEYEXCEPTION(QString("Could not load sqlStoragePlugin '%1', (error: %2)").arg(iid, errorMsg)); | 2662 | throw MYMONEYEXCEPTION(QString::fromLatin1("Could not load sqlStoragePlugin '%1', (error: %2)").arg(iid, errorMsg)); | ||
2662 | 2663 | | |||
2663 | MyMoneyDbTransaction t(*q, Q_FUNC_INFO); | 2664 | MyMoneyDbTransaction t(*q, Q_FUNC_INFO); | ||
2664 | if (plugin->setupDatabase(*q)) { | 2665 | if (plugin->setupDatabase(*q)) { | ||
Context not available. | |||||
2666 | return true; | 2667 | return true; | ||
2667 | } | 2668 | } | ||
2668 | 2669 | | |||
2669 | throw MYMONEYEXCEPTION(QString("Could not install sqlStoragePlugin '%1' in database.").arg(iid)); | 2670 | throw MYMONEYEXCEPTION(QString::fromLatin1("Could not install sqlStoragePlugin '%1' in database.").arg(iid)); | ||
2670 | } | 2671 | } | ||
2671 | 2672 | | |||
2672 | void insertStorableObject(const databaseStoreableObject& obj, const QString& id) | 2673 | void insertStorableObject(const databaseStoreableObject& obj, const QString& id) | ||
Context not available. | |||||
2674 | Q_Q(MyMoneyStorageSql); | 2675 | Q_Q(MyMoneyStorageSql); | ||
2675 | setupStoragePlugin(obj.storagePluginIid()); | 2676 | setupStoragePlugin(obj.storagePluginIid()); | ||
2676 | if (!obj.sqlSave(*q, id)) | 2677 | if (!obj.sqlSave(*q, id)) | ||
2677 | throw MYMONEYEXCEPTION(QString("Could not save object with id '%1' in database (plugin failed).").arg(id)); | 2678 | throw MYMONEYEXCEPTION(QString::fromLatin1("Could not save object with id '%1' in database (plugin failed).").arg(id)); | ||
2678 | } | 2679 | } | ||
2679 | 2680 | | |||
2680 | void updateStorableObject(const databaseStoreableObject& obj, const QString& id) | 2681 | void updateStorableObject(const databaseStoreableObject& obj, const QString& id) | ||
Context not available. | |||||
2682 | Q_Q(MyMoneyStorageSql); | 2683 | Q_Q(MyMoneyStorageSql); | ||
2683 | setupStoragePlugin(obj.storagePluginIid()); | 2684 | setupStoragePlugin(obj.storagePluginIid()); | ||
2684 | if (!obj.sqlModify(*q, id)) | 2685 | if (!obj.sqlModify(*q, id)) | ||
2685 | throw MYMONEYEXCEPTION(QString("Could not modify object with id '%1' in database (plugin failed).").arg(id)); | 2686 | throw MYMONEYEXCEPTION(QString::fromLatin1("Could not modify object with id '%1' in database (plugin failed).").arg(id)); | ||
2686 | } | 2687 | } | ||
2687 | 2688 | | |||
2688 | void deleteStorableObject(const databaseStoreableObject& obj, const QString& id) | 2689 | void deleteStorableObject(const databaseStoreableObject& obj, const QString& id) | ||
Context not available. | |||||
2690 | Q_Q(MyMoneyStorageSql); | 2691 | Q_Q(MyMoneyStorageSql); | ||
2691 | setupStoragePlugin(obj.storagePluginIid()); | 2692 | setupStoragePlugin(obj.storagePluginIid()); | ||
2692 | if (!obj.sqlRemove(*q, id)) | 2693 | if (!obj.sqlRemove(*q, id)) | ||
2693 | throw MYMONEYEXCEPTION(QString("Could not remove object with id '%1' from database (plugin failed).").arg(id)); | 2694 | throw MYMONEYEXCEPTION(QString::fromLatin1("Could not remove object with id '%1' from database (plugin failed).").arg(id)); | ||
2694 | } | 2695 | } | ||
2695 | 2696 | | |||
2696 | void alert(QString s) const // FIXME: remove... | 2697 | void alert(QString s) const // FIXME: remove... | ||
Context not available. |