A?adida un mejor gesti?n de los errores al manejar las bases de datos

This commit is contained in:
Luis Ángel San Martín 2013-05-24 16:31:17 +02:00
parent df08b6e4d2
commit b1e03d015d
4 changed files with 58 additions and 74 deletions

View File

@ -69,10 +69,15 @@ void LibraryCreator::run()
//se crea la base de datos .yacreaderlibrary/library.ydb //se crea la base de datos .yacreaderlibrary/library.ydb
_database = DataBaseManagement::createDatabase("library",_target);// _database = DataBaseManagement::createDatabase("library",_target);//
/*if(!_database.open()) if(!_database.isOpen())
return; //TODO avisar del problema {
emit failedCreatingDB(_database.lastError().databaseText() + "-" + _database.lastError().driverText());
emit finished();
creation = false;
return;
}
QSqlQuery pragma("PRAGMA foreign_keys = ON",_database);*/ /*QSqlQuery pragma("PRAGMA foreign_keys = ON",_database);*/
_database.transaction(); _database.transaction();
//se crea la librería //se crea la librería
create(QDir(_source)); create(QDir(_source));
@ -87,8 +92,13 @@ void LibraryCreator::run()
_currentPathFolders.append(Folder(1,1,"root","/")); _currentPathFolders.append(Folder(1,1,"root","/"));
_database = DataBaseManagement::loadDatabase(_target); _database = DataBaseManagement::loadDatabase(_target);
//_database.setDatabaseName(_target+"/library.ydb"); //_database.setDatabaseName(_target+"/library.ydb");
/*if(!_database.open()) if(!_database.open())
return; //TODO avisar del problema*/ {
emit failedOpeningDB(_database.lastError().databaseText() + "-" + _database.lastError().driverText());
emit finished();
creation = false;
return;
}
//QSqlQuery pragma("PRAGMA foreign_keys = ON",_database); //QSqlQuery pragma("PRAGMA foreign_keys = ON",_database);
_database.transaction(); _database.transaction();
update(QDir(_source)); update(QDir(_source));
@ -101,7 +111,7 @@ void LibraryCreator::run()
else else
emit(created()); emit(created());
} }
msleep(100);//TODO try to solve the problem with the udpate dialog msleep(100);//TODO try to solve the problem with the udpate dialog (ya no se usa más...)
emit(finished()); emit(finished());
creation = false; creation = false;
} }

View File

@ -55,6 +55,8 @@
void comicAdded(QString,QString); void comicAdded(QString,QString);
void updated(); void updated();
void created(); void created();
void failedCreatingDB(QString);
void failedOpeningDB(QString);
}; };
class ThumbnailCreator : public QObject class ThumbnailCreator : public QObject

View File

@ -624,16 +624,16 @@ void LibraryWindow::createConnections()
connect(importComicsInfoDialog,SIGNAL(finished(int)),this,SLOT(reloadCurrentLibrary())); connect(importComicsInfoDialog,SIGNAL(finished(int)),this,SLOT(reloadCurrentLibrary()));
connect(libraryCreator,SIGNAL(coverExtracted(QString)),createLibraryDialog,SLOT(showCurrentFile(QString))); connect(libraryCreator,SIGNAL(coverExtracted(QString)),createLibraryDialog,SLOT(showCurrentFile(QString)));
connect(libraryCreator,SIGNAL(finished()),createLibraryDialog,SLOT(close()));
connect(libraryCreator,SIGNAL(coverExtracted(QString)),updateLibraryDialog,SLOT(showCurrentFile(QString))); connect(libraryCreator,SIGNAL(coverExtracted(QString)),updateLibraryDialog,SLOT(showCurrentFile(QString)));
connect(libraryCreator,SIGNAL(finished()),updateLibraryDialog,SLOT(close()));
connect(libraryCreator,SIGNAL(finished()),this,SLOT(showRootWidget())); connect(libraryCreator,SIGNAL(finished()),this,SLOT(showRootWidget()));
connect(libraryCreator,SIGNAL(updated()),this,SLOT(reloadCurrentLibrary())); connect(libraryCreator,SIGNAL(updated()),this,SLOT(reloadCurrentLibrary()));
connect(libraryCreator,SIGNAL(created()),this,SLOT(openLastCreated())); connect(libraryCreator,SIGNAL(created()),this,SLOT(openLastCreated()));
//new import widget
connect(libraryCreator,SIGNAL(comicAdded(QString,QString)),importWidget,SLOT(newComic(QString,QString))); connect(libraryCreator,SIGNAL(comicAdded(QString,QString)),importWidget,SLOT(newComic(QString,QString)));
//connect(libraryCreator,SIGNAL(finished()),importWidget,SLOT(clear())); //libraryCreator errors
//connect(importWidget,SIGNAL(stop()),this,SLOT(cancelCreating())); connect(libraryCreator,SIGNAL(failedCreatingDB(QString)),this,SLOT(manageCreatingError(QString)));
connect(libraryCreator,SIGNAL(failedUpdatingDB(QString)),this,SLOT(manageUpdatingError(QString)));
//new import widget
connect(importWidget,SIGNAL(stop()),this,SLOT(stopLibraryCreator())); connect(importWidget,SIGNAL(stop()),this,SLOT(stopLibraryCreator()));
//packageManager connections //packageManager connections
@ -812,17 +812,25 @@ void LibraryWindow::loadLibrary(const QString & name)
deleteCurrentLibrary(); deleteCurrentLibrary();
} }
} }
else//si existe el path, puede ser que la librería sea alguna versión pre-5.0 ó que esté corrupta else//si existe el path, puede ser que la librería sea alguna versión pre-5.0 ó que esté corrupta o que no haya drivers sql
{ {
QString currentLibrary = selectedLibrary->currentText(); QSqlDatabase db = DataBaseManagement::loadDatabase(path);
QString path = libraries.value(selectedLibrary->currentText()); if(d.exists(path+"/library.ydb"))
if(QMessageBox::question(this,tr("Old library or corrupted"),tr("Library ")+currentLibrary+tr(" is corrupted or has been created with an older version of YACReaderLibrary. It must be created again. Do you want to create the library now?"),QMessageBox::Yes,QMessageBox::No)==QMessageBox::Yes)
{ {
QDir d(path+"/.yacreaderlibrary"); manageOpeningLibraryError(db.lastError().databaseText() + "-" + db.lastError().driverText());
delTree(d); }
d.rmdir(path+"/.yacreaderlibrary"); else
createLibraryDialog->setDataAndStart(currentLibrary,path); {
//create(path,path+"/.yacreaderlibrary",currentLibrary); QString currentLibrary = selectedLibrary->currentText();
QString path = libraries.value(selectedLibrary->currentText());
if(QMessageBox::question(this,tr("Old library"),tr("Library ")+currentLibrary+tr("has been created with an older version of YACReaderLibrary. It must be created again. Do you want to create the library now?"),QMessageBox::Yes,QMessageBox::No)==QMessageBox::Yes)
{
QDir d(path+"/.yacreaderlibrary");
delTree(d);
d.rmdir(path+"/.yacreaderlibrary");
createLibraryDialog->setDataAndStart(currentLibrary,path);
//create(path,path+"/.yacreaderlibrary",currentLibrary);
}
} }
} }
} }
@ -1148,17 +1156,6 @@ void LibraryWindow::updateLibrary()
libraryCreator->start(); libraryCreator->start();
} }
/*
void LibraryWindow::deleteLibrary()
{
QString currentLibrary = selectedLibrary->currentText();
if(QMessageBox::question(this,tr("Are you sure?"),tr("Do you want delete ")+currentLibrary+" library?",QMessageBox::Yes,QMessageBox::No)==QMessageBox::Yes)
{
deleteCurrentLibrary();
}
}
*/
void LibraryWindow::deleteCurrentLibrary() void LibraryWindow::deleteCurrentLibrary()
{ {
//QSqlDatabase db = dm->getDatabase(); //QSqlDatabase db = dm->getDatabase();
@ -1429,47 +1426,6 @@ void LibraryWindow::reloadOptions()
comicFlow->updateConfig(settings); comicFlow->updateConfig(settings);
} }
//TODO esto sobra
void LibraryWindow::updateFoldersView(QString path)
{
//QModelIndex mi = dm->index(path);
//int rowCount = dm->rowCount(mi);
//if(!fetching)
//{
// //fetching = true;
// for(int i=0;i<rowCount;i++)
// {
// dm->fetchMore(dm->index(i,0,mi));
// //int childCount = dm->rowCount(dm->index(i,0,mi));
// //if(childCount>0)
// // QMessageBox::critical(NULL,tr("..."),tr("-----"));
// fetching = false;
// }
//}
}
void LibraryWindow::searchInFiles(int state)
{
if(state == Qt::Checked)
{
if(!foldersFilter->text().isEmpty())
{
dm->setFilter(foldersFilter->text(), true);
foldersView->expandAll();
}
}
else
{
if(!foldersFilter->text().isEmpty())
{
dm->setFilter(foldersFilter->text(), false);
foldersView->expandAll();
}
}
}
QString LibraryWindow::currentPath() QString LibraryWindow::currentPath()
{ {
return libraries.value(selectedLibrary->currentText()); return libraries.value(selectedLibrary->currentText());
@ -1599,4 +1555,19 @@ void LibraryWindow::showImportingWidget()
importWidget->clear(); importWidget->clear();
libraryToolBar->setDisabled(true); libraryToolBar->setDisabled(true);
mainWidget->setCurrentIndex(2); mainWidget->setCurrentIndex(2);
}
void LibraryWindow::manageCreatingError(const QString & error)
{
QMessageBox::critical(this,tr("Error creating the library"),error);
}
void LibraryWindow::manageUpdatingError(const QString & error)
{
QMessageBox::critical(this,tr("Error updating the library"),error);
}
void LibraryWindow::manageOpeningLibraryError(const QString & error)
{
QMessageBox::critical(this,tr("Error opening the library"),error);
} }

View File

@ -218,13 +218,11 @@ public:
void exportLibrary(QString destPath); void exportLibrary(QString destPath);
void importLibrary(QString clc,QString destPath,QString name); void importLibrary(QString clc,QString destPath,QString name);
void reloadOptions(); void reloadOptions();
void updateFoldersView(QString);
void setCurrentComicsStatusReaded(bool readed); void setCurrentComicsStatusReaded(bool readed);
void setCurrentComicReaded(); void setCurrentComicReaded();
void setCurrentComicUnreaded(); void setCurrentComicUnreaded();
void setComicsReaded(); void setComicsReaded();
void setComicsUnreaded(); void setComicsUnreaded();
void searchInFiles(int);
void hideComicFlow(bool hide); void hideComicFlow(bool hide);
void showExportComicsInfo(); void showExportComicsInfo();
void showImportComicsInfo(); void showImportComicsInfo();
@ -232,6 +230,9 @@ public:
void showNoLibrariesWidget(); void showNoLibrariesWidget();
void showRootWidget(); void showRootWidget();
void showImportingWidget(); void showImportingWidget();
void manageCreatingError(const QString & error);
void manageUpdatingError(const QString & error);
void manageOpeningLibraryError(const QString & error);
//server interface //server interface
QMap<QString,QString> getLibraries(){return libraries;}; QMap<QString,QString> getLibraries(){return libraries;};