Cached Updates error
Posted: Fri 11 May 2007 18:17
Hi there!
I'm a brazilian Delphi developer and I guess I have found a bug on SDAC/ODAC 3.80.0.37:
The error occurs when I use the UpdateAction uaSkip on method OnUpdateRecord.
You can see below how the error happens:
1 - OnPostRecord of the dataset I execute ApplyUpdates;
2 - OnUpdateRecord I skip the record when it is in InsertMode, and the field 'au_LName' is empty
3 - To get the error I insert a new record, fill another field (not 'au_LName'), edit other record and go back to the 'skipped record'. When I try to post the changes of the skipped record the application raises an 'Access Violation'.
For more details see the following code:
One question more:
Is there a version 3.80.0.37 for Delphi 2007? (I'm using Sdac std edition).
I'm a brazilian Delphi developer and I guess I have found a bug on SDAC/ODAC 3.80.0.37:
The error occurs when I use the UpdateAction uaSkip on method OnUpdateRecord.
You can see below how the error happens:
1 - OnPostRecord of the dataset I execute ApplyUpdates;
2 - OnUpdateRecord I skip the record when it is in InsertMode, and the field 'au_LName' is empty
3 - To get the error I insert a new record, fill another field (not 'au_LName'), edit other record and go back to the 'skipped record'. When I try to post the changes of the skipped record the application raises an 'Access Violation'.
For more details see the following code:
Code: Select all
program Project1;
uses
Forms, DB, DBAccess, MSAccess, MemDS, Grids, DBGrids;
{$R *.res}
var
MainForm: TForm;
Query: TMSQuery;
Grid: TDBGrid;
type
TProcs = class
public
procedure UpdateRecord(DataSet: TDataSet; UpdateKind:
TUpdateKind; var UpdateAction: TUpdateAction);
procedure AfterPost(DataSet: TDataSet);
end;
procedure TProcs.UpdateRecord(DataSet: TDataSet; UpdateKind:
TUpdateKind; var UpdateAction: TUpdateAction);
begin
case UpdateKind of
ukModify,
ukInsert:
if Query.FieldByName('au_lname').IsNull then
UpdateAction := uaSkip
else
UpdateAction := TUpdateAction(uaDefault);
ukDelete:
UpdateAction := TUpdateAction(uaDefault);
end;
end;
procedure TProcs.AfterPost(DataSet: TDataSet);
begin
Query.Connection.StartTransaction;
try
Query.ApplyUpdates;
Query.Connection.Commit;
Query.CommitUpdates;
except
Query.RestoreUpdates;
Query.Connection.Rollback;
raise;
end;
end;
begin
Application.Initialize;
Application.CreateForm(TForm, MainForm);
MainForm.Width := 800;
MainForm.Position := poDesktopCenter;
Query := TMSQuery.Create(MainForm);
Query.Connection := TMSConnection.Create(MainForm);
Query.Connection.Server := '.';
Query.Connection.Database := 'pubs';
Query.Connection.Username := 'sa';
Query.Connection.Password := '';
Query.SQL.Text := 'select * from authors';
Query.CachedUpdates := True;
Query.OnUpdateRecord := TProcs(nil).UpdateRecord;
Query.AfterPost := TProcs(nil).AfterPost;
Query.Open;
Grid := TDBGrid.Create(MainForm);
Grid.Parent := MainForm;
Grid.Top := 10;
Grid.Left := 10;
Grid.Height := MainForm.ClientHeight - 20;
Grid.Width := MainForm.ClientWidth - 20;
Grid.DataSource := TDataSource.Create(MainForm);
Grid.DataSource.DataSet := Query;
Application.Run;
end.
Is there a version 3.80.0.37 for Delphi 2007? (I'm using Sdac std edition).