Inital commit with most of the completed code
This commit is contained in:
60
__history/TestDatabaseManager.pas.~4~
Normal file
60
__history/TestDatabaseManager.pas.~4~
Normal file
@@ -0,0 +1,60 @@
|
||||
unit TestDatabaseManager;
|
||||
|
||||
interface
|
||||
uses
|
||||
System.SysUtils,
|
||||
ZConnection,
|
||||
ZDataset,
|
||||
ZExceptions;
|
||||
|
||||
|
||||
type
|
||||
TDatabaseManager = class
|
||||
|
||||
private
|
||||
FConnection: TZConnection;
|
||||
|
||||
public
|
||||
constructor Create(connection:TZConnection);
|
||||
function SetupDatabase: Boolean;
|
||||
|
||||
end;
|
||||
|
||||
|
||||
implementation
|
||||
constructor TDatabaseManager.Create(connection:TZConnection);
|
||||
begin
|
||||
FConnection := connection;
|
||||
end;
|
||||
|
||||
function TDatabaseManager.SetupDatabase: Boolean;
|
||||
begin
|
||||
var Query: TZQuery;
|
||||
Query := TZQuery.Create(nil);
|
||||
Query.Connection := FConnection;
|
||||
|
||||
Query.Sql.Add('DROP TABLE IF EXISTS users');
|
||||
try
|
||||
Query.ExecSQL;
|
||||
except
|
||||
on E: EZSQLException do
|
||||
begin
|
||||
Exit(False);
|
||||
end;
|
||||
end;
|
||||
|
||||
Query.SQL.Clear;
|
||||
Query.SQL.Add('CREATE TABLE IF NOT EXISTS users (id INT PRIMARY KEY, first_name VARCHAR(255), last_name VARCHAR(255), social_security_number VARCHAR(255), age INT);');
|
||||
try
|
||||
Query.ExecSQL;
|
||||
except
|
||||
on E: EZSQLException do
|
||||
begin
|
||||
Exit(False);
|
||||
end;
|
||||
end;
|
||||
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
end.
|
||||
Reference in New Issue
Block a user