Changeset 606c155 for src/mvc/track.cpp


Ignore:
Timestamp:
01/21/10 13:59:22 (12 years ago)
Author:
korrco <korrco@…>
Branches:
master, qt5
Children:
96fe8fb
Parents:
72cd3af
Message:

activities tab implemented

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mvc/track.cpp

    r72cd3af r606c155  
    11/*
    2  * track.cpp
     2 * activity.cpp
    33 *
    44 *  Created on: Dec 27, 2009
     
    77
    88#include "track.h"
     9#include <QSqlTableModel>
    910
    1011QString const Track::sTableName = QString("track");
    1112int const Track::sTableColCount = 2;
     13const QString Track::NAME = "name";
    1214
    1315QSqlRecord const Track::sColumns = Track::toRecord(QList<QSqlField>()
    1416    << QSqlField("id", QVariant::Int)
    15     << QSqlField("name", QVariant::String));
     17    << QSqlField(NAME, QVariant::String));
    1618
    1719QMap<int, Track> Track::mIdToTrack;
     20
     21class TrackInsertException : OrmSqlException
     22{
     23public:
     24    TrackInsertException(const QString& text) : OrmSqlException(text) {}
     25};
     26
     27int Track::insert()
     28{
     29    QSqlQuery query;
     30    query.prepare("INSERT INTO " + sTableName + " (" + NAME + ")" + " VALUES " + "(\"" + name() + "\")");
     31    if (!query.exec())
     32    {
     33        throw TrackInsertException("Exec Error");
     34    }
     35    QVariant variant = query.lastInsertId();
     36    if (variant.isValid())
     37        return variant.toInt();
     38    else
     39        throw TrackInsertException("Last Insert Id Error");
     40}
     41
     42Track Track::retrieveByName(QString name)
     43{
     44    QSqlQuery query;
     45    query.prepare(
     46            selectQuery()
     47            + QString("WHERE %1.name = :name").arg(sTableName));
     48    query.bindValue(":name", name);
     49    return loadOne(query);
     50}
    1851
    1952QList<Track> Track::getAll()
     
    3972    QString name = mIdToTrack.value(id).name();
    4073    if (name == "") {
    41         qDebug() << QString("Error: undefined track name for id %1").arg(id);
     74        qDebug() << QString("Error: undefined activity name for id %1").arg(id);
    4275    }
    4376    return name;
Note: See TracChangeset for help on using the changeset viewer.