Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add sqlite3_database_unique_ptr::exec (initial author: Matthias Kuhn …
…<matthias@opengis.ch>)

Partial backport of 49d8060
needed to backport e19bf11
  • Loading branch information
rouault committed Feb 6, 2019
1 parent 7aca6af commit 76c48e6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/core/qgssqliteutils.cpp
Expand Up @@ -91,6 +91,21 @@ sqlite3_statement_unique_ptr sqlite3_database_unique_ptr::prepare( const QString
return s;
}

int sqlite3_database_unique_ptr::exec( const QString &sql, QString &errorMessage ) const
{
char *errMsg;

int ret = sqlite3_exec( get(), sql.toUtf8(), nullptr, nullptr, &errMsg );

if ( errMsg )
{
errorMessage = QString::fromUtf8( errMsg );
sqlite3_free( errMsg );
}

return ret;
}

QString QgsSqliteUtils::quotedString( const QString &value )
{
if ( value.isNull() )
Expand Down
13 changes: 12 additions & 1 deletion src/core/qgssqliteutils.h
Expand Up @@ -21,6 +21,8 @@
#define SIP_NO_FILE

#include "qgis_core.h"
#include "qgis_sip.h"

#include <memory>
#include <QString>

Expand Down Expand Up @@ -134,8 +136,17 @@ class CORE_EXPORT sqlite3_database_unique_ptr : public std::unique_ptr< sqlite3,
* Prepares a \a sql statement, returning the result. The \a resultCode
* argument will be filled with the sqlite3 result code.
*/
sqlite3_statement_unique_ptr prepare( const QString &sql, int &resultCode ) const;
sqlite3_statement_unique_ptr prepare( const QString &sql, int &resultCode SIP_OUT ) const;

/**
* Executes the \a sql command in the database. Multiple sql queries can be run within
* one single command.
* Errors are reported to \a errorMessage.
* Returns SQLITE_OK in case of success or an sqlite error code.
*
* \since QGIS 3.4.5
*/
int exec( const QString &sql, QString &errorMessage SIP_OUT ) const;
};

/**
Expand Down

0 comments on commit 76c48e6

Please sign in to comment.