Board index » delphi » Modifying records in a read-only SQL result set

Modifying records in a read-only SQL result set

I have a TQuery which selects all records input more than 'n' days ago.
I am passing a parameter to the Query with todays date.

This returns a non-live data set, but I want to modify a field in each
of the records to show that they have been reported on.

The manual says:

"If an application needs to update the data in a read-only result set,
it must use a separate TQuery to construct an UPDATE statement. By
setting the parameters of the update query based on the data retrieved
in the first query, the application can perform the desired update
operation."

How do I do this? I have added a second query which uses update, but how
do I restrict this to the records selected from the first query?

Using Delphi 1.02, Paradox tables.

Any help would be much appreciated,

Dan
<dan...@homesell.demon.co.uk>

 

Re:Modifying records in a read-only SQL result set


Quote
Dan Champion wrote:

> I have a TQuery which selects all records input more than 'n' days ago.
> I am passing a parameter to the Query with todays date.

> This returns a non-live data set, but I want to modify a field in each
> of the records to show that they have been reported on.

> The manual says:

> "If an application needs to update the data in a read-only result set,
> it must use a separate TQuery to construct an UPDATE statement. By
> setting the parameters of the update query based on the data retrieved
> in the first query, the application can perform the desired update
> operation."

> How do I do this? I have added a second query which uses update, but how
> do I restrict this to the records selected from the first query?

> Using Delphi 1.02, Paradox tables.

> Any help would be much appreciated,

> Dan
> <dan...@homesell.demon.co.uk>

The simplest way would be to use the exact same WHERE clause in the
second query. That way, the affected records will be exactly the ones
selected in the first query. Unless of course the data may have changed
since the first query run (not likely from the context of your
question).

Good Luck

Peter Antypas
panty...@hic.net

Re:Modifying records in a read-only SQL result set


Quote
Dan Champion <ad...@homesell.demon.co.uk> wrote:
>I have a TQuery which selects all records input more than 'n' days ago.
>I am passing a parameter to the Query with todays date.
>This returns a non-live data set, but I want to modify a field in each
>of the records to show that they have been reported on.

It sounds really strange you have not a live result set.
Is you SQL something like:

  Select * from MyTable
  where DateField >= :ADATE

If so, this actually return a live result set (have you set
RequestLive := TRUE; ?)
The only thing can avoid a live result set with a statement like the
above is to join two tables (or are you using a "like" statement?)

Quote
>The manual says:
>"If an application needs to update the data in a read-only result set,
>it must use a separate TQuery to construct an UPDATE statement. By
>setting the parameters of the update query based on the data retrieved
>in the first query, the application can perform the desired update
>operation."
>How do I do this? I have added a second query which uses update, but how
>do I restrict this to the records selected from the first query?

  Update MyTable
  where DateField >= :ADATE
  set AField = :AVALUE

Hope it helps,
        Corrado
Corrado Labinaz        
Vicenza (Italy)
internet:  c...@gpnet.it
fidonet:   2:333/209.6

Other Threads