type
TSpecialConnector = class(TSQLConnector)
protected
procedure DoInternalConnect; override;
end;
function CreateSQLConnection(ThisDatabaseLocation: string = '';
ThisType: DatabaseType = dtSQLite; ThisUser: string = ''; ThisPass: string = ''):
TSpecialConnector;
implementation
procedure TSpecialConnector.DoInternalConnect;
begin
if ConnectorType = 'SQLite3' then TSQLite3Connection(Proxy).OpenFlags :=
[sofReadWrite, sofCreate, sofFullMutex, sofSharedCache];
inherited DoInternalConnect;
end;
function CreateSQLConnection(ThisDatabaseLocation: string;
ThisType: DatabaseType; ThisUser: string; ThisPass: string): TSpecialConnector;
begin
Result := TSpecialConnector.Create(nil);
Result.KeepConnection := False;
case ThisType of
dtSQLite:
begin
Result.ConnectorType := 'SQLite3';
if Empty(ThisDatabaseLocation) then
Result.DatabaseName := DefaultDatabase
else Result.DatabaseName := ThisDatabaseLocation;
Result.Params.Add('foreign_keys=ON');
Result.Params.Add('journal_mode=WAL');
end;
dtMSSQL:
begin
Result.ConnectorType := 'MSSQLServer';
if Empty(ThisDatabaseLocation) then
Result.HostName := 'localhost'
else Result.HostName := ThisDatabaseLocation;
Result.DatabaseName := 'DefaultDatabase';
end;
dtPostgreSQL:
begin
Result.ConnectorType := 'PostgreSQL';
if Empty(ThisDatabaseLocation) then
begin
Result.HostName := 'localhost';
Result.DatabaseName := DefaultDatabaseName;
end
else Result.HostName := ThisDatabaseLocation;
end;
dtODBC:
begin
Result.ConnectorType := 'ODBC';
{$IFDEF UNIX}
Result.Params.Add('DRIVER=MDBTools');
{$ELSE}
Result.Params.Add('DRIVER=Microsoft Access Driver (*.mdb, *.accdb)');
{$ENDIF}
Result.Params.Add('DBQ=' + ThisDatabaseLocation);
end;
else
end;
Result.UserName := ThisUser;
Result.Password := ThisPass;
Result.Transaction := TSQLTransaction.Create(Result);
end;