Skip to content

Commit 35808f1

Browse files
committed
delete spatialite_database_unique_ptr::reset( sqlite3 * )
1 parent 48e8656 commit 35808f1

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed

src/core/qgsspatialiteutils.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ int spatialite_database_unique_ptr::open( const QString &path )
3333

3434
sqlite3 *database = nullptr;
3535
int result = sqlite3_open( path.toUtf8(), &database );
36-
reset( database );
36+
std::unique_ptr< sqlite3, QgsSpatialiteCloser>::reset( database );
3737

3838
#if defined(SPATIALITE_HAS_INIT_EX)
3939
if ( result == SQLITE_OK )
@@ -43,6 +43,11 @@ int spatialite_database_unique_ptr::open( const QString &path )
4343
return result;
4444
}
4545

46+
void spatialite_database_unique_ptr::reset()
47+
{
48+
std::unique_ptr< sqlite3, QgsSpatialiteCloser>::reset();
49+
}
50+
4651
int spatialite_database_unique_ptr::open_v2( const QString &path, int flags, const char *zVfs )
4752
{
4853
#if defined(SPATIALITE_HAS_INIT_EX)
@@ -54,7 +59,7 @@ int spatialite_database_unique_ptr::open_v2( const QString &path, int flags, con
5459

5560
sqlite3 *database = nullptr;
5661
int result = sqlite3_open_v2( path.toUtf8(), &database, flags, zVfs );
57-
reset( database );
62+
std::unique_ptr< sqlite3, QgsSpatialiteCloser>::reset( database );
5863

5964
#if defined(SPATIALITE_HAS_INIT_EX)
6065
if ( result == SQLITE_OK )

src/core/qgsspatialiteutils.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,20 @@ class CORE_EXPORT spatialite_database_unique_ptr : public std::unique_ptr< sqlit
6464
*/
6565
int open( const QString &path );
6666

67+
/**
68+
* Will close the connection and set the internal pointer to nullptr.
69+
*/
70+
void reset();
71+
72+
/**
73+
* It is not allowed to set an arbitrary sqlite3 handle on this object.
74+
*
75+
* A dedicated spatialite context (connection) is created when calling open or
76+
* open_v2. This context needs to be kept together with the handle, hence it is
77+
* not allowed to reset to a handle with missing context.
78+
*/
79+
void reset( sqlite3 *handle ) = delete;
80+
6781
/**
6882
* Opens the database at the specified file \a path.
6983
*

src/providers/spatialite/qspatialite/qsql_spatialite.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -494,16 +494,6 @@ QSpatiaLiteDriver::QSpatiaLiteDriver(QObject * parent)
494494
d = new QSpatiaLiteDriverPrivate();
495495
}
496496

497-
QSpatiaLiteDriver::QSpatiaLiteDriver(sqlite3 *connection, QObject *parent)
498-
: QSqlDriver(parent)
499-
{
500-
d = new QSpatiaLiteDriverPrivate();
501-
d->access.reset( connection );
502-
setOpen(true);
503-
setOpenError(false);
504-
}
505-
506-
507497
QSpatiaLiteDriver::~QSpatiaLiteDriver()
508498
{
509499
delete d;

src/providers/spatialite/qspatialite/qsql_spatialite.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,7 @@ class Q_EXPORT_SQLDRIVER_SQLITE QSpatiaLiteDriver : public QSqlDriver
9292
friend class QSpatiaLiteResult;
9393
public:
9494
explicit QSpatiaLiteDriver(QObject *parent = 0);
95-
/**
96-
* Ownership of \a connection is taken.
97-
*/
98-
explicit QSpatiaLiteDriver(sqlite3 *connection, QObject *parent = 0);
95+
9996
~QSpatiaLiteDriver();
10097
bool hasFeature(DriverFeature f) const;
10198
bool open(const QString & db,

0 commit comments

Comments
 (0)