Inital commit with most of the completed code
This commit is contained in:
98
__history/Main.dpr.~12~
Normal file
98
__history/Main.dpr.~12~
Normal file
@@ -0,0 +1,98 @@
|
||||
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;
|
||||
Writeln('-------------------------');
|
||||
|
||||
var LNumActions: Integer;
|
||||
LNumActions := 10000;
|
||||
|
||||
WriteLn('Testing Database Inserts');
|
||||
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;
|
||||
|
||||
Writeln('-------------------------');
|
||||
WriteLn('Testing reading back each record by primary key');
|
||||
|
||||
var LReadTimes: TArray<Double>;
|
||||
LReadTimes := TArray<Double>.Create();
|
||||
LReadTimes := DatabaseManager.TestReads(LNumActions);
|
||||
|
||||
var LMeanReadTime: Double;
|
||||
LMeanReadTime := Mean(LInsertTimes);
|
||||
|
||||
if Length(LInsertTimes) <> LNumActions then
|
||||
begin
|
||||
WriteLn('All inserts did not complete, got=' + Length(LReadTimes).ToString + ' expected=' + LNumActions.ToString);
|
||||
end
|
||||
else
|
||||
begin
|
||||
WriteLn(LNumActions.ToString + ' reads completed, average time ' + LMeanReadTime.ToString + 'ms');
|
||||
end;
|
||||
|
||||
|
||||
|
||||
finally
|
||||
FreeAndNil(LConnection);
|
||||
end;
|
||||
|
||||
Writeln('-------------------------');
|
||||
Writeln('Press Enter to exit...');
|
||||
Readln;
|
||||
end.
|
||||
Reference in New Issue
Block a user