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