Changeset 20a6010 for src/model


Ignore:
Timestamp:
12/30/09 14:50:23 (13 years ago)
Author:
komarma <komarma@…>
Branches:
master, qt5
Children:
489f262
Parents:
5a73d27
Message:

Adding database loading and data conversion to orm module

Location:
src/model
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/model/event.cpp

    r5a73d27 r20a6010  
    11#include "event.h"
    22
    3 QStringList const Event::sColNames = QStringList()
    4     << "id" << "xid_conference" << "start" << "duration" << "xid_activity" << "type" << "language";
     3QSqlRecord const Event::sColumns = Event::toRecord(QList<QSqlField>()
     4    << QSqlField("id", QVariant::Int)
     5    << QSqlField("xid_conference", QVariant::Int)
     6    << QSqlField("start", QVariant::DateTime)
     7    << QSqlField("duration", QVariant::Int)
     8    << QSqlField("xid_activity", QVariant::Int)
     9    << QSqlField("type", QVariant::String)
     10    << QSqlField("language", QVariant::String));
    511
    612QString const Event::sTableName = QString("event");
     13
     14Event Event::getById(int id, int conferenceId)
     15{
     16    QString query = selectQuery() + "WHERE id = :id AND xid_conference = :conf";
     17
     18    QSqlQuery q;
     19    q.prepare(query);
     20    q.bindValue(":id", id);
     21    q.bindValue(":conf", conferenceId);
     22    return loadOne(q);
     23}
  • src/model/event.h

    r5a73d27 r20a6010  
    1616};
    1717
    18 class Event : public OrmRecord <Event>
     18class Event : public OrmRecord<Event>
    1919{
    2020public:
    21     // column definition
    22     enum Column
    23     {
    24         Id = 0,
    25         Conference,
    26         Start,
    27         Duration,
    28         Activity,
    29         Type,
    30         Language
    31     };
    32 
    33     static QStringList const sColNames;
    34 
     21    static QSqlRecord const sColumns;
    3522    static QString const sTableName;
    3623
    3724public:
    38     static Event getById(int id, int conferenceId) { return Event(); } //EventTable::selectOne("id=1"); }
     25    static Event getById(int id, int conferenceId);
    3926
    4027public:
    41     int id() const { return value(Id).toInt(); }
    42     int conferenceId() const { return value(Conference).toInt(); }
    43     QDateTime start() const { return value(Start).toDateTime(); }
    44     int duration() const { return value(Duration).toInt(); }
    45     int activityId() const { return value(Activity).toInt(); }
    46     int typeId() const { return value(Type).toInt(); }
    47     int languageId() const { return value(Language).toInt(); }
     28    int id() const { return value("id").toInt(); }
     29    int conferenceId() const { return value("xid_conference").toInt(); }
     30    QDateTime start() const { return value("start").toDateTime(); }
     31    int duration() const { return value("duration").toInt(); }
     32    int activityId() const { return value("xid_activity").toInt(); }
     33    int typeId() const { return value("type").toInt(); }
     34    int languageId() const { return value("language").toInt(); }
    4835
    49     void setId(int id) { setValue(Id, id); }
    50     void setConferenceId(int conferenceId) { setValue(Conference, conferenceId); }
    51     void setStart(const QDateTime& start) { setValue(Start, start); }
    52     void setDuration(int duration) { setValue(Duration, duration); }
    53     void setActivityId(int activityId) { setValue(Activity, activityId); }
    54     void setTypeId(int typeId) { setValue(Type, typeId); }
    55     void setLanguageId(int languageId) { setValue(Language, languageId); }
     36    void setId(int id) { setValue("id", id); }
     37    void setConferenceId(int conferenceId) { setValue("xid_conference", conferenceId); }
     38    void setStart(const QDateTime& start) { setValue("start", start); }
     39    void setDuration(int duration) { setValue("duration", duration); }
     40    void setActivityId(int activityId) { setValue("xid_activity", activityId); }
     41    void setTypeId(int typeId) { setValue("type", typeId); }
     42    void setLanguageId(int languageId) { setValue("language", languageId); }
     43
     44friend class EventTest;
    5645};
    5746
Note: See TracChangeset for help on using the changeset viewer.