[fpc-pascal] Using database-specific functionality with TSQLConnector

Reinier Olislagers reinierolislagers at gmail.com
Tue Oct 2 20:49:36 CEST 2012


Hi list,

For a fpcunit database test listener I'm implementing multi-connector
support using TSQLConnector. This seems to work nicely.

If the Firebird connector is chosen and the hostname is empty, I assume
Firebird embedded is used and if not present, a database needs to be
created using .CreateDB

For this, I need TIBConnection-specific CreateDB. Currently I've managed
to do that with the Proxy property of the TSQLConnector, which however
is protected.
Also it appears CheckProxy is needed:

{ THackSQLConnector }
THackSQLConnector = class(TSQLConnector)
  //we really only want access to a working proxy
private
  function GetProxyConnector: TSQLConnection;
public
  Property ProxyConnection : TSQLConnection Read GetProxyConnector;
end;

function THackSQLConnector.GetProxyConnector: TSQLConnection;
begin
  CheckProxy; //seems to be required to get valid proxy
  result:=inherited Proxy;
end;

and

var
FConn: THackSQLConnector;
...

  IBConn:TIBConnection;
...
IBConn:=TIBConnection(FConn.ProxyConnection);
IBConn.UserName:=FConn.UserName;
IBConn.Password:=FConn.Password;
IBConn.DatabaseName:=FConn.DatabaseName;
...
IBConn.CreateDB;

Is that the best/easiest way? Would it make sense to make the proxy code
in TSQLConnector public?



More information about the fpc-pascal mailing list