OraQuery How to .UpdateBatch

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
jansonwu
Posts: 8
Joined: Fri 21 Nov 2008 03:50

OraQuery How to .UpdateBatch

Post by jansonwu » Fri 21 Nov 2008 04:29

OraQuery How to .UpdateBatch like adoquery.UpdateBatch?

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Fri 21 Nov 2008 11:11

You should set the CachedUpdates property of TOraQuery to True, and call the ApplyUpdates method that is an analog of the TADOQuery.UpdateBatch method.

jansonwu
Posts: 8
Joined: Fri 21 Nov 2008 03:50

Post by jansonwu » Tue 25 Nov 2008 01:40

i set the oraquery.CachedUpdates:=true,but TOraQuery have not .UpdateBatch method,what is method i can use ?

jansonwu
Posts: 8
Joined: Fri 21 Nov 2008 03:50

Post by jansonwu » Tue 25 Nov 2008 07:02

i set the .CachedUpdates as true and LocalUpdate as true , and use the method of .ApplyUpdates. but it noticed that this poeration on an opendataset.
I can't find the method of UpdateBatch like TAdoQuery.

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Tue 25 Nov 2008 08:52

The LocalUpdate property must be False.

Both methods TADOQuery.UpdateBatch and TOraQuery.ApplyUpdates should be called on opened dataset. You should open the dataset, make some changes to data, then call the ApplyUpdates method.

jansonwu
Posts: 8
Joined: Fri 21 Nov 2008 03:50

Post by jansonwu » Wed 26 Nov 2008 01:24

//q:toraquery;

opensql:='select CODE,XM,DZ from A1 where CODE is NULL';
if q.Active then q.Close;
q:=openquery(opensql,psession);
self.DataSource1.DataSet:=q;
q.ReadOnly:=false;
q.LocalUpdate:=false;
for i :=1 to 100 do // Iterate
begin
q.AppendRecord([InttoStr(i),'XXXX,'111']);
end; // for
q.CachedUpdates:=true;
q.ApplyUpdates;

Is there someting wrong? It noticed that "can't modify a read-only dataset".

jansonwu
Posts: 8
Joined: Fri 21 Nov 2008 03:50

Post by jansonwu » Wed 26 Nov 2008 01:38

I set LocalUpdate property to be False, but can't not appendrecord.

jansonwu
Posts: 8
Joined: Fri 21 Nov 2008 03:50

Post by jansonwu » Wed 26 Nov 2008 01:50

I want to append record in batch in locally and finally append all the data to database.

I use dbgrid to list the data, dbgrid.readonly:=false.

I set LocalUpdate property to be False, but can't not appendrecord.
but I set LocalUpdate property to be True, it can appendrecord,but can't applyupdate.

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Wed 26 Nov 2008 08:45

Set CachedUpdates = True before opening the dataset.

If you are using ODAC version before 6.0, TOraQuery component is read-only unless you have set the SQLInsert property. You can you the TSmartQuery component instead of TOraQuery. TSmartQuery generates INSERT statement automatically.

Code: Select all

SmartQuery.SQL.Text := 'select CODE,XM,DZ from A1 where CODE is NULL';
SmartQuery.CachedUpdates := True;
SmartQuery.Open;
for i := 1 to 100 do
begin
  SmartQuery.AppendRecord([InttoStr(i),'XXXX,'111']); 
end;
SmartQuery.ApplyUpdates; 
SmartQuery.CommitUpdates; 

jansonwu
Posts: 8
Joined: Fri 21 Nov 2008 03:50

Post by jansonwu » Thu 27 Nov 2008 01:56

thank you very much. I change ODAC version 6.7.. I succeeded.

Post Reply