<div dir="ltr"><div>Hi,</div><div><br></div><div>I'm not sure if bForwardWhereToSourceLayer should not be set in this case, since the special field FID in pszWHEREIn has already been replaced.</div><div>Or the OpenFileGDB driver should indeed expose OBJECTID as a column according to #4253</div><div><br></div><div>Best regards,</div><div><br></div><div>Tamas</div><div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr"> Even Rouault <<a href="mailto:even.rouault@spatialys.com">even.rouault@spatialys.com</a>> ezt írta (időpont: 2019. szept. 5., Cs, 13:13):<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On mercredi 4 septembre 2019 22:13:40 CEST Tamas Szekeres wrote:<br>
> Hi,<br>
> <br>
> It looks like  the sql queries with -dialect "OGRSQL" doesn't seem to work<br>
> as expected. When I specify the FID in the where clause, it doesn't filter<br>
> anything. The same query is also described as a solution in the following<br>
> ticket <a href="https://trac.osgeo.org/gdal/ticket/4253" rel="noreferrer" target="_blank">https://trac.osgeo.org/gdal/ticket/4253</a> but I doubt if that works at<br>
> all.<br>
> <br>
> The code causing this problem is fairly generic (ogr_gensql.cpp)<br>
> <br>
> if( psSelectInfo->where_expr && pszDialect != nullptr &&<br>
>             EQUAL(pszDialect, "OGRSQL") )<br>
>         {<br>
>             int nMinIndexForSpecialField =<br>
> poSrcLayer->GetLayerDefn()->GetFieldCount();<br>
>             bForwardWhereToSourceLayer =<br>
> !OGRGenSQLResultsLayerHasSpecialField<br>
>                             (psSelectInfo->where_expr,<br>
> nMinIndexForSpecialField);<br>
>         }<br>
>         if (bForwardWhereToSourceLayer)<br>
>             pszWHERE = CPLStrdup(pszWHEREIn);<br>
>         else<br>
>             pszWHERE = nullptr;<br>
> <br>
> In the "where" expression, the FID field is thanslated to OBJECTID and it<br>
> is now treated as a special field, therefore the "where" expression is not<br>
> being passed to the driver.<br>
> <br>
> I'm also unsure if that is a correct action to omit passing "where" to the<br>
> layer instead of providing an error message.<br>
<br>
Actually the where isn't completely discarded. It is set on the <br>
OGRGenSQLResultsLayer per<br>
<br>
    if( !bForwardWhereToSourceLayer )<br>
        OGRGenSQLResultsLayer::SetAttributeFilter( pszWHEREIn );<br>
<br>
around line 492<br>
<br>
The issue is that the GenSQL layer has no FID column set, and thus this filter <br>
fails. One could potentially set the FID Column name on it from the source <br>
layer, but that wouldn't be really appropriate in the case of JOIN. That said <br>
I see a poDstFeat->SetFID( poSrcFeat->GetFID() ); at line 1332 of <br>
TranslateFeature(), so...<br>
<br>
(there might have been other fixes since #4253 that have made this case <br>
broken)<br>
<br>
-- <br>
Spatialys - Geospatial professional services<br>
<a href="http://www.spatialys.com" rel="noreferrer" target="_blank">http://www.spatialys.com</a><br>
</blockquote></div></div>