]> ToastFreeware Gitweb - toast/confclerk.git/blobdiff - src/mvc/track.cpp
Bump copyright years.
[toast/confclerk.git] / src / mvc / track.cpp
index 9cadb47be481e6703ced6295c9769748b7818a54..f7893e8ca98eb4bf328c3a416358f2fea573c94e 100644 (file)
@@ -1,20 +1,21 @@
 /*
  * Copyright (C) 2010 Ixonos Plc.
+ * Copyright (C) 2011-2024 Philipp Spitzer, gregor herrmann, Stefan Stahl
  *
- * This file is part of fosdem-schedule.
+ * This file is part of ConfClerk.
  *
- * fosdem-schedule is free software: you can redistribute it and/or modify it
+ * ConfClerk is free software: you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the Free
  * Software Foundation, either version 2 of the License, or (at your option)
  * any later version.
  *
- * fosdem-schedule is distributed in the hope that it will be useful, but
+ * ConfClerk is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
  * You should have received a copy of the GNU General Public License along with
- * fosdem-schedule.  If not, see <http://www.gnu.org/licenses/>.
+ * ConfClerk.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include "track.h"
@@ -29,7 +30,7 @@ QSqlRecord const Track::sColumns = Track::toRecord(QList<QSqlField>()
     << QSqlField(CONFERENCEID, QVariant::Int)
     << QSqlField(NAME, QVariant::String));
 
-class TrackInsertException : OrmSqlException
+class TrackInsertException : public OrmSqlException
 {
 public:
     TrackInsertException(const QString& text) : OrmSqlException(text) {}
@@ -38,10 +39,17 @@ public:
 int Track::insert()
 {
     QSqlQuery query;
-    query.prepare("INSERT INTO " + sTableName + " (" + CONFERENCEID + "," + NAME + ")" + " VALUES " + "(\"" + QString::number(conferenceid()) + "\",\"" + name() + "\")");
+    QString trackname = name();
+    query.prepare(
+            QString("INSERT INTO %1 (%2, %3) VALUES (:xid_conference, :name)")
+            .arg(sTableName, CONFERENCEID, NAME));
+    query.bindValue(":xid_conference", conferenceid());
+    query.bindValue(":name", trackname);
     if (!query.exec())
     {
-        throw TrackInsertException("Exec Error");
+        throw TrackInsertException(
+                "Inserting track '" + trackname + "' into database failed: " +
+                query.lastError().text());
     }
     QVariant variant = query.lastInsertId();
     if (variant.isValid())
@@ -50,12 +58,13 @@ int Track::insert()
         throw TrackInsertException("Last Insert Id Error");
 }
 
-Track Track::retrieveByName(QString name)
+Track Track::retrieveByName(int conferenceid, QString name)
 {
     QSqlQuery query;
     query.prepare(
             selectQuery()
-            + QString("WHERE %1.name = :name").arg(sTableName));
+            + QString("WHERE %1.xid_conference = :xid_conference and %1.name = :name").arg(sTableName));
+    query.bindValue(":xid_conference", conferenceid);
     query.bindValue(":name", name);
     return loadOne(query);
 }