I am using uib in a Delphi 2010 application. I reuse a TUIBQuery component across several executions with different parameters. When a parameter-value returns an empty dataset access to the Fields returns stale data.
Here is a pseudocode representation/extract of what I do:
// Open query for a set of parameter values
Q.Params.ByNameAsInteger[aParamName] := 1;
Q.Open;
// For this parameter value data is returned, access the first record:
i := Q.Fields.ByNameAsInteger[aFieldName];
Q.Close;
// Open query for a different set of parameter values
Q.Params.ByNameAsInteger[aParamName] := 2;
Q.Open;
// For this parameter value there is no data on the DB.
j := Q.Fields.ByNameAsInteger[aFieldName];
Q.Close;
What I get after the last Open()
is
Q.Eof = true
Q.Bof = true
i = j // Some non-null value
So it does know the result set was empty, but still returns the value for aFieldName that was queried when the resultset was not empty for old parameter-valie when accessing the field by name.
I would rather have it give a NULL (or 0 as I access AsInteger())
for the field.
My workaround is a test for Eof=Bof=true
, but is there a more elegant way?
In my real code the two Open()
calls are in separate web-requests. Is there a way of explicitly resetting the field values when I call Close()
?
Thank you for reading this and devoting some thought to it.