Subject Re: best way of selecting some records of a table
Author Adam
--- In firebird-support@yahoogroups.com, Fulvio Senore <mailing@...>
wrote:
>
> What about storing the IDs in memory instead of writing them to a
> temporary table?
> You could use an array or something smarter like a c++ vector, if
> available in Delphi.

Be prepared to be smacked by some implementation limitations if you
take this approach.

Once you have a list of IDs in memory, you have to tell that to the
database. This means contending with the having a 1499 items limit in
an "IN" clause, and possibly also contending with a maximum SQL
statement size of 64KB as well as some not so pretty PLANS (efficient,
just not pretty).

With 2.1 you can use Temporary tables which is a much better solution.

eg

create global temporary table MYSELECTION(ID) ON COMMIT DELETE ROWS;
COMMIT;

(Use ON COMMIT PRESERVE ROWS instead if you want the records to remain
for the duration of your connection instead of being emptied on commit).

To select an item, insert it into MySelection. To unselect an item,
delete it from MySelection.

When you run your query, simply perform an inner join to MYSELECTION.

You can implement the same sort of thing with a normal table and the
CURRENT_TRANSACTION or CURRENT_CONNECTION context variables, but you
have to do your own cleanup.

Adam