source: src/mvc/track.cpp

Last change on this file was ffb6be7, checked in by gregor herrmann <gregor@…>, 4 months ago

Bump copyright years.

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/*
2 * Copyright (C) 2010 Ixonos Plc.
3 * Copyright (C) 2011-2021 Philipp Spitzer, gregor herrmann, Stefan Stahl
4 *
5 * This file is part of ConfClerk.
6 *
7 * ConfClerk is free software: you can redistribute it and/or modify it
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 *
12 * ConfClerk is distributed in the hope that it will be useful, but
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
18 * ConfClerk.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include "track.h"
22
23QString const Track::sTableName = QString("track");
24int const Track::sTableColCount = 3;
25const QString Track::CONFERENCEID = "xid_conference";
26const QString Track::NAME = "name";
27
28QSqlRecord const Track::sColumns = Track::toRecord(QList<QSqlField>()
29    << QSqlField("id", QVariant::Int)
30    << QSqlField(CONFERENCEID, QVariant::Int)
31    << QSqlField(NAME, QVariant::String));
32
33class TrackInsertException : public OrmSqlException
34{
35public:
36    TrackInsertException(const QString& text) : OrmSqlException(text) {}
37};
38
39int Track::insert()
40{
41    QSqlQuery query;
42    QString trackname = name();
43    query.prepare(
44            QString("INSERT INTO %1 (%2, %3) VALUES (:xid_conference, :name)")
45            .arg(sTableName, CONFERENCEID, NAME));
46    query.bindValue(":xid_conference", conferenceid());
47    query.bindValue(":name", trackname);
48    if (!query.exec())
49    {
50        throw TrackInsertException(
51                "Inserting track '" + trackname + "' into database failed: " +
52                query.lastError().text());
53    }
54    QVariant variant = query.lastInsertId();
55    if (variant.isValid())
56        return variant.toInt();
57    else
58        throw TrackInsertException("Last Insert Id Error");
59}
60
61Track Track::retrieveByName(int conferenceid, QString name)
62{
63    QSqlQuery query;
64    query.prepare(
65            selectQuery()
66            + QString("WHERE %1.xid_conference = :xid_conference and %1.name = :name").arg(sTableName));
67    query.bindValue(":xid_conference", conferenceid);
68    query.bindValue(":name", name);
69    return loadOne(query);
70}
71
72QList<Track> Track::getAll()
73{
74    QSqlQuery query;
75    query.prepare(selectQuery());
76    return load(query);
77}
78
79Track Track::retrieve(int id)
80{
81    QSqlQuery query;
82    query.prepare(selectQuery()
83            + QString("WHERE %1.id = :id").arg(sTableName));
84    query.bindValue(":id", id);
85    return loadOne(query);
86}
87
88QString Track::retrieveTrackName(int id)
89{
90    Track track = retrieve(id);
91    return track.name();
92}
Note: See TracBrowser for help on using the repository browser.