23 #include <spatialite.h> 27 auto &deleter = get_deleter();
28 deleter.mSpatialiteContext = spatialite_alloc_connection();
31 int result = sqlite3_open( path.toUtf8(), &database );
32 std::unique_ptr< sqlite3, QgsSpatialiteCloser>::reset( database );
34 if ( result == SQLITE_OK )
35 spatialite_init_ex( database, deleter.mSpatialiteContext, 0 );
42 std::unique_ptr< sqlite3, QgsSpatialiteCloser>::reset();
47 auto &deleter = get_deleter();
48 deleter.mSpatialiteContext = spatialite_alloc_connection();
51 int result = sqlite3_open_v2( path.toUtf8(), &database, flags, zVfs );
52 std::unique_ptr< sqlite3, QgsSpatialiteCloser>::reset( database );
54 if ( result == SQLITE_OK )
55 spatialite_init_ex( database, deleter.mSpatialiteContext, 0 );
62 return QString( sqlite3_errmsg(
get() ) );
67 sqlite3_stmt *preparedStatement =
nullptr;
68 const char *tail =
nullptr;
69 const QByteArray sqlUtf8 = sql.toUtf8();
70 resultCode = sqlite3_prepare(
get(), sqlUtf8, sqlUtf8.length(), &preparedStatement, &tail );
72 s.reset( preparedStatement );
78 int res = sqlite3_close_v2( handle );
79 if ( res != SQLITE_OK )
81 QgsDebugMsg( QStringLiteral(
"sqlite3_close_v2() failed: %1" ).arg( res ) );
84 spatialite_cleanup_ex( mSpatialiteContext );
85 mSpatialiteContext =
nullptr;
int open(const QString &path)
Opens the database at the specified file path.
int open_v2(const QString &path, int flags, const char *zVfs)
Opens the database at the specified file path.
Unique pointer for sqlite3 prepared statements, which automatically finalizes the statement when the ...
QString errorMessage() const
Returns the most recent error message encountered by the database.
void reset()
Will close the connection and set the internal pointer to nullptr.
void operator()(sqlite3 *database)
Closes an spatialite database.
sqlite3_statement_unique_ptr prepare(const QString &sql, int &resultCode)
Prepares a sql statement, returning the result.