tvplanit: Fix Firebird datastore missing commit after updating contacts table structure to current version.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5181 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2016-09-18 20:24:52 +00:00
parent 0662015dbe
commit 27bb5c51fe
2 changed files with 65 additions and 72 deletions

View File

@ -19,9 +19,9 @@ object ContactEditForm: TContactEditForm
Height = 592 Height = 592
Top = 0 Top = 0
Width = 575 Width = 575
ActivePage = tabAddresses ActivePage = tabBaseData
Align = alClient Align = alClient
TabIndex = 1 TabIndex = 0
TabOrder = 0 TabOrder = 0
OnChange = PageControlChange OnChange = PageControlChange
object tabBaseData: TTabSheet object tabBaseData: TTabSheet
@ -1095,7 +1095,7 @@ object ContactEditForm: TContactEditForm
BorderSpacing.Left = 4 BorderSpacing.Left = 4
BorderSpacing.Right = 8 BorderSpacing.Right = 8
ParentFont = False ParentFont = False
TabOrder = 2 TabOrder = 1
end end
object edWebsite2: TEdit object edWebsite2: TEdit
AnchorSideLeft.Control = cbWebsite2 AnchorSideLeft.Control = cbWebsite2
@ -1142,7 +1142,7 @@ object ContactEditForm: TContactEditForm
ItemHeight = 15 ItemHeight = 15
MaxLength = 65535 MaxLength = 65535
ParentFont = False ParentFont = False
TabOrder = 1 TabOrder = 2
end end
end end
end end

View File

@ -417,55 +417,63 @@ begin
list := TStringList.Create; list := TStringList.Create;
try try
FConnection.GetFieldNames(ContactsTableName, list); FConnection.GetFieldNames(ContactsTableName, list);
// Fields renamed in 1.05
if list.IndexOf('Address') > -1 then
RenameField(ContactsTableName, 'Address', 'Address1');
if list.IndexOf('City') > -1 then
RenameField(ContactsTableName, 'City', 'City1');
if list.IndexOf('State') > -1 then
RenameField(ContactsTableName, 'State', 'State1');
if list.IndexOf('Zip') > -1 then
RenameField(ContactsTableName, 'Zip', 'Zip1');
if list.IndexOf('Country') > -1 then
RenameField(ContactsTableName, 'Country', 'Country1');
if list.IndexOf('EMail') > -1 then
RenameField(ContactsTableName, 'EMail', 'EMail1');
// Fields added in 1.05 try
if list.IndexOf('Department') = -1 then // Fields renamed in 1.05
AddField(ContactsTableName, 'Department', ftString, 50); if list.IndexOf('Address') > -1 then
if list.IndexOf('AddressType1') = -1 then RenameField(ContactsTableName, 'Address', 'Address1');
AddField(ContactsTableName, 'AddressType1', ftInteger); if list.IndexOf('City') > -1 then
if list.IndexOf('AddressType2') = -1 then RenameField(ContactsTableName, 'City', 'City1');
AddField(ContactsTableName, 'AddressType2', ftInteger); if list.IndexOf('State') > -1 then
if list.IndexOf('Address2') = -1 then RenameField(ContactsTableName, 'State', 'State1');
AddField(ContactsTableName, 'Address2', ftString, 100); if list.IndexOf('Zip') > -1 then
if list.IndexOf('City2') = -1 then RenameField(ContactsTableName, 'Zip', 'Zip1');
AddField(ContactsTableName, 'City2', ftString, 50); if list.IndexOf('Country') > -1 then
if list.IndexOf('State2') = -1 then RenameField(ContactsTableName, 'Country', 'Country1');
AddField(ContactsTableName, 'State2', ftString, 25); if list.IndexOf('EMail') > -1 then
if list.IndexOf('Zip2') = -1 then RenameField(ContactsTableName, 'EMail', 'EMail1');
AddField(ContactsTableName, 'Zip2', ftString, 10);
if list.IndexOf('country2') = -1 then // Fields added in 1.05
AddField(ContactsTableName, 'Country2', ftString, 25); if list.IndexOf('Department') = -1 then
if list.IndexOf('EMail2') = -1 then AddField(ContactsTableName, 'Department', ftString, 50);
AddField(ContactsTableName, 'EMail2', ftString, 100); if list.IndexOf('AddressType1') = -1 then
if list.IndexOf('EMail3') = -1 then AddField(ContactsTableName, 'AddressType1', ftInteger);
AddField(ContactsTableName, 'EMail3', ftString, 100); if list.IndexOf('AddressType2') = -1 then
if list.IndexOf('EMailType1') = -1 then AddField(ContactsTableName, 'AddressType2', ftInteger);
AddField(ContactsTableName, 'EMailType1', ftInteger); if list.IndexOf('Address2') = -1 then
if list.IndexOf('EMailType2') = -1 then AddField(ContactsTableName, 'Address2', ftString, 100);
AddField(ContactsTableName, 'EMailType2', ftInteger); if list.IndexOf('City2') = -1 then
if list.IndexOf('EMailType3') = -1 then AddField(ContactsTableName, 'City2', ftString, 50);
AddField(ContactsTableName, 'EMailType3', ftInteger); if list.IndexOf('State2') = -1 then
if list.IndexOf('Website1') = -1 then AddField(ContactsTableName, 'State2', ftString, 25);
AddField(ContactsTableName, 'Website1', ftString, 100); if list.IndexOf('Zip2') = -1 then
if list.IndexOf('Website2') = -1 then AddField(ContactsTableName, 'Zip2', ftString, 10);
AddField(ContactsTableName, 'Website2', ftString, 100); if list.IndexOf('country2') = -1 then
if list.IndexOf('WebsiteType1') = -1 then AddField(ContactsTableName, 'Country2', ftString, 25);
AddField(ContactsTableName, 'WebsiteType1', ftInteger); if list.IndexOf('EMail2') = -1 then
if list.IndexOf('WebsiteType2') = -1 then AddField(ContactsTableName, 'EMail2', ftString, 100);
AddField(ContactsTableName, 'WebsiteType2', ftInteger); if list.IndexOf('EMail3') = -1 then
AddField(ContactsTableName, 'EMail3', ftString, 100);
if list.IndexOf('EMailType1') = -1 then
AddField(ContactsTableName, 'EMailType1', ftInteger);
if list.IndexOf('EMailType2') = -1 then
AddField(ContactsTableName, 'EMailType2', ftInteger);
if list.IndexOf('EMailType3') = -1 then
AddField(ContactsTableName, 'EMailType3', ftInteger);
if list.IndexOf('Website1') = -1 then
AddField(ContactsTableName, 'Website1', ftString, 100);
if list.IndexOf('Website2') = -1 then
AddField(ContactsTableName, 'Website2', ftString, 100);
if list.IndexOf('WebsiteType1') = -1 then
AddField(ContactsTableName, 'WebsiteType1', ftInteger);
if list.IndexOf('WebsiteType2') = -1 then
AddField(ContactsTableName, 'WebsiteType2', ftInteger);
FConnection.Transaction.Commit;
except
FConnection.Transaction.Rollback;
raise Exception.Create('Failure to update table structure to current VisualPlanIt version');
end;
finally finally
list.Free; list.Free;
end; end;
@ -519,32 +527,16 @@ 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
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
FEventsTable.Transaction := FConnection.Transaction;
}
FEventsTable.Open; FEventsTable.Open;
FEventsTable.Fields[0].Required := false; FEventsTable.Fields[0].Required := false;
{
if FResourceTable.Transaction = nil then
FResourceTable.Transaction := FConnection.Transaction;
}
FResourceTable.Open; FResourceTable.Open;
FResourceTable.Fields[0].Required := false; FResourceTable.Fields[0].Required := false;
{
if FTasksTable.Transaction = nil then
FTasksTable.Transaction := FConnection.Transaction;
}
FTasksTable.Open; FTasksTable.Open;
FTasksTable.Fields[0].Required := false; FTasksTable.Fields[0].Required := false;
end; end;
@ -553,7 +545,7 @@ procedure TVpFirebirdDatastore.PostContacts;
begin begin
inherited; inherited;
FContactsTable.ApplyUpdates; FContactsTable.ApplyUpdates;
FConnection.Transaction.CommitRetaining; //FConnection.Transaction.CommitRetaining;
FContactsTable.Refresh; FContactsTable.Refresh;
end; end;
@ -561,7 +553,7 @@ procedure TVpFirebirdDatastore.PostEvents;
begin begin
inherited; inherited;
FEventsTable.ApplyUpdates; FEventsTable.ApplyUpdates;
FConnection.Transaction.CommitRetaining; //FConnection.Transaction.CommitRetaining;
FEventsTable.Refresh; FEventsTable.Refresh;
end; end;
@ -569,7 +561,8 @@ procedure TVpFirebirdDatastore.PostResources;
begin begin
inherited; inherited;
FResourceTable.ApplyUpdates; FResourceTable.ApplyUpdates;
FConnection.Transaction.CommitRetaining; //FConnection.Transaction.CommitRetaining;
// Refresh needed in order to get the resource id for the other tables. // 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. // Without it the other datasets would not be stored after adding a resource.
// Seems to be pecularity of Firebird. // Seems to be pecularity of Firebird.
@ -580,7 +573,7 @@ procedure TVpFirebirdDatastore.PostTasks;
begin begin
inherited; inherited;
FTasksTable.ApplyUpdates; FTasksTable.ApplyUpdates;
FConnection.Transaction.CommitRetaining; //FConnection.Transaction.CommitRetaining;
FTasksTable.Refresh; FTasksTable.Refresh;
end; end;