QGIS API Documentation  2.10.1-Pisa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsslconnect.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsslconnect.cpp - thin wrapper class to connect to spatialite databases
3  ----------------------
4  begin : May 2015
5  copyright : (C) 2015 by Jürgen fischer
6  email : jef at norbit dot de
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "qgsslconnect.h"
17 
18 #include <sqlite3.h>
19 #include <spatialite.h>
20 
21 #if defined(SPATIALITE_HAS_INIT_EX)
22 QHash<sqlite3 *, void *> QgsSLConnect::mSLconns;
23 #endif
24 
25 int QgsSLConnect::sqlite3_open( const char *filename, sqlite3 **ppDb )
26 {
27 #if defined(SPATIALITE_HAS_INIT_EX)
28  void *conn = spatialite_alloc_connection();
29 #else
30  spatialite_init( 0 );
31 #endif
32 
33  int res = ::sqlite3_open( filename, ppDb );
34 
35 #if defined(SPATIALITE_HAS_INIT_EX)
36  if ( res == SQLITE_OK )
37  {
38  spatialite_init_ex( *ppDb, conn, 0 );
39  mSLconns.insert( *ppDb, conn );
40  }
41 #endif
42 
43  return res;
44 }
45 
47 {
48  int res = ::sqlite3_close( db );
49 
50 #if defined(SPATIALITE_HAS_INIT_EX)
51  if ( mSLconns.contains( db ) )
52  spatialite_cleanup_ex( mSLconns.take( db ) );
53 #endif
54 
55  return res;
56 }
57 
58 int QgsSLConnect::sqlite3_open_v2( const char *filename, sqlite3 **ppDb, int flags, const char *zVfs )
59 {
60 #if defined(SPATIALITE_HAS_INIT_EX)
61  void *conn = spatialite_alloc_connection();
62 #else
63  spatialite_init( 0 );
64 #endif
65 
66  int res = ::sqlite3_open_v2( filename, ppDb, flags, zVfs );
67 
68 #if defined(SPATIALITE_HAS_INIT_EX)
69  if ( res == SQLITE_OK )
70  {
71  spatialite_init_ex( *ppDb, conn, 0 );
72  mSLconns.insert( *ppDb, conn );
73  }
74 #endif
75 
76  return res;
77 }
78 
80 {
81  int res = ::sqlite3_close( db );
82 
83 #if defined(SPATIALITE_HAS_INIT_EX)
84  if ( mSLconns.contains( db ) )
85  spatialite_cleanup_ex( mSLconns.take( db ) );
86 #endif
87 
88  return res;
89 }
static int sqlite3_close(sqlite3 *)
static int sqlite3_open(const char *filename, sqlite3 **ppDb)
static int sqlite3_open_v2(const char *filename, sqlite3 **ppDb, int flags, const char *zVfs)
struct sqlite3 sqlite3
static int sqlite3_close_v2(sqlite3 *)