tvplanit: Fix Firebird datastore not writing events, contacts, tasks after creation of a new resource.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5180 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2016-09-18 16:51:51 +00:00
parent 6a1b6b86de
commit 0662015dbe
3 changed files with 27 additions and 8 deletions

View File

@ -7,6 +7,4 @@ Login parameters for the created database:
NOTE: NOTE:
The project creates a new database on the fly using above-menitoned login The project creates a new database on the fly using above-menitoned login
parameters. For reasons unknown at the moment, the first program entries after parameters.
adding a resource are not stored --> a restart of the demo program is required
after adding the first resource.

View File

@ -331,6 +331,6 @@ object Form1: TForm1
Options = [] Options = []
Params = <> Params = <>
left = 149 left = 149
top = 511 top = 512
end end
end end

View File

@ -79,15 +79,16 @@ begin
FContactsTable := TSQLQuery.Create(self); FContactsTable := TSQLQuery.Create(self);
FContactsTable.SQL.Add('SELECT * FROM Contacts'); FContactsTable.SQL.Add('SELECT * FROM Contacts');
FContactsTable.UpdateMode := upWhereAll;
FEventsTable := TSQLQuery.Create(Self); FEventsTable := TSQLQuery.Create(Self);
FEventsTable.SQL.Add('SELECT * FROM Events'); FEventsTable.SQL.Add('SELECT * FROM Events');
FEventsTable.UpdateMode := upWhereAll;
FResourceTable := TSQLQuery.Create(self); FResourceTable := TSQLQuery.Create(self);
FResourceTable.SQL.Add( FResourceTable.SQL.Add('SELECT * FROM Resources');
'SELECT * '+ FResourceTable.UpdateMode := upWhereAll;
'FROM Resources'
);
{ {
FResourceTable.InsertSQL.Add( FResourceTable.InsertSQL.Add(
'INSERT INTO Resources (' + 'INSERT INTO Resources (' +
@ -102,6 +103,7 @@ begin
} }
FTasksTable := TSQLQuery.Create(self); FTasksTable := TSQLQuery.Create(self);
FTasksTable.SQL.Add('SELECT * FROM Tasks'); FTasksTable.SQL.Add('SELECT * FROM Tasks');
FTasksTable.UpdateMode := upWhereAll;
end; end;
procedure TVpFirebirdDatastore.AddField(ATableName, AFieldName: String; procedure TVpFirebirdDatastore.AddField(ATableName, AFieldName: String;
@ -517,24 +519,32 @@ end;
Firebird will complain about this field not being specified when posting. } Firebird will complain about this field not being specified when posting. }
procedure TVpFirebirdDatastore.OpenTables; procedure TVpFirebirdDatastore.OpenTables;
begin begin
{
if FContactsTable.Transaction = nil then if FContactsTable.Transaction = nil then
FContactsTable.Transaction := FConnection.Transaction; FContactsTable.Transaction := FConnection.Transaction;
}
FixContactsTable; FixContactsTable;
FContactsTable.Open; FContactsTable.Open;
FContactsTable.Fields[0].Required := false; FContactsTable.Fields[0].Required := false;
{
if FEventsTable.Transaction = nil then if FEventsTable.Transaction = nil then
FEventsTable.Transaction := FConnection.Transaction; FEventsTable.Transaction := FConnection.Transaction;
}
FEventsTable.Open; FEventsTable.Open;
FEventsTable.Fields[0].Required := false; FEventsTable.Fields[0].Required := false;
{
if FResourceTable.Transaction = nil then if FResourceTable.Transaction = nil then
FResourceTable.Transaction := FConnection.Transaction; FResourceTable.Transaction := FConnection.Transaction;
}
FResourceTable.Open; FResourceTable.Open;
FResourceTable.Fields[0].Required := false; FResourceTable.Fields[0].Required := false;
{
if FTasksTable.Transaction = nil then if FTasksTable.Transaction = nil then
FTasksTable.Transaction := FConnection.Transaction; FTasksTable.Transaction := FConnection.Transaction;
}
FTasksTable.Open; FTasksTable.Open;
FTasksTable.Fields[0].Required := false; FTasksTable.Fields[0].Required := false;
end; end;
@ -543,24 +553,35 @@ procedure TVpFirebirdDatastore.PostContacts;
begin begin
inherited; inherited;
FContactsTable.ApplyUpdates; FContactsTable.ApplyUpdates;
FConnection.Transaction.CommitRetaining;
FContactsTable.Refresh;
end; end;
procedure TVpFirebirdDatastore.PostEvents; procedure TVpFirebirdDatastore.PostEvents;
begin begin
inherited; inherited;
FEventsTable.ApplyUpdates; FEventsTable.ApplyUpdates;
FConnection.Transaction.CommitRetaining;
FEventsTable.Refresh;
end; end;
procedure TVpFirebirdDatastore.PostResources; procedure TVpFirebirdDatastore.PostResources;
begin begin
inherited; inherited;
FResourceTable.ApplyUpdates; FResourceTable.ApplyUpdates;
FConnection.Transaction.CommitRetaining;
// Refresh needed in order to get the resource id for the other tables.
// Without it the other datasets would not be stored after adding a resource.
// Seems to be pecularity of Firebird.
FResourceTable.Refresh;
end; end;
procedure TVpFirebirdDatastore.PostTasks; procedure TVpFirebirdDatastore.PostTasks;
begin begin
inherited; inherited;
FTasksTable.ApplyUpdates; FTasksTable.ApplyUpdates;
FConnection.Transaction.CommitRetaining;
FTasksTable.Refresh;
end; end;
procedure TVpFirebirdDatastore.SetConnected(const AValue: Boolean); procedure TVpFirebirdDatastore.SetConnected(const AValue: Boolean);