The database is now created from the program. We don't need to copy or provide fosdem...
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Wed, 22 Jun 2011 21:33:29 +0000 (21:33 +0000)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Wed, 22 Jun 2011 21:33:29 +0000 (21:33 +0000)
src/db.qrc
src/sql/sqlengine.cpp

index 37282e0..03d8d30 100644 (file)
@@ -1,6 +1,6 @@
 <!DOCTYPE RCC><RCC version="1.0">
 <qresource>
 <!DOCTYPE RCC><RCC version="1.0">
 <qresource>
-    <file>fosdem.sqlite</file>
+    <file>create_tables.sql</file>
 </qresource>
 </RCC>
 
 </qresource>
 </RCC>
 
index 9b2948b..8e3e780 100644 (file)
@@ -50,12 +50,15 @@ QString SqlEngine::login(const QString &aDatabaseType, const QString &aDatabaseN
     bool result = false;
     if(!QFile::exists(aDatabaseName)) // the DB (tables) doesn't exists, and so we have to create one
     {
     bool result = false;
     if(!QFile::exists(aDatabaseName)) // the DB (tables) doesn't exists, and so we have to create one
     {
-        // copy conference Db from resource, instead of creating
-        // empty tables and then parsing the schedule
-        QFile dbFile(aDatabaseName);
-        QFile(":/fosdem.sqlite").copy(aDatabaseName);
-        dbFile.setPermissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ReadGroup | QFile::WriteGroup);
-        database.open();
+        // create Db
+        if (!database.open()) qDebug() << "Could not open database" << database.lastError();
+        QFile file(":/create_tables.sql");
+        file.open(QIODevice::ReadOnly | QIODevice::Text);
+        QString allSqlStatements = file.readAll();
+        foreach(QString sql, allSqlStatements.split(";")) {
+            QSqlQuery query(database);
+            if (!query.exec(sql)) qDebug() << "Could not execute query" << query.lastError();
+        }
     }
     else
     {
     }
     else
     {