using namespace std;
const int DbCreator::TABLES_COUNT = 3;
-const QString DbCreator::TABLES[] = {"platform", "mediatype", "filetype"};
+const QString DbCreator::TABLES[] = {"platform", "mediatype", "filepath"};
DbCreator::DbCreator(QObject *parent) : QObject(parent)
{
/*if (!tableExists("platform"))
{*/
qDebug() << "Creating table platform";
+ query.exec("drop table if exists platform");
ret = query.exec("create table if not exists platform "
"(id integer primary key, "
"name varchar(30), "
if (!tableExists("mediatype"))
{*/
qDebug() << "Creating table mediatype ";
+ query.exec("drop table if exists mediatype");
ret = query.exec("create table if not exists mediatype "
"(id integer primary key, "
"name varchar(30), "
if (!tableExists("filepath"))
{*/
qDebug() << "Creating table filepath";
- query.exec("create table filepath "
+ query.exec("drop table if exists filepath");
+ ret = query.exec("create table if not exists filepath "
"(id integer primary key, "
"name text, "
"filetypeid integer, "
"platformid integer, "
"mediatypeid integer, "
- "lastscanned numeric)");
+ "lastscanned numeric, "
+ "foreign key (platformid) references platform(id), "
+ "foreign key (mediatypeid) references mediatype(id))");
+ if (ret) qDebug() << "Table filepath created succesfully!";
if (!ret) throw QString("filepath");
//}
#include <QApplication>
#include <QTextStream>
+#include <QDebug>
#include <iostream>
#include "mainwindow.h"
#include "db/databasemanager.h"
{
QApplication app(argc, argv);
QTextStream cout(stdout, QIODevice::WriteOnly);
+ QStringList arglst = app.arguments();
+
+ bool reset = arglst.contains("reset", Qt::CaseInsensitive);
+
+ if (reset) qDebug() << "Database Reset requested";
if (DatabaseManager::openDB())
cout << " Database opened succesfully!" << endl;
else cout << " Database connection failed!" << endl;
- if (DbCreator::dbExists())
- {
- cout << " Database exists!" << endl;
- }
- else
+ if (reset || !DbCreator::dbExists())
{
try
{
exit(1);
}
}
- MainWindow *mw = new MainWindow;
+ else cout << " Database exists!" << endl;
+
+ MainWindow *mw = new MainWindow;
mw->show();
return app.exec();
}