[ca90cb1] | 1 | /* |
---|
| 2 | * Copyright (C) 2010 Ixonos Plc. |
---|
[68b2df2] | 3 | * Copyright (C) 2011 Philipp Spitzer, gregor herrmann |
---|
[ca90cb1] | 4 | * |
---|
[6df32f2] | 5 | * This file is part of ConfClerk. |
---|
[ca90cb1] | 6 | * |
---|
[6df32f2] | 7 | * ConfClerk is free software: you can redistribute it and/or modify it |
---|
[ca90cb1] | 8 | * under the terms of the GNU General Public License as published by the Free |
---|
| 9 | * Software Foundation, either version 2 of the License, or (at your option) |
---|
| 10 | * any later version. |
---|
| 11 | * |
---|
[6df32f2] | 12 | * ConfClerk is distributed in the hope that it will be useful, but |
---|
[ca90cb1] | 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
---|
| 14 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
---|
| 15 | * more details. |
---|
| 16 | * |
---|
| 17 | * You should have received a copy of the GNU General Public License along with |
---|
[6df32f2] | 18 | * ConfClerk. If not, see <http://www.gnu.org/licenses/>. |
---|
[ca90cb1] | 19 | */ |
---|
[72f6fe4] | 20 | |
---|
| 21 | #include <QSqlError> |
---|
| 22 | #include <QSqlQuery> |
---|
| 23 | #include <QSqlRecord> |
---|
| 24 | #include <QVariant> |
---|
| 25 | #include <QDateTime> |
---|
| 26 | |
---|
| 27 | #include <QDir> |
---|
[9f97eaf] | 28 | #include <QDesktopServices> |
---|
[72f6fe4] | 29 | #include "sqlengine.h" |
---|
[72cd3af] | 30 | #include <track.h> |
---|
[1735f55] | 31 | #include <conference.h> |
---|
[72f6fe4] | 32 | |
---|
| 33 | #include <QDebug> |
---|
| 34 | |
---|
| 35 | const QString DATE_FORMAT ("yyyy-MM-dd"); |
---|
| 36 | const QString TIME_FORMAT ("hh:mm"); |
---|
| 37 | |
---|
| 38 | SqlEngine::SqlEngine(QObject *aParent) |
---|
| 39 | : QObject(aParent) |
---|
| 40 | { |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | SqlEngine::~SqlEngine() |
---|
| 44 | { |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | QString SqlEngine::login(const QString &aDatabaseType, const QString &aDatabaseName) |
---|
| 48 | { |
---|
| 49 | QSqlDatabase database = QSqlDatabase::addDatabase(aDatabaseType); |
---|
| 50 | database.setDatabaseName(aDatabaseName); |
---|
| 51 | |
---|
| 52 | bool result = false; |
---|
| 53 | if(!QFile::exists(aDatabaseName)) // the DB (tables) doesn't exists, and so we have to create one |
---|
| 54 | { |
---|
[4b8ce66] | 55 | // create Db |
---|
| 56 | if (!database.open()) qDebug() << "Could not open database" << database.lastError(); |
---|
| 57 | QFile file(":/create_tables.sql"); |
---|
| 58 | file.open(QIODevice::ReadOnly | QIODevice::Text); |
---|
| 59 | QString allSqlStatements = file.readAll(); |
---|
| 60 | foreach(QString sql, allSqlStatements.split(";")) { |
---|
| 61 | QSqlQuery query(database); |
---|
| 62 | if (!query.exec(sql)) qDebug() << "Could not execute query" << query.lastError(); |
---|
| 63 | } |
---|
[72f6fe4] | 64 | } |
---|
[e662750] | 65 | else |
---|
| 66 | { |
---|
| 67 | database.open(); |
---|
| 68 | } |
---|
[72f6fe4] | 69 | |
---|
| 70 | //LOG_INFO(QString("Opening '%1' database '%2'").arg(aDatabaseType).arg(aDatabaseName)); |
---|
| 71 | |
---|
| 72 | return result ? QString() : database.lastError().text(); |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | void SqlEngine::initialize() |
---|
| 76 | { |
---|
| 77 | QString databaseName; |
---|
[9f97eaf] | 78 | QString dataDirName; |
---|
| 79 | dataDirName = QDesktopServices::storageLocation(QDesktopServices::DataLocation); |
---|
| 80 | QDir dataDir = QDir(dataDirName).absolutePath(); |
---|
| 81 | if(!dataDir.exists()) |
---|
| 82 | dataDir.mkpath(dataDirName); |
---|
[df884b3] | 83 | databaseName = dataDirName + "/ConfClerk.sqlite"; |
---|
[72f6fe4] | 84 | login("QSQLITE",databaseName); |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | void SqlEngine::addConferenceToDB(QHash<QString,QString> &aConference) |
---|
| 88 | { |
---|
| 89 | QSqlDatabase db = QSqlDatabase::database(); |
---|
| 90 | |
---|
| 91 | if (db.isValid() && db.isOpen()) |
---|
| 92 | { |
---|
[1735f55] | 93 | int confId = 0; |
---|
| 94 | QList<Conference> confsList = Conference::getAll(); |
---|
| 95 | if(confsList.count()) |
---|
| 96 | { |
---|
| 97 | QListIterator<Conference> i(confsList); |
---|
| 98 | while (i.hasNext()) |
---|
| 99 | { |
---|
| 100 | Conference conf = i.next(); |
---|
| 101 | if( aConference["title"] == conf.title() ) |
---|
| 102 | { |
---|
| 103 | confId = conf.id(); |
---|
| 104 | aConference["id"] = QString::number(confId); |
---|
| 105 | break; |
---|
| 106 | } |
---|
| 107 | } |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | if(!confId) // conference 'aConference' isn't in the table => insert |
---|
| 111 | { |
---|
[d06ae27] | 112 | QSqlQuery query(db); |
---|
| 113 | query.prepare("INSERT INTO CONFERENCE (title,url,subtitle,venue,city,start,end,days," |
---|
| 114 | "day_change,timeslot_duration,active) " |
---|
| 115 | " VALUES (:title,:url,:subtitle,:venue,:city,:start,:end,:days," |
---|
| 116 | ":day_change,:timeslot_duration,:active)"); |
---|
| 117 | foreach (QString prop_name, (QList<QString>() << "title" << "url" << "subtitle" << "venue" << "city" << "days")) { |
---|
| 118 | query.bindValue(QString(":") + prop_name, aConference[prop_name]); |
---|
| 119 | } |
---|
| 120 | query.bindValue(":start", QDateTime(QDate::fromString(aConference["start"],DATE_FORMAT),QTime(0,0),Qt::UTC).toTime_t()); |
---|
| 121 | query.bindValue(":end", QDateTime(QDate::fromString(aConference["end"],DATE_FORMAT),QTime(0,0),Qt::UTC).toTime_t()); |
---|
| 122 | query.bindValue(":day_change", -QTime::fromString(aConference["day_change"],TIME_FORMAT).secsTo(QTime(0,0))); |
---|
| 123 | query.bindValue(":day_change", -QTime::fromString(aConference["timeslot_duration"],TIME_FORMAT).secsTo(QTime(0,0))); |
---|
| 124 | query.bindValue(":active", confsList.count() > 0 ? 0 : 1); |
---|
[f657e9c] | 125 | if (!query.exec()) qDebug() << "Could not execute query to insert a conference:" << query.lastError(); |
---|
[d06ae27] | 126 | aConference["id"] = query.lastInsertId().toString(); // 'id' is assigned automatically |
---|
[1735f55] | 127 | } |
---|
[72f6fe4] | 128 | } |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | void SqlEngine::addEventToDB(QHash<QString,QString> &aEvent) |
---|
| 132 | { |
---|
| 133 | QSqlDatabase db = QSqlDatabase::database(); |
---|
| 134 | |
---|
| 135 | if (db.isValid() && db.isOpen()) |
---|
| 136 | { |
---|
[005e2b7] | 137 | //insert event track to table and get track id |
---|
[51529bd] | 138 | int conference = aEvent["conference_id"].toInt(); |
---|
[72cd3af] | 139 | QString name = aEvent["track"]; |
---|
| 140 | Track track; |
---|
| 141 | int trackId; |
---|
| 142 | try |
---|
[926f106] | 143 | { |
---|
[141a5c2] | 144 | track = Track::retrieveByName(conference, name); |
---|
[72cd3af] | 145 | trackId = track.id(); |
---|
[926f106] | 146 | } |
---|
[72cd3af] | 147 | catch (OrmNoObjectException &e) { |
---|
[51529bd] | 148 | track.setConference(conference); |
---|
[72cd3af] | 149 | track.setName(name); |
---|
| 150 | trackId = track.insert(); |
---|
[926f106] | 151 | } |
---|
[5d9409d] | 152 | QDateTime startDateTime; |
---|
| 153 | startDateTime.setTimeSpec(Qt::UTC); |
---|
| 154 | startDateTime = QDateTime(QDate::fromString(aEvent["date"],DATE_FORMAT),QTime::fromString(aEvent["start"],TIME_FORMAT),Qt::UTC); |
---|
[f548c17] | 155 | |
---|
| 156 | bool event_exists = false; |
---|
| 157 | { |
---|
| 158 | QSqlQuery check_event_query; |
---|
| 159 | check_event_query.prepare("SELECT * FROM EVENT WHERE xid_conference = :xid_conference AND id = :id"); |
---|
[c129da26] | 160 | check_event_query.bindValue(":xid_conference", aEvent["conference_id"]); |
---|
[f548c17] | 161 | check_event_query.bindValue(":id", aEvent["id"]); |
---|
[c129da26] | 162 | if (!check_event_query.exec()) { |
---|
| 163 | qWarning() << "check event failed, conference id:" << aEvent["xid_conference"] |
---|
| 164 | << "event id:" << aEvent["id"] |
---|
| 165 | << "error:" << check_event_query.lastError() |
---|
| 166 | ; |
---|
| 167 | return; |
---|
| 168 | } |
---|
| 169 | if (check_event_query.isActive() and check_event_query.isSelect() and check_event_query.next()) { |
---|
[f548c17] | 170 | event_exists = true; |
---|
| 171 | } |
---|
| 172 | } |
---|
| 173 | |
---|
[7d7659d] | 174 | QSqlQuery result; |
---|
[f548c17] | 175 | if (event_exists) { |
---|
| 176 | result.prepare("UPDATE EVENT SET" |
---|
| 177 | " start = :start" |
---|
| 178 | ", duration = :duration" |
---|
| 179 | ", xid_track = :xid_track" |
---|
| 180 | ", type = :type" |
---|
| 181 | ", language = :language" |
---|
| 182 | ", tag = :tag" |
---|
| 183 | ", title = :title" |
---|
| 184 | ", subtitle = :subtitle" |
---|
| 185 | ", abstract = :abstract" |
---|
| 186 | ", description = :description" |
---|
| 187 | " WHERE id = :id AND xid_conference = :xid_conference"); |
---|
| 188 | } else { |
---|
| 189 | result.prepare("INSERT INTO EVENT " |
---|
| 190 | " (xid_conference, id, start, duration, xid_track, type, " |
---|
| 191 | " language, tag, title, subtitle, abstract, description) " |
---|
[c129da26] | 192 | " VALUES (:xid_conference, :id, :start, :duration, :xid_track, :type, " |
---|
[f548c17] | 193 | ":language, :tag, :title, :subtitle, :abstract, :description)"); |
---|
| 194 | } |
---|
| 195 | result.bindValue(":xid_conference", aEvent["conference_id"]); |
---|
| 196 | result.bindValue(":start", QString::number(startDateTime.toTime_t())); |
---|
| 197 | result.bindValue(":duration", -QTime::fromString(aEvent["duration"],TIME_FORMAT).secsTo(QTime(0,0))); |
---|
| 198 | result.bindValue(":xid_track", trackId); |
---|
| 199 | static const QList<QString> props = QList<QString>() |
---|
| 200 | << "id" << "type" << "language" << "tag" << "title" << "subtitle" << "abstract" << "description"; |
---|
| 201 | foreach (QString prop_name, props) { |
---|
| 202 | result.bindValue(QString(":") + prop_name, aEvent[prop_name]); |
---|
| 203 | } |
---|
[c129da26] | 204 | if (!result.exec()) { |
---|
| 205 | qWarning() << "event insert/update failed:" << result.lastError(); |
---|
| 206 | } |
---|
[72f6fe4] | 207 | } |
---|
| 208 | } |
---|
| 209 | |
---|
| 210 | void SqlEngine::addPersonToDB(QHash<QString,QString> &aPerson) |
---|
| 211 | { |
---|
| 212 | QSqlDatabase db = QSqlDatabase::database(); |
---|
| 213 | |
---|
| 214 | if (db.isValid() && db.isOpen()) |
---|
| 215 | { |
---|
[dcefa71] | 216 | QSqlQuery query(db); |
---|
| 217 | query.prepare("INSERT INTO PERSON (xid_conference,id,name) VALUES (:xid_conference, :id, :name)"); |
---|
| 218 | query.bindValue(":xid_conference", aPerson["conference_id"]); |
---|
| 219 | query.bindValue(":id", aPerson["id"]); |
---|
| 220 | query.bindValue(":name", aPerson["name"]); |
---|
| 221 | query.exec(); // some queries fail due to the unique key constraint |
---|
| 222 | // if (!query.exec()) qDebug() << "SQL query 'insert into person' failed: " << query.lastError(); |
---|
| 223 | |
---|
| 224 | query = QSqlQuery(db); |
---|
| 225 | query.prepare("INSERT INTO EVENT_PERSON (xid_conference,xid_event,xid_person) VALUES (:xid_conference, :xid_event, :xid_person)"); |
---|
| 226 | query.bindValue(":xid_conference", aPerson["conference_id"]); |
---|
| 227 | query.bindValue(":xid_event", aPerson["event_id"]); |
---|
| 228 | query.bindValue(":xid_person", aPerson["id"]); |
---|
| 229 | query.exec(); // some queries fail due to the unique key constraint |
---|
| 230 | // if (!query.exec()) qDebug() << "SQL query 'insert into event_person' failed: " << query.lastError(); |
---|
[72f6fe4] | 231 | } |
---|
| 232 | } |
---|
| 233 | |
---|
| 234 | void SqlEngine::addRoomToDB(QHash<QString,QString> &aRoom) |
---|
| 235 | { |
---|
| 236 | QSqlDatabase db = QSqlDatabase::database(); |
---|
| 237 | |
---|
| 238 | if (db.isValid() && db.isOpen()) |
---|
| 239 | { |
---|
[63b2343] | 240 | QSqlQuery query(db); |
---|
| 241 | query.prepare("SELECT id FROM ROOM WHERE xid_conference=:conference_id and name=:name"); |
---|
| 242 | query.bindValue(":conference_id", aRoom["conference_id"]); |
---|
| 243 | query.bindValue(":name", aRoom["name"]); |
---|
| 244 | if (!query.exec()) qDebug() << "Could not execute select room query: " << query.lastError(); |
---|
[72f6fe4] | 245 | // now we have to check whether ROOM record with 'name' exists or not, |
---|
| 246 | // - if it doesn't exist yet, then we have to add that record to 'ROOM' table |
---|
| 247 | // and assign autoincremented 'id' to aRoom |
---|
| 248 | // - if it exists, then we need to get its 'id' and assign it to aRoom |
---|
[909ea23] | 249 | aRoom["id"] = ""; |
---|
[63b2343] | 250 | if(query.next()) // ROOM record with 'name' already exists: we need to get its 'id' |
---|
[72f6fe4] | 251 | { |
---|
[f09a1b9] | 252 | aRoom["id"] = query.value(0).toString(); |
---|
[72f6fe4] | 253 | } |
---|
| 254 | else // ROOM record doesn't exist yet, need to create it |
---|
| 255 | { |
---|
[909ea23] | 256 | query = QSqlQuery(db); |
---|
[e6ab8a2] | 257 | query.prepare("INSERT INTO ROOM (xid_conference,name,picture) VALUES (:xid_conference, :name, '')"); |
---|
[909ea23] | 258 | query.bindValue(":xid_conference", aRoom["conference_id"]); |
---|
| 259 | query.bindValue(":xid_name", aRoom["name"]); |
---|
| 260 | if (!query.exec()) qDebug() << "Could not execute 'insert into room ...' query." << query.lastError(); |
---|
[f09a1b9] | 261 | aRoom["id"]= query.lastInsertId().toString(); // 'id' is assigned automatically |
---|
[72f6fe4] | 262 | //LOG_AUTOTEST(query); |
---|
| 263 | } |
---|
[63b2343] | 264 | query = QSqlQuery(db); |
---|
[f09a1b9] | 265 | query.prepare("INSERT INTO EVENT_ROOM (xid_conference,xid_event,xid_room) VALUES (:conference_id, :event_id, :room_id)"); |
---|
[63b2343] | 266 | query.bindValue(":conference_id", aRoom["conference_id"]); |
---|
| 267 | query.bindValue(":event_id", aRoom["event_id"]); |
---|
[f09a1b9] | 268 | query.bindValue(":room_id", aRoom["id"]); |
---|
[909ea23] | 269 | if (!query.exec()) qDebug() << "Could not 'execute insert into event_room' query:" << query.lastError(); |
---|
[72f6fe4] | 270 | } |
---|
| 271 | } |
---|
| 272 | |
---|
| 273 | void SqlEngine::addLinkToDB(QHash<QString,QString> &aLink) |
---|
| 274 | { |
---|
| 275 | QSqlDatabase db = QSqlDatabase::database(); |
---|
| 276 | |
---|
| 277 | //TODO: check if the link doesn't exist before inserting |
---|
| 278 | if (db.isValid() && db.isOpen()) |
---|
| 279 | { |
---|
[dc54e87] | 280 | QSqlQuery query(db); |
---|
| 281 | query.prepare("INSERT INTO LINK (xid_event, xid_conference, name, url) VALUES (:xid_event, :xid_conference, :name, :url)"); |
---|
| 282 | query.bindValue(":xid_event", aLink["event_id"]); |
---|
| 283 | query.bindValue(":xid_conference", aLink["conference_id"]); |
---|
| 284 | query.bindValue(":name", aLink["name"]); |
---|
| 285 | query.bindValue(":url", aLink["url"]); |
---|
| 286 | if (!query.exec()) qDebug() << "Error executing 'insert into link' query: " << query.lastError(); |
---|
[72f6fe4] | 287 | } |
---|
| 288 | } |
---|
| 289 | |
---|
[c7b58d4] | 290 | int SqlEngine::searchEvent(int aConferenceId, const QHash<QString,QString> &aColumns, const QString &aKeyword) |
---|
[990afd5] | 291 | { |
---|
| 292 | QSqlDatabase db = QSqlDatabase::database(); |
---|
| 293 | |
---|
| 294 | if ( !db.isValid() || !db.isOpen()) |
---|
| 295 | return -1; |
---|
| 296 | |
---|
[a55781e] | 297 | if (aColumns.empty()) return -1; |
---|
[990afd5] | 298 | |
---|
[e662750] | 299 | // DROP |
---|
[63b2343] | 300 | execQuery( db, "DROP TABLE IF EXISTS SEARCH_EVENT"); |
---|
[e662750] | 301 | // CREATE |
---|
[e388cda] | 302 | execQuery( db, "CREATE TEMP TABLE SEARCH_EVENT ( xid_conference INTEGER NOT NULL, id INTEGER NOT NULL )"); |
---|
[e662750] | 303 | // INSERT |
---|
[a55781e] | 304 | QString sql = QString("INSERT INTO SEARCH_EVENT ( xid_conference, id ) " |
---|
[66698a6] | 305 | "SELECT DISTINCT EVENT.xid_conference, EVENT.id FROM EVENT "); |
---|
[c7b58d4] | 306 | if( aColumns.contains("ROOM") ){ |
---|
[a55781e] | 307 | sql += "INNER JOIN EVENT_ROOM ON ( EVENT.xid_conference = EVENT_ROOM.xid_conference AND EVENT.id = EVENT_ROOM.xid_event ) "; |
---|
| 308 | sql += "INNER JOIN ROOM ON ( EVENT_ROOM.xid_room = ROOM.id ) "; |
---|
[c7b58d4] | 309 | } |
---|
| 310 | if( aColumns.contains("PERSON") ){ |
---|
[a55781e] | 311 | sql += "INNER JOIN EVENT_PERSON ON ( EVENT.xid_conference = EVENT_PERSON.xid_conference AND EVENT.id = EVENT_PERSON.xid_event ) "; |
---|
| 312 | sql += "INNER JOIN PERSON ON ( EVENT_PERSON.xid_person = PERSON.id ) "; |
---|
[c7b58d4] | 313 | } |
---|
[a55781e] | 314 | sql += QString("WHERE EVENT.xid_conference = %1 AND (").arg( aConferenceId ); |
---|
[c7b58d4] | 315 | |
---|
[47eda2b] | 316 | QStringList searchKeywords = aKeyword.split(QRegExp("\\s+")); |
---|
[c7b58d4] | 317 | foreach (QString table, aColumns.uniqueKeys()){ |
---|
| 318 | foreach (QString column, aColumns.values(table)){ |
---|
[47eda2b] | 319 | for (int i=0; i < searchKeywords.count(); i++){ |
---|
| 320 | sql += QString("%1.%2 LIKE '\%' || :%1%2 || '\%' OR ").arg( table, column ); |
---|
| 321 | } |
---|
[c7b58d4] | 322 | } |
---|
[990afd5] | 323 | } |
---|
[a55781e] | 324 | sql.chop( QString(" OR ").length() ); |
---|
| 325 | sql += QString(")"); |
---|
[990afd5] | 326 | |
---|
[a55781e] | 327 | QSqlQuery query(db); |
---|
| 328 | query.prepare(sql); |
---|
| 329 | foreach (QString table, aColumns.uniqueKeys()){ |
---|
| 330 | foreach (QString column, aColumns.values(table)){ |
---|
[47eda2b] | 331 | foreach (QString keyword, searchKeywords){ |
---|
| 332 | query.bindValue(QString(":%1%2").arg(table, column), keyword ); |
---|
| 333 | } |
---|
[a55781e] | 334 | } |
---|
| 335 | } |
---|
| 336 | |
---|
| 337 | if( !query.exec() ){ |
---|
| 338 | qDebug() << "Could not execute search query: " << query.lastError().text(); |
---|
| 339 | return -1; |
---|
| 340 | } |
---|
[990afd5] | 341 | |
---|
[e662750] | 342 | return 1; |
---|
| 343 | } |
---|
| 344 | |
---|
[1bad318] | 345 | bool SqlEngine::beginTransaction() |
---|
| 346 | { |
---|
| 347 | QSqlDatabase db = QSqlDatabase::database(); |
---|
| 348 | |
---|
| 349 | return execQuery(db, "BEGIN IMMEDIATE TRANSACTION"); |
---|
| 350 | } |
---|
| 351 | |
---|
| 352 | bool SqlEngine::commitTransaction() |
---|
| 353 | { |
---|
| 354 | QSqlDatabase db = QSqlDatabase::database(); |
---|
| 355 | |
---|
| 356 | return execQuery(db, "COMMIT"); |
---|
| 357 | } |
---|
| 358 | |
---|
[d97bcab] | 359 | void SqlEngine::deleteConference(int id) |
---|
| 360 | { |
---|
| 361 | QSqlDatabase db = QSqlDatabase::database(); |
---|
| 362 | |
---|
| 363 | if ( !db.isValid() || !db.isOpen()) { |
---|
| 364 | return; |
---|
| 365 | } |
---|
| 366 | |
---|
| 367 | beginTransaction(); |
---|
| 368 | |
---|
| 369 | QHash<QString, QVariant> params; |
---|
| 370 | params["xid_conference"] = id; |
---|
| 371 | execQueryWithParameter(db, "DELETE FROM LINK WHERE xid_conference = :xid_conference", params); |
---|
| 372 | execQueryWithParameter(db, "DELETE FROM EVENT_ROOM WHERE xid_conference = :xid_conference", params); |
---|
| 373 | execQueryWithParameter(db, "DELETE FROM EVENT_PERSON WHERE xid_conference = :xid_conference", params); |
---|
| 374 | execQueryWithParameter(db, "DELETE FROM EVENT WHERE xid_conference = :xid_conference", params); |
---|
[c8b84e1] | 375 | execQueryWithParameter(db, "DELETE FROM ROOM WHERE xid_conference = :xid_conference", params); |
---|
| 376 | execQueryWithParameter(db, "DELETE FROM PERSON WHERE xid_conference = :xid_conference", params); |
---|
| 377 | execQueryWithParameter(db, "DELETE FROM TRACK WHERE xid_conference = :xid_conference", params); |
---|
[d97bcab] | 378 | execQueryWithParameter(db, "DELETE FROM CONFERENCE WHERE id = :xid_conference", params); |
---|
| 379 | |
---|
| 380 | commitTransaction(); |
---|
| 381 | } |
---|
| 382 | |
---|
[e662750] | 383 | bool SqlEngine::execQuery(QSqlDatabase &aDatabase, const QString &aQuery) |
---|
| 384 | { |
---|
| 385 | QSqlQuery sqlQuery(aDatabase); |
---|
| 386 | if( !sqlQuery.exec(aQuery) ){ |
---|
| 387 | qDebug() << "SQL ERR: " << sqlQuery.lastError().number() << ", " << sqlQuery.lastError().text(); |
---|
| 388 | return false; |
---|
[990afd5] | 389 | } |
---|
[cf385cd] | 390 | return true; |
---|
[990afd5] | 391 | } |
---|
[9f367eb] | 392 | |
---|
[d97bcab] | 393 | bool SqlEngine::execQueryWithParameter(QSqlDatabase &aDatabase, const QString &aQuery, const QHash<QString, QVariant>& params) |
---|
| 394 | { |
---|
| 395 | QSqlQuery sqlQuery(aDatabase); |
---|
| 396 | sqlQuery.prepare(aQuery); |
---|
| 397 | foreach (QString param_key, params.keys()) { |
---|
| 398 | sqlQuery.bindValue(param_key, params[param_key]); |
---|
| 399 | } |
---|
| 400 | if( !sqlQuery.exec() ){ |
---|
| 401 | qDebug() << "SQL ERR: " << sqlQuery.lastError().number() << ", " << sqlQuery.lastError().text(); |
---|
| 402 | return false; |
---|
| 403 | } |
---|
[cf385cd] | 404 | return true; |
---|
[d97bcab] | 405 | } |
---|