source: src/mvc/track.cpp @ 68b2df2

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

Add copyright to source.

  • Property mode set to 100644
File size: 2.5 KB
Line 
1/*
2 * Copyright (C) 2010 Ixonos Plc.
3 * Copyright (C) 2011 Philipp Spitzer, gregor herrmann
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 : OrmSqlException
34{
35public:
36    TrackInsertException(const QString& text) : OrmSqlException(text) {}
37};
38
39int Track::insert()
40{
41    QSqlQuery query;
42    query.prepare("INSERT INTO " + sTableName + " (" + CONFERENCEID + "," + NAME + ")" + " VALUES " + "(\"" + QString::number(conferenceid()) + "\",\"" + name() + "\")");
43    if (!query.exec())
44    {
45        throw TrackInsertException("Exec Error");
46    }
47    QVariant variant = query.lastInsertId();
48    if (variant.isValid())
49        return variant.toInt();
50    else
51        throw TrackInsertException("Last Insert Id Error");
52}
53
54Track Track::retrieveByName(int conferenceid, QString name)
55{
56    QSqlQuery query;
57    query.prepare(
58            selectQuery()
59            + QString("WHERE %1.xid_conference = :xid_conference and %1.name = :name").arg(sTableName));
60    query.bindValue(":xid_conference", conferenceid);
61    query.bindValue(":name", name);
62    return loadOne(query);
63}
64
65QList<Track> Track::getAll()
66{
67    QSqlQuery query;
68    query.prepare(selectQuery());
69    return load(query);
70}
71
72Track Track::retrieve(int id)
73{
74    QSqlQuery query;
75    query.prepare(selectQuery()
76            + QString("WHERE %1.id = :id").arg(sTableName));
77    query.bindValue(":id", id);
78    return loadOne(query);
79}
80
81QString Track::retrieveTrackName(int id)
82{
83    Track track = retrieve(id);
84    return track.name();
85}
Note: See TracBrowser for help on using the repository browser.