Skip to content
Permalink
Browse files

ogr provider: use utf8 also for SQL statements with GDAL 1.8

git-svn-id: http://svn.osgeo.org/qgis/trunk@15354 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef
jef committed Mar 6, 2011
1 parent c2e9450 commit a7979d143b5e69243b445ef915d57ed93906d891
Showing with 13 additions and 13 deletions.
  1. +13 −13 src/providers/ogr/qgsogrprovider.cpp
@@ -246,7 +246,7 @@ bool QgsOgrProvider::setSubsetString( QString theSQL, bool updateFeatureCount )
.arg( quotedIdentifier( OGR_FD_GetName( OGR_L_GetLayerDefn( ogrOrigLayer ) ) ) )
.arg( mSubsetString );
QgsDebugMsg( QString( "SQL: %1" ).arg( sql ) );
ogrLayer = OGR_DS_ExecuteSQL( ogrDataSource, mEncoding->fromUnicode( sql ).constData(), NULL, NULL );
ogrLayer = OGR_DS_ExecuteSQL( ogrDataSource, TO8( sql ), NULL, NULL );

if ( !ogrLayer )
{
@@ -921,7 +921,7 @@ bool QgsOgrProvider::addAttributes( const QList<QgsField> &attributes )
continue;
}

OGRFieldDefnH fielddefn = OGR_Fld_Create( mEncoding->fromUnicode( iter->name() ).data(), type );
OGRFieldDefnH fielddefn = OGR_Fld_Create( TO8( iter->name() ), type );
OGR_Fld_SetWidth( fielddefn, iter->length() );
OGR_Fld_SetPrecision( fielddefn, iter->precision() );

@@ -1074,7 +1074,7 @@ bool QgsOgrProvider::createSpatialIndex()

QString sql = QString( "CREATE SPATIAL INDEX ON %1" ).arg( quotedIdentifier( layerName ) ); // quote the layer name so spaces are handled
QgsDebugMsg( QString( "SQL: %1" ).arg( sql ) );
OGR_DS_ExecuteSQL( ogrDataSource, mEncoding->fromUnicode( sql ).data(), OGR_L_GetSpatialFilter( ogrOrigLayer ), "" );
OGR_DS_ExecuteSQL( ogrDataSource, TO8( sql ), OGR_L_GetSpatialFilter( ogrOrigLayer ), "" );

QFileInfo fi( mFilePath ); // to get the base name
//find out, if the .qix file is there
@@ -1087,8 +1087,8 @@ bool QgsOgrProvider::createAttributeIndex( int field )
QString layerName = OGR_FD_GetName( OGR_L_GetLayerDefn( ogrOrigLayer ) );
QString dropSql = QString( "DROP INDEX ON %1" ).arg( quotedIdentifier( layerName ) );
QString createSql = QString( "CREATE INDEX ON %1 USING %2" ).arg( quotedIdentifier( layerName ) ).arg( fields()[field].name() );
OGR_DS_ExecuteSQL( ogrDataSource, mEncoding->fromUnicode( dropSql ).data(), OGR_L_GetSpatialFilter( ogrOrigLayer ), "SQL" );
OGR_DS_ExecuteSQL( ogrDataSource, mEncoding->fromUnicode( createSql ).data(), OGR_L_GetSpatialFilter( ogrOrigLayer ), "SQL" );
OGR_DS_ExecuteSQL( ogrDataSource, TO8( dropSql ), OGR_L_GetSpatialFilter( ogrOrigLayer ), "SQL" );
OGR_DS_ExecuteSQL( ogrDataSource, TO8( createSql ), OGR_L_GetSpatialFilter( ogrOrigLayer ), "SQL" );

QFileInfo fi( mFilePath ); // to get the base name
//find out, if the .idm file is there
@@ -1118,7 +1118,7 @@ bool QgsOgrProvider::deleteFeatures( const QgsFeatureIds & id )

QString sql = QString( "REPACK %1" ).arg( layerName ); // don't quote the layer name as it works with spaces in the name and won't work if the name is quoted
QgsDebugMsg( QString( "SQL: %1" ).arg( sql ) );
OGR_DS_ExecuteSQL( ogrDataSource, mEncoding->fromUnicode( sql ).data(), NULL, NULL );
OGR_DS_ExecuteSQL( ogrDataSource, TO8( sql ), NULL, NULL );

recalculateFeatureCount();

@@ -1747,7 +1747,7 @@ QGISEXTERN bool createEmptyDataSource( const QString &uri,
if ( precision < 0 )
precision = 3;

field = OGR_Fld_Create( codec->fromUnicode( it->first ).data(), OFTReal );
field = OGR_Fld_Create( TO8( it->first ), OFTReal );
OGR_Fld_SetWidth( field, width );
OGR_Fld_SetPrecision( field, precision );
}
@@ -1756,7 +1756,7 @@ QGISEXTERN bool createEmptyDataSource( const QString &uri,
if ( width < 0 || width > 10 )
width = 10;

field = OGR_Fld_Create( codec->fromUnicode( it->first ).data(), OFTInteger );
field = OGR_Fld_Create( TO8( it->first ), OFTInteger );
// limit to 10. otherwise OGR sets it to 11 and recognizes as OFTDouble later
OGR_Fld_SetWidth( field, width );
}
@@ -1765,7 +1765,7 @@ QGISEXTERN bool createEmptyDataSource( const QString &uri,
if ( width < 0 || width > 255 )
width = 255;

field = OGR_Fld_Create( codec->fromUnicode( it->first ).data(), OFTString );
field = OGR_Fld_Create( TO8( it->first ), OFTString );
OGR_Fld_SetWidth( field, width );
}
else
@@ -1880,10 +1880,10 @@ void QgsOgrProvider::uniqueValues( int index, QList<QVariant> &uniqueValues, int
sql += QString( " WHERE %1" ).arg( mSubsetString );
}

sql += QString( " ORDER BY %1" ).arg( fld.name() );
sql += QString( " ORDER BY %1" ).arg( quotedIdentifier( fld.name() ) );

QgsDebugMsg( QString( "SQL: %1" ).arg( sql ) );
OGRLayerH l = OGR_DS_ExecuteSQL( ogrDataSource, mEncoding->fromUnicode( sql ).data(), NULL, "SQL" );
OGRLayerH l = OGR_DS_ExecuteSQL( ogrDataSource, TO8( sql ), NULL, "SQL" );
if ( l == 0 )
return QgsVectorDataProvider::uniqueValues( index, uniqueValues, limit );

@@ -1914,7 +1914,7 @@ QVariant QgsOgrProvider::minimumValue( int index )
sql += QString( " WHERE %1" ).arg( mSubsetString );
}

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

if ( l == 0 )
return QgsVectorDataProvider::minimumValue( index );
@@ -1948,7 +1948,7 @@ QVariant QgsOgrProvider::maximumValue( int index )
sql += QString( " WHERE %1" ).arg( mSubsetString );
}

OGRLayerH l = OGR_DS_ExecuteSQL( ogrDataSource, mEncoding->fromUnicode( sql ).data(), NULL, "SQL" );
OGRLayerH l = OGR_DS_ExecuteSQL( ogrDataSource, TO8( sql ), NULL, "SQL" );
if ( l == 0 )
return QgsVectorDataProvider::maximumValue( index );

0 comments on commit a7979d1

Please sign in to comment.
You can’t perform that action at this time.