Subject Re: [IBO] SQL Error 335544569
Author Nando Dessena
Hello,

c> I have one SQL with UNION ALL statements, after open the query, this
c> command cause error
c> query.recordcount

<SNIP>

c> the property RecordCountAccurate of query is True

I think you will have to set that to False; while not impossible,
getting the record count of a union select statement through count(*)
is beyond what IBO reparsing currently does. What IBO is probably
sending to the server to satisfy your RecordCount query is something
along the lines of

select count(*)
from first_table
where ...
union all
select ...
from second_table
where ...

which obviously won't work. A possible enhancement to IBO would be
recognizing the UNION token and forge this query instead:

select count(*)
from first_table
where ...
union all
select count(*)
from second_table
where ...

It would then have to iterate through the result set summing up all
the counts and return the value, which involves using a cursor instead
of an immediate statement. I'm sure it would be a piece of cake
for Jason to fix it if you consider it important; I think it's a
rather uncommon case, though.
There's also a way to obtain the count as a single value, but massive
manipulation of the SQL string would be needed:

select ((select count(*)
from first_table
where ...) +
(select count(*)
from second_table
where ...))
from RDB$DATABASE

This would eliminate the need for a cursor.

An an alternative, you could try to fix it yourself in
IB_Parse.GetCountSQL (but the callers need to be fixed as well), or
use the OnGetRecordCount event.

Overall, I think the simplest, although less efficient, solution in
your case is what I wrote at the beginning of this post.
Ciao
--
Nando mailto:nandod@...