Page 1 of 1

OraQuery How to .UpdateBatch

Posted: Fri 21 Nov 2008 04:29
by jansonwu
OraQuery How to .UpdateBatch like adoquery.UpdateBatch?

Posted: Fri 21 Nov 2008 11:11
by Plash
You should set the CachedUpdates property of TOraQuery to True, and call the ApplyUpdates method that is an analog of the TADOQuery.UpdateBatch method.

Posted: Tue 25 Nov 2008 01:40
by jansonwu
i set the oraquery.CachedUpdates:=true,but TOraQuery have not .UpdateBatch method,what is method i can use ?

Posted: Tue 25 Nov 2008 07:02
by jansonwu
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.

Posted: Tue 25 Nov 2008 08:52
by Plash
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.

Posted: Wed 26 Nov 2008 01:24
by jansonwu
//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".

Posted: Wed 26 Nov 2008 01:38
by jansonwu
I set LocalUpdate property to be False, but can't not appendrecord.

Posted: Wed 26 Nov 2008 01:50
by jansonwu
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.

Posted: Wed 26 Nov 2008 08:45
by Plash
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; 

Posted: Thu 27 Nov 2008 01:56
by jansonwu
thank you very much. I change ODAC version 6.7.. I succeeded.