24 #ifdef HAVE_SPATIALITE
25 #include <spatialite.h>
29 #ifdef SPATIALITE_PRINT_ALL_SQL
33 static int trace_callback(
unsigned,
void *ctx,
void *p,
void * )
35 sqlite3_stmt *stmt = ( sqlite3_stmt * )p;
36 char *sql = sqlite3_expanded_sql( stmt );
37 qDebug() <<
"SPATIALITE" << QThread::currentThreadId() << (
sqlite3 * ) ctx << sql;
46 #ifdef HAVE_SPATIALITE
47 auto &deleter = get_deleter();
48 deleter.mSpatialiteContext = spatialite_alloc_connection();
52 const int result = sqlite3_open( path.toUtf8(), &database );
53 std::unique_ptr< sqlite3, QgsSpatialiteCloser>::reset( database );
55 #ifdef HAVE_SPATIALITE
56 if ( result == SQLITE_OK )
57 spatialite_init_ex( database, deleter.mSpatialiteContext, 0 );
65 std::unique_ptr< sqlite3, QgsSpatialiteCloser>::reset();
70 #ifdef HAVE_SPATIALITE
71 auto &deleter = get_deleter();
72 deleter.mSpatialiteContext = spatialite_alloc_connection();
76 const int result = sqlite3_open_v2( path.toUtf8(), &database, flags, zVfs );
77 std::unique_ptr< sqlite3, QgsSpatialiteCloser>::reset( database );
79 #ifdef HAVE_SPATIALITE
80 if ( result == SQLITE_OK )
81 spatialite_init_ex( database, deleter.mSpatialiteContext, 0 );
84 #ifdef SPATIALITE_PRINT_ALL_SQL
99 return QString( sqlite3_errmsg( get() ) );
104 sqlite3_stmt *preparedStatement =
nullptr;
105 const char *tail =
nullptr;
106 const QByteArray sqlUtf8 = sql.toUtf8();
107 resultCode = sqlite3_prepare( get(), sqlUtf8, sqlUtf8.length(), &preparedStatement, &tail );
109 s.reset( preparedStatement );
115 const int res = sqlite3_close_v2( handle );
116 if ( res != SQLITE_OK )
118 QgsDebugMsg( QStringLiteral(
"sqlite3_close_v2() failed: %1" ).arg( res ) );
121 #ifdef HAVE_SPATIALITE