Rev 286 |
Rev 639 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
#include "sqlhelper.h"
#include <QtSql>
SqlHelper::SqlHelper()
{
}
/** execute 'query' against database 'database'. The first column of the first row are returned.
A Null-Variant is returned, if the query has no results. */
QVariant SqlHelper::queryValue(const QString &query, const QSqlDatabase &database)
{
QSqlQuery q(database);
if (!q.exec(query)) {
qDebug() << "query"<< query << " raised SQL-Error:" << q.lastError().text();
return QVariant();
}
if (q.next()) {
return q.value(0);
}
return QVariant();
}
/** execute 'query' against database 'database'.
Use for insert, update, ... statements without return values. */
bool SqlHelper::executeSql(const QString &query, const QSqlDatabase &database)
{
QSqlQuery q(database);
bool success = q.exec(query);
if (!success)
qDebug() << "query"<< query << " raised SQL-Error:" << q.lastError().text();
return success;
}