PageRenderTime 102ms CodeModel.GetById 40ms app.highlight 5ms RepoModel.GetById 56ms app.codeStats 0ms

/src/libtomahawk/database/DatabaseCommand_GenericSelect.h

http://github.com/tomahawk-player/tomahawk
C Header | 90 lines | 37 code | 14 blank | 39 comment | 0 complexity | 87592fcc698536cac73266199ed9a6a7 MD5 | raw file
 1/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
 2 *
 3 *   Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
 4 *
 5 *   Tomahawk is free software: you can redistribute it and/or modify
 6 *   it under the terms of the GNU General Public License as published by
 7 *   the Free Software Foundation, either version 3 of the License, or
 8 *   (at your option) any later version.
 9 *
10 *   Tomahawk is distributed in the hope that it will be useful,
11 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
12 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 *   GNU General Public License for more details.
14 *
15 *   You should have received a copy of the GNU General Public License
16 *   along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef DATABASECOMMAND_GENERICSELECT_H
20#define DATABASECOMMAND_GENERICSELECT_H
21
22#include <QVariantMap>
23
24#include "DatabaseCommand.h"
25#include "Typedefs.h"
26
27#include <QStringList>
28#include <QMetaType>
29
30#include "DllMacro.h"
31
32namespace Tomahawk
33{
34
35/**
36 * This dbcmd takes a generic SELECT command that operates on the database and returns a list of query_ptrs
37 *  that match.
38 *
39 * In order for the conversion to query_ptr to work, the SELECT command should select the following items:
40 *
41 * track query:
42 *      track.name, artist.name [, optional extra values ]
43 *
44 *  artist query:
45 *      artist.id, artist.name [, optional extra values ]
46 *
47 *  album query:
48 *      album.id, album.name, artist.id, artist.name [, optional extra values ]
49 *
50 * Any extra values in the resultset will be returned as a QVariantList attached to the "data" property of each query_ptr
51 *
52 * Notes:
53 *      * Do not trail your SQL command with ;
54 *      * Do not use the LIMIT command if you pass limitResults > -1
55 *
56 */
57class DLLEXPORT DatabaseCommand_GenericSelect : public DatabaseCommand
58{
59    Q_OBJECT
60
61public:
62    enum QueryType {
63        Track,
64        Artist,
65        Album
66    };
67
68    explicit DatabaseCommand_GenericSelect( const QString& sqlSelect, QueryType type, int limitResults = -1, QObject* parent = 0 );
69    explicit DatabaseCommand_GenericSelect( const QString& sqlSelect, QueryType type, bool rawData, QObject* parent = 0 );
70    virtual void exec( DatabaseImpl* lib );
71    virtual bool doesMutates() const { return false; }
72
73    virtual QString commandname() const { return "genericselect"; }
74
75signals:
76    void tracks( const QList< Tomahawk::query_ptr >& tracks );
77    void artists( const QList< Tomahawk::artist_ptr >& artists );
78    void albums( const QList< Tomahawk::album_ptr >& albums );
79
80    void rawData( const QList< QStringList >& data );
81private:
82    QString m_sqlSelect;
83    QueryType m_queryType;
84    int m_limit;
85    bool m_raw;
86};
87
88}
89
90#endif // DATABASECOMMAND_GENERICSELECT_H