TPlanIt: Fix ZEOS datastore to work with PostgreSQL database and expand datastore example.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8285 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2022-06-08 11:09:59 +00:00
parent 6f2dd11e48
commit 7048d249ff
4 changed files with 70 additions and 15 deletions

View File

@@ -34,6 +34,7 @@ type
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
procedure SetConnected(const AValue: Boolean); override;
procedure SetTableConnections(AConnection: TZConnection);
function TableExists(ATableName: String): Boolean;
function TablesExist: boolean;
protected
@@ -82,19 +83,19 @@ begin
FAutoCreate := false;
FContactsTable := TZTable.Create(self);
FContactsTable.TableName := 'Contacts';
FContactsTable.TableName := ContactsTableName;
FContactsTable.UpdateMode := umUpdateAll;
FEventsTable := TZTable.Create(Self);
FEventsTable.TableName := 'Events';
FEventsTable.TableName := EventsTableName;
FEventsTable.UpdateMode := umUpdateAll;
FResourceTable := TZTable.Create(self);
FResourceTable.TableName := 'Resources';
FResourceTable.TableName := ResourceTableName;
FResourceTable.UpdateMode := umUpdateAll;
FTasksTable := TZTable.Create(self);
FTasksTable.TableName := 'Tasks';
FTasksTable.TableName := TasksTableName;
FTasksTable.UpdateMode := umUpdateAll;
end;
@@ -158,10 +159,10 @@ begin
SetTableConnections(FConnection);
end;
FConnection.Connected := true;
if not FContactsTable.Exists then CreateTable(ContactsTableName);
if not FEventsTable.Exists then CreateTable(EventsTableName);
if not FResourceTable.Exists then CreateTable(ResourceTableName);
if not FTasksTable.Exists then CreateTable(TasksTableName);
if not TableExists(ContactsTableName) then CreateTable(ContactsTableName);
if not TableExists(EventsTableName) then CreateTable(EventsTableName);
if not TableExists(ResourceTableName) then CreateTable(ResourceTableName);
if not TableExists(TasksTableName) then CreateTable(TasksTableName);
finally
FConnection.Connected := wasConnected;
end;
@@ -681,6 +682,24 @@ begin
end;
end;
function TVpZeosDatastore.TableExists(ATableName: String): Boolean;
var
L: TStringList;
begin
Result := false;
if not FConnection.Connected then
exit;
L := TStringList.Create;
try
L.CaseSensitive := false;
FConnection.GetTableNames('', L);
Result := L.IndexOf(ATablename) <> -1;;
finally
L.Free;
end;
end;
function TVpZeosDatastore.TablesExist: Boolean;
var
L: TStringList;