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

LacaK lacak at zoznam.sk
Wed Oct 3 08:03:58 CEST 2012


Hm, i see these ways:

1. Add CreateDB/DropDB methods to SQLConnector (like others methods, 
CreateDB is virtual at TSQLConnection level):
procedure TSQLConnector.CreateDB;
begin
  CheckProxy;
  FProxy.CreateDB;
end;

2. Add getter for Proxy property:
function TSQLConnector.GetProxy: TSQLConnection;
begin
  CheckProxy;
  Result := FProxy;
end;

it will be IMO easiest ;-)))
L.

> 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?
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
>   




More information about the fpc-pascal mailing list