Board index » delphi » calculating sum in query that uses cachedupdates

calculating sum in query that uses cachedupdates

Hello!
I've got query1 with some fields and I must calculate sum of one field.
I created another query2 and i wrote sql statement. If I wouldnt be using
cachedupdates the query2.sql statement,

select sum(field) from imenik {thats a name of a paradox table}

would be enough, because the psyihical table is the same as data in
a query1. But when I do it with query1.cachedupdates:=true. It calculates
sum from psyihical table and it doesnt look in the query1s cache.

I tried with setting query2.datasource :=query1datasource.
I thought that it would look into the cache of a query1.
 But even this doesnt work.

How can I acomplish this.

Thanks.

t...@homemail.com

 

Re:calculating sum in query that uses cachedupdates


Hi,

Quote
On Tue, 08 Dec 1998 19:35:59 GMT, "tex" <t...@homemail.com> wrote:
>Hello!
>I've got query1 with some fields and I must calculate sum of one field.
>I created another query2 and i wrote sql statement. If I wouldnt be using
>cachedupdates the query2.sql statement,

>select sum(field) from imenik {thats a name of a paradox table}

>would be enough, because the psyihical table is the same as data in
>a query1. But when I do it with query1.cachedupdates:=true. It calculates
>sum from psyihical table and it doesnt look in the query1s cache.

>I tried with setting query2.datasource :=query1datasource.
>I thought that it would look into the cache of a query1.
> But even this doesnt work.

>How can I acomplish this.

You can't as far as I know.  Cached updates are not visible after
posting until an ApplyUpdates, and then only if all goes well
(UpdatesPending=False).

You should keep track of the total yourself.  Calculate the sum before
any Edit, Insert or Delete.  Then:
 * BeforePost of inserted record you should add the new field value
 * BeforeDelete you should subtract the old field value
 * BeforePost of edited record you should subtract the old field value
and add the new field value.

...or something like that.

Regards,

--
Marco Rocci
MicroEra srl
Turin, Italy

Other Threads