205 changes: 103 additions & 102 deletions src/providers/spatialite/qgsspatialiteprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,22 +443,22 @@ QgsSpatiaLiteProvider::QgsSpatiaLiteProvider( QString const &uri )
gaiaVectorLayerPtr lyr = NULL;
bool specialCase = false;
if ( mGeometryColumn.isNull() )
specialCase = true; // non-spatial table
specialCase = true; // non-spatial table
if ( mQuery.startsWith( "(" ) && mQuery.endsWith( ")" ) )
specialCase = true;
specialCase = true;

if ( specialCase == false )
{
// using v.4.0 Abstract Interface
ret = true;
list = gaiaGetVectorLayersList ( handle->handle(),
mTableName.toUtf8().constData(),
mGeometryColumn.toUtf8().constData(),
GAIA_VECTORS_LIST_OPTIMISTIC);
list = gaiaGetVectorLayersList( handle->handle(),
mTableName.toUtf8().constData(),
mGeometryColumn.toUtf8().constData(),
GAIA_VECTORS_LIST_OPTIMISTIC );
if ( list != NULL )
lyr = list->First;
lyr = list->First;
if ( lyr == NULL )
ret = false;
ret = false;
else
{
ret = checkLayerTypeAbstractInterface( lyr );
Expand Down Expand Up @@ -501,53 +501,54 @@ QgsSpatiaLiteProvider::QgsSpatiaLiteProvider( QString const &uri )
if ( lyr != NULL )
{
// using the v.4.0 AbstractInterface
if ( !getGeometryDetailsAbstractInterface( lyr ) ) // gets srid and geometry type
{
// the table is not a geometry table
numberFeatures = 0;
valid = false;
QgsDebugMsg( "Invalid SpatiaLite layer" );
closeDb();
gaiaFreeVectorLayersList ( list );
return;
}
if ( !getTableSummaryAbstractInterface( lyr ) ) // gets the extent and feature count
{
numberFeatures = 0;
valid = false;
QgsDebugMsg( "Invalid SpatiaLite layer" );
closeDb();
gaiaFreeVectorLayersList ( list );
return;
}
// load the columns list
loadFieldsAbstractInterface( lyr );
gaiaFreeVectorLayersList ( list );
alreadyDone = true;
if ( !getGeometryDetailsAbstractInterface( lyr ) ) // gets srid and geometry type
{
// the table is not a geometry table
numberFeatures = 0;
valid = false;
QgsDebugMsg( "Invalid SpatiaLite layer" );
closeDb();
gaiaFreeVectorLayersList( list );
return;
}
if ( !getTableSummaryAbstractInterface( lyr ) ) // gets the extent and feature count
{
numberFeatures = 0;
valid = false;
QgsDebugMsg( "Invalid SpatiaLite layer" );
closeDb();
gaiaFreeVectorLayersList( list );
return;
}
// load the columns list
loadFieldsAbstractInterface( lyr );
gaiaFreeVectorLayersList( list );
alreadyDone = true;
}
#endif

if ( alreadyDone == false ) {
if ( alreadyDone == false )
{
// using the traditional methods
if ( !getGeometryDetails() ) // gets srid and geometry type
{
// the table is not a geometry table
numberFeatures = 0;
valid = false;
QgsDebugMsg( "Invalid SpatiaLite layer" );
closeDb();
return;
}
if ( !getTableSummary() ) // gets the extent and feature count
{
numberFeatures = 0;
valid = false;
QgsDebugMsg( "Invalid SpatiaLite layer" );
closeDb();
return;
}
// load the columns list
loadFields();
if ( !getGeometryDetails() ) // gets srid and geometry type
{
// the table is not a geometry table
numberFeatures = 0;
valid = false;
QgsDebugMsg( "Invalid SpatiaLite layer" );
closeDb();
return;
}
if ( !getTableSummary() ) // gets the extent and feature count
{
numberFeatures = 0;
valid = false;
QgsDebugMsg( "Invalid SpatiaLite layer" );
closeDb();
return;
}
// load the columns list
loadFields();
}
if ( sqliteHandle == NULL )
{
Expand Down Expand Up @@ -580,7 +581,7 @@ void QgsSpatiaLiteProvider::loadFieldsAbstractInterface( gaiaVectorLayerPtr lyr
}

attributeFields.clear();
mPrimaryKey.clear(); // cazzo cazzo cazzo
mPrimaryKey.clear(); // cazzo cazzo cazzo

gaiaLayerAttributeFieldPtr fld = lyr->First;
if ( fld == NULL )
Expand All @@ -597,7 +598,7 @@ void QgsSpatiaLiteProvider::loadFieldsAbstractInterface( gaiaVectorLayerPtr lyr
if ( name != mGeometryColumn )
{
const char *type = "TEXT";
QVariant::Type fieldType = QVariant::String; // default: SQLITE_TEXT
QVariant::Type fieldType = QVariant::String; // default: SQLITE_TEXT
if ( fld->IntegerValuesCount != 0 && fld->DoubleValuesCount == 0 &&
fld->TextValuesCount == 0 && fld->BlobValuesCount == 0 )
{
Expand Down Expand Up @@ -4362,7 +4363,7 @@ QString QgsSpatiaLiteProvider::quotedValue( QString value )
}

#ifdef SPATIALITE_RECENT_VERSION
// only if libspatialite version is >= 4.0.0
// only if libspatialite version is >= 4.0.0
bool QgsSpatiaLiteProvider::checkLayerTypeAbstractInterface( gaiaVectorLayerPtr lyr )
{
if ( lyr == NULL )
Expand All @@ -4379,24 +4380,24 @@ bool QgsSpatiaLiteProvider::checkLayerTypeAbstractInterface( gaiaVectorLayerPtr
switch ( lyr->LayerType )
{
case GAIA_VECTOR_TABLE:
mTableBased = true;
break;
mTableBased = true;
break;
case GAIA_VECTOR_VIEW:
mViewBased = true;
break;
mViewBased = true;
break;
case GAIA_VECTOR_VIRTUAL:
mVShapeBased = true;
break;
mVShapeBased = true;
break;
};

if ( lyr->AuthInfos )
{
if ( lyr->AuthInfos->IsReadOnly )
mReadOnly = true;
mReadOnly = true;
}
else if ( mViewBased == true)
else if ( mViewBased == true )
{
mReadOnly = !hasTriggers();
mReadOnly = !hasTriggers();
}

if ( !isQuery )
Expand Down Expand Up @@ -4589,7 +4590,7 @@ bool QgsSpatiaLiteProvider::checkLayerType()
}

#ifdef SPATIALITE_RECENT_VERSION
// only if libspatialite version is >= 4.0.0
// only if libspatialite version is >= 4.0.0
bool QgsSpatiaLiteProvider::getGeometryDetailsAbstractInterface( gaiaVectorLayerPtr lyr )
{
if ( lyr == NULL )
Expand All @@ -4600,29 +4601,29 @@ bool QgsSpatiaLiteProvider::getGeometryDetailsAbstractInterface( gaiaVectorLayer
mIndexTable = mTableName;
mIndexGeometry = mGeometryColumn;

switch (lyr->GeometryType)
switch ( lyr->GeometryType )
{
case GAIA_VECTOR_POINT:
geomType = QGis::WKBPoint;
break;
geomType = QGis::WKBPoint;
break;
case GAIA_VECTOR_LINESTRING:
geomType = QGis::WKBLineString;
break;
geomType = QGis::WKBLineString;
break;
case GAIA_VECTOR_POLYGON:
geomType = QGis::WKBPolygon;
break;
geomType = QGis::WKBPolygon;
break;
case GAIA_VECTOR_MULTIPOINT:
geomType = QGis::WKBMultiPoint;
break;
geomType = QGis::WKBMultiPoint;
break;
case GAIA_VECTOR_MULTILINESTRING:
geomType = QGis::WKBMultiLineString;
break;
geomType = QGis::WKBMultiLineString;
break;
case GAIA_VECTOR_MULTIPOLYGON:
geomType = QGis::WKBMultiPolygon;
break;
geomType = QGis::WKBMultiPolygon;
break;
default:
geomType = QGis::WKBUnknown;
break;
geomType = QGis::WKBUnknown;
break;
};
mSrid = lyr->Srid;
if ( lyr->SpatialIndex == GAIA_SPATIAL_INDEX_RTREE )
Expand All @@ -4636,17 +4637,17 @@ bool QgsSpatiaLiteProvider::getGeometryDetailsAbstractInterface( gaiaVectorLayer
switch ( lyr->Dimensions )
{
case GAIA_XY:
nDims = GAIA_XY;
break;
nDims = GAIA_XY;
break;
case GAIA_XY_Z:
nDims = GAIA_XY_Z;
break;
nDims = GAIA_XY_Z;
break;
case GAIA_XY_M:
nDims = GAIA_XY_M;
break;
nDims = GAIA_XY_M;
break;
case GAIA_XY_Z_M:
nDims = GAIA_XY_Z_M;
break;
nDims = GAIA_XY_Z_M;
break;
};

if ( mViewBased && spatialIndexRTree )
Expand Down Expand Up @@ -5125,7 +5126,7 @@ bool QgsSpatiaLiteProvider::getSridDetails()
}

#ifdef SPATIALITE_RECENT_VERSION
// only if libspatialite version is >= 4.0.0
// only if libspatialite version is >= 4.0.0
bool QgsSpatiaLiteProvider::getTableSummaryAbstractInterface( gaiaVectorLayerPtr lyr )
{
if ( lyr == NULL )
Expand Down Expand Up @@ -5367,21 +5368,21 @@ QGISEXTERN bool deleteLayer( const QString& dbPath, const QString& tableName, QS
{
// if libspatialite is v.4.0 (or higher) using the internal library
// method is highly recommended
if ( !gaiaDropTable( sqlite_handle, tableName.toUtf8().constData() ) )
{
// unexpected error
errCause = QObject::tr( "Unable to delete table %1\n" ).arg( tableName );
QgsSpatiaLiteProvider::SqliteHandles::closeDb( hndl );
return false;
}
// run VACUUM to free unused space and compact the database
int ret = sqlite3_exec( sqlite_handle, "VACUUM", NULL, NULL, NULL );
if ( ret != SQLITE_OK )
{
QgsDebugMsg( "Failed to run VACUUM after deleting table on database " + dbPath );
}
if ( !gaiaDropTable( sqlite_handle, tableName.toUtf8().constData() ) )
{
// unexpected error
errCause = QObject::tr( "Unable to delete table %1\n" ).arg( tableName );
QgsSpatiaLiteProvider::SqliteHandles::closeDb( hndl );
return true;
return false;
}
// run VACUUM to free unused space and compact the database
int ret = sqlite3_exec( sqlite_handle, "VACUUM", NULL, NULL, NULL );
if ( ret != SQLITE_OK )
{
QgsDebugMsg( "Failed to run VACUUM after deleting table on database " + dbPath );
}
QgsSpatiaLiteProvider::SqliteHandles::closeDb( hndl );
return true;
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/providers/spatialite/qgsspatialiteprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ class QgsSpatiaLiteProvider: public QgsVectorDataProvider
bool getSridDetails();
bool getTableSummary();
#ifdef SPATIALITE_RECENT_VERSION
// only if libspatialite version is >= 4.0.0
// only if libspatialite version is >= 4.0.0
bool checkLayerTypeAbstractInterface( gaiaVectorLayerPtr lyr );
bool getGeometryDetailsAbstractInterface( gaiaVectorLayerPtr lyr );
bool getTableSummaryAbstractInterface( gaiaVectorLayerPtr lyr );
Expand Down
8 changes: 4 additions & 4 deletions src/providers/spatialite/qgsspatialitesourceselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ void QgsSpatiaLiteSourceSelect::updateStatistics()
if ( idx > 0 )
subKey.truncate( idx );

QString msg = tr( "Do you confirm updating the Internal Statistics for DB: %1 ?\n\n"
QString msg = tr( "Are you sure you want to update the internal statistics for DB: %1?\n\n"
"This could take a long time (depending on the DB size),\n"
"but implies better performances in the afterwhile" ).arg( subKey );
"but implies better performance thereafter." ).arg( subKey );
QMessageBox::StandardButton result =
QMessageBox::information( this, tr( "Confirm Update Statistics" ), msg, QMessageBox::Ok | QMessageBox::Cancel );
if ( result != QMessageBox::Ok )
Expand All @@ -157,12 +157,12 @@ void QgsSpatiaLiteSourceSelect::updateStatistics()
if ( conn.updateStatistics() == true )
{
QMessageBox::information( this, tr( "Update Statistics" ),
tr( "Internal Statistics succesfully updated for: %1" ).arg( subKey ) );
tr( "Internal statistics successfully updated for: %1" ).arg( subKey ) );
}
else
{
QMessageBox::critical( this, tr( "Update Statistics" ),
tr( "Error while updating Internal Statistics for: %1" ).arg( subKey ) );
tr( "Error while updating internal statistics for: %1" ).arg( subKey ) );
}
}

Expand Down