Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
delete spatialite_database_unique_ptr::reset( sqlite3 * )
  • Loading branch information
m-kuhn committed Nov 15, 2017
1 parent 48e8656 commit 35808f1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
9 changes: 7 additions & 2 deletions src/core/qgsspatialiteutils.cpp
Expand Up @@ -33,7 +33,7 @@ int spatialite_database_unique_ptr::open( const QString &path )

sqlite3 *database = nullptr;
int result = sqlite3_open( path.toUtf8(), &database );
reset( database );
std::unique_ptr< sqlite3, QgsSpatialiteCloser>::reset( database );

#if defined(SPATIALITE_HAS_INIT_EX)
if ( result == SQLITE_OK )
Expand All @@ -43,6 +43,11 @@ int spatialite_database_unique_ptr::open( const QString &path )
return result;
}

void spatialite_database_unique_ptr::reset()
{
std::unique_ptr< sqlite3, QgsSpatialiteCloser>::reset();
}

int spatialite_database_unique_ptr::open_v2( const QString &path, int flags, const char *zVfs )
{
#if defined(SPATIALITE_HAS_INIT_EX)
Expand All @@ -54,7 +59,7 @@ int spatialite_database_unique_ptr::open_v2( const QString &path, int flags, con

sqlite3 *database = nullptr;
int result = sqlite3_open_v2( path.toUtf8(), &database, flags, zVfs );
reset( database );
std::unique_ptr< sqlite3, QgsSpatialiteCloser>::reset( database );

#if defined(SPATIALITE_HAS_INIT_EX)
if ( result == SQLITE_OK )
Expand Down
14 changes: 14 additions & 0 deletions src/core/qgsspatialiteutils.h
Expand Up @@ -64,6 +64,20 @@ class CORE_EXPORT spatialite_database_unique_ptr : public std::unique_ptr< sqlit
*/
int open( const QString &path );

/**
* Will close the connection and set the internal pointer to nullptr.
*/
void reset();

/**
* It is not allowed to set an arbitrary sqlite3 handle on this object.
*
* A dedicated spatialite context (connection) is created when calling open or
* open_v2. This context needs to be kept together with the handle, hence it is
* not allowed to reset to a handle with missing context.
*/
void reset( sqlite3 *handle ) = delete;

/**
* Opens the database at the specified file \a path.
*
Expand Down
10 changes: 0 additions & 10 deletions src/providers/spatialite/qspatialite/qsql_spatialite.cpp
Expand Up @@ -494,16 +494,6 @@ QSpatiaLiteDriver::QSpatiaLiteDriver(QObject * parent)
d = new QSpatiaLiteDriverPrivate();
}

QSpatiaLiteDriver::QSpatiaLiteDriver(sqlite3 *connection, QObject *parent)
: QSqlDriver(parent)
{
d = new QSpatiaLiteDriverPrivate();
d->access.reset( connection );
setOpen(true);
setOpenError(false);
}


QSpatiaLiteDriver::~QSpatiaLiteDriver()
{
delete d;
Expand Down
5 changes: 1 addition & 4 deletions src/providers/spatialite/qspatialite/qsql_spatialite.h
Expand Up @@ -92,10 +92,7 @@ class Q_EXPORT_SQLDRIVER_SQLITE QSpatiaLiteDriver : public QSqlDriver
friend class QSpatiaLiteResult;
public:
explicit QSpatiaLiteDriver(QObject *parent = 0);
/**
* Ownership of \a connection is taken.
*/
explicit QSpatiaLiteDriver(sqlite3 *connection, QObject *parent = 0);

~QSpatiaLiteDriver();
bool hasFeature(DriverFeature f) const;
bool open(const QString & db,
Expand Down

0 comments on commit 35808f1

Please sign in to comment.