Changeset c790268 for src/mvc


Ignore:
Timestamp:
01/17/10 17:22:03 (12 years ago)
Author:
pavelpa <pavelpa@…>
Branches:
master, qt5
Children:
6f39595
Parents:
680a4da
Message:

implemented JOINing two tables

  • modified 'ormrecord' to support JOINing two tables
  • modified 'event' accordingly, since its items/columns are splitted into two separate tables
Location:
src/mvc
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/mvc/delegate.cpp

    r680a4da rc790268  
    137137
    138138    // draw title
    139     QPointF titlePointF(option.rect.x(),option.rect.y()+option.rect.height()-10);
    140     QString text = qVariantValue<QString>(index.data());
     139    QPointF titlePointF(option.rect.x()+SPACER,option.rect.y()+option.rect.height()-10);
     140    QString text;
     141    if(index.parent().isValid()) // event
     142        text = qVariantValue<QString>(index.data()) + ": " + static_cast<Event*>(index.internalPointer())->title();
     143    else // group
     144        text = qVariantValue<QString>(index.data());
    141145    painter->drawText(titlePointF,text);
    142146
  • src/mvc/event.cpp

    r680a4da rc790268  
    11#include "event.h"
    22
     3// 'event' record is splitted into two separate tables 'event' and 'virtual_event'
     4// for the FTS (Full-Text-Search) support and so, it is necessary to provide/use
     5// two table names + corresponding parameters/methods, see bellow
     6QString const Event::sTable1Name = QString("event");
     7QString const Event::sTable2Name = QString("virtual_event");
     8int const Event::sTable1ColCount = 8; // see 'toRecord()' for more details
     9int const Event::sTable2ColCount = 5; // see 'toRecord()' for more details
     10
    311QSqlRecord const Event::sColumns = Event::toRecord(QList<QSqlField>()
     12    /* 'columns from Table 1 */
    413    << QSqlField("id", QVariant::Int)
    514    << QSqlField("xid_conference", QVariant::Int)
     
    918    << QSqlField("type", QVariant::String)
    1019    << QSqlField("language", QVariant::String)
    11     << QSqlField("favourite", QVariant::Bool));
     20    << QSqlField("favourite", QVariant::Bool)
     21    /* 'columns' from Table2 */
     22    << QSqlField("tag", QVariant::String)
     23    << QSqlField("title", QVariant::String)
     24    << QSqlField("subtitle", QVariant::String)
     25    << QSqlField("abstract", QVariant::String)
     26    << QSqlField("description", QVariant::String));
    1227
    13 QString const Event::sTableName = QString("event");
    1428
    1529Event Event::getById(int id, int conferenceId)
    1630{
    1731    QSqlQuery query;
    18     query.prepare(selectQuery() + "WHERE id = :id AND xid_conference = :conf");
     32    query.prepare(selectQueryJoin2T("id") + "WHERE event.id = :id AND event.xid_conference = :conf");
    1933    query.bindValue(":id", id);
    2034    query.bindValue(":conf", conferenceId);
     35
    2136    return loadOne(query);
    2237}
     
    2540{
    2641    QSqlQuery query;
    27     query.prepare(selectQuery() + "WHERE xid_conference = :conf AND start >= :start AND start < :end ORDER BY start");
     42    query.prepare(selectQueryJoin2T("id") + "WHERE event.xid_conference = :conf AND event.start >= :start AND event.start < :end ORDER BY event.start");
    2843    query.bindValue(":conf", conferenceId);
    2944    query.bindValue(":start", convertToDb(date, QVariant::DateTime));
  • src/mvc/event.h

    r680a4da rc790268  
    1919public:
    2020    static QSqlRecord const sColumns;
    21     static QString const sTableName;
     21    //static QString const sTableName;
     22    static QString const sTable1Name;
     23    static QString const sTable2Name;
     24    static int const sTable1ColCount;
     25    static int const sTable2ColCount;
    2226
    2327public:
     
    2630
    2731public:
     32    // Table 1
    2833    int id() const { return value("id").toInt(); }
    2934    int conferenceId() const { return value("xid_conference").toInt(); }
     
    3439    QString language() const { return value("language").toString(); }
    3540    bool isFavourite() const { return value("favourite").toBool(); }
     41    // Table 2 : virtual table for FTS (Full Text Search)
     42    QString tag() const { return value("tag").toString(); }
     43    QString title() const { return value("title").toString(); }
     44    QString subtitle() const { return value("subtitle").toString(); }
     45    QString abstract() const { return value("abstract").toString(); }
     46    QString description() const { return value("description").toString(); }
    3647
     48    // Table 1
    3749    void setId(int id) { setValue("id", id); }
    3850    void setConferenceId(int conferenceId) { setValue("xid_conference", conferenceId); }
     
    4355    void setLanguage(const QString& language) { setValue("language", language); }
    4456    void setFavourite(bool favourite) { setValue("favourite", favourite); }
     57    // Table 2 : virtual table for FTS (Full Text Search)
     58    void setTag(const QString& tag) { setValue("tag", tag); }
     59    void setTitle(const QString& title) { setValue("title", title); }
     60    void setSubtitle(const QString& subtitle) { setValue("subtitle", subtitle); }
     61    void setAbstract(const QString& abstract) { setValue("abstract", abstract); }
     62    void setDescription(const QString& description) { setValue("description", description); }
    4563
    4664friend class EventTest;
Note: See TracChangeset for help on using the changeset viewer.