diff --git a/YACReaderLibrary/db/comic_db.cpp b/YACReaderLibrary/db/comic_db.cpp index ea5b50e5..845a2c18 100644 --- a/YACReaderLibrary/db/comic_db.cpp +++ b/YACReaderLibrary/db/comic_db.cpp @@ -136,15 +136,6 @@ void ComicDB::update(QSqlDatabase & db) } -void ComicDB::removeFromDB(QSqlDatabase & db) -{ - QSqlQuery query(db); - query.prepare("DELETE FROM comic WHERE id = :id"); - query.bindValue(":id", id); - query.exec(); - //query.finish(); -} - bool ComicDB::isDir() { return false; diff --git a/YACReaderLibrary/db/comic_db.h b/YACReaderLibrary/db/comic_db.h index 4b9076bc..9dec8338 100644 --- a/YACReaderLibrary/db/comic_db.h +++ b/YACReaderLibrary/db/comic_db.h @@ -128,7 +128,6 @@ public: bool load(qulonglong id, QSqlDatabase & db); qulonglong insert(QSqlDatabase & db); - void removeFromDB(QSqlDatabase & db); void update(QSqlDatabase & db); bool hasCover() {return _hasCover;}; diff --git a/YACReaderLibrary/db/folder.cpp b/YACReaderLibrary/db/folder.cpp index 4ba06e2e..7cc10264 100644 --- a/YACReaderLibrary/db/folder.cpp +++ b/YACReaderLibrary/db/folder.cpp @@ -77,13 +77,4 @@ QList Folder::getFoldersFromParent(qulonglong parentId, QSqlDatab } return list; -} - -void Folder::removeFromDB(QSqlDatabase & db) -{ - QSqlQuery query(db); - query.prepare("DELETE FROM folder WHERE id = :id"); - query.bindValue(":id", id); - query.exec(); -} - +} \ No newline at end of file diff --git a/YACReaderLibrary/db/folder.h b/YACReaderLibrary/db/folder.h index 99698689..a2c2455a 100644 --- a/YACReaderLibrary/db/folder.h +++ b/YACReaderLibrary/db/folder.h @@ -21,7 +21,6 @@ public: static QList getFoldersFromParent(qulonglong parentId, QSqlDatabase & db, bool sort = true); qulonglong insert(QSqlDatabase & db); bool isDir(){return true;}; - void removeFromDB(QSqlDatabase & db); }; #endif \ No newline at end of file diff --git a/YACReaderLibrary/db/library_item.h b/YACReaderLibrary/db/library_item.h index 52c3d654..bd365012 100644 --- a/YACReaderLibrary/db/library_item.h +++ b/YACReaderLibrary/db/library_item.h @@ -1,13 +1,10 @@ #ifndef __LIBRARY_ITEM_H #define __LIBRARY_ITEM_H -#include - class LibraryItem { public: virtual bool isDir() = 0; - virtual void removeFromDB(QSqlDatabase & db) = 0; QString name; QString path; qulonglong parentId; diff --git a/YACReaderLibrary/db_helper.cpp b/YACReaderLibrary/db_helper.cpp index 90a8b05e..44bf6977 100644 --- a/YACReaderLibrary/db_helper.cpp +++ b/YACReaderLibrary/db_helper.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include "library_item.h" #include "comic_db.h" @@ -124,4 +125,27 @@ QString DBHelper::getFolderName(const QString & libraryName, qulonglong id) db.close(); QSqlDatabase::removeDatabase(libraryPath); return name; +} + +//objects management +void DBHelper::removeFromDB(LibraryItem * item, QSqlDatabase & db) +{ + if(item->isDir()) + DBHelper::removeFromDB(dynamic_cast(item),db); + else + DBHelper::removeFromDB(dynamic_cast(item),db); +} +void DBHelper::removeFromDB(Folder * folder, QSqlDatabase & db) +{ + QSqlQuery query(db); + query.prepare("DELETE FROM folder WHERE id = :id"); + query.bindValue(":id", folder->id); + query.exec(); +} +void DBHelper::removeFromDB(ComicDB * comic, QSqlDatabase & db) +{ + QSqlQuery query(db); + query.prepare("DELETE FROM comic WHERE id = :id"); + query.bindValue(":id", comic->id); + query.exec(); } \ No newline at end of file diff --git a/YACReaderLibrary/db_helper.h b/YACReaderLibrary/db_helper.h index 9d1520ca..d5e02e5f 100644 --- a/YACReaderLibrary/db_helper.h +++ b/YACReaderLibrary/db_helper.h @@ -2,11 +2,14 @@ #define DB_HELPER_H class QString; -class LibraryItem; -#include "comic_db.h" #include #include +class ComicDB; +class Folder; +class LibraryItem; +class QSqlDatabase; + class DBHelper { public: @@ -16,7 +19,12 @@ public: static QList getFolderComicsFromLibrary(const QString & libraryName, qulonglong folderId); static qulonglong getParentFromComicFolderId(const QString & libraryName, qulonglong id); static ComicDB getComicInfo(const QString & libraryName, qulonglong id); - static QString getFolderName(const QString & libraryName, qulonglong id); + static QString getFolderName(const QString & libraryName, qulonglong id); + + //objects management + static void removeFromDB(LibraryItem * item, QSqlDatabase & db); + static void removeFromDB(Folder * folder, QSqlDatabase & db); + static void removeFromDB(ComicDB * comic, QSqlDatabase & db); }; #endif \ No newline at end of file diff --git a/YACReaderLibrary/library_creator.cpp b/YACReaderLibrary/library_creator.cpp index 79d7542d..89151bad 100644 --- a/YACReaderLibrary/library_creator.cpp +++ b/YACReaderLibrary/library_creator.cpp @@ -7,6 +7,7 @@ #include #include "data_base_management.h" #include "qnaturalsorting.h" +#include "db_helper.h" #include using namespace std; @@ -241,7 +242,7 @@ void LibraryCreator::update(QDir dirS) { if(stopRunning) return; - listD.at(j)->removeFromDB(_database); + DBHelper::removeFromDB(listD.at(j),(_database)); } updated = true; } @@ -298,7 +299,7 @@ void LibraryCreator::update(QDir dirS) { if(nameS!="/.yacreaderlibrary") { - fileInfoD->removeFromDB(_database); + DBHelper::removeFromDB(fileInfoD,_database); j++; } else @@ -318,7 +319,7 @@ void LibraryCreator::update(QDir dirS) else if(fileInfoD->isDir()) //delete this folder from library { - fileInfoD->removeFromDB(_database); + DBHelper::removeFromDB(fileInfoD,_database); j++; } else //both are files //BUG on windows (no case sensitive) @@ -334,7 +335,7 @@ void LibraryCreator::update(QDir dirS) { if(comparation > 0) //delete thumbnail { - fileInfoD->removeFromDB(_database); + DBHelper::removeFromDB(fileInfoD,_database); j++; } else //same file