mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
added ordering field to all the 'lists' tables
This commit is contained in:
parent
eb0fa7e0fb
commit
27d096162d
@ -320,10 +320,11 @@ void ComicModel::setupLabelModelData(unsigned long long parentLabel, const QStri
|
||||
selectQuery.prepare("SELECT ci.number,ci.title,c.fileName,ci.numPages,c.id,c.parentId,c.path,ci.hash,ci.read,ci.isBis,ci.currentPage,ci.rating,ci.hasBeenOpened "
|
||||
"FROM comic c INNER JOIN comic_info ci ON (c.comicInfoId = ci.id) "
|
||||
"INNER JOIN comic_label cl ON (c.id == cl.comic_id) "
|
||||
"WHERE cl.label_id = :parentLabelId");
|
||||
"WHERE cl.label_id = :parentLabelId "
|
||||
"ORDER BY cl.ordering");
|
||||
selectQuery.bindValue(":parentLabelId", parentLabel);
|
||||
selectQuery.exec();
|
||||
setupModelData(selectQuery);
|
||||
setupModelDataForList(selectQuery);
|
||||
}
|
||||
db.close();
|
||||
QSqlDatabase::removeDatabase(_databasePath);
|
||||
@ -361,7 +362,8 @@ void ComicModel::setupReadingListModelData(unsigned long long parentReadingList,
|
||||
selectQuery.prepare("SELECT ci.number,ci.title,c.fileName,ci.numPages,c.id,c.parentId,c.path,ci.hash,ci.read,ci.isBis,ci.currentPage,ci.rating,ci.hasBeenOpened "
|
||||
"FROM comic c INNER JOIN comic_info ci ON (c.comicInfoId = ci.id) "
|
||||
"INNER JOIN comic_reading_list crl ON (c.id == crl.comic_id) "
|
||||
"WHERE crl.reading_list_id = :parentReadingList");
|
||||
"WHERE crl.reading_list_id = :parentReadingList "
|
||||
"ORDER BY crl.ordering");
|
||||
selectQuery.bindValue(":parentReadingList", id);
|
||||
selectQuery.exec();
|
||||
|
||||
@ -393,7 +395,8 @@ void ComicModel::setupFavoritesModelData(const QString &databasePath)
|
||||
selectQuery.prepare("SELECT ci.number,ci.title,c.fileName,ci.numPages,c.id,c.parentId,c.path,ci.hash,ci.read,ci.isBis,ci.currentPage,ci.rating,ci.hasBeenOpened "
|
||||
"FROM comic c INNER JOIN comic_info ci ON (c.comicInfoId = ci.id) "
|
||||
"INNER JOIN comic_default_reading_list cdrl ON (c.id == cdrl.comic_id) "
|
||||
"WHERE cdrl.default_reading_list_id = :parentDefaultListId");
|
||||
"WHERE cdrl.default_reading_list_id = :parentDefaultListId "
|
||||
"ORDER BY cdrl.ordering");
|
||||
selectQuery.bindValue(":parentDefaultListId", 1);
|
||||
selectQuery.exec();
|
||||
setupModelData(selectQuery);
|
||||
@ -588,7 +591,21 @@ void ComicModel::setupModelData(QSqlQuery &sqlquery)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//comics are sorted by "ordering", the sorting is done in the sql query
|
||||
void ComicModel::setupModelDataForList(QSqlQuery &sqlquery)
|
||||
{
|
||||
while (sqlquery.next())
|
||||
{
|
||||
QList<QVariant> data;
|
||||
QSqlRecord record = sqlquery.record();
|
||||
for(int i=0;i<record.count();i++)
|
||||
data << record.value(i);
|
||||
|
||||
_data.append(new ComicItem(data));
|
||||
}
|
||||
}
|
||||
|
||||
ComicDB ComicModel::getComic(const QModelIndex & mi)
|
||||
|
@ -127,6 +127,7 @@ protected:
|
||||
|
||||
private:
|
||||
void setupModelData( QSqlQuery &sqlquery);
|
||||
void setupModelDataForList(QSqlQuery &sqlquery);
|
||||
ComicDB _getComic(const QModelIndex & mi);
|
||||
QList<ComicItem *> _data;
|
||||
|
||||
|
@ -220,7 +220,7 @@ bool DataBaseManagement::createTables(QSqlDatabase & database)
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
#include "QsLog.h"
|
||||
bool DataBaseManagement::createV8Tables(QSqlDatabase &database)
|
||||
{
|
||||
bool success = true;
|
||||
@ -228,73 +228,83 @@ bool DataBaseManagement::createV8Tables(QSqlDatabase &database)
|
||||
//8.0> tables
|
||||
//LABEL
|
||||
QSqlQuery queryLabel(database);
|
||||
queryLabel.prepare("CREATE TABLE label (id INTEGER PRIMARY KEY, "
|
||||
"name TEXT NOT NULL, "
|
||||
"color TEXT NOT NULL, "
|
||||
"ordering INTEGER NOT NULL)"); //order depends on the color
|
||||
success = success && queryLabel.exec();
|
||||
success = success && queryLabel.exec("CREATE TABLE label (id INTEGER PRIMARY KEY, "
|
||||
"name TEXT NOT NULL, "
|
||||
"color TEXT NOT NULL, "
|
||||
"ordering INTEGER NOT NULL); "); //order depends on the color
|
||||
|
||||
QSqlQuery queryIndexLabel(database);
|
||||
success = success && queryIndexLabel.exec("CREATE INDEX label_ordering_index ON label (ordering)");
|
||||
|
||||
//COMIC LABEL
|
||||
QSqlQuery queryComicLabel(database);
|
||||
queryComicLabel.prepare("CREATE TABLE comic_label ("
|
||||
"comic_id INTEGER, "
|
||||
"label_id INTEGER, "
|
||||
//"order INTEGER, " //TODO order????
|
||||
"FOREIGN KEY(label_id) REFERENCES label(id) ON DELETE CASCADE, "
|
||||
"FOREIGN KEY(comic_id) REFERENCES comic(id) ON DELETE CASCADE, "
|
||||
"PRIMARY KEY(label_id, comic_id))");
|
||||
success = success && queryComicLabel.exec();
|
||||
success = success && queryComicLabel.exec("CREATE TABLE comic_label ("
|
||||
"comic_id INTEGER, "
|
||||
"label_id INTEGER, "
|
||||
"ordering INTEGER, " //TODO order????
|
||||
"FOREIGN KEY(label_id) REFERENCES label(id) ON DELETE CASCADE, "
|
||||
"FOREIGN KEY(comic_id) REFERENCES comic(id) ON DELETE CASCADE, "
|
||||
"PRIMARY KEY(label_id, comic_id))");
|
||||
|
||||
QSqlQuery queryIndexComicLabel(database);
|
||||
success = success && queryIndexComicLabel.exec("CREATE INDEX comic_label_ordering_index ON label (ordering)");
|
||||
|
||||
//READING LIST
|
||||
QSqlQuery queryReadingList(database);
|
||||
queryReadingList.prepare("CREATE TABLE reading_list ("
|
||||
"id INTEGER PRIMARY KEY, "
|
||||
"parentId INTEGER, "
|
||||
"ordering INTEGER DEFAULT 0, " //only use it if the parentId is NULL
|
||||
"name TEXT NOT NULL, "
|
||||
"finished BOOLEAN DEFAULT 0, "
|
||||
"completed BOOLEAN DEFAULT 1, "
|
||||
"FOREIGN KEY(parentId) REFERENCES reading_list(id) ON DELETE CASCADE)");
|
||||
success = success && queryReadingList.exec();
|
||||
success = success && queryReadingList.exec("CREATE TABLE reading_list ("
|
||||
"id INTEGER PRIMARY KEY, "
|
||||
"parentId INTEGER, "
|
||||
"ordering INTEGER DEFAULT 0, " //only use it if the parentId is NULL
|
||||
"name TEXT NOT NULL, "
|
||||
"finished BOOLEAN DEFAULT 0, "
|
||||
"completed BOOLEAN DEFAULT 1, "
|
||||
"FOREIGN KEY(parentId) REFERENCES reading_list(id) ON DELETE CASCADE)");
|
||||
|
||||
QSqlQuery queryIndexReadingList(database);
|
||||
success = success && queryIndexReadingList.exec("CREATE INDEX reading_list_ordering_index ON label (ordering)");
|
||||
|
||||
//COMIC READING LIST
|
||||
QSqlQuery queryComicReadingList(database);
|
||||
queryComicReadingList.prepare("CREATE TABLE comic_reading_list ("
|
||||
"reading_list_id INTEGER, "
|
||||
"comic_id INTEGER, "
|
||||
"ordering INTEGER, "
|
||||
"FOREIGN KEY(reading_list_id) REFERENCES reading_list(id) ON DELETE CASCADE, "
|
||||
"FOREIGN KEY(comic_id) REFERENCES comic(id) ON DELETE CASCADE, "
|
||||
"PRIMARY KEY(reading_list_id, comic_id))");
|
||||
success = success && queryComicReadingList.exec();
|
||||
success = success && queryComicReadingList.exec("CREATE TABLE comic_reading_list ("
|
||||
"reading_list_id INTEGER, "
|
||||
"comic_id INTEGER, "
|
||||
"ordering INTEGER, "
|
||||
"FOREIGN KEY(reading_list_id) REFERENCES reading_list(id) ON DELETE CASCADE, "
|
||||
"FOREIGN KEY(comic_id) REFERENCES comic(id) ON DELETE CASCADE, "
|
||||
"PRIMARY KEY(reading_list_id, comic_id))");
|
||||
|
||||
QSqlQuery queryIndexComicReadingList(database);
|
||||
success = success && queryIndexComicReadingList.exec("CREATE INDEX comic_reading_list_ordering_index ON label (ordering)");
|
||||
|
||||
//DEFAULT READING LISTS
|
||||
QSqlQuery queryDefaultReadingList(database);
|
||||
queryDefaultReadingList.prepare("CREATE TABLE default_reading_list ("
|
||||
"id INTEGER PRIMARY KEY, "
|
||||
"name TEXT NOT NULL"
|
||||
//TODO icon????
|
||||
")");
|
||||
success = success && queryDefaultReadingList.exec();
|
||||
success = success && queryDefaultReadingList.exec("CREATE TABLE default_reading_list ("
|
||||
"id INTEGER PRIMARY KEY, "
|
||||
"name TEXT NOT NULL"
|
||||
//TODO icon????
|
||||
")");
|
||||
|
||||
//COMIC DEFAULT READING LISTS
|
||||
QSqlQuery queryComicDefaultReadingList(database);
|
||||
queryComicDefaultReadingList.prepare("CREATE TABLE comic_default_reading_list ("
|
||||
"comic_id INTEGER, "
|
||||
"default_reading_list_id INTEGER, "
|
||||
//"order INTEGER, " //order????
|
||||
"FOREIGN KEY(default_reading_list_id) REFERENCES default_reading_list(id) ON DELETE CASCADE, "
|
||||
"FOREIGN KEY(comic_id) REFERENCES comic(id) ON DELETE CASCADE,"
|
||||
"PRIMARY KEY(default_reading_list_id, comic_id))");
|
||||
success = success && queryComicDefaultReadingList.exec();
|
||||
success = success && queryComicDefaultReadingList.exec("CREATE TABLE comic_default_reading_list ("
|
||||
"comic_id INTEGER, "
|
||||
"default_reading_list_id INTEGER, "
|
||||
"ordering INTEGER, " //order????
|
||||
"FOREIGN KEY(default_reading_list_id) REFERENCES default_reading_list(id) ON DELETE CASCADE, "
|
||||
"FOREIGN KEY(comic_id) REFERENCES comic(id) ON DELETE CASCADE,"
|
||||
"PRIMARY KEY(default_reading_list_id, comic_id))");
|
||||
|
||||
QSqlQuery queryIndexComicDefaultReadingList(database);
|
||||
success = success && queryIndexComicDefaultReadingList.exec("CREATE INDEX comic_default_reading_list_ordering_index ON label (ordering)");
|
||||
|
||||
//INSERT DEFAULT READING LISTS
|
||||
QSqlQuery queryInsertDefaultReadingList(database);
|
||||
queryInsertDefaultReadingList.prepare("INSERT INTO default_reading_list (name) VALUES (:name)");
|
||||
//if(!queryInsertDefaultReadingList.prepare())
|
||||
|
||||
//1 Favorites
|
||||
queryInsertDefaultReadingList.bindValue(":name", "Favorites");
|
||||
success = success && queryInsertDefaultReadingList.exec();
|
||||
//queryInsertDefaultReadingList.bindValue(":name", "Favorites");
|
||||
success = success && queryInsertDefaultReadingList.exec("INSERT INTO default_reading_list (name) VALUES (\"Favorites\")");
|
||||
QLOG_ERROR() << success;
|
||||
|
||||
//Reading doesn't need its onw list
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user