Feed column in Messages table is now TEXT.

This commit is contained in:
Martin Rotter 2015-12-06 19:50:58 +01:00
parent cff9c84b5a
commit 3d026ec955
8 changed files with 39 additions and 17 deletions

View File

@ -74,7 +74,7 @@ CREATE TABLE IF NOT EXISTS Messages (
is_read INTEGER(1) NOT NULL DEFAULT 0 CHECK (is_read >= 0 AND is_read <= 1),
is_deleted INTEGER(1) NOT NULL DEFAULT 0 CHECK (is_deleted >= 0 AND is_deleted <= 1),
is_important INTEGER(1) NOT NULL DEFAULT 0 CHECK (is_important >= 0 AND is_important <= 1),
feed INTEGER NOT NULL,
feed TEXT,
title TEXT NOT NULL CHECK (title != ''),
url TEXT NOT NULL,
author TEXT NOT NULL,

View File

@ -69,7 +69,7 @@ CREATE TABLE IF NOT EXISTS Messages (
is_read INTEGER(1) NOT NULL CHECK (is_read >= 0 AND is_read <= 1) DEFAULT (0),
is_deleted INTEGER(1) NOT NULL CHECK (is_deleted >= 0 AND is_deleted <= 1) DEFAULT (0),
is_important INTEGER(1) NOT NULL CHECK (is_important >= 0 AND is_important <= 1) DEFAULT (0),
feed INTEGER NOT NULL,
feed TEXT,
title TEXT NOT NULL CHECK (title != ''),
url TEXT NOT NULL,
author TEXT NOT NULL,

View File

@ -37,4 +37,7 @@ ADD COLUMN custom_id TEXT;
ALTER TABLE Messages
DROP FOREIGN KEY feed;
-- !
ALTER TABLE Messages
MODIFY Feeds TEXT;
-- !
UPDATE Information SET inf_value = '4' WHERE inf_key = 'schema_version';

View File

@ -34,4 +34,31 @@ ADD COLUMN custom_id TEXT;
ALTER TABLE Categories
ADD COLUMN custom_id TEXT;
-- !
CREATE TABLE backup_Messages AS SELECT * FROM Messages;
-- !
DROP TABLE Messages;
-- !
CREATE TABLE Messages (
id INTEGER PRIMARY KEY,
is_read INTEGER(1) NOT NULL CHECK (is_read >= 0 AND is_read <= 1) DEFAULT (0),
is_deleted INTEGER(1) NOT NULL CHECK (is_deleted >= 0 AND is_deleted <= 1) DEFAULT (0),
is_important INTEGER(1) NOT NULL CHECK (is_important >= 0 AND is_important <= 1) DEFAULT (0),
feed TEXT,
title TEXT NOT NULL CHECK (title != ''),
url TEXT NOT NULL,
author TEXT NOT NULL,
date_created INTEGER NOT NULL CHECK (date_created != 0),
contents TEXT,
is_pdeleted INTEGER(1) NOT NULL DEFAULT 0 CHECK (is_pdeleted >= 0 AND is_pdeleted <= 1),
enclosures TEXT,
account_id INTEGER NOT NULL,
custom_id TEXT,
FOREIGN KEY (account_id) REFERENCES Accounts (id)
);
-- !
INSERT INTO Messages SELECT * FROM backup_Messages;
-- !
DROP TABLE backup_Messages;
-- !
UPDATE Information SET inf_value = '4' WHERE inf_key = 'schema_version';

View File

@ -26,8 +26,6 @@ LabelWithStatus::LabelWithStatus(QWidget *parent)
: WidgetWithStatus(parent) {
m_wdgInput = new QLabel(this);
qobject_cast<QLabel*>(m_wdgInput)->setWordWrap(true);
// Set correct size for the tool button.
int label_height = m_wdgInput->sizeHint().height();
m_btnStatus->setFixedSize(label_height, label_height);

View File

@ -189,15 +189,15 @@ void StandardFeed::updateCounts(bool including_total_count) {
query_all.setForwardOnly(true);
if (including_total_count) {
if (query_all.exec(QString("SELECT count(*) FROM Messages WHERE feed = %1 AND is_deleted = 0 AND account_id = %2;").arg(QString::number(id()),
QString::number(const_cast<StandardFeed*>(this)->serviceRoot()->accountId()))) && query_all.next()) {
if (query_all.exec(QString("SELECT count(*) FROM Messages WHERE feed = '%1' AND is_deleted = 0 AND account_id = %2;").arg(QString::number(id()),
QString::number(const_cast<StandardFeed*>(this)->serviceRoot()->accountId()))) && query_all.next()) {
m_totalCount = query_all.value(0).toInt();
}
}
// Obtain count of unread messages.
if (query_all.exec(QString("SELECT count(*) FROM Messages WHERE feed = %1 AND is_deleted = 0 AND is_read = 0 AND account_id = %2;").arg(QString::number(id()),
QString::number(const_cast<StandardFeed*>(this)->serviceRoot()->accountId()))) && query_all.next()) {
if (query_all.exec(QString("SELECT count(*) FROM Messages WHERE feed = '%1' AND is_deleted = 0 AND is_read = 0 AND account_id = %2;").arg(QString::number(id()),
QString::number(const_cast<StandardFeed*>(this)->serviceRoot()->accountId()))) && query_all.next()) {
int new_unread_count = query_all.value(0).toInt();
if (status() == NewMessages && new_unread_count < m_unreadCount) {

View File

@ -167,7 +167,7 @@ bool FeedsImportExportModel::importAsOPML20(const QByteArray &data) {
return false;
}
StandardServiceRoot *root_item = new StandardServiceRoot(false);
StandardServiceRoot *root_item = new StandardServiceRoot();
QStack<RootItem*> model_items; model_items.push(root_item);
QStack<QDomElement> elements_to_process; elements_to_process.push(opml_document.documentElement().elementsByTagName(QSL("body")).at(0).toElement());

View File

@ -586,7 +586,7 @@ QStringList StandardServiceRoot::textualFeedIds(const QList<Feed*> &feeds) {
stringy_ids.reserve(feeds.size());
foreach (Feed *feed, feeds) {
stringy_ids.append(QString::number(feed->id()));
stringy_ids.append(QString("'%1'").arg(QString::number(feed->id())));
}
return stringy_ids;
@ -632,13 +632,7 @@ bool StandardServiceRoot::loadMessagesForItem(RootItem *item, QSqlTableModel *mo
}
else {
QList<Feed*> children = item->getSubTreeFeeds();
QStringList stringy_ids;
foreach (Feed *child, children) {
stringy_ids.append(QString::number(child->id()));
}
QString filter_clause = stringy_ids.join(QSL(", "));
QString filter_clause = textualFeedIds(children).join(QSL(", "));
model->setFilter(QString(QSL("feed IN (%1) AND is_deleted = 0 AND is_pdeleted = 0")).arg(filter_clause));
qDebug("Loading messages from feeds: %s.", qPrintable(filter_clause));