Skip to content
Permalink
Browse files
ogr provider update: better support column names containing internati…
…onal characters

git-svn-id: http://svn.osgeo.org/qgis/trunk@9415 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Sep 26, 2008
1 parent d9f3afa commit c23a4d989223c29c38e0c5d2151169f52d933d4b
Showing with 23 additions and 6 deletions.
  1. +21 −6 src/providers/ogr/qgsogrprovider.cpp
  2. +2 −0 src/providers/ogr/qgsogrprovider.h
@@ -1263,11 +1263,14 @@ void QgsOgrProvider::uniqueValues( int index, QList<QVariant> &uniqueValues )
if ( !fi.exists() )
return;

QString sql = QString( "SELECT DISTINCT %1 FROM %2 ORDER BY %1" ).arg( fld.name() ).arg( fi.baseName() );
QString sql = QString( "SELECT DISTINCT %1 FROM %2 ORDER BY %1" )
.arg( quotedIdentifier( fld.name() ) )
.arg( quotedIdentifier( fi.baseName() ) );

uniqueValues.clear();

OGRLayerH lyr = OGR_DS_ExecuteSQL( ogrDataSource, sql.toAscii(), NULL, "SQL" );
QgsDebugMsg( QString( "SQL: %1" ).arg( sql ) );
OGRLayerH lyr = OGR_DS_ExecuteSQL( ogrDataSource, mEncoding->fromUnicode( sql ).data(), NULL, "SQL" );
if ( 0 == lyr )
return;

@@ -1290,9 +1293,11 @@ QVariant QgsOgrProvider::minimumValue( int index )
if ( !fi.exists() )
return QVariant();

QString sql = QString( "SELECT MIN(%1) FROM %2" ).arg( fld.name() ).arg( fi.baseName() );
QString sql = QString( "SELECT MIN(%1) FROM %2" )
.arg( quotedIdentifier( fld.name() ) )
.arg( quotedIdentifier( fi.baseName() ) );

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

if ( l == 0 )
return QVariant();
@@ -1319,9 +1324,11 @@ QVariant QgsOgrProvider::maximumValue( int index )
if ( !fi.exists() )
return QVariant();

QString sql = QString( "SELECT MAX(%1) FROM %2" ).arg( fld.name() ).arg( fi.baseName() );
QString sql = QString( "SELECT MAX(%1) FROM %2" )
.arg( quotedIdentifier( fld.name() ) )
.arg( quotedIdentifier( fi.baseName() ) );

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

@@ -1339,3 +1346,11 @@ QVariant QgsOgrProvider::maximumValue( int index )

return value;
}

QString QgsOgrProvider::quotedIdentifier( QString field )
{
field.replace( '\\', "\\\\" );
field.replace( '"', "\\\"" );
field.replace( "'", "\\'" );
return field.prepend( "\"" ).append( "\"" );
}
@@ -251,4 +251,6 @@ class QgsOgrProvider : public QgsVectorDataProvider
bool addFeature( QgsFeature& f );
/**Deletes one feature*/
bool deleteFeature( int id );

QString quotedIdentifier( QString field );
};

0 comments on commit c23a4d9

Please sign in to comment.