source: src/mvc/track.cpp @ 909ea23

qt5
Last change on this file since 909ea23 was 51529bd, checked in by gregor herrmann <gregoa@…>, 11 years ago

Insert new field xid_conference into table track, room and person.

  • Property mode set to 100644
File size: 2.4 KB
Line 
1/*
2 * Copyright (C) 2010 Ixonos Plc.
3 *
4 * This file is part of fosdem-schedule.
5 *
6 * fosdem-schedule is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation, either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 * fosdem-schedule is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * fosdem-schedule.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "track.h"
21
22QString const Track::sTableName = QString("track");
23int const Track::sTableColCount = 3;
24const QString Track::CONFERENCEID = "xid_conference";
25const QString Track::NAME = "name";
26
27QSqlRecord const Track::sColumns = Track::toRecord(QList<QSqlField>()
28    << QSqlField("id", QVariant::Int)
29    << QSqlField(CONFERENCEID, QVariant::Int)
30    << QSqlField(NAME, QVariant::String));
31
32class TrackInsertException : OrmSqlException
33{
34public:
35    TrackInsertException(const QString& text) : OrmSqlException(text) {}
36};
37
38int Track::insert()
39{
40    QSqlQuery query;
41    query.prepare("INSERT INTO " + sTableName + " (" + CONFERENCEID + "," + NAME + ")" + " VALUES " + "(\"" + QString::number(conferenceid()) + "\",\"" + name() + "\")");
42    if (!query.exec())
43    {
44        throw TrackInsertException("Exec Error");
45    }
46    QVariant variant = query.lastInsertId();
47    if (variant.isValid())
48        return variant.toInt();
49    else
50        throw TrackInsertException("Last Insert Id Error");
51}
52
53Track Track::retrieveByName(QString name)
54{
55    QSqlQuery query;
56    query.prepare(
57            selectQuery()
58            + QString("WHERE %1.name = :name").arg(sTableName));
59    query.bindValue(":name", name);
60    return loadOne(query);
61}
62
63QList<Track> Track::getAll()
64{
65    QSqlQuery query;
66    query.prepare(selectQuery());
67    return load(query);
68}
69
70Track Track::retrieve(int id)
71{
72    QSqlQuery query;
73    query.prepare(selectQuery()
74            + QString("WHERE %1.id = :id").arg(sTableName));
75    query.bindValue(":id", id);
76    return loadOne(query);
77}
78
79QString Track::retrieveTrackName(int id)
80{
81    Track track = retrieve(id);
82    return track.name();
83}
Note: See TracBrowser for help on using the repository browser.