Skip to content

Commit

Permalink
ogr provider: use utf8 also for SQL statements with GDAL 1.8
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@15354 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Mar 6, 2011
1 parent c2e9450 commit a7979d1
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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() );

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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 );
}
Expand All @@ -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 );
}
Expand All @@ -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
Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );

Expand Down

0 comments on commit a7979d1

Please sign in to comment.