Skip to content

Commit 3b6f972

Browse files
author
mhugent
committedDec 13, 2008
Applied patch #1295 from smizuno. Thanks!
git-svn-id: http://svn.osgeo.org/qgis/trunk@9787 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent e787978 commit 3b6f972

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed
 

‎src/providers/ogr/qgsogrprovider.cpp

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -723,15 +723,11 @@ bool QgsOgrProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
723723

724724
bool QgsOgrProvider::createSpatialIndex()
725725
{
726-
QString fileName = dataSourceUri().section( '/', -1, -1 );//find out the file name from the uri
727-
QString layerName = fileName.section( '.', 0, 0 );
728-
QString sql = "CREATE SPATIAL INDEX ON " + layerName;
729-
OGR_DS_ExecuteSQL( ogrDataSource, sql.toAscii(), OGR_L_GetSpatialFilter( ogrLayer ), "" );
726+
QFileInfo fi( dataSourceUri() ); // to get the base name
727+
QString sql = QString( "CREATE SPATIAL INDEX ON %1" ).arg( quotedIdentifier( fi.completeBaseName() ) ); // quote the layer name so spaces are handled
728+
OGR_DS_ExecuteSQL( ogrDataSource, mEncoding->fromUnicode( sql ).data(), OGR_L_GetSpatialFilter( ogrLayer ), "" );
730729
//find out, if the .qix file is there
731-
QString indexname = dataSourceUri();
732-
indexname.truncate( dataSourceUri().length() - fileName.length() );
733-
indexname = indexname + layerName + ".qix";
734-
QFile indexfile( indexname );
730+
QFile indexfile( fi.path().append( "/").append( fi.completeBaseName() ).append( ".qix" ) );
735731
if ( indexfile.exists() )
736732
{
737733
return true;
@@ -753,11 +749,10 @@ bool QgsOgrProvider::deleteFeatures( const QgsFeatureIds & id )
753749
}
754750
}
755751

756-
OGR_L_SyncToDisk( ogrLayer );
757-
QString fileName = dataSourceUri().section( '/', -1, -1 );//find out the file name from the uri
758-
QString layerName = fileName.section( '.', 0, 0 );
759-
QString sql = "REPACK " + layerName;
760-
OGR_DS_ExecuteSQL( ogrDataSource, sql.toLocal8Bit().data(), NULL, NULL );
752+
OGR_L_SyncToDisk( ogrLayer );
753+
QFileInfo fi( dataSourceUri() ); // to get the base name
754+
QString sql = QString( "REPACK %1" ).arg( fi.completeBaseName() ); // don't quote the layer name as it works with spaces in the name and won't work if the name is quoted
755+
OGR_DS_ExecuteSQL( ogrDataSource, mEncoding->fromUnicode( sql ).data(), NULL, NULL );
761756
featuresCounted = OGR_L_GetFeatureCount( ogrLayer, TRUE ); //new feature count
762757
return returnvalue;
763758
}
@@ -1177,7 +1172,7 @@ QGISEXTERN bool createEmptyDataSource( const QString& uri,
11771172
}
11781173

11791174
OGRLayerH layer;
1180-
layer = OGR_DS_CreateLayer( dataSource, QFile::encodeName( QFileInfo( uri ).baseName() ).constData(), reference, OGRvectortype, NULL );
1175+
layer = OGR_DS_CreateLayer( dataSource, QFile::encodeName( QFileInfo( uri ).completeBaseName() ).constData(), reference, OGRvectortype, NULL );
11811176
if ( layer == NULL )
11821177
{
11831178
return false;
@@ -1268,7 +1263,7 @@ void QgsOgrProvider::uniqueValues( int index, QList<QVariant> &uniqueValues )
12681263

12691264
QString sql = QString( "SELECT DISTINCT %1 FROM %2 ORDER BY %1" )
12701265
.arg( quotedIdentifier( fld.name() ) )
1271-
.arg( quotedIdentifier( fi.baseName() ) );
1266+
.arg( quotedIdentifier( fi.completeBaseName() ) );
12721267

12731268
uniqueValues.clear();
12741269

@@ -1298,7 +1293,7 @@ QVariant QgsOgrProvider::minimumValue( int index )
12981293

12991294
QString sql = QString( "SELECT MIN(%1) FROM %2" )
13001295
.arg( quotedIdentifier( fld.name() ) )
1301-
.arg( quotedIdentifier( fi.baseName() ) );
1296+
.arg( quotedIdentifier( fi.completeBaseName() ) );
13021297

13031298
OGRLayerH l = OGR_DS_ExecuteSQL( ogrDataSource, mEncoding->fromUnicode( sql ).data(), NULL, "SQL" );
13041299

@@ -1329,7 +1324,7 @@ QVariant QgsOgrProvider::maximumValue( int index )
13291324

13301325
QString sql = QString( "SELECT MAX(%1) FROM %2" )
13311326
.arg( quotedIdentifier( fld.name() ) )
1332-
.arg( quotedIdentifier( fi.baseName() ) );
1327+
.arg( quotedIdentifier( fi.completeBaseName() ) );
13331328

13341329
OGRLayerH l = OGR_DS_ExecuteSQL( ogrDataSource, mEncoding->fromUnicode( sql ).data(), NULL, "SQL" );
13351330
if ( l == 0 )

0 commit comments

Comments
 (0)
Please sign in to comment.