Move sqlrow to core
This commit is contained in:
@@ -47,10 +47,10 @@
|
||||
#include "core/database.h"
|
||||
#include "core/scopedtransaction.h"
|
||||
#include "core/song.h"
|
||||
#include "core/sqlrow.h"
|
||||
#include "smartplaylists/smartplaylistsearch.h"
|
||||
|
||||
#include "directory.h"
|
||||
#include "sqlrow.h"
|
||||
#include "collectionbackend.h"
|
||||
#include "collectionquery.h"
|
||||
#include "collectiontask.h"
|
||||
|
||||
@@ -59,12 +59,12 @@
|
||||
#include "core/iconloader.h"
|
||||
#include "core/logging.h"
|
||||
#include "core/taskmanager.h"
|
||||
#include "core/sqlrow.h"
|
||||
#include "collectionquery.h"
|
||||
#include "collectionbackend.h"
|
||||
#include "collectiondirectorymodel.h"
|
||||
#include "collectionitem.h"
|
||||
#include "collectionmodel.h"
|
||||
#include "sqlrow.h"
|
||||
#include "playlist/playlistmanager.h"
|
||||
#include "playlist/songmimedata.h"
|
||||
#include "covermanager/albumcoverloader.h"
|
||||
|
||||
@@ -45,10 +45,10 @@
|
||||
|
||||
#include "core/simpletreemodel.h"
|
||||
#include "core/song.h"
|
||||
#include "core/sqlrow.h"
|
||||
#include "covermanager/albumcoverloader.h"
|
||||
#include "collectionquery.h"
|
||||
#include "collectionitem.h"
|
||||
#include "sqlrow.h"
|
||||
#include "covermanager/albumcoverloaderoptions.h"
|
||||
|
||||
class QSettings;
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2018-2021, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry 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.
|
||||
*
|
||||
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QVariant>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
#include <QSqlQuery>
|
||||
#include <QSqlRecord>
|
||||
|
||||
#include "sqlrow.h"
|
||||
|
||||
SqlRow::SqlRow(const QSqlQuery &query) { Init(query); }
|
||||
|
||||
void SqlRow::Init(const QSqlQuery &query) {
|
||||
|
||||
const QSqlRecord r = query.record();
|
||||
for (int i = 0; i < r.count(); ++i) {
|
||||
columns_by_number_.insert(i, query.value(i));
|
||||
const QString field_name = r.fieldName(i);
|
||||
if (!columns_by_name_.contains(field_name) || columns_by_name_[field_name].isNull()) {
|
||||
columns_by_name_.insert(field_name, query.value(i));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const QVariant SqlRow::value(const int number) const {
|
||||
|
||||
if (columns_by_number_.contains(number)) {
|
||||
return columns_by_number_[number];
|
||||
}
|
||||
else {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const QVariant SqlRow::value(const QString &name) const {
|
||||
|
||||
if (columns_by_name_.contains(name)) {
|
||||
return columns_by_name_[name];
|
||||
}
|
||||
else {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
QString SqlRow::ValueToString(const QString &n) const {
|
||||
return value(n).isNull() ? QString() : value(n).toString();
|
||||
}
|
||||
|
||||
QUrl SqlRow::ValueToUrl(const QString &n) const {
|
||||
return value(n).isNull() ? QUrl() : QUrl(value(n).toString());
|
||||
}
|
||||
|
||||
int SqlRow::ValueToInt(const QString &n) const {
|
||||
return value(n).isNull() ? -1 : value(n).toInt();
|
||||
}
|
||||
|
||||
uint SqlRow::ValueToUInt(const QString &n) const {
|
||||
return value(n).isNull() || value(n).toInt() < 0 ? 0 : value(n).toInt();
|
||||
}
|
||||
|
||||
qint64 SqlRow::ValueToLongLong(const QString &n) const {
|
||||
return value(n).isNull() ? -1 : value(n).toLongLong();
|
||||
}
|
||||
|
||||
float SqlRow::ValueToFloat(const QString &n) const {
|
||||
return value(n).isNull() ? -1.0F : value(n).toFloat();
|
||||
}
|
||||
|
||||
bool SqlRow::ValueToBool(const QString &n) const {
|
||||
return !value(n).isNull() && value(n).toInt() == 1;
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2018-2021, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry 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.
|
||||
*
|
||||
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SQLROW_H
|
||||
#define SQLROW_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QList>
|
||||
#include <QVariant>
|
||||
#include <QUrl>
|
||||
#include <QSqlQuery>
|
||||
|
||||
class SqlRow {
|
||||
|
||||
public:
|
||||
SqlRow(const QSqlQuery &query);
|
||||
|
||||
const QVariant value(const int number) const;
|
||||
const QVariant value(const QString &name) const;
|
||||
|
||||
QString ValueToString(const QString &n) const;
|
||||
QUrl ValueToUrl(const QString &n) const;
|
||||
int ValueToInt(const QString &n) const;
|
||||
uint ValueToUInt(const QString &n) const;
|
||||
qint64 ValueToLongLong(const QString &n) const;
|
||||
float ValueToFloat(const QString &n) const;
|
||||
bool ValueToBool(const QString& n) const;
|
||||
|
||||
private:
|
||||
SqlRow();
|
||||
|
||||
void Init(const QSqlQuery &query);
|
||||
|
||||
QMap<int, QVariant> columns_by_number_;
|
||||
QMap<QString, QVariant> columns_by_name_;
|
||||
|
||||
};
|
||||
|
||||
typedef QList<SqlRow> SqlRowList;
|
||||
|
||||
#endif // SQLROW_H
|
||||
Reference in New Issue
Block a user