Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2012-10

Using database-specific functionality with TSQLConnector

4 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Reinier Olislagers

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?

Reply by email

LacaK
to Reinier Olislagers

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.

Show quoted text 51 lines
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 - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Unknown author
to Reinier Olislagers: For a fpcunit database test listener I'm implementing multi-connector support using…
Reinier Olislagers wrote 14 lines
Hi list, 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?

No. The whole idea is just to hide it.

What you want to do is not supported, and is not meant to be supported.

To do what you want, we'd need to promote CreateDB to TSQLConnection, and let descendants handle it if they can.

Then it can be delegated to the proxy in TSQLConnector.

Michael.

Reply by email

Reinier Olislagers
to Unknown author
Show quoted text 22 lines
On Tue, 2 Oct 2012, Reinier Olislagers wrote: > Hi list, > > > 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? To do what you want, we'd need to promote CreateDB to TSQLConnection, and let descendants handle it if they can. Then it can be delegated to the proxy in TSQLConnector.

Ok.

Reply by email