mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
DBManager: ORDER BY parameter added to getRecord(s) (#770)
-> All instances are now sorted in ascending order using the instance ID -> The web interface gets an incorrect instance order, which causes further problems
This commit is contained in:
@@ -185,7 +185,7 @@ bool DBManager::updateRecord(const VectorPair& conditions, const QVariantMap& co
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DBManager::getRecord(const VectorPair& conditions, QVariantMap& results, const QStringList& tColumns) const
|
||||
bool DBManager::getRecord(const VectorPair& conditions, QVariantMap& results, const QStringList& tColumns, const QStringList& tOrder) const
|
||||
{
|
||||
QSqlDatabase idb = getDB();
|
||||
QSqlQuery query(idb);
|
||||
@@ -195,18 +195,24 @@ bool DBManager::getRecord(const VectorPair& conditions, QVariantMap& results, co
|
||||
if(!tColumns.isEmpty())
|
||||
sColumns = tColumns.join(", ");
|
||||
|
||||
QString sOrder("");
|
||||
if(!tOrder.isEmpty())
|
||||
{
|
||||
sOrder = " ORDER BY ";
|
||||
sOrder.append(tOrder.join(", "));
|
||||
}
|
||||
// prep conditions
|
||||
QStringList prepCond;
|
||||
QVariantList bindVal;
|
||||
if(!conditions.isEmpty())
|
||||
prepCond << "WHERE";
|
||||
prepCond << " WHERE";
|
||||
|
||||
for(const auto& pair : conditions)
|
||||
{
|
||||
prepCond << pair.first+"=?";
|
||||
bindVal << pair.second;
|
||||
}
|
||||
query.prepare(QString("SELECT %1 FROM %2 %3").arg(sColumns,_table).arg(prepCond.join(" ")));
|
||||
query.prepare(QString("SELECT %1 FROM %2%3%4").arg(sColumns,_table).arg(prepCond.join(" ")).arg(sOrder));
|
||||
doAddBindValue(query, bindVal);
|
||||
|
||||
if(!query.exec())
|
||||
@@ -227,7 +233,7 @@ bool DBManager::getRecord(const VectorPair& conditions, QVariantMap& results, co
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DBManager::getRecords(QVector<QVariantMap>& results, const QStringList& tColumns) const
|
||||
bool DBManager::getRecords(QVector<QVariantMap>& results, const QStringList& tColumns, const QStringList& tOrder) const
|
||||
{
|
||||
QSqlDatabase idb = getDB();
|
||||
QSqlQuery query(idb);
|
||||
@@ -237,7 +243,14 @@ bool DBManager::getRecords(QVector<QVariantMap>& results, const QStringList& tCo
|
||||
if(!tColumns.isEmpty())
|
||||
sColumns = tColumns.join(", ");
|
||||
|
||||
query.prepare(QString("SELECT %1 FROM %2").arg(sColumns,_table));
|
||||
QString sOrder("");
|
||||
if(!tOrder.isEmpty())
|
||||
{
|
||||
sOrder = " ORDER BY ";
|
||||
sOrder.append(tOrder.join(", "));
|
||||
}
|
||||
|
||||
query.prepare(QString("SELECT %1 FROM %2%3").arg(sColumns,_table,sOrder));
|
||||
|
||||
if(!query.exec())
|
||||
{
|
||||
|
Reference in New Issue
Block a user