mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
movido el codigo de eliminaci?n de objetos de la base de datos a DBHelper
This commit is contained in:
parent
62a6561485
commit
250152898d
@ -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()
|
bool ComicDB::isDir()
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -128,7 +128,6 @@ public:
|
|||||||
|
|
||||||
bool load(qulonglong id, QSqlDatabase & db);
|
bool load(qulonglong id, QSqlDatabase & db);
|
||||||
qulonglong insert(QSqlDatabase & db);
|
qulonglong insert(QSqlDatabase & db);
|
||||||
void removeFromDB(QSqlDatabase & db);
|
|
||||||
void update(QSqlDatabase & db);
|
void update(QSqlDatabase & db);
|
||||||
bool hasCover() {return _hasCover;};
|
bool hasCover() {return _hasCover;};
|
||||||
|
|
||||||
|
@ -77,13 +77,4 @@ QList<LibraryItem *> Folder::getFoldersFromParent(qulonglong parentId, QSqlDatab
|
|||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Folder::removeFromDB(QSqlDatabase & db)
|
|
||||||
{
|
|
||||||
QSqlQuery query(db);
|
|
||||||
query.prepare("DELETE FROM folder WHERE id = :id");
|
|
||||||
query.bindValue(":id", id);
|
|
||||||
query.exec();
|
|
||||||
}
|
|
||||||
|
|
@ -21,7 +21,6 @@ public:
|
|||||||
static QList<LibraryItem *> getFoldersFromParent(qulonglong parentId, QSqlDatabase & db, bool sort = true);
|
static QList<LibraryItem *> getFoldersFromParent(qulonglong parentId, QSqlDatabase & db, bool sort = true);
|
||||||
qulonglong insert(QSqlDatabase & db);
|
qulonglong insert(QSqlDatabase & db);
|
||||||
bool isDir(){return true;};
|
bool isDir(){return true;};
|
||||||
void removeFromDB(QSqlDatabase & db);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -1,13 +1,10 @@
|
|||||||
#ifndef __LIBRARY_ITEM_H
|
#ifndef __LIBRARY_ITEM_H
|
||||||
#define __LIBRARY_ITEM_H
|
#define __LIBRARY_ITEM_H
|
||||||
|
|
||||||
#include <QSqlDatabase>
|
|
||||||
|
|
||||||
class LibraryItem
|
class LibraryItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual bool isDir() = 0;
|
virtual bool isDir() = 0;
|
||||||
virtual void removeFromDB(QSqlDatabase & db) = 0;
|
|
||||||
QString name;
|
QString name;
|
||||||
QString path;
|
QString path;
|
||||||
qulonglong parentId;
|
qulonglong parentId;
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
|
#include <QSqlDatabase>
|
||||||
|
|
||||||
#include "library_item.h"
|
#include "library_item.h"
|
||||||
#include "comic_db.h"
|
#include "comic_db.h"
|
||||||
@ -124,4 +125,27 @@ QString DBHelper::getFolderName(const QString & libraryName, qulonglong id)
|
|||||||
db.close();
|
db.close();
|
||||||
QSqlDatabase::removeDatabase(libraryPath);
|
QSqlDatabase::removeDatabase(libraryPath);
|
||||||
return name;
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
//objects management
|
||||||
|
void DBHelper::removeFromDB(LibraryItem * item, QSqlDatabase & db)
|
||||||
|
{
|
||||||
|
if(item->isDir())
|
||||||
|
DBHelper::removeFromDB(dynamic_cast<Folder *>(item),db);
|
||||||
|
else
|
||||||
|
DBHelper::removeFromDB(dynamic_cast<ComicDB *>(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();
|
||||||
}
|
}
|
@ -2,11 +2,14 @@
|
|||||||
#define DB_HELPER_H
|
#define DB_HELPER_H
|
||||||
|
|
||||||
class QString;
|
class QString;
|
||||||
class LibraryItem;
|
|
||||||
#include "comic_db.h"
|
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
|
||||||
|
class ComicDB;
|
||||||
|
class Folder;
|
||||||
|
class LibraryItem;
|
||||||
|
class QSqlDatabase;
|
||||||
|
|
||||||
class DBHelper
|
class DBHelper
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -16,7 +19,12 @@ public:
|
|||||||
static QList<LibraryItem *> getFolderComicsFromLibrary(const QString & libraryName, qulonglong folderId);
|
static QList<LibraryItem *> getFolderComicsFromLibrary(const QString & libraryName, qulonglong folderId);
|
||||||
static qulonglong getParentFromComicFolderId(const QString & libraryName, qulonglong id);
|
static qulonglong getParentFromComicFolderId(const QString & libraryName, qulonglong id);
|
||||||
static ComicDB getComicInfo(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
|
#endif
|
@ -7,6 +7,7 @@
|
|||||||
#include <QSqlRecord>
|
#include <QSqlRecord>
|
||||||
#include "data_base_management.h"
|
#include "data_base_management.h"
|
||||||
#include "qnaturalsorting.h"
|
#include "qnaturalsorting.h"
|
||||||
|
#include "db_helper.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@ -241,7 +242,7 @@ void LibraryCreator::update(QDir dirS)
|
|||||||
{
|
{
|
||||||
if(stopRunning)
|
if(stopRunning)
|
||||||
return;
|
return;
|
||||||
listD.at(j)->removeFromDB(_database);
|
DBHelper::removeFromDB(listD.at(j),(_database));
|
||||||
}
|
}
|
||||||
updated = true;
|
updated = true;
|
||||||
}
|
}
|
||||||
@ -298,7 +299,7 @@ void LibraryCreator::update(QDir dirS)
|
|||||||
{
|
{
|
||||||
if(nameS!="/.yacreaderlibrary")
|
if(nameS!="/.yacreaderlibrary")
|
||||||
{
|
{
|
||||||
fileInfoD->removeFromDB(_database);
|
DBHelper::removeFromDB(fileInfoD,_database);
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -318,7 +319,7 @@ void LibraryCreator::update(QDir dirS)
|
|||||||
else
|
else
|
||||||
if(fileInfoD->isDir()) //delete this folder from library
|
if(fileInfoD->isDir()) //delete this folder from library
|
||||||
{
|
{
|
||||||
fileInfoD->removeFromDB(_database);
|
DBHelper::removeFromDB(fileInfoD,_database);
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
else //both are files //BUG on windows (no case sensitive)
|
else //both are files //BUG on windows (no case sensitive)
|
||||||
@ -334,7 +335,7 @@ void LibraryCreator::update(QDir dirS)
|
|||||||
{
|
{
|
||||||
if(comparation > 0) //delete thumbnail
|
if(comparation > 0) //delete thumbnail
|
||||||
{
|
{
|
||||||
fileInfoD->removeFromDB(_database);
|
DBHelper::removeFromDB(fileInfoD,_database);
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
else //same file
|
else //same file
|
||||||
|
Loading…
x
Reference in New Issue
Block a user