source: src/mvc/track.cpp @ a790a90

qt5
Last change on this file since a790a90 was a790a90, checked in by pavelpa <pavelpa@…>, 12 years ago

removed headers from *.h and *.cpp

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