1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-20 07:49:42 +01:00

* Added a convenient sql escaping method to TomahawkSqlQuery. It uses the sql drivers internal escaping mechanism.

This commit is contained in:
Christian Muehlhaeuser 2012-06-07 08:33:08 +02:00
parent 9443992ff9
commit 14ee71e665
2 changed files with 14 additions and 2 deletions

View File

@ -18,6 +18,8 @@
#include "database/TomahawkSqlQuery.h"
#include "database/Database.h"
#include "database/DatabaseImpl.h"
#include "utils/TomahawkUtils.h"
#include "utils/Logger.h"
@ -42,6 +44,13 @@ TomahawkSqlQuery::TomahawkSqlQuery( const QSqlDatabase& db )
}
QString
TomahawkSqlQuery::escape( const QString& identifier, QSqlDriver::IdentifierType type )
{
return Database::instance()->impl()->database().driver()->escapeIdentifier( identifier, type );
}
bool
TomahawkSqlQuery::exec( const QString& query )
{
@ -114,7 +123,7 @@ TomahawkSqlQuery::showError()
bool
TomahawkSqlQuery::isBusyError( const QSqlError& error )
TomahawkSqlQuery::isBusyError( const QSqlError& error ) const
{
const QString text = error.text().toLower();

View File

@ -21,6 +21,7 @@
// subclass QSqlQuery so that it prints the error msg if a query fails
#include <QSqlDriver>
#include <QSqlQuery>
#define TOMAHAWK_QUERY_ANALYZE 1
@ -32,13 +33,15 @@ public:
TomahawkSqlQuery();
TomahawkSqlQuery( const QSqlDatabase& db );
static QString escape( const QString& identifier, QSqlDriver::IdentifierType type = QSqlDriver::FieldName );
bool exec( const QString& query );
bool exec();
bool commitTransaction();
private:
bool isBusyError( const QSqlError& error );
bool isBusyError( const QSqlError& error ) const;
void showError();