source: src/mvc/track.cpp @ 6df32f2

qt5
Last change on this file since 6df32f2 was 6df32f2, checked in by gregor herrmann <gregoa@…>, 10 years ago

Update GPL blurb in source files.

  • Property mode set to 100644
File size: 2.4 KB
RevLine 
[ca90cb1]1/*
2 * Copyright (C) 2010 Ixonos Plc.
3 *
[6df32f2]4 * This file is part of ConfClerk.
[ca90cb1]5 *
[6df32f2]6 * ConfClerk is free software: you can redistribute it and/or modify it
[ca90cb1]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 *
[6df32f2]11 * ConfClerk is distributed in the hope that it will be useful, but
[ca90cb1]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
[6df32f2]17 * ConfClerk.  If not, see <http://www.gnu.org/licenses/>.
[ca90cb1]18 */
[4693fa6]19
20#include "track.h"
21
22QString const Track::sTableName = QString("track");
[51529bd]23int const Track::sTableColCount = 3;
24const QString Track::CONFERENCEID = "xid_conference";
[606c155]25const QString Track::NAME = "name";
[4693fa6]26
27QSqlRecord const Track::sColumns = Track::toRecord(QList<QSqlField>()
28    << QSqlField("id", QVariant::Int)
[51529bd]29    << QSqlField(CONFERENCEID, QVariant::Int)
[606c155]30    << QSqlField(NAME, QVariant::String));
[4693fa6]31
[606c155]32class TrackInsertException : OrmSqlException
33{
34public:
35    TrackInsertException(const QString& text) : OrmSqlException(text) {}
36};
37
38int Track::insert()
39{
40    QSqlQuery query;
[51529bd]41    query.prepare("INSERT INTO " + sTableName + " (" + CONFERENCEID + "," + NAME + ")" + " VALUES " + "(\"" + QString::number(conferenceid()) + "\",\"" + name() + "\")");
[606c155]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
[141a5c2]53Track Track::retrieveByName(int conferenceid, QString name)
[606c155]54{
55    QSqlQuery query;
56    query.prepare(
57            selectQuery()
[141a5c2]58            + QString("WHERE %1.xid_conference = :xid_conference and %1.name = :name").arg(sTableName));
59    query.bindValue(":xid_conference", conferenceid);
[606c155]60    query.bindValue(":name", name);
61    return loadOne(query);
62}
63
[4693fa6]64QList<Track> Track::getAll()
65{
66    QSqlQuery query;
67    query.prepare(selectQuery());
68    return load(query);
69}
70
[005e2b7]71Track Track::retrieve(int id)
[4693fa6]72{
[005e2b7]73    QSqlQuery query;
74    query.prepare(selectQuery()
75            + QString("WHERE %1.id = :id").arg(sTableName));
76    query.bindValue(":id", id);
77    return loadOne(query);
[4693fa6]78}
79
[005e2b7]80QString Track::retrieveTrackName(int id)
[4693fa6]81{
[005e2b7]82    Track track = retrieve(id);
83    return track.name();
[4693fa6]84}
Note: See TracBrowser for help on using the repository browser.