2 * Copyright (C) 2010 Ixonos Plc.
4 * This file is part of ConfClerk.
6 * ConfClerk 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)
11 * ConfClerk 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
16 * You should have received a copy of the GNU General Public License along with
17 * ConfClerk. If not, see <http://www.gnu.org/licenses/>.
22 QString const Track::sTableName = QString("track");
23 int const Track::sTableColCount = 3;
24 const QString Track::CONFERENCEID = "xid_conference";
25 const QString Track::NAME = "name";
27 QSqlRecord const Track::sColumns = Track::toRecord(QList<QSqlField>()
28 << QSqlField("id", QVariant::Int)
29 << QSqlField(CONFERENCEID, QVariant::Int)
30 << QSqlField(NAME, QVariant::String));
32 class TrackInsertException : OrmSqlException
35 TrackInsertException(const QString& text) : OrmSqlException(text) {}
41 query.prepare("INSERT INTO " + sTableName + " (" + CONFERENCEID + "," + NAME + ")" + " VALUES " + "(\"" + QString::number(conferenceid()) + "\",\"" + name() + "\")");
44 throw TrackInsertException("Exec Error");
46 QVariant variant = query.lastInsertId();
47 if (variant.isValid())
48 return variant.toInt();
50 throw TrackInsertException("Last Insert Id Error");
53 Track Track::retrieveByName(int conferenceid, QString name)
58 + QString("WHERE %1.xid_conference = :xid_conference and %1.name = :name").arg(sTableName));
59 query.bindValue(":xid_conference", conferenceid);
60 query.bindValue(":name", name);
61 return loadOne(query);
64 QList<Track> Track::getAll()
67 query.prepare(selectQuery());
71 Track Track::retrieve(int id)
74 query.prepare(selectQuery()
75 + QString("WHERE %1.id = :id").arg(sTableName));
76 query.bindValue(":id", id);
77 return loadOne(query);
80 QString Track::retrieveTrackName(int id)
82 Track track = retrieve(id);