The first is a read-only Exists property, which would return whether a table with the corresponding name exists in the database. This may also be implemented as a method, perhaps like so:
Code: Select all
function TZTable.Exists: Boolean;
var
TableList: TStringList;
begin
TableList := TStringList.Create;
try
if (not Assigned(Connection)) then
raise SomeException.Create('no connection'); // <-- adjust this line
{TODO: handle closed connection somehow}
Connection.GetTableNames(TableName, TableList);
TableList.CaseSensitive := False;
Result := (TableList.IndexOf(TableName) >= 0); // how to handle wildcard chars?
finally
TableList.Free;
end;
end;
The second request is a CreateTable method, which would use the various TZTable properties to construct the appropriate 'create table' query and then run it. It should also automatically clear or even update the appropriate parts of the metadata cache.
This may require some additional infrastructure to allow the full definition of a table, including indexes and other constraints (don't know what is missing, if anything), but maybe it can be at least partially implemented even with the existing infrastructure...