Skip to content

Commit bb6fda6

Browse files
committed
Bump minimum spatialite version to 4.2
1 parent 4420eba commit bb6fda6

8 files changed

Lines changed: 9 additions & 119 deletions

File tree

CMakeLists.txt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -250,16 +250,6 @@ IF(WITH_CORE)
250250

251251
FIND_PACKAGE(SpatiaLite REQUIRED)
252252

253-
IF(SPATIALITE_VERSION_GE_4_0_0)
254-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSPATIALITE_VERSION_GE_4_0_0")
255-
ENDIF(SPATIALITE_VERSION_GE_4_0_0)
256-
IF(SPATIALITE_VERSION_G_4_1_1)
257-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSPATIALITE_VERSION_G_4_1_1")
258-
ENDIF(SPATIALITE_VERSION_G_4_1_1)
259-
IF(SPATIALITE_HAS_INIT_EX)
260-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSPATIALITE_HAS_INIT_EX")
261-
ENDIF(SPATIALITE_HAS_INIT_EX)
262-
263253
IF (NOT PROJ_FOUND OR NOT GEOS_FOUND OR NOT GDAL_FOUND)
264254
MESSAGE (SEND_ERROR "Some dependencies were not found! Proj: ${PROJ_FOUND}, Geos: ${GEOS_FOUND}, GDAL: ${GDAL_FOUND}")
265255
ENDIF (NOT PROJ_FOUND OR NOT GEOS_FOUND OR NOT GDAL_FOUND)

cmake/FindSpatiaLite.cmake

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,15 @@ IF (SPATIALITE_FOUND)
6565
MESSAGE(STATUS "Found SpatiaLite: ${SPATIALITE_LIBRARY}")
6666
ENDIF (NOT SPATIALITE_FIND_QUIETLY)
6767

68-
# Check for symbol gaiaDropTable
6968
IF(APPLE)
7069
# no extra LDFLAGS used in link test, may fail in OS X SDK
7170
SET(CMAKE_REQUIRED_LIBRARIES "-F/Library/Frameworks" ${CMAKE_REQUIRED_LIBRARIES})
7271
ENDIF(APPLE)
73-
check_library_exists("${SPATIALITE_LIBRARY}" gaiaDropTable "" SPATIALITE_VERSION_GE_4_0_0)
74-
check_library_exists("${SPATIALITE_LIBRARY}" gaiaStatisticsInvalidate "" SPATIALITE_VERSION_G_4_1_1)
75-
check_library_exists("${SPATIALITE_LIBRARY}" spatialite_init_ex "" SPATIALITE_HAS_INIT_EX)
72+
73+
check_library_exists("${SPATIALITE_LIBRARY}" gaiaStatisticsInvalidate "" SPATIALITE_VERSION_GE_4_2_0)
74+
IF (NOT SPATIALITE_VERSION_GE_4_2_0)
75+
MESSAGE(FATAL_ERROR "Found SpatiaLite, but version is too old. Requires at least version 4.2.0")
76+
ENDIF (NOT SPATIALITE_VERSION_GE_4_2_0)
7677

7778
ELSE (SPATIALITE_FOUND)
7879

doc/overview.t2t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Required build dependencies:
1919
- Proj >= 4.4.x
2020
- GEOS >= 3.4
2121
- Sqlite3 >= 3.0.0
22-
- SpatiaLite
22+
- SpatiaLite >= 4.2.0
2323
- libspatialindex
2424
- GDAL/OGR >= 2.1
2525
- Qwt >= 5.0 & (< 6.1 with internal QwtPolar)

src/core/qgsspatialiteutils.cpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,15 @@
2424

2525
int spatialite_database_unique_ptr::open( const QString &path )
2626
{
27-
#if defined(SPATIALITE_HAS_INIT_EX)
2827
auto &deleter = get_deleter();
2928
deleter.mSpatialiteContext = spatialite_alloc_connection();
30-
#else
31-
spatialite_init( 0 );
32-
#endif
3329

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

38-
#if defined(SPATIALITE_HAS_INIT_EX)
3934
if ( result == SQLITE_OK )
4035
spatialite_init_ex( database, deleter.mSpatialiteContext, 0 );
41-
#endif
4236

4337
return result;
4438
}
@@ -50,21 +44,15 @@ void spatialite_database_unique_ptr::reset()
5044

5145
int spatialite_database_unique_ptr::open_v2( const QString &path, int flags, const char *zVfs )
5246
{
53-
#if defined(SPATIALITE_HAS_INIT_EX)
5447
auto &deleter = get_deleter();
5548
deleter.mSpatialiteContext = spatialite_alloc_connection();
56-
#else
57-
spatialite_init( 0 );
58-
#endif
5949

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

64-
#if defined(SPATIALITE_HAS_INIT_EX)
6554
if ( result == SQLITE_OK )
6655
spatialite_init_ex( database, deleter.mSpatialiteContext, 0 );
67-
#endif
6856

6957
return result;
7058
}
@@ -92,9 +80,7 @@ void QgsSpatialiteCloser::operator()( sqlite3 *handle )
9280
{
9381
QgsDebugMsg( QStringLiteral( "sqlite3_close() failed: %1" ).arg( res ) );
9482
}
95-
#if defined(SPATIALITE_HAS_INIT_EX)
83+
9684
spatialite_cleanup_ex( mSpatialiteContext );
9785
mSpatialiteContext = nullptr;
98-
#endif
99-
10086
}

src/providers/spatialite/qgsspatialiteconnection.cpp

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -77,27 +77,7 @@ QgsSpatiaLiteConnection::Error QgsSpatiaLiteConnection::fetchTables( bool loadGe
7777
return FailedToCheckMetadata;
7878
}
7979

80-
bool recentVersion = false;
81-
#ifdef SPATIALITE_VERSION_GE_4_0_0
82-
// only if libspatialite version is >= 4.0.0
83-
recentVersion = true;
84-
#endif
85-
86-
if ( ret == LayoutCurrent && !recentVersion )
87-
{
88-
// obsolete library version
89-
mErrorMsg = tr( "obsolete libspatialite: connecting to this DB requires using v.4.0 (or any subsequent)" );
90-
return FailedToCheckMetadata;
91-
}
92-
93-
#ifdef SPATIALITE_VERSION_GE_4_0_0
94-
// only if libspatialite version is >= 4.0.0
95-
// using v.4.0 Abstract Interface
9680
if ( !getTableInfoAbstractInterface( database.get(), loadGeometrylessTables ) )
97-
#else
98-
// obsolete library: still using the traditional approach
99-
if ( !getTableInfo( database.get(), loadGeometrylessTables ) )
100-
#endif
10181
{
10282
return FailedToGetTables;
10383
}
@@ -107,7 +87,6 @@ QgsSpatiaLiteConnection::Error QgsSpatiaLiteConnection::fetchTables( bool loadGe
10787

10888
bool QgsSpatiaLiteConnection::updateStatistics()
10989
{
110-
#ifdef SPATIALITE_VERSION_GE_4_0_0
11190
QFileInfo fi( mPath );
11291
if ( !fi.exists() )
11392
return false;
@@ -120,9 +99,6 @@ bool QgsSpatiaLiteConnection::updateStatistics()
12099
ret = update_layer_statistics( database.get(), nullptr, nullptr );
121100

122101
return ret;
123-
#else
124-
return false;
125-
#endif
126102
}
127103

128104
int QgsSpatiaLiteConnection::checkHasMetadataTables( sqlite3 *handle )
@@ -242,8 +218,6 @@ int QgsSpatiaLiteConnection::checkHasMetadataTables( sqlite3 *handle )
242218
return false;
243219
}
244220

245-
#ifdef SPATIALITE_VERSION_GE_4_0_0
246-
// only if libspatialite version is >= 4.0.0
247221
bool QgsSpatiaLiteConnection::getTableInfoAbstractInterface( sqlite3 *handle, bool loadGeometrylessTables )
248222
{
249223
int ret;
@@ -353,7 +327,6 @@ bool QgsSpatiaLiteConnection::getTableInfoAbstractInterface( sqlite3 *handle, bo
353327
}
354328
return false;
355329
}
356-
#endif
357330

358331
bool QgsSpatiaLiteConnection::getTableInfo( sqlite3 *handle, bool loadGeometrylessTables )
359332
{

src/providers/spatialite/qgsspatialiteconnection.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,6 @@ class QgsSpatiaLiteConnection : public QObject
9292
\returns true if querying of tables was successful, false on error */
9393
bool getTableInfo( sqlite3 *handle, bool loadGeometrylessTables );
9494

95-
#ifdef SPATIALITE_VERSION_GE_4_0_0
96-
// only if libspatialite version is >= 4.0.0
97-
9895
/**
9996
* Inserts information about the spatial tables into mTables
10097
* please note: this method is fully based on the Abstract Interface
@@ -105,7 +102,6 @@ class QgsSpatiaLiteConnection : public QObject
105102
* thus completely freeing the client application to take care of them.
106103
*/
107104
bool getTableInfoAbstractInterface( sqlite3 *handle, bool loadGeometrylessTables );
108-
#endif
109105

110106
//! Cleaning well-formatted SQL strings
111107
QString quotedValue( QString value ) const;

src/providers/spatialite/qgsspatialiteprovider.cpp

Lines changed: 2 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,6 @@ QgsSpatiaLiteProvider::QgsSpatiaLiteProvider( QString const &uri )
475475
bool alreadyDone = false;
476476
bool ret = false;
477477

478-
#ifdef SPATIALITE_VERSION_GE_4_0_0
479-
// only if libspatialite version is >= 4.0.0
480478
gaiaVectorLayersListPtr list = nullptr;
481479
gaiaVectorLayerPtr lyr = nullptr;
482480
bool specialCase = false;
@@ -500,7 +498,6 @@ QgsSpatiaLiteProvider::QgsSpatiaLiteProvider( QString const &uri )
500498
QgsDebugMsg( "Using checkLayerTypeAbstractInterface" );
501499
alreadyDone = true;
502500
}
503-
#endif
504501

505502
if ( !alreadyDone )
506503
{
@@ -533,7 +530,6 @@ QgsSpatiaLiteProvider::QgsSpatiaLiteProvider( QString const &uri )
533530

534531
alreadyDone = false;
535532

536-
#ifdef SPATIALITE_VERSION_GE_4_0_0
537533
if ( lyr )
538534
{
539535
// using the v.4.0 AbstractInterface
@@ -559,7 +555,6 @@ QgsSpatiaLiteProvider::QgsSpatiaLiteProvider( QString const &uri )
559555
gaiaFreeVectorLayersList( list );
560556
alreadyDone = true;
561557
}
562-
#endif
563558

564559
if ( !alreadyDone )
565560
{
@@ -665,9 +660,6 @@ static TypeSubType getVariantType( const QString &type )
665660
return TypeSubType( QVariant::String, QVariant::Invalid );
666661
}
667662

668-
#ifdef SPATIALITE_VERSION_GE_4_0_0
669-
// only if libspatialite version is >= 4.0.0
670-
671663
void QgsSpatiaLiteProvider::loadFieldsAbstractInterface( gaiaVectorLayerPtr lyr )
672664
{
673665
if ( !lyr )
@@ -774,7 +766,6 @@ void QgsSpatiaLiteProvider::loadFieldsAbstractInterface( gaiaVectorLayerPtr lyr
774766

775767
sqlite3_free_table( results );
776768
}
777-
#endif
778769

779770
QString QgsSpatiaLiteProvider::spatialiteVersion()
780771
{
@@ -4185,16 +4176,9 @@ bool QgsSpatiaLiteProvider::addAttributes( const QList<QgsField> &attributes )
41854176
handleError( sql, errMsg, true );
41864177
return false;
41874178
}
4188-
#ifdef SPATIALITE_VERSION_GE_4_0_0
4189-
sql = QStringLiteral( "UPDATE geometry_columns_statistics set last_verified = 0 WHERE f_table_name=\"%1\" AND f_geometry_column=\"%2\";" )
4190-
.arg( mTableName,
4191-
mGeometryColumn );
4192-
ret = sqlite3_exec( mSqliteHandle, sql.toUtf8().constData(), nullptr, nullptr, &errMsg );
4193-
update_layer_statistics( mSqliteHandle, mTableName.toUtf8().constData(), mGeometryColumn.toUtf8().constData() );
4194-
#elif SPATIALITE_VERSION_G_4_1_1
4195-
gaiaStatisticsInvalidate( mSqliteHandle, tableName.toUtf8().constData(), mGeometryColumn.toUtf8().constData() );
4179+
4180+
gaiaStatisticsInvalidate( mSqliteHandle, mTableName.toUtf8().constData(), mGeometryColumn.toUtf8().constData() );
41964181
update_layer_statistics( mSqliteHandle, mTableName.toUtf8().constData(), mGeometryColumn.toUtf8().constData() );
4197-
#endif
41984182

41994183
// reload columns
42004184
loadFields();
@@ -4401,8 +4385,6 @@ QString QgsSpatiaLiteProvider::quotedValue( QString value )
44014385
return value.prepend( '\'' ).append( '\'' );
44024386
}
44034387

4404-
#ifdef SPATIALITE_VERSION_GE_4_0_0
4405-
// only if libspatialite version is >= 4.0.0
44064388
bool QgsSpatiaLiteProvider::checkLayerTypeAbstractInterface( gaiaVectorLayerPtr lyr )
44074389
{
44084390
if ( !lyr )
@@ -4444,7 +4426,6 @@ bool QgsSpatiaLiteProvider::checkLayerTypeAbstractInterface( gaiaVectorLayerPtr
44444426

44454427
return true;
44464428
}
4447-
#endif
44484429

44494430
bool QgsSpatiaLiteProvider::checkLayerType()
44504431
{
@@ -4626,8 +4607,6 @@ bool QgsSpatiaLiteProvider::checkLayerType()
46264607
return count == 1;
46274608
}
46284609

4629-
#ifdef SPATIALITE_VERSION_GE_4_0_0
4630-
// only if libspatialite version is >= 4.0.0
46314610
bool QgsSpatiaLiteProvider::getGeometryDetailsAbstractInterface( gaiaVectorLayerPtr lyr )
46324611
{
46334612
if ( !lyr )
@@ -4728,7 +4707,6 @@ void QgsSpatiaLiteProvider::getViewSpatialIndexName()
47284707
}
47294708
sqlite3_free_table( results );
47304709
}
4731-
#endif
47324710

47334711
bool QgsSpatiaLiteProvider::getGeometryDetails()
47344712
{
@@ -5143,8 +5121,6 @@ bool QgsSpatiaLiteProvider::getSridDetails()
51435121
return true;
51445122
}
51455123

5146-
#ifdef SPATIALITE_VERSION_GE_4_0_0
5147-
// only if libspatialite version is >= 4.0.0
51485124
bool QgsSpatiaLiteProvider::getTableSummaryAbstractInterface( gaiaVectorLayerPtr lyr )
51495125
{
51505126
if ( !lyr )
@@ -5164,7 +5140,6 @@ bool QgsSpatiaLiteProvider::getTableSummaryAbstractInterface( gaiaVectorLayerPtr
51645140

51655141
return true;
51665142
}
5167-
#endif
51685143

51695144
bool QgsSpatiaLiteProvider::getTableSummary()
51705145
{
@@ -5389,41 +5364,13 @@ QGISEXTERN bool deleteLayer( const QString &dbPath, const QString &tableName, QS
53895364
}
53905365
sqlite3 *sqlite_handle = hndl->handle();
53915366
int ret;
5392-
#ifdef SPATIALITE_VERSION_GE_4_0_0
5393-
// only if libspatialite version is >= 4.0.0
5394-
// if libspatialite is v.4.0 (or higher) using the internal library
5395-
// method is highly recommended
53965367
if ( !gaiaDropTable( sqlite_handle, tableName.toUtf8().constData() ) )
53975368
{
53985369
// unexpected error
53995370
errCause = QObject::tr( "Unable to delete table %1\n" ).arg( tableName );
54005371
QgsSqliteHandle::closeDb( hndl );
54015372
return false;
54025373
}
5403-
#else
5404-
// drop the table
5405-
QString sql = QString( "DROP TABLE " ) + QgsSpatiaLiteProvider::quotedIdentifier( tableName );
5406-
QgsDebugMsg( sql );
5407-
char *errMsg = nullptr;
5408-
ret = sqlite3_exec( sqlite_handle, sql.toUtf8().constData(), nullptr, nullptr, &errMsg );
5409-
if ( ret != SQLITE_OK )
5410-
{
5411-
errCause = QObject::tr( "Unable to delete table %1:\n" ).arg( tableName );
5412-
errCause += QString::fromUtf8( errMsg );
5413-
sqlite3_free( errMsg );
5414-
QgsSqliteHandle::closeDb( hndl );
5415-
return false;
5416-
}
5417-
5418-
// remove table from geometry columns
5419-
sql = QString( "DELETE FROM geometry_columns WHERE upper(f_table_name) = upper(%1)" )
5420-
.arg( QgsSpatiaLiteProvider::quotedValue( tableName ) );
5421-
ret = sqlite3_exec( sqlite_handle, sql.toUtf8().constData(), nullptr, nullptr, nullptr );
5422-
if ( ret != SQLITE_OK )
5423-
{
5424-
QgsDebugMsg( "sqlite error: " + QString::fromUtf8( sqlite3_errmsg( sqlite_handle ) ) );
5425-
}
5426-
#endif
54275374

54285375
// TODO: remove spatial indexes?
54295376
// run VACUUM to free unused space and compact the database

src/providers/spatialite/qgsspatialiteprovider.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,14 +325,11 @@ class QgsSpatiaLiteProvider: public QgsVectorDataProvider
325325
bool getQueryGeometryDetails();
326326
bool getSridDetails();
327327
bool getTableSummary();
328-
#ifdef SPATIALITE_VERSION_GE_4_0_0
329-
// only if libspatialite version is >= 4.0.0
330328
bool checkLayerTypeAbstractInterface( gaiaVectorLayerPtr lyr );
331329
bool getGeometryDetailsAbstractInterface( gaiaVectorLayerPtr lyr );
332330
bool getTableSummaryAbstractInterface( gaiaVectorLayerPtr lyr );
333331
void loadFieldsAbstractInterface( gaiaVectorLayerPtr lyr );
334332
void getViewSpatialIndexName();
335-
#endif
336333
bool prepareStatement( sqlite3_stmt *&stmt,
337334
const QgsAttributeList &fetchAttributes,
338335
bool fetchGeometry,

0 commit comments

Comments
 (0)