ghkweon / dwscript

Automatically exported from code.google.com/p/dwscript
0 stars 0 forks source link

Make it possible for the host app to provide connection obj for the TdwsDataBase #410

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Currently the TdwsDataBase gets the driver name and connection info as the 
parameters from the script, but sometimes it is desirable that the "script 
user" wouldn't know the connection details (especially user name and password). 
So make an overloaded constructor where script user provides only datasource 
name and then the host app provides the "connection object" (ie in the case of 
TdwsUIBDataBase host provides the fully initialised TUIBDataBase) for the 
script engine (perhaps via an OnGetDatabaseConnection event). By the datasource 
name I mean an string which would have meaning only for the host app not some 
ODBC datasource name or some such.
So in the script side user would write

var db := DataBase.Create('customers');

which would fire event in the host app:

procedure DWS.OnGetDatabaseConnection(const aDatasourceName: string; var 
aDriver: TObject);
begin
  if(aDatasourceName = 'customers')then aDriver := FDatabase;
end;

Original issue reported on code.google.com by ain.val...@gmail.com on 31 May 2013 at 3:22

GoogleCodeExporter commented 8 years ago
And the host app should be responsible for the database object it exposes to 
the script so there should also be an OnDisconnect event so that the host knows 
that the script has finished with it and can free (it in case the host itself 
doesn't need it for other connections).

Original comment by ain.val...@gmail.com on 31 May 2013 at 3:34

GoogleCodeExporter commented 8 years ago
Made the UIB driver subclassing friendly.

So you can just subclass it, and provide your own factory, where you can pass 
existing objects and assign them.

If you call the inherited constructor, it'll create the transaction if not 
already defined. Be sure to override the destructor and nil the DB if you don't 
want it freed. (same for the transaction if you want it created externally).

Original comment by zar...@gmail.com on 5 Jun 2013 at 6:52