bool result = false;
if(!QFile::exists(aDatabaseName)) // the DB (tables) doesn't exists, and so we have to create one
{
- /*
- // creating empty DB + tables
- // ??? what is the best way of creating new empty DB ???
- // we can either:
- // - create new DB + tables by issuing corresponding queries (used solution)
- // - create new DB from resource, which contains empty DB with tables
- result = createTables(database);
- */
-
// copy conference Db from resource, instead of creating
// empty tables and then parsing the schedule
QFile dbFile(aDatabaseName);
}
}
-bool SqlEngine::createTables(QSqlDatabase &aDatabase)
-{
- bool result = aDatabase.open();
-
- if (aDatabase.isValid() && aDatabase.isOpen())
- {
- QSqlQuery query(aDatabase);
-
- query.exec("CREATE TABLE CONFERENCE ( "
- "id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "
- "title VARCHAR UNIQUE NOT NULL, "
- "subtitle VARCHAR, "
- "venue VARCHAR, "
- "city VARCHAR NOT NULL, "
- "start INTEGER NOT NULL, "
- "end INTEGER NOT NULL, "
- "days INTEGER, "
- "day_change INTEGER, "
- "timeslot_duration INTEGER, "
- "active INTEGER DEFAULT 0);");
-
- query.exec("CREATE TABLE TRACK ( "
- "id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "
- "name VARCHAR UNIQUE NOT NULL );");
-
- query.exec("CREATE TABLE ROOM ( "
- "id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "
- "name VARCHAR UNIQUE NOT NULL, "
- "picture VARCHAR NOT NULL);");
-
- query.exec("CREATE TABLE PERSON ( "
- "id INTEGER PRIMARY KEY NOT NULL, "
- "name VARCHAR UNIQUE NOT NULL);");
-
- query.exec("CREATE TABLE EVENT ( "
- "xid_conference INTEGER NOT NULL, "
- "id INTEGER NOT NULL, "
- "start INTEGER NOT NULL, "
- "duration INTEGER NOT NULL, "
- "xid_track INTEGER NOT NULL REFERENCES TRACK(id), "
- "type VARCHAR, "
- "language VARCHAR, "
- "tag VARCHAR,title VARCHAR NOT NULL, "
- "subtitle VARCHAR, "
- "abstract VARCHAR, "
- "description VARCHAR, "
- "favourite INTEGER DEFAULT 0, "
- "alarm INTEGER DEFAULT 0, "
- "PRIMARY KEY (xid_conference,id), "
- "FOREIGN KEY(xid_conference) REFERENCES CONFERENCE(id), "
- "FOREIGN KEY(xid_track) REFERENCES TRACK(id));");
-
- query.exec("CREATE TABLE EVENT_PERSON ( "
- "xid_conference INTEGER NOT NULL, "
- "xid_event INTEGER NOT NULL, "
- "xid_person INTEGER NOT NULL, "
- "UNIQUE ( xid_conference, xid_event, xid_person ) ON CONFLICT REPLACE, "
- "FOREIGN KEY(xid_conference) REFERENCES CONFERENCE(id), "
- "FOREIGN KEY(xid_event) REFERENCES EVENT(id), "
- "FOREIGN KEY(xid_person) REFERENCES PERSON(id));");
-
- query.exec("CREATE TABLE EVENT_ROOM ( "
- "xid_conference INTEGER NOT NULL, "
- "xid_event INTEGER NOT NULL, "
- "xid_room INTEGER NOT NULL, "
- "UNIQUE ( xid_conference, xid_event, xid_room ) ON CONFLICT REPLACE, "
- "FOREIGN KEY(xid_conference) REFERENCES CONFERENCE(id), "
- "FOREIGN KEY(xid_event) REFERENCES EVENT(id), "
- "FOREIGN KEY(xid_room) REFERENCES ROOM(id));");
-
- query.exec("CREATE TABLE LINK ( "
- "id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "
- "xid_conference INTEGER NOT NULL, "
- "xid_event INTEGER NOT NULL, "
- "name VARCHAR, "
- "url VARCHAR NOT NULL, "
- "UNIQUE ( xid_conference, xid_event, url ) ON CONFLICT REPLACE, "
- "FOREIGN KEY(xid_conference) REFERENCES CONFERENCE(id), "
- "FOREIGN KEY(xid_event) REFERENCES EVENT(id));");
- }
- else
- {
- //LOG_WARNING("Database is not opened");
- }
-
- return result;
-}
-
int SqlEngine::searchEvent(int aConferenceId, const QHash<QString,QString> &aColumns, const QString &aKeyword)
{
QSqlDatabase db = QSqlDatabase::database();