23 #include <spatialite.h>
26 #ifdef SPATIALITE_PRINT_ALL_SQL
30 static int trace_callback(
unsigned,
void *ctx,
void *p,
void * )
32 sqlite3_stmt *stmt = ( sqlite3_stmt * )p;
33 char *sql = sqlite3_expanded_sql( stmt );
34 qDebug() <<
"SPATIALITE" << QThread::currentThreadId() << (
sqlite3 * ) ctx << sql;
43 auto &deleter = get_deleter();
44 deleter.mSpatialiteContext = spatialite_alloc_connection();
47 int result = sqlite3_open( path.toUtf8(), &database );
48 std::unique_ptr< sqlite3, QgsSpatialiteCloser>::reset( database );
50 if ( result == SQLITE_OK )
51 spatialite_init_ex( database, deleter.mSpatialiteContext, 0 );
58 std::unique_ptr< sqlite3, QgsSpatialiteCloser>::reset();
63 auto &deleter = get_deleter();
64 deleter.mSpatialiteContext = spatialite_alloc_connection();
67 int result = sqlite3_open_v2( path.toUtf8(), &database, flags, zVfs );
68 std::unique_ptr< sqlite3, QgsSpatialiteCloser>::reset( database );
70 if ( result == SQLITE_OK )
71 spatialite_init_ex( database, deleter.mSpatialiteContext, 0 );
73 #ifdef SPATIALITE_PRINT_ALL_SQL
88 return QString( sqlite3_errmsg( get() ) );
93 sqlite3_stmt *preparedStatement =
nullptr;
94 const char *tail =
nullptr;
95 const QByteArray sqlUtf8 = sql.toUtf8();
96 resultCode = sqlite3_prepare( get(), sqlUtf8, sqlUtf8.length(), &preparedStatement, &tail );
98 s.reset( preparedStatement );
104 int res = sqlite3_close_v2( handle );
105 if ( res != SQLITE_OK )
107 QgsDebugMsg( QStringLiteral(
"sqlite3_close_v2() failed: %1" ).arg( res ) );