fix number of inserted articles when some article does not meet constraints

This commit is contained in:
Martin Rotter 2022-02-03 09:21:07 +01:00
parent b76ce364c2
commit 9934786c8c
4 changed files with 21 additions and 11 deletions

View file

@ -26,7 +26,7 @@
<url type="donation">https://github.com/sponsors/martinrotter</url> <url type="donation">https://github.com/sponsors/martinrotter</url>
<content_rating type="oars-1.1" /> <content_rating type="oars-1.1" />
<releases> <releases>
<release version="4.1.2" date="2022-02-02"/> <release version="4.1.2" date="2022-02-03"/>
</releases> </releases>
<content_rating type="oars-1.0"> <content_rating type="oars-1.0">
<content_attribute id="violence-cartoon">none</content_attribute> <content_attribute id="violence-cartoon">none</content_attribute>

View file

@ -242,6 +242,7 @@ bool DatabaseQueries::createLabel(const QSqlDatabase& db, Label* label, int acco
q.bindValue(QSL(":color"), label->color().name()); q.bindValue(QSL(":color"), label->color().name());
q.bindValue(QSL(":custom_id"), label->customId()); q.bindValue(QSL(":custom_id"), label->customId());
q.bindValue(QSL(":account_id"), account_id); q.bindValue(QSL(":account_id"), account_id);
auto res = q.exec(); auto res = q.exec();
if (res && q.lastInsertId().isValid()) { if (res && q.lastInsertId().isValid()) {
@ -1368,6 +1369,14 @@ QPair<int, int> DatabaseQueries::updateMessages(QSqlDatabase db,
<< "Message" << "Message"
<< QUOTE_W_SPACE(msg->m_customId) << QUOTE_W_SPACE(msg->m_customId)
<< "will not be inserted to DB because it does not meet DB constraints."; << "will not be inserted to DB because it does not meet DB constraints.";
// Message is not inserted to DB at last,
// fix numbers.
if (!msg->m_isRead) {
updated_messages.first--;
}
updated_messages.second--;
continue; continue;
} }
@ -1398,7 +1407,6 @@ QPair<int, int> DatabaseQueries::updateMessages(QSqlDatabase db,
if (bulk_error.isValid()) { if (bulk_error.isValid()) {
QString txt = bulk_error.text() + bulk_error.databaseText() + bulk_error.driverText(); QString txt = bulk_error.text() + bulk_error.databaseText() + bulk_error.driverText();
//IOFactory::writeFile("aa.sql", final_bulk.toUtf8());
qCriticalNN << LOGSEC_DB qCriticalNN << LOGSEC_DB
<< "Failed bulk insert of articles:" << "Failed bulk insert of articles:"
<< QUOTE_W_SPACE_DOT(txt); << QUOTE_W_SPACE_DOT(txt);
@ -1761,7 +1769,7 @@ bool DatabaseQueries::purgeLabelsAndLabelAssignments(const QSqlDatabase& db, int
return succ; return succ;
} }
bool DatabaseQueries::storeAccountTree(const QSqlDatabase& db, RootItem* tree_root, int account_id) { void DatabaseQueries::storeAccountTree(const QSqlDatabase& db, RootItem* tree_root, int account_id) {
// Iterate all children. // Iterate all children.
auto str = tree_root->getSubTree(); auto str = tree_root->getSubTree();
@ -1779,14 +1787,10 @@ bool DatabaseQueries::storeAccountTree(const QSqlDatabase& db, RootItem* tree_ro
for (RootItem* lbl : qAsConst(ch)) { for (RootItem* lbl : qAsConst(ch)) {
Label* label = lbl->toLabel(); Label* label = lbl->toLabel();
if (!createLabel(db, label, account_id)) { createLabel(db, label, account_id);
return false;
}
} }
} }
} }
return true;
} }
QStringList DatabaseQueries::customIdsOfMessagesFromAccount(const QSqlDatabase& db, int account_id, bool* ok) { QStringList DatabaseQueries::customIdsOfMessagesFromAccount(const QSqlDatabase& db, int account_id, bool* ok) {

View file

@ -121,7 +121,7 @@ class DatabaseQueries {
static bool cleanImportantMessages(const QSqlDatabase& db, bool clean_read_only, int account_id); static bool cleanImportantMessages(const QSqlDatabase& db, bool clean_read_only, int account_id);
static bool cleanUnreadMessages(const QSqlDatabase& db, int account_id); static bool cleanUnreadMessages(const QSqlDatabase& db, int account_id);
static bool cleanFeeds(const QSqlDatabase& db, const QStringList& ids, bool clean_read_only, int account_id); static bool cleanFeeds(const QSqlDatabase& db, const QStringList& ids, bool clean_read_only, int account_id);
static bool storeAccountTree(const QSqlDatabase& db, RootItem* tree_root, int account_id); static void storeAccountTree(const QSqlDatabase& db, RootItem* tree_root, int account_id);
static void createOverwriteFeed(const QSqlDatabase& db, Feed* feed, int account_id, int parent_id); static void createOverwriteFeed(const QSqlDatabase& db, Feed* feed, int account_id, int parent_id);
static void createOverwriteCategory(const QSqlDatabase& db, Category* category, int account_id, int parent_id); static void createOverwriteCategory(const QSqlDatabase& db, Category* category, int account_id, int parent_id);
static bool deleteFeed(const QSqlDatabase& db, int feed_custom_id, int account_id); static bool deleteFeed(const QSqlDatabase& db, int feed_custom_id, int account_id);

View file

@ -4,6 +4,7 @@
#include "database/databasefactory.h" #include "database/databasefactory.h"
#include "database/databasequeries.h" #include "database/databasequeries.h"
#include "exceptions/applicationexception.h"
#include "gui/dialogs/formaddeditlabel.h" #include "gui/dialogs/formaddeditlabel.h"
#include "miscellaneous/application.h" #include "miscellaneous/application.h"
#include "miscellaneous/iconfactory.h" #include "miscellaneous/iconfactory.h"
@ -61,9 +62,14 @@ void LabelsNode::createLabel() {
if (new_lbl != nullptr) { if (new_lbl != nullptr) {
QSqlDatabase db = qApp->database()->driver()->connection(metaObject()->className()); QSqlDatabase db = qApp->database()->driver()->connection(metaObject()->className());
DatabaseQueries::createLabel(db, new_lbl, getParentServiceRoot()->accountId()); try {
DatabaseQueries::createLabel(db, new_lbl, getParentServiceRoot()->accountId());
getParentServiceRoot()->requestItemReassignment(new_lbl, this); getParentServiceRoot()->requestItemReassignment(new_lbl, this);
}
catch (const ApplicationException& ex) {
new_lbl->deleteLater();
}
} }
} }
else { else {