Currently Output columns are incorrectly handled while generating SELECT query for MySql after update via UPSERT operation.
Relevant code snippet:

Link to file:
|
selections.Add($"{structure.Values[index]} AS {quotedColName}"); |
Where is the bug?
As we can observe that in the attached code snippet, we are processing the output columns one by one. The IF block for line 293 is hit when we find a column which is present in the structure.InsertColumns. We add such a column to the final selections and increment the index:
selections.Add($"{structure.Values[index]} AS {quotedColName}");
index++;
What have we assumed here?
We have assumed that the order of columns in structure.InsertColumns is same as structure.OutputColumns. Well that is certainly not true as output columns can have columns other that insertColumns and even if the columns are same, the order can differ. So, we cannot just reference structure.Values[index] on line 293 and increment the index on line 294.. We need to be sure that this output column, which is also an insert column, corresponds to this parameter name at structure.Values[index] (structure.Values essentially stores parameter names for each of the insert columns).
Currently Output columns are incorrectly handled while generating SELECT query for MySql after update via UPSERT operation.

Relevant code snippet:
Link to file:
data-api-builder/src/Core/Resolvers/MySqlQueryBuilder.cs
Line 293 in 5e3874e
Where is the bug?
As we can observe that in the attached code snippet, we are processing the output columns one by one. The IF block for line 293 is hit when we find a column which is present in the
structure.InsertColumns. We add such a column to the finalselectionsand increment the index:selections.Add($"{structure.Values[index]} AS {quotedColName}");index++;What have we assumed here?
We have assumed that the order of columns in
structure.InsertColumnsis same asstructure.OutputColumns. Well that is certainly not true as output columns can have columns other that insertColumns and even if the columns are same, the order can differ. So, we cannot just referencestructure.Values[index]on line 293 and increment the index on line 294.. We need to be sure that this output column, which is also an insert column, corresponds to this parameter name atstructure.Values[index](structure.Values essentially stores parameter names for each of the insert columns).