-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/*************************************************************************** | ||
qgsslconnect.cpp - thin wrapper class to connect to spatialite databases | ||
---------------------- | ||
begin : May 2015 | ||
copyright : (C) 2015 by Jürgen fischer | ||
email : jef at norbit dot de | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsslconnect.h" | ||
|
||
#include <sqlite3.h> | ||
#include <spatialite.h> | ||
|
||
QHash<sqlite3 *, void *> QgsSLConnect::mSLconns; | ||
|
||
int QgsSLConnect::sqlite3_open( const char *filename, sqlite3 **ppDb ) | ||
{ | ||
#if defined(SPATIALITE_VERSION_GE_4_0_0) | ||
void *conn = spatialite_alloc_connection(); | ||
#else | ||
spatialite_init( 0 ); | ||
#endif | ||
|
||
int res = ::sqlite3_open( filename, ppDb ); | ||
|
||
#if defined(SPATIALITE_VERSION_GE_4_0_0) | ||
if ( res == SQLITE_OK ) | ||
{ | ||
spatialite_init_ex( *ppDb, conn, 0 ); | ||
mSLconns.insert( *ppDb, conn ); | ||
} | ||
#endif | ||
|
||
return res; | ||
} | ||
|
||
int QgsSLConnect::sqlite3_close( sqlite3 *db ) | ||
{ | ||
int res = ::sqlite3_close( db ); | ||
|
||
#if defined(SPATIALITE_VERSION_GE_4_0_0) | ||
if ( mSLconns.contains( db ) ) | ||
spatialite_cleanup_ex( mSLconns.take( db ) ); | ||
#endif | ||
|
||
return res; | ||
} | ||
|
||
int QgsSLConnect::sqlite3_open_v2( const char *filename, sqlite3 **ppDb, int flags, const char *zVfs ) | ||
{ | ||
#if defined(SPATIALITE_VERSION_GE_4_0_0) | ||
void *conn = spatialite_alloc_connection(); | ||
#else | ||
spatialite_init( 0 ); | ||
#endif | ||
|
||
int res = ::sqlite3_open_v2( filename, ppDb, flags, zVfs ); | ||
|
||
#if defined(SPATIALITE_VERSION_GE_4_0_0) | ||
if ( res == SQLITE_OK ) | ||
{ | ||
spatialite_init_ex( *ppDb, conn, 0 ); | ||
mSLconns.insert( *ppDb, conn ); | ||
} | ||
#endif | ||
|
||
return res; | ||
} | ||
|
||
int QgsSLConnect::sqlite3_close_v2( sqlite3 *db ) | ||
{ | ||
int res = ::sqlite3_close( db ); | ||
|
||
#if defined(SPATIALITE_VERSION_GE_4_0_0) | ||
if ( mSLconns.contains( db ) ) | ||
spatialite_cleanup_ex( mSLconns.take( db ) ); | ||
#endif | ||
|
||
return res; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/*************************************************************************** | ||
qgsslconnect.h - thin wrapper class to connect to spatialite databases | ||
---------------------- | ||
begin : May 2015 | ||
copyright : (C) 2015 by Jürgen fischer | ||
email : jef at norbit dot de | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSSLCONNECT_H | ||
#define QGSSLCONNECT_H | ||
|
||
#include <QHash> | ||
|
||
class sqlite3; | ||
|
||
class CORE_EXPORT QgsSLConnect | ||
{ | ||
public: | ||
static int sqlite3_open( const char *filename, sqlite3 **ppDb ); | ||
static int sqlite3_close( sqlite3* ); | ||
|
||
static int sqlite3_open_v2( const char *filename, sqlite3 **ppDb, int flags, const char *zVfs ); | ||
static int sqlite3_close_v2( sqlite3* ); | ||
|
||
#if defined(SPATIALITE_VERSION_GE_4_0_0) | ||
private: | ||
static QHash<sqlite3 *, void *> mSLconns; | ||
#endif | ||
}; | ||
|
||
#endif | ||
|