Ignore:
Timestamp:
04/15/10 14:49:59 (12 years ago)
Author:
kirilma <kirilma@…>
Branches:
master, qt5
Children:
04acaf9
Parents:
f5b68a4
Message:

implement deleting a conference

pass event about it to mainwindow to update select control
fix Conference::activeConference() to work when first conference is removed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sql/sqlengine.cpp

    rf5b68a4 rd97bcab  
    321321}
    322322
     323void SqlEngine::deleteConference(int id)
     324{
     325    QSqlDatabase db = QSqlDatabase::database();
     326
     327    if ( !db.isValid() || !db.isOpen()) {
     328        return;
     329    }
     330
     331    beginTransaction();
     332
     333    QHash<QString, QVariant> params;
     334    params["xid_conference"] = id;
     335    execQueryWithParameter(db, "DELETE FROM LINK WHERE xid_conference = :xid_conference", params);
     336    execQueryWithParameter(db, "DELETE FROM EVENT_ROOM WHERE xid_conference = :xid_conference", params);
     337    execQueryWithParameter(db, "DELETE FROM EVENT_PERSON WHERE xid_conference = :xid_conference", params);
     338    execQueryWithParameter(db, "DELETE FROM EVENT WHERE xid_conference = :xid_conference", params);
     339    execQueryWithParameter(db, "DELETE FROM CONFERENCE WHERE id = :xid_conference", params);
     340    execQuery(db, "DELETE FROM ROOM WHERE NOT EXISTS(SELECT * FROM EVENT_ROOM WHERE xid_room = ROOM.id)");
     341    execQuery(db, "DELETE FROM PERSON WHERE NOT EXISTS(SELECT * FROM EVENT_PERSON WHERE xid_person = PERSON.id)");
     342
     343    commitTransaction();
     344}
     345
    323346bool SqlEngine::execQuery(QSqlDatabase &aDatabase, const QString &aQuery)
    324347{
     
    336359}
    337360
     361bool SqlEngine::execQueryWithParameter(QSqlDatabase &aDatabase, const QString &aQuery, const QHash<QString, QVariant>& params)
     362{
     363    qDebug() << "SQL:" << aQuery << "params:" << params;
     364
     365    QSqlQuery sqlQuery(aDatabase);
     366    sqlQuery.prepare(aQuery);
     367    foreach (QString param_key, params.keys()) {
     368        sqlQuery.bindValue(param_key, params[param_key]);
     369    }
     370    if( !sqlQuery.exec() ){
     371       qDebug() << "SQL ERR: " << sqlQuery.lastError().number() << ", " << sqlQuery.lastError().text();
     372       return false;
     373    }
     374    else{
     375       //qDebug() << "SQL OK.\n";
     376       return true;
     377    }
     378}
     379
Note: See TracChangeset for help on using the changeset viewer.