- Timestamp:
- 04/09/10 14:02:43 (13 years ago)
- Branches:
- master, qt5
- Children:
- 77e06ae
- Parents:
- 1bad318
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sql/sqlengine.cpp
r1bad318 rf548c17 157 157 startDateTime = QDateTime(QDate::fromString(aEvent["date"],DATE_FORMAT),QTime::fromString(aEvent["start"],TIME_FORMAT),Qt::UTC); 158 158 qDebug() << "startDateTime: " << startDateTime.toString(); 159 QString values = QString("'%1', '%2', '%3', '%4', '%5', '%6', '%7', ? , ? , ? , ? , ? , '%8', '%9'") \ 160 .arg(aEvent["conference_id"]) \ 161 .arg(aEvent["id"]) \ 162 .arg(QString::number(startDateTime.toTime_t())) \ 163 .arg(-QTime::fromString(aEvent["duration"],TIME_FORMAT).secsTo(QTime(0,0))) \ 164 .arg(trackId) \ 165 .arg(aEvent["type"]) \ 166 .arg(aEvent["language"]) \ 167 .arg("0") \ 168 .arg("0"); 169 170 QString query = 171 QString("INSERT INTO EVENT (xid_conference, id, start, duration, xid_track, type, language, tag, title, subtitle, abstract, description, favourite, alarm) VALUES (%1)") 172 .arg(values); 173 174 qDebug() << query; 159 160 bool event_exists = false; 161 { 162 QSqlQuery check_event_query; 163 check_event_query.prepare("SELECT * FROM EVENT WHERE xid_conference = :xid_conference AND id = :id"); 164 check_event_query.bindValue(":xid_conference", aEvent["xid_conference"]); 165 check_event_query.bindValue(":id", aEvent["id"]); 166 if (check_event_query.isActive() and check_event_query.isSelect() and check_event_query.first()) { 167 event_exists = true; 168 } 169 } 170 175 171 QSqlQuery result; 176 result.prepare(query); 177 result.bindValue(0,aEvent["tag"]); 178 result.bindValue(1,aEvent["title"]); 179 result.bindValue(2,aEvent["subtitle"]); 180 result.bindValue(3,aEvent["abstract"]); 181 result.bindValue(4,aEvent["description"]); 172 if (event_exists) { 173 result.prepare("UPDATE EVENT SET" 174 " start = :start" 175 ", duration = :duration" 176 ", xid_track = :xid_track" 177 ", type = :type" 178 ", language = :language" 179 ", tag = :tag" 180 ", title = :title" 181 ", subtitle = :subtitle" 182 ", abstract = :abstract" 183 ", description = :description" 184 " WHERE id = :id AND xid_conference = :xid_conference"); 185 } else { 186 result.prepare("INSERT INTO EVENT " 187 " (xid_conference, id, start, duration, xid_track, type, " 188 " language, tag, title, subtitle, abstract, description) " 189 " VALUES (:xid_conference, :id, :start, :duration, :xid_track " 190 ":language, :tag, :title, :subtitle, :abstract, :description)"); 191 } 192 result.bindValue(":xid_conference", aEvent["conference_id"]); 193 result.bindValue(":start", QString::number(startDateTime.toTime_t())); 194 result.bindValue(":duration", -QTime::fromString(aEvent["duration"],TIME_FORMAT).secsTo(QTime(0,0))); 195 result.bindValue(":xid_track", trackId); 196 static const QList<QString> props = QList<QString>() 197 << "id" << "type" << "language" << "tag" << "title" << "subtitle" << "abstract" << "description"; 198 foreach (QString prop_name, props) { 199 result.bindValue(QString(":") + prop_name, aEvent[prop_name]); 200 } 182 201 result.exec(); 183 202 } … … 298 317 "favourite INTEGER DEFAULT 0, " 299 318 "alarm INTEGER DEFAULT 0, " 300 "PRIMARY KEY (xid_conference,id) ON CONFLICT REPLACE, "319 "PRIMARY KEY (xid_conference,id), " 301 320 "FOREIGN KEY(xid_conference) REFERENCES CONFERENCE(id), " 302 321 "FOREIGN KEY(xid_track) REFERENCES TRACK(id));");
Note: See TracChangeset
for help on using the changeset viewer.