used 'MAEMO' define to create 'non-virtual' 'VIRUAL_EVENT' table
[toast/confclerk.git] / src / sql / sqlengine.cpp
index 48db577..0650590 100644 (file)
@@ -51,7 +51,7 @@ void SqlEngine::initialize()
     if(!QDir::home().exists(".fosdem"))
         QDir::home().mkdir(".fosdem");
     databaseName = QDir::homePath() + "/.fosdem/" + "fosdem.sqlite";
-
+qDebug()<<databaseName;
     login("QSQLITE",databaseName);
 }
 
@@ -67,8 +67,8 @@ void SqlEngine::addConferenceToDB(QHash<QString,QString> &aConference)
                          .arg(aConference["subtitle"]) \
                          .arg(aConference["venue"]) \
                          .arg(aConference["city"]) \
-                         .arg(QDateTime(QDate::fromString(aConference["start"],DATE_FORMAT)).toTime_t()) \
-                         .arg(QDateTime(QDate::fromString(aConference["end"],DATE_FORMAT)).toTime_t()) \
+                         .arg(QDateTime(QDate::fromString(aConference["start"],DATE_FORMAT),QTime(0,0),Qt::UTC).toTime_t()) \
+                         .arg(QDateTime(QDate::fromString(aConference["end"],DATE_FORMAT),QTime(0,0),Qt::UTC).toTime_t()) \
                          .arg(aConference["days"]) \
                          .arg(-QTime::fromString(aConference["day_change"],TIME_FORMAT).secsTo(QTime(0,0))) \
                          .arg(-QTime::fromString(aConference["timeslot_duration"],TIME_FORMAT).secsTo(QTime(0,0)));
@@ -90,16 +90,17 @@ void SqlEngine::addEventToDB(QHash<QString,QString> &aEvent)
         // The items of the Event are divided into the two tables EVENT and VIRTUAL_EVENT
         // VIRTUAL_EVENT is for Full-Text-Serach Support
         QDateTime startDateTime = QDateTime(QDate::fromString(aEvent["date"],DATE_FORMAT),QTime::fromString(aEvent["start"],TIME_FORMAT));
-        QString values = QString("'%1', '%2', '%3', '%4', '%5', '%6', '%7'") \
+        QString values = QString("'%1', '%2', '%3', '%4', '%5', '%6', '%7', '%8'") \
                          .arg(aEvent["conference_id"]) \
                          .arg(aEvent["id"]) \
                          .arg(QString::number(startDateTime.toTime_t())) \
                          .arg(-QTime::fromString(aEvent["duration"],TIME_FORMAT).secsTo(QTime(0,0))) \
                          .arg("123456") \
                          .arg(aEvent["type"]) \
-                         .arg(aEvent["language"]);
+                         .arg(aEvent["language"]) \
+                         .arg("0"); // not favourite when added
 
-        QString query = QString("INSERT INTO EVENT (xid_conference, id, start, duration, xid_activity, type, language) VALUES (%1)").arg(values);
+        QString query = QString("INSERT INTO EVENT (xid_conference, id, start, duration, xid_activity, type, language, favourite) VALUES (%1)").arg(values);
         QSqlQuery result (query, db);
         //LOG_AUTOTEST(query);
 
@@ -119,6 +120,7 @@ void SqlEngine::addEventToDB(QHash<QString,QString> &aEvent)
     }
 }
 
+
 void SqlEngine::addPersonToDB(QHash<QString,QString> &aPerson)
 {
     QSqlDatabase db = QSqlDatabase::database();
@@ -226,10 +228,24 @@ bool SqlEngine::createTables(QSqlDatabase &aDatabase)
             xid_activity INTEGER NOT NULL REFERENCES ACTIVITY(id), \
             type VARCHAR, \
             language VARCHAR, \
+            favourite INTEGER DEFAULT 0, \
             PRIMARY KEY (xid_conference,id), \
             FOREIGN KEY(xid_conference) REFERENCES CONFERENCE(id) \
             FOREIGN KEY(xid_activity) REFERENCES ACTIVITY(id))");
 
+#ifdef MAEMO
+        // TBD: MAEMO Virtual tables compatibility (waiting for Marek).
+        // MAEMO sqlite Qt driver doesn't provide FTS support by default - use the following HACK
+        qDebug() << "MAEMO: Creating 'general', not 'virtual' table 'VIRTUAL_EVENT'";
+        query.exec("CREATE TABLE VIRTUAL_EVENT ( \
+            xid_conference INTEGER  NOT NULL, \
+            id INTEGER NOT NULL , \
+            tag VARCHAR,title VARCHAR NOT NULL , \
+            subtitle VARCHAR, \
+            abstract VARCHAR, \
+            description VARCHAR, \
+            PRIMARY KEY (xid_conference,id))");
+#else
         query.exec("CREATE VIRTUAL TABLE VIRTUAL_EVENT using fts3 ( \
             xid_conference INTEGER  NOT NULL, \
             id INTEGER NOT NULL , \
@@ -238,6 +254,7 @@ bool SqlEngine::createTables(QSqlDatabase &aDatabase)
             abstract VARCHAR, \
             description VARCHAR, \
             PRIMARY KEY (xid_conference,id))");
+#endif
 
         query.exec("CREATE TABLE EVENT_PERSON ( \
             xid_conference INTEGER NOT NULL , \