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>
23 #include "dbcreator.h"
25 DbCreator::DbCreator(QObject *parent) : QObject(parent)
30 bool DbCreator::createDB()
35 if (!tableExists("platform"))
37 query.exec("create table platform "
38 "(id integer primary key, "
40 "filename varchar(125))");
42 if (!tableExists("mediatype"))
44 query.exec("create table mediatype "
45 "(id integer primary key, "
47 "filename varchar(125))");
49 if (!tableExists("filetype"))
51 query.exec("create table filetype "
52 "(id integer primary key, "
54 query.exec("insert into filetype (id, name) values (1, 'media image container')");
55 query.exec("insert into filetype (id, name) values (2, 'screenshot')");
56 query.exec("insert into filetype (id, name) values (3, 'platform icon')");
57 query.exec("insert into filetype (id, name) values (4, 'media type icon')");
59 /*if (!tableExists("filepath"))
61 query.exec("create table filepath "
62 "(id integer primary key, "
63 "name varchar(255))");
70 * Check if database already exists.
71 * Returns false if doesn't or we don't have a connection.
73 bool DbCreator::dbExists()
75 return tableExists("platform");
78 bool DbCreator::tableExists(QString table)
81 query.exec(QString("SELECT name FROM sqlite_master WHERE name='%1'").arg(table));
85 bool DbCreator::deleteDB()
87 // return QFile::remove(getDbPath());