79 lines
1.9 KiB
Plaintext
79 lines
1.9 KiB
Plaintext
program Main;
|
|
|
|
{$APPTYPE CONSOLE}
|
|
|
|
{$R *.res}
|
|
|
|
uses
|
|
System.SysUtils,
|
|
System.Math,
|
|
ZConnection,
|
|
ZDataset,
|
|
DatabaseTestExecutor in 'DatabaseTestExecutor.pas',
|
|
DataGenerator in 'DataGenerator.pas';
|
|
|
|
var
|
|
LConnection: TZConnection;
|
|
|
|
begin
|
|
LConnection := TZConnection.Create(nil);
|
|
LConnection.LibraryLocation := ExtractFilePath(ParamStr(0)) + 'libpq.dll';
|
|
|
|
try
|
|
LConnection.Protocol := 'postgresql';
|
|
LConnection.HostName := 'localhost';
|
|
LConnection.Port := 5433;
|
|
LConnection.Database := 'test_db';
|
|
LConnection.User := 'postgres';
|
|
LConnection.Password := 'postgres';
|
|
|
|
Writeln('Connecting to PostgreSQL...');
|
|
LConnection.Connect;
|
|
Writeln('Connected successfully!');
|
|
Writeln('-------------------------');
|
|
|
|
var DatabaseManager: TDatabaseManager;
|
|
DatabaseManager := TDatabaseManager.Create(LConnection, 1234);
|
|
var SetupSuccess: Boolean;
|
|
|
|
SetupSuccess := DatabaseManager.SetupDatabase();
|
|
|
|
if SetupSuccess then
|
|
begin
|
|
Writeln('Done setting up database!');
|
|
end
|
|
else
|
|
begin
|
|
Writeln('Failed to setup database connection!');
|
|
end;
|
|
|
|
var LNumActions: Integer;
|
|
LNumActions := 10000;
|
|
|
|
var LInsertTimes: TArray<Double>;
|
|
LInsertTimes := DatabaseManager.TestInserts(LNumActions);
|
|
|
|
var LMeanInsertTime: Double;
|
|
LMeanInsertTime := Mean(LInsertTimes);
|
|
|
|
if Length(LInsertTimes) <> LNumActions then
|
|
begin
|
|
WriteLn('All inserts did not complete, got=' + Length(LInsertTimes).ToString + ' expected=' + LNumActions.ToString);
|
|
end
|
|
else
|
|
begin
|
|
WriteLn(LNumActions.ToString + ' inserts completed, average time =' + LMeanInsertTime.ToString + 'ms');
|
|
end;
|
|
|
|
|
|
|
|
|
|
finally
|
|
FreeAndNil(LConnection);
|
|
end;
|
|
|
|
Writeln('-------------------------');
|
|
Writeln('Press Enter to exit...');
|
|
Readln;
|
|
end.
|