Index: src/providers/ogr/qgsogrprovider.cpp =================================================================== --- src/providers/ogr/qgsogrprovider.cpp (revision 9462) +++ src/providers/ogr/qgsogrprovider.cpp (working copy) @@ -720,15 +720,11 @@ bool QgsOgrProvider::createSpatialIndex() { - QString fileName = dataSourceUri().section( '/', -1, -1 );//find out the file name from the uri - QString layerName = fileName.section( '.', 0, 0 ); - QString sql = "CREATE SPATIAL INDEX ON " + layerName; - OGR_DS_ExecuteSQL( ogrDataSource, sql.toAscii(), OGR_L_GetSpatialFilter( ogrLayer ), "" ); + QFileInfo fi( dataSourceUri() ); // to get the base name + QString sql = QString( "CREATE SPATIAL INDEX ON %1" ).arg( quotedIdentifier( fi.completeBaseName() ) ); // quote the layer name so spaces are handled + OGR_DS_ExecuteSQL( ogrDataSource, mEncoding->fromUnicode( sql ).data(), OGR_L_GetSpatialFilter( ogrLayer ), "" ); //find out, if the .qix file is there - QString indexname = dataSourceUri(); - indexname.truncate( dataSourceUri().length() - fileName.length() ); - indexname = indexname + layerName + ".qix"; - QFile indexfile( indexname ); + QFile indexfile( fi.path().append( "/").append( fi.completeBaseName() ).append( ".qix" ) ); if ( indexfile.exists() ) { return true; @@ -751,10 +747,9 @@ } OGR_L_SyncToDisk( ogrLayer ); - QString fileName = dataSourceUri().section( '/', -1, -1 );//find out the file name from the uri - QString layerName = fileName.section( '.', 0, 0 ); - QString sql = "REPACK " + layerName; - OGR_DS_ExecuteSQL( ogrDataSource, sql.toLocal8Bit().data(), NULL, NULL ); + QFileInfo fi( dataSourceUri() ); // to get the base name + 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 + OGR_DS_ExecuteSQL( ogrDataSource, mEncoding->fromUnicode( sql ).data(), NULL, NULL ); numberFeatures = OGR_L_GetFeatureCount( ogrLayer, TRUE ); //new feature count return returnvalue; } @@ -1174,7 +1169,7 @@ } OGRLayerH layer; - layer = OGR_DS_CreateLayer( dataSource, QFile::encodeName( QFileInfo( uri ).baseName() ).constData(), reference, OGRvectortype, NULL ); + layer = OGR_DS_CreateLayer( dataSource, QFile::encodeName( QFileInfo( uri ).completeBaseName() ).constData(), reference, OGRvectortype, NULL ); if ( layer == NULL ) { return false; @@ -1265,7 +1260,7 @@ QString sql = QString( "SELECT DISTINCT %1 FROM %2 ORDER BY %1" ) .arg( quotedIdentifier( fld.name() ) ) - .arg( quotedIdentifier( fi.baseName() ) ); + .arg( quotedIdentifier( fi.completeBaseName() ) ); uniqueValues.clear(); @@ -1295,7 +1290,7 @@ QString sql = QString( "SELECT MIN(%1) FROM %2" ) .arg( quotedIdentifier( fld.name() ) ) - .arg( quotedIdentifier( fi.baseName() ) ); + .arg( quotedIdentifier( fi.completeBaseName() ) ); OGRLayerH l = OGR_DS_ExecuteSQL( ogrDataSource, mEncoding->fromUnicode( sql ).data(), NULL, "SQL" ); @@ -1326,7 +1321,7 @@ QString sql = QString( "SELECT MAX(%1) FROM %2" ) .arg( quotedIdentifier( fld.name() ) ) - .arg( quotedIdentifier( fi.baseName() ) ); + .arg( quotedIdentifier( fi.completeBaseName() ) ); OGRLayerH l = OGR_DS_ExecuteSQL( ogrDataSource, mEncoding->fromUnicode( sql ).data(), NULL, "SQL" ); if ( l == 0 )