@@ -723,15 +723,11 @@ bool QgsOgrProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
723
723
724
724
bool QgsOgrProvider::createSpatialIndex ()
725
725
{
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 ), " " );
730
729
// 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" ) );
735
731
if ( indexfile.exists () )
736
732
{
737
733
return true ;
@@ -753,11 +749,10 @@ bool QgsOgrProvider::deleteFeatures( const QgsFeatureIds & id )
753
749
}
754
750
}
755
751
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 );
761
756
featuresCounted = OGR_L_GetFeatureCount ( ogrLayer, TRUE ); // new feature count
762
757
return returnvalue;
763
758
}
@@ -1177,7 +1172,7 @@ QGISEXTERN bool createEmptyDataSource( const QString& uri,
1177
1172
}
1178
1173
1179
1174
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 );
1181
1176
if ( layer == NULL )
1182
1177
{
1183
1178
return false ;
@@ -1268,7 +1263,7 @@ void QgsOgrProvider::uniqueValues( int index, QList<QVariant> &uniqueValues )
1268
1263
1269
1264
QString sql = QString ( " SELECT DISTINCT %1 FROM %2 ORDER BY %1" )
1270
1265
.arg ( quotedIdentifier ( fld.name () ) )
1271
- .arg ( quotedIdentifier ( fi.baseName () ) );
1266
+ .arg ( quotedIdentifier ( fi.completeBaseName () ) );
1272
1267
1273
1268
uniqueValues.clear ();
1274
1269
@@ -1298,7 +1293,7 @@ QVariant QgsOgrProvider::minimumValue( int index )
1298
1293
1299
1294
QString sql = QString ( " SELECT MIN(%1) FROM %2" )
1300
1295
.arg ( quotedIdentifier ( fld.name () ) )
1301
- .arg ( quotedIdentifier ( fi.baseName () ) );
1296
+ .arg ( quotedIdentifier ( fi.completeBaseName () ) );
1302
1297
1303
1298
OGRLayerH l = OGR_DS_ExecuteSQL ( ogrDataSource, mEncoding ->fromUnicode ( sql ).data (), NULL , " SQL" );
1304
1299
@@ -1329,7 +1324,7 @@ QVariant QgsOgrProvider::maximumValue( int index )
1329
1324
1330
1325
QString sql = QString ( " SELECT MAX(%1) FROM %2" )
1331
1326
.arg ( quotedIdentifier ( fld.name () ) )
1332
- .arg ( quotedIdentifier ( fi.baseName () ) );
1327
+ .arg ( quotedIdentifier ( fi.completeBaseName () ) );
1333
1328
1334
1329
OGRLayerH l = OGR_DS_ExecuteSQL ( ogrDataSource, mEncoding ->fromUnicode ( sql ).data (), NULL , " SQL" );
1335
1330
if ( l == 0 )
0 commit comments