room view added - finished
[toast/confclerk.git] / src / mvc / room.cpp
1 /*
2  * room.cpp
3  *
4  *  Created on: Dec 27, 2009
5  *      Author: user
6  */
7
8 #include "room.h"
9
10 QString const Room::sTableName = QString("room");
11 int const Room::sTableColCount = 3;
12 const QString Room::NAME = "name";
13
14 QSqlRecord const Room::sColumns = Room::toRecord(QList<QSqlField>()
15     << QSqlField("id", QVariant::Int)
16     << QSqlField(NAME, QVariant::String)
17     << QSqlField("picture", QVariant::String));
18
19 Room Room::retrieveByName(QString name)
20 {
21     QSqlQuery query;
22     query.prepare(
23             selectQuery()
24             + QString("WHERE %1.name = :name").arg(sTableName));
25     query.bindValue(":name", name);
26     return loadOne(query);
27 }
28
29 QList<Room> Room::getAll()
30 {
31     QSqlQuery query;
32     query.prepare(selectQuery());
33     return load(query);
34 }
35
36 Room Room::retrieve(int id)
37 {
38     QSqlQuery query;
39     query.prepare(selectQuery()
40             + QString("WHERE %1.id = :id").arg(sTableName));
41     query.bindValue(":id", id);
42     return loadOne(query);
43 }
44
45 QString Room::retrieveRoomName(int id)
46 {
47     Room room = retrieve(id);
48     return room.name();
49 }
50