I suppose this is a good example of not giving "definitive" replies when the code is not in front of you. What I had forgotten is that IBX does its own disambiguation of Firebird column aliasnames adding a numeric suffix to each duplicate aliasname. In the above example, Firebird gives both the fieldname and the aliasname as "CONCATENATION" for all columns derived from a concatenation. IBX adds the numeric suffix.
That in itself is not the problem. After investigation, I found that when the internal buffers are set up, IBX uses the (ambiguous) aliasname to link columns to dataset field names. Normally this is not a problem. However, the bug occurs because the fieldname is derived from the disambiguated aliasname provided by IBX, and comparing it using the (ambiguous) aliasname will always return the first instance.
The solution is to use the disambiguated aliasname rather than the Firebird provided aliasname for the comparison. It's a one line change and you can try it for yourself by editing runtime/nongui/IBBufferedCursors.pas and patching line 1722 as follows
- field := aFields.FindField(colMetadata.GetAliasName);
+ field := aFields.FindField(colMetadata.GetName);
I'll update the release soon, but it would be nice to get some early feedback before I bother the OPM admin for the second time in a week.
Otherwise, I would always recommend providing your own aliasnames (using the AS <name> syntax) when using aggregations or concatenations, etc, This is because the disambiguated aliasnames generated by IBX use a simple sequence no and a change of field order or adding your own alias to a field will change the sequence no for all subsequent fields. That is relying on generated aliasnames will give you a maintenance issue. They are only really suitable for ad hoc queries.