2010-03-24 00:11:46 +01:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-03-24 00:11:46 +01:00
|
|
|
|
|
|
|
Clementine is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
#ifndef LIBRARYQUERY_H
|
|
|
|
#define LIBRARYQUERY_H
|
|
|
|
|
|
|
|
#include <QString>
|
|
|
|
#include <QVariant>
|
|
|
|
#include <QSqlQuery>
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QVariantList>
|
|
|
|
|
2010-01-15 22:43:57 +01:00
|
|
|
class Song;
|
2010-05-09 02:10:26 +02:00
|
|
|
class LibraryBackend;
|
2010-01-15 22:43:57 +01:00
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
struct QueryOptions {
|
2010-05-09 02:10:26 +02:00
|
|
|
QueryOptions();
|
2010-03-31 02:30:57 +02:00
|
|
|
|
2010-01-15 22:43:57 +01:00
|
|
|
bool Matches(const Song& song) const;
|
2010-05-08 23:54:36 +02:00
|
|
|
|
2011-01-30 22:00:49 +01:00
|
|
|
// Please note that this attribute is mutually exclusive with the 'duplicates_only'
|
|
|
|
// flag!
|
2009-12-24 20:16:07 +01:00
|
|
|
QString filter;
|
|
|
|
int max_age;
|
2011-01-30 22:00:49 +01:00
|
|
|
// If true, the query will operate not on the whole songs table but only on those rows
|
|
|
|
// which are duplicated. By duplication we mean a situation where two or more songs
|
|
|
|
// with equal (artist, album, title) tuple exist (case sensitive).
|
|
|
|
// Please note that this flag is mutually exclusive with the 'filter' attribute!
|
|
|
|
bool duplicates_only;
|
2009-12-24 20:16:07 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class LibraryQuery {
|
|
|
|
public:
|
2010-05-08 23:54:36 +02:00
|
|
|
LibraryQuery(const QueryOptions& options = QueryOptions());
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2011-01-30 22:00:49 +01:00
|
|
|
// Sets contents of SELECT clause on the query (list of columns to get).
|
2009-12-24 20:16:07 +01:00
|
|
|
void SetColumnSpec(const QString& spec) { column_spec_ = spec; }
|
2011-01-30 22:00:49 +01:00
|
|
|
// Sets an ORDER BY clause on the query.
|
2010-02-28 19:04:50 +01:00
|
|
|
void SetOrderBy(const QString& order_by) { order_by_ = order_by; }
|
2011-01-30 22:00:49 +01:00
|
|
|
|
2011-01-18 17:34:43 +01:00
|
|
|
// Adds a fragment of WHERE clause. When executed, this Query will connect all
|
|
|
|
// the fragments with AND operator.
|
|
|
|
// Please note that IN operator expects a QStringList as value.
|
2010-06-12 00:35:41 +02:00
|
|
|
void AddWhere(const QString& column, const QVariant& value, const QString& op = "=");
|
2011-01-30 22:00:49 +01:00
|
|
|
|
2010-02-27 21:12:22 +01:00
|
|
|
void AddCompilationRequirement(bool compilation);
|
2010-06-20 18:30:10 +02:00
|
|
|
void SetLimit(int limit) { limit_ = limit; }
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-06-20 18:30:10 +02:00
|
|
|
QSqlError Exec(QSqlDatabase db, const QString& songs_table, const QString& fts_table);
|
2010-03-31 02:30:57 +02:00
|
|
|
bool Next();
|
|
|
|
QVariant Value(int column) const;
|
|
|
|
|
|
|
|
operator const QSqlQuery& () const { return query_; }
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
private:
|
2011-01-30 22:00:49 +01:00
|
|
|
QString GetInnerQuery();
|
|
|
|
|
2010-06-20 18:30:10 +02:00
|
|
|
bool join_with_fts_;
|
2009-12-24 20:16:07 +01:00
|
|
|
QString column_spec_;
|
2010-02-28 19:04:50 +01:00
|
|
|
QString order_by_;
|
2009-12-24 20:16:07 +01:00
|
|
|
QStringList where_clauses_;
|
|
|
|
QVariantList bound_values_;
|
2010-06-20 18:30:10 +02:00
|
|
|
int limit_;
|
2011-01-30 22:00:49 +01:00
|
|
|
bool duplicates_only_;
|
2010-03-31 02:30:57 +02:00
|
|
|
|
|
|
|
QSqlQuery query_;
|
2009-12-24 20:16:07 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // LIBRARYQUERY_H
|