Skip to content
Permalink
Browse files
add missing files to 252aaab
  • Loading branch information
jef-n committed May 26, 2015
1 parent 252aaab commit 23ef9dafd248e4edf4bb63b01763d174c457e846
Showing with 126 additions and 0 deletions.
  1. +87 −0 src/core/qgsslconnect.cpp
  2. +39 −0 src/core/qgsslconnect.h
@@ -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;
}
@@ -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

0 comments on commit 23ef9da

Please sign in to comment.