Skip to content

Commit 76c48e6

Browse files
committed
Add sqlite3_database_unique_ptr::exec (initial author: Matthias Kuhn <matthias@opengis.ch>)
Partial backport of 49d8060 needed to backport e19bf11
1 parent 7aca6af commit 76c48e6

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/core/qgssqliteutils.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,21 @@ sqlite3_statement_unique_ptr sqlite3_database_unique_ptr::prepare( const QString
9191
return s;
9292
}
9393

94+
int sqlite3_database_unique_ptr::exec( const QString &sql, QString &errorMessage ) const
95+
{
96+
char *errMsg;
97+
98+
int ret = sqlite3_exec( get(), sql.toUtf8(), nullptr, nullptr, &errMsg );
99+
100+
if ( errMsg )
101+
{
102+
errorMessage = QString::fromUtf8( errMsg );
103+
sqlite3_free( errMsg );
104+
}
105+
106+
return ret;
107+
}
108+
94109
QString QgsSqliteUtils::quotedString( const QString &value )
95110
{
96111
if ( value.isNull() )

src/core/qgssqliteutils.h

+12-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#define SIP_NO_FILE
2222

2323
#include "qgis_core.h"
24+
#include "qgis_sip.h"
25+
2426
#include <memory>
2527
#include <QString>
2628

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

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

141152
/**

0 commit comments

Comments
 (0)