patch_for1295.txt

patch for #1295 / #1244 - Steven Mizuno, 2008-10-08 07:20 PM

Download (3.5 KB)

 
1
Index: src/providers/ogr/qgsogrprovider.cpp
2
===================================================================
3
--- src/providers/ogr/qgsogrprovider.cpp	(revision 9462)
4
+++ src/providers/ogr/qgsogrprovider.cpp	(working copy)
5
@@ -720,15 +720,11 @@
6
 
7
 bool QgsOgrProvider::createSpatialIndex()
8
 {
9
-  QString fileName = dataSourceUri().section( '/', -1, -1 );//find out the file name from the uri
10
-  QString layerName = fileName.section( '.', 0, 0 );
11
-  QString sql = "CREATE SPATIAL INDEX ON " + layerName;
12
-  OGR_DS_ExecuteSQL( ogrDataSource, sql.toAscii(), OGR_L_GetSpatialFilter( ogrLayer ), "" );
13
+  QFileInfo fi( dataSourceUri() );	// to get the base name
14
+  QString sql = QString( "CREATE SPATIAL INDEX ON %1" ).arg( quotedIdentifier( fi.completeBaseName() ) );	// quote the layer name so spaces are handled
15
+  OGR_DS_ExecuteSQL( ogrDataSource, mEncoding->fromUnicode( sql ).data(), OGR_L_GetSpatialFilter( ogrLayer ), "" );
16
   //find out, if the .qix file is there
17
-  QString indexname = dataSourceUri();
18
-  indexname.truncate( dataSourceUri().length() - fileName.length() );
19
-  indexname = indexname + layerName + ".qix";
20
-  QFile indexfile( indexname );
21
+  QFile indexfile( fi.path().append( "/").append( fi.completeBaseName() ).append( ".qix" ) );
22
   if ( indexfile.exists() )
23
   {
24
     return true;
25
@@ -751,10 +747,9 @@
26
   }
27
 
28
   OGR_L_SyncToDisk( ogrLayer );
29
-  QString fileName = dataSourceUri().section( '/', -1, -1 );//find out the file name from the uri
30
-  QString layerName = fileName.section( '.', 0, 0 );
31
-  QString sql = "REPACK " + layerName;
32
-  OGR_DS_ExecuteSQL( ogrDataSource, sql.toLocal8Bit().data(), NULL, NULL );
33
+  QFileInfo fi( dataSourceUri() );	// to get the base name
34
+  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 
35
+  OGR_DS_ExecuteSQL( ogrDataSource, mEncoding->fromUnicode( sql ).data(), NULL, NULL );
36
   numberFeatures = OGR_L_GetFeatureCount( ogrLayer, TRUE ); //new feature count
37
   return returnvalue;
38
 }
39
@@ -1174,7 +1169,7 @@
40
   }
41
 
42
   OGRLayerH layer;
43
-  layer = OGR_DS_CreateLayer( dataSource, QFile::encodeName( QFileInfo( uri ).baseName() ).constData(), reference, OGRvectortype, NULL );
44
+  layer = OGR_DS_CreateLayer( dataSource, QFile::encodeName( QFileInfo( uri ).completeBaseName() ).constData(), reference, OGRvectortype, NULL );
45
   if ( layer == NULL )
46
   {
47
     return false;
48
@@ -1265,7 +1260,7 @@
49
 
50
   QString sql = QString( "SELECT DISTINCT %1 FROM %2 ORDER BY %1" )
51
                 .arg( quotedIdentifier( fld.name() ) )
52
-                .arg( quotedIdentifier( fi.baseName() ) );
53
+                .arg( quotedIdentifier( fi.completeBaseName() ) );
54
 
55
   uniqueValues.clear();
56
 
57
@@ -1295,7 +1290,7 @@
58
 
59
   QString sql = QString( "SELECT MIN(%1) FROM %2" )
60
                 .arg( quotedIdentifier( fld.name() ) )
61
-                .arg( quotedIdentifier( fi.baseName() ) );
62
+                .arg( quotedIdentifier( fi.completeBaseName() ) );
63
 
64
   OGRLayerH l = OGR_DS_ExecuteSQL( ogrDataSource, mEncoding->fromUnicode( sql ).data(), NULL, "SQL" );
65
 
66
@@ -1326,7 +1321,7 @@
67
 
68
   QString sql = QString( "SELECT MAX(%1) FROM %2" )
69
                 .arg( quotedIdentifier( fld.name() ) )
70
-                .arg( quotedIdentifier( fi.baseName() ) );
71
+                .arg( quotedIdentifier( fi.completeBaseName() ) );
72
 
73
   OGRLayerH l = OGR_DS_ExecuteSQL( ogrDataSource, mEncoding->fromUnicode( sql ).data(), NULL, "SQL" );
74
   if ( l == 0 )