source: src/mvc/track.cpp @ c7b58d4

qt5
Last change on this file since c7b58d4 was 7620de0, checked in by korrco <korrco@…>, 12 years ago

room view added - need to test it

  • Property mode set to 100644
File size: 1.6 KB
Line 
1/*
2 * activity.cpp
3 *
4 *  Created on: Dec 27, 2009
5 *      Author: Pavol Korinek
6 */
7
8#include "track.h"
9
10QString const Track::sTableName = QString("track");
11int const Track::sTableColCount = 2;
12const QString Track::NAME = "name";
13
14QSqlRecord const Track::sColumns = Track::toRecord(QList<QSqlField>()
15    << QSqlField("id", QVariant::Int)
16    << QSqlField(NAME, QVariant::String));
17
18class TrackInsertException : OrmSqlException
19{
20public:
21    TrackInsertException(const QString& text) : OrmSqlException(text) {}
22};
23
24int Track::insert()
25{
26    QSqlQuery query;
27    query.prepare("INSERT INTO " + sTableName + " (" + NAME + ")" + " VALUES " + "(\"" + name() + "\")");
28    if (!query.exec())
29    {
30        throw TrackInsertException("Exec Error");
31    }
32    QVariant variant = query.lastInsertId();
33    if (variant.isValid())
34        return variant.toInt();
35    else
36        throw TrackInsertException("Last Insert Id Error");
37}
38
39Track Track::retrieveByName(QString name)
40{
41    QSqlQuery query;
42    query.prepare(
43            selectQuery()
44            + QString("WHERE %1.name = :name").arg(sTableName));
45    query.bindValue(":name", name);
46    return loadOne(query);
47}
48
49QList<Track> Track::getAll()
50{
51    QSqlQuery query;
52    query.prepare(selectQuery());
53    return load(query);
54}
55
56Track Track::retrieve(int id)
57{
58    QSqlQuery query;
59    query.prepare(selectQuery()
60            + QString("WHERE %1.id = :id").arg(sTableName));
61    query.bindValue(":id", id);
62    return loadOne(query);
63}
64
65QString Track::retrieveTrackName(int id)
66{
67    Track track = retrieve(id);
68    return track.name();
69}
Note: See TracBrowser for help on using the repository browser.