You've already forked lazarus-ccr
tvplanit: Fixing exceptions related to combinations of AutoCreate and AutoConnect for ZeosDatastore (still crashing in case of AutoCreate=false and Autoconnect=true at first access to data).
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4762 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -19,9 +19,9 @@ type
|
|||||||
|
|
||||||
protected
|
protected
|
||||||
procedure CreateTable(const ATableName: String);
|
procedure CreateTable(const ATableName: String);
|
||||||
|
procedure CreateAllTables;
|
||||||
function GetContactsTable: TDataset; override;
|
function GetContactsTable: TDataset; override;
|
||||||
function GetEventsTable: TDataset; override;
|
function GetEventsTable: TDataset; override;
|
||||||
function GetNextID(TableName: string): int64; override;
|
|
||||||
function GetResourceTable: TDataset; override;
|
function GetResourceTable: TDataset; override;
|
||||||
function GetTasksTable: TDataset; override;
|
function GetTasksTable: TDataset; override;
|
||||||
procedure Loaded; override;
|
procedure Loaded; override;
|
||||||
@ -31,6 +31,7 @@ type
|
|||||||
public
|
public
|
||||||
constructor Create(AOwner: TComponent); override;
|
constructor Create(AOwner: TComponent); override;
|
||||||
procedure CreateTables;
|
procedure CreateTables;
|
||||||
|
function GetNextID(TableName: string): int64; override;
|
||||||
|
|
||||||
property ResourceTable;
|
property ResourceTable;
|
||||||
property EventsTable;
|
property EventsTable;
|
||||||
@ -72,19 +73,12 @@ begin
|
|||||||
FTasksTable.TableName := 'Tasks';
|
FTasksTable.TableName := 'Tasks';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// Connection and tables are active afterwards!
|
procedure TVpZeosDatastore.CreateAllTables;
|
||||||
procedure TVpZeosDatastore.CreateTables;
|
|
||||||
begin
|
begin
|
||||||
FConnection.Connected := true;
|
|
||||||
if not FContactsTable.Exists then CreateTable(ContactsTableName);
|
if not FContactsTable.Exists then CreateTable(ContactsTableName);
|
||||||
if not FEventsTable.Exists then CreateTable(EventsTableName);
|
if not FEventsTable.Exists then CreateTable(EventsTableName);
|
||||||
if not FResourceTable.Exists then CreateTable(ResourceTableName);
|
if not FResourceTable.Exists then CreateTable(ResourceTableName);
|
||||||
if not FTasksTable.Exists then CreateTable(TasksTableName);
|
if not FTasksTable.Exists then CreateTable(TasksTableName);
|
||||||
|
|
||||||
ContactsTable.Open;
|
|
||||||
EventsTable.Open;
|
|
||||||
ResourceTable.Open;
|
|
||||||
TasksTable.Open;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TVpZeosDatastore.CreateTable(const ATableName: String);
|
procedure TVpZeosDatastore.CreateTable(const ATableName: String);
|
||||||
@ -241,6 +235,16 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TVpZeosDatastore.CreateTables;
|
||||||
|
var
|
||||||
|
wasConnected: Boolean;
|
||||||
|
begin
|
||||||
|
wasConnected := FConnection.Connected;
|
||||||
|
FConnection.Connected := true;
|
||||||
|
CreateAllTables;
|
||||||
|
SetConnected(wasConnected or AutoConnect);
|
||||||
|
end;
|
||||||
|
|
||||||
function TVpZeosDatastore.GetContactsTable: TDataset;
|
function TVpZeosDatastore.GetContactsTable: TDataset;
|
||||||
begin
|
begin
|
||||||
Result := FContactsTable;
|
Result := FContactsTable;
|
||||||
@ -272,7 +276,10 @@ procedure TVpZeosDatastore.Loaded;
|
|||||||
begin
|
begin
|
||||||
inherited;
|
inherited;
|
||||||
if not (csDesigning in ComponentState) then
|
if not (csDesigning in ComponentState) then
|
||||||
Connected := AutoConnect;
|
Connected := AutoConnect and (
|
||||||
|
AutoCreate or
|
||||||
|
(FContactsTable.Exists and FEventsTable.Exists and FResourceTable.Exists and FTasksTable.Exists)
|
||||||
|
);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TVpZeosDatastore.Notification(AComponent: TComponent;
|
procedure TVpZeosDatastore.Notification(AComponent: TComponent;
|
||||||
@ -285,14 +292,14 @@ end;
|
|||||||
|
|
||||||
procedure TVpZeosDatastore.SetConnected(const AValue: Boolean);
|
procedure TVpZeosDatastore.SetConnected(const AValue: Boolean);
|
||||||
begin
|
begin
|
||||||
if AValue = Connected then
|
if {(AValue = Connected) or }(FConnection = nil) then
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
if AValue and AutoCreate then
|
if AValue and AutoCreate then
|
||||||
CreateTables;
|
CreateTables;
|
||||||
|
|
||||||
FConnection.Connected := AValue;
|
FConnection.Connected := AValue;
|
||||||
if AValue then begin
|
if FConnection.Connected then begin
|
||||||
FContactsTable.Open;
|
FContactsTable.Open;
|
||||||
FEventsTable.Open;
|
FEventsTable.Open;
|
||||||
FResourceTable.Open;
|
FResourceTable.Open;
|
||||||
|
Reference in New Issue
Block a user