2 // Copyright 2010 Mikko Keinänen
4 // This file is part of EmuFront.
7 // EmuFront is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
12 // Foobar is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with Foobar. If not, see <http://www.gnu.org/licenses/>.
21 #include <QSqlDatabase>
25 #include "dbcreator.h"
29 DbCreator::DbCreator(QObject *parent) : QObject(parent)
34 bool DbCreator::createDB()
41 if (!tableExists("platform"))
43 qDebug() << "Creating table platform";
44 ret = query.exec("create table platform "
45 "(id integer primary key, "
47 "filename varchar(125))");
48 if (!ret) throw QString("platform.");
50 if (!tableExists("mediatype"))
52 qDebug() << "Creating table mediatype";
53 ret = query.exec("create table mediatype "
54 "(id integer primary key, "
56 "filename varchar(125))");
57 if (!ret) throw QString("mediatype.");
59 if (!tableExists("filetype"))
61 qDebug() << "Creating table filetype";
62 ret = query.exec("create table filetype "
63 "(id integer primary key, "
65 if (!ret) throw QString("filetype.");
66 query.exec("insert into filetype (id, name) values (1, 'media image container')");
67 query.exec("insert into filetype (id, name) values (2, 'screenshot')");
68 query.exec("insert into filetype (id, name) values (3, 'platform icon')");
69 query.exec("insert into filetype (id, name) values (4, 'media type icon')");
71 /*if (!tableExists("filepath"))
73 qDebug() << "Creating table filepath";
74 query.exec("create table filepath "
75 "(id integer primary key, "
76 "name varchar(255))");
78 if (!ret) throw QString("filepath");
83 throw QString("Couldn't create database '%1'!").arg(tbl);
89 * Check if database already exists.
90 * Returns false if doesn't or we don't have a connection.
92 bool DbCreator::dbExists()
94 return tableExists("platform");
97 bool DbCreator::tableExists(QString table)
100 query.exec(QString("SELECT name FROM sqlite_master WHERE name='%1'").arg(table));
104 bool DbCreator::deleteDB()
106 // return QFile::remove(getDbPath());