1

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.

rusty bit
  • 371
  • 2
  • 17
Marian Aldenhövel
  • 677
  • 1
  • 6
  • 24
  • At first glance I would have expected it to return NULL as you seem to do - maybe some will know whether it's a quirk of the TUIBQuery component implementation or similar. BTW, it's nearly always better to post actual code, rather than pseudo code, here, because with pseudo code readers will wonder whether apparent errors in the pseudo code are also present in your actual code, and some will regard that as a bit inconsiderate and wasting their time, seeing that you're asking for free help. – MartynA Jun 27 '14 at 11:54
  • I think it is better to check whether the returnable amount > 0. In other languages ​​is that for example with `mysql_num_rows` done. In delphi you have `RecordCount` for example `0.RecordCount > 0` . – moskito-x Jun 27 '14 at 18:03

0 Answers0