Update to dms control phase1.
This commit is contained in:
@@ -135,3 +135,48 @@ void SQLHelper::QueryMap(const QString& sql, QMap<QString, QVariant> &result, co
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool SQLHelper::exec(const QString& aSql)
|
||||
{
|
||||
QSqlQuery query(*defaultDatabase);
|
||||
bool result = query.exec(aSql);
|
||||
if(!result)
|
||||
{
|
||||
qDebug() << query.lastError().text();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
QVariant SQLHelper::queryValue(const QString& aSql)
|
||||
{
|
||||
QSqlQuery query(*defaultDatabase);
|
||||
if (!query.exec(aSql))
|
||||
{
|
||||
qDebug()<<query.lastError().text();
|
||||
return QVariant();
|
||||
}
|
||||
if(query.next())
|
||||
{
|
||||
return query.value(0);
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QList<QVariant> SQLHelper::queryValues(const QString& aSql)
|
||||
{
|
||||
QList<QVariant> result;
|
||||
QSqlQuery query(*defaultDatabase);
|
||||
if (!query.exec(aSql))
|
||||
{
|
||||
qDebug()<<query.lastError().text();
|
||||
return QList<QVariant>();
|
||||
}
|
||||
|
||||
while(query.next())
|
||||
{
|
||||
result.append(query.value(0));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,9 @@ public:
|
||||
static QSqlQueryModel* QueryModel(const QString &queryName);
|
||||
static QSqlQueryModel* QueryModel(const QString &queryName, const QString &sql, const QMap<QString, QVariant> ¶ms = QMap<QString, QVariant>());
|
||||
static QSqlTableModel* getTable(const QString & tableName);
|
||||
static bool exec(const QString& aSql);
|
||||
static QVariant queryValue(const QString& aSql);
|
||||
static QList<QVariant> queryValues(const QString& aSql);
|
||||
private:
|
||||
static QSqlDatabase* defaultDatabase;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user