Adding database loading and data conversion to orm module
[toast/confclerk.git] / src / model / event.cpp
index 58b6730aff61a08be5cb70fe42eb86b46a81cabf..ff7f1d2fc17622701b0ccedab11b9299df83e1d4 100644 (file)
@@ -1,6 +1,23 @@
 #include "event.h"
 
-QStringList const Event::sColNames = QStringList()
-    << "id" << "xid_conference" << "start" << "duration" << "xid_activity" << "type" << "language";
+QSqlRecord const Event::sColumns = Event::toRecord(QList<QSqlField>()
+    << QSqlField("id", QVariant::Int)
+    << QSqlField("xid_conference", QVariant::Int)
+    << QSqlField("start", QVariant::DateTime)
+    << QSqlField("duration", QVariant::Int)
+    << QSqlField("xid_activity", QVariant::Int)
+    << QSqlField("type", QVariant::String)
+    << QSqlField("language", QVariant::String));
 
 QString const Event::sTableName = QString("event");
+
+Event Event::getById(int id, int conferenceId)
+{
+    QString query = selectQuery() + "WHERE id = :id AND xid_conference = :conf";
+
+    QSqlQuery q;
+    q.prepare(query);
+    q.bindValue(":id", id);
+    q.bindValue(":conf", conferenceId);
+    return loadOne(q);
+}