Ignore:
Timestamp:
01/21/10 13:54:58 (12 years ago)
Author:
korrco <korrco@…>
Branches:
master, qt5
Children:
606c155
Parents:
e662750
Message:

activities tab implemented

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sql/sqlengine.cpp

    re662750 r72cd3af  
    88#include <QDir>
    99#include "sqlengine.h"
     10#include <track.h>
    1011
    1112#include <QDebug>
     
    8990    if (db.isValid() && db.isOpen())
    9091    {
    91         // track has to be handled as the first, since it is necessary to get
    92         // track ID from the TRACK table, or to create new TRACK record
    93         // and get the ID from newly created record
    94         QString queryExist = QString("SELECT id FROM track WHERE name='%1'").arg(aEvent["track"]);
    95         QSqlQuery resultExist(queryExist,db);
    96         // now we have to check whether TRACK record with 'name' exists or not,
    97         // - if it doesn't exist yet, then we have to add that record to 'TRACK' table
    98         // - if it exists, then we need to get its 'id'
    99         int actId = -1;
    100         if(resultExist.next()) // TRACK record with 'name' already exists: we need to get its 'id'
     92        //insert event track to table
     93        QString name = aEvent["track"];
     94        Track track;
     95        int trackId;
     96        try
    10197        {
    102             actId = resultExist.value(0).toInt();
     98            track = Track::retrieveByName(name);
     99            trackId = track.id();
     100            /*qDebug() << QString("DEBUG: Track %1 in DB").arg(name);*/
    103101        }
    104         else // TRACK record doesn't exist yet, need to create it
    105         {
    106             QString values = QString("'%1'").arg(aEvent["track"]);
    107             QString query = QString("INSERT INTO track (name) VALUES (%1)").arg(values);
    108             QSqlQuery result (query, db);
    109             actId = result.lastInsertId().toInt(); // 'id' is assigned automatically
     102        catch (OrmNoObjectException &e) {
     103            track.setName(name);
     104            trackId = track.insert();
     105            /*qDebug() << QString("DEBUG: Track %1 added to DB").arg(name);*/
    110106        }
    111 
    112107        // The items of the Event are divided into the two tables EVENT and VIRTUAL_EVENT
    113108        // VIRTUAL_EVENT is for Full-Text-Serach Support
     
    118113                         .arg(QString::number(startDateTime.toTime_t())) \
    119114                         .arg(-QTime::fromString(aEvent["duration"],TIME_FORMAT).secsTo(QTime(0,0))) \
    120                          .arg(QString::number(actId)) \
     115                         .arg(trackId) \
    121116                         .arg(aEvent["type"]) \
    122117                         .arg(aEvent["language"]) \
     
    236231        query.exec("CREATE TABLE TRACK ( \
    237232            id INTEGER  PRIMARY KEY AUTOINCREMENT  NOT NULL , \
    238             name VARCHAR NOT NULL )");
     233            name VARCHAR UNIQUE NOT NULL )");
    239234
    240235        query.exec("CREATE TABLE ROOM ( \
Note: See TracChangeset for help on using the changeset viewer.