Automatically replace NULL strings with EMPTY strings. Fixes #169.

This commit is contained in:
Martin Rotter 2017-12-15 08:41:56 +01:00
parent a5340cce99
commit 4175dc2265
4 changed files with 23 additions and 18 deletions

View File

@ -2,6 +2,8 @@
—————
Fixed:
▪ Bad handling of null/empty strings when inserting messages into DB. (bug #169)
▪ Bad conversion of "created on" date/time in TT-RSS plugin. (bug #172)
▪ Missing obligatory attribute in OPML 2.0 files. (bug #166)
3.5.5

View File

@ -48,7 +48,7 @@ QString Enclosures::encodeEnclosuresToString(const QList<Enclosure>& enclosures)
}
Message::Message() {
m_title = m_url = m_author = m_contents = m_feedId = m_customId = m_customHash = QSL("");
m_title = m_url = m_author = m_contents = m_feedId = m_customId = m_customHash = "";
m_enclosures = QList<Enclosure>();
m_accountId = m_id = 0;
m_isRead = m_isImportant = false;

View File

@ -30,6 +30,8 @@
#include <QUrl>
#include <QVariant>
#define EMPT_STR_NULL(x) ( ## x ## .isNull() ? "" : x)
bool DatabaseQueries::markMessagesReadUnread(QSqlDatabase db, const QStringList& ids, RootItem::ReadStatus read) {
QSqlQuery q(db);
@ -516,10 +518,10 @@ int DatabaseQueries::updateMessages(QSqlDatabase db,
if (message.m_customId.isEmpty()) {
// We need to recognize existing messages according URL & AUTHOR & TITLE.
// NOTE: This particularly concerns messages from standard account.
query_select_with_url.bindValue(QSL(":feed"), feed_custom_id);
query_select_with_url.bindValue(QSL(":title"), message.m_title);
query_select_with_url.bindValue(QSL(":url"), message.m_url);
query_select_with_url.bindValue(QSL(":author"), message.m_author);
query_select_with_url.bindValue(QSL(":feed"), EMPT_STR_NULL(feed_custom_id));
query_select_with_url.bindValue(QSL(":title"), EMPT_STR_NULL(message.m_title));
query_select_with_url.bindValue(QSL(":url"), EMPT_STR_NULL(message.m_url));
query_select_with_url.bindValue(QSL(":author"), EMPT_STR_NULL(message.m_author));
query_select_with_url.bindValue(QSL(":account_id"), account_id);
qDebug("Checking if message with title '%s', url '%s' and author '%s' is present in DB.",
@ -545,7 +547,7 @@ int DatabaseQueries::updateMessages(QSqlDatabase db,
// We can recognize existing messages via their custom ID.
// NOTE: This concerns messages from custom accounts, like TT-RSS or ownCloud News.
query_select_with_id.bindValue(QSL(":account_id"), account_id);
query_select_with_id.bindValue(QSL(":custom_id"), message.m_customId);
query_select_with_id.bindValue(QSL(":custom_id"), EMPT_STR_NULL(message.m_customId));
qDebug("Checking if message with custom ID %s is present in DB.", qPrintable(message.m_customId));
@ -582,15 +584,15 @@ int DatabaseQueries::updateMessages(QSqlDatabase db,
/* 2 */ (message.m_createdFromFeed && message.m_created.toMSecsSinceEpoch() != date_existing_message
&& message.m_contents != contents_existing_message)) {
// Message exists, it is changed, update it.
query_update.bindValue(QSL(":title"), message.m_title);
query_update.bindValue(QSL(":title"), EMPT_STR_NULL(message.m_title));
query_update.bindValue(QSL(":is_read"), (int) message.m_isRead);
query_update.bindValue(QSL(":is_important"), (int) message.m_isImportant);
query_update.bindValue(QSL(":url"), message.m_url);
query_update.bindValue(QSL(":author"), message.m_author);
query_update.bindValue(QSL(":url"), EMPT_STR_NULL(message.m_url));
query_update.bindValue(QSL(":author"), EMPT_STR_NULL(message.m_author));
query_update.bindValue(QSL(":date_created"), message.m_created.toMSecsSinceEpoch());
query_update.bindValue(QSL(":contents"), message.m_contents);
query_update.bindValue(QSL(":contents"), EMPT_STR_NULL(message.m_contents));
query_update.bindValue(QSL(":enclosures"), Enclosures::encodeEnclosuresToString(message.m_enclosures));
query_update.bindValue(QSL(":feed"), message.m_feedId);
query_update.bindValue(QSL(":feed"), EMPT_STR_NULL(feed_id_existing_message));
query_update.bindValue(QSL(":id"), id_existing_message);
*any_message_changed = true;
@ -610,17 +612,17 @@ int DatabaseQueries::updateMessages(QSqlDatabase db,
}
else {
// Message with this URL is not fetched in this feed yet.
query_insert.bindValue(QSL(":feed"), feed_custom_id);
query_insert.bindValue(QSL(":title"), message.m_title);
query_insert.bindValue(QSL(":feed"), EMPT_STR_NULL(feed_custom_id));
query_insert.bindValue(QSL(":title"), EMPT_STR_NULL(message.m_title));
query_insert.bindValue(QSL(":is_read"), (int) message.m_isRead);
query_insert.bindValue(QSL(":is_important"), (int) message.m_isImportant);
query_insert.bindValue(QSL(":url"), message.m_url);
query_insert.bindValue(QSL(":author"), message.m_author);
query_insert.bindValue(QSL(":url"), EMPT_STR_NULL( message.m_url));
query_insert.bindValue(QSL(":author"), EMPT_STR_NULL(message.m_author));
query_insert.bindValue(QSL(":date_created"), message.m_created.toMSecsSinceEpoch());
query_insert.bindValue(QSL(":contents"), message.m_contents);
query_insert.bindValue(QSL(":contents"), EMPT_STR_NULL(message.m_contents));
query_insert.bindValue(QSL(":enclosures"), Enclosures::encodeEnclosuresToString(message.m_enclosures));
query_insert.bindValue(QSL(":custom_id"), message.m_customId);
query_insert.bindValue(QSL(":custom_hash"), message.m_customHash);
query_insert.bindValue(QSL(":custom_id"), EMPT_STR_NULL(message.m_customId));
query_insert.bindValue(QSL(":custom_hash"), EMPT_STR_NULL(message.m_customHash));
query_insert.bindValue(QSL(":account_id"), account_id);
if (query_insert.exec() && query_insert.numRowsAffected() == 1) {

View File

@ -59,6 +59,7 @@ Message AtomParser::extractMessage(const QDomElement& msg_element, QDateTime cur
new_message.m_title = qApp->web()->stripTags(title);
new_message.m_contents = summary;
new_message.m_author = qApp->web()->escapeHtml(messageAuthor(msg_element));
QString updated = textsFromPath(msg_element, m_atomNamespace, QSL("updated"), true).join(QSL(", "));
if (updated.isEmpty()) {