Skip to content
Permalink
Browse files

[OGR] Use a ORIG_OGC_FID constant instead of hard-coding orig_ogc_fid

  • Loading branch information
manisandro committed Sep 25, 2017
1 parent d02cca9 commit 758ae63dcd10ba4b6962fd9bef9bfdce59f8d4cb
Showing with 6 additions and 4 deletions.
  1. +6 −4 src/providers/ogr/qgsogrprovider.cpp
@@ -95,6 +95,8 @@ class QgsCPLErrorHandler
}
};
static const QByteArray ORIG_OGC_FID = "orig_ogc_fid";
bool QgsOgrProvider::convertField( QgsField &field, const QTextCodec &encoding )
{
@@ -1031,7 +1033,7 @@ void QgsOgrProviderUtils::setRelevantFields( OGRLayerH ogrLayer, int fieldCount,
{
// add to ignored fields
const char *fieldName = OGR_Fld_GetNameRef( OGR_FD_GetFieldDefn( featDefn, firstAttrIsFid ? i - 1 : i ) );
if ( qstrcmp( fieldName, "orig_ogc_fid" ) != 0 )
if ( qstrcmp( fieldName, ORIG_OGC_FID ) != 0 )
{
ignoredFields.append( fieldName );
}
@@ -3470,15 +3472,15 @@ OGRLayerH QgsOgrProviderUtils::setSubsetString( OGRLayerH layer, OGRDataSourceH
fidColumn = "FID";
}

QByteArray sql = sqlPart1 + ", " + fidColumn + " as orig_ogc_fid" + sqlPart3;
QByteArray sql = sqlPart1 + ", " + fidColumn + " as " + ORIG_OGC_FID + sqlPart3;
QgsDebugMsg( QString( "SQL: %1" ).arg( encoding->toUnicode( sql ) ) );
subsetLayer = GDALDatasetExecuteSQL( ds, sql.constData(), nullptr, nullptr );

// See https://lists.osgeo.org/pipermail/qgis-developer/2017-September/049802.html
// If execute SQL fails because it did not find the fidColumn, retry with hardcoded FID
if ( !subsetLayer )
{
QByteArray sql = sqlPart1 + ", " + "FID as orig_ogc_fid" + sqlPart3;
QByteArray sql = sqlPart1 + ", " + "FID as " + ORIG_OGC_FID + sqlPart3;
QgsDebugMsg( QString( "SQL: %1" ).arg( encoding->toUnicode( sql ) ) );
subsetLayer = GDALDatasetExecuteSQL( ds, sql.constData(), nullptr, nullptr );
}
@@ -3500,7 +3502,7 @@ OGRLayerH QgsOgrProviderUtils::setSubsetString( OGRLayerH layer, OGRDataSourceH
if ( fieldCount > 0 )
{
OGRFieldDefnH fldDef = OGR_FD_GetFieldDefn( fdef, fieldCount - 1 );
origFidAdded = qstrcmp( OGR_Fld_GetNameRef( fldDef ), "orig_ogc_fid" ) == 0;
origFidAdded = qstrcmp( OGR_Fld_GetNameRef( fldDef ), ORIG_OGC_FID ) == 0;
}
}

0 comments on commit 758ae63

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