[fpc-pascal] TSQLQuery and buffering.

Michael Van Canneyt michael at freepascal.org
Sat Mar 25 08:57:46 CET 2017

On Fri, 24 Mar 2017, Gary Doades wrote:

> Hi everyone,
> Firstly, I realise this is an old subject, but I still can't find any easy
> answer.
> Really, the question is simple: Is there ANY way of TSQLQuery NOT reading
> the entire result set into memory?

Set Unidirectional to True, and it will keep only 1 row in memory.
When you are simply scanning through the result set, this is all you need.

The problem is that most drivers also do not support arbitrary navigation 
in the result set, so when we want to support navigating backwards, we have
no choice but to keep everything in memory. (barring re-running the query
and refetching everything, I'm sure you don't want that either)

If you need to move back and forth in the result set, then you 'll need to
set unidirectional to true, and store the needed records yourself.  You can
copy the structure of the dataset really easy to a TBufDataset using

in the TBufDataset you can keep as many records as you like, and just delete the old
ones (you need to call mergechangelog or somesuch). 
We could maybe try to find a way to copy the buffer from one
bufdataset to another (since TSQLQuery is just a TBufDataset Descendent)


More information about the fpc-pascal mailing list