You are not logged in.
I initialize mORMot like below
FConnProps := TSQLDBFireDACConnectionProperties.Create(GetServer, GetDatabase, GetUsername, GetPassword);
FSQLModel := TSQLModel.Create([TSQLCustomer]);
VirtualTableExternalRegister(FSQLModel, [TSQLCustomer], FConnProps, 'CUSTOMER');
FRestServerDB := TSQLRestServerDB.Create(FSQLModel, false);
FRestServerDB.CreateMissingTables();
FRestClientDB := TSQLRestClientDB.Create(FRestServerDB);
I have also the client code like
Customers := TSQLCustomer.CreateAndFillPrepare(FRestClientDB, 'SPECIFIC_CUSTOMER_DATABASE', 'SPECIFIC_CUSTOMER_TABLE', 'Company = "mORMot"')
try
while Customers.FillOne do
begin
// ...
end;
finally
Customers.Free;
end;
In the class TSQLCustomer I have the following constructor and would like to have the access to the external db connection properties. Can you built it in?
TSQLCustomer = class(TSQLRecord);
TSQLCustomer.Create(aClient: TSQLRest; const aDatabase, aTable: string; const aSQLWhere: RawUTF8); overload; virtual;
begin
ConProps := TSQLRestClientDB(aClient).Server.ConnectionDefinition;
// OR better
ConProps := TSQLRestClientDB(aClient).Server.ConnectionProperties;
end;
In the current version of mORMot if I call the code below the returned TSynConnectionDefinition object is empty :-(
TSQLCustomer.Create(aClient: TSQLRest; const aDatabase, aTable: string; const aSQLWhere: RawUTF8); overload; virtual;
var
ConnDef: TSynConnectionDefinition;
begin
ConnDef := TSynConnectionDefinition.Create;
try
TSQLRestClientDB(aClient).Server.DefinitionTo(ConnDef);
// ConnDef --> DOESN'T HAVE ANYTHING
finally
ConnDef.Free;
end;
end;
Could you fix it? Or what am I doing wrong?
I hope, this improvement will be helpful for the mORMot framework in general! Thank you, AB, very much for you job! The mORMot is awesome! :-)
Last edited by cypriotcalm (2015-10-09 07:29:15)
Offline
You are mixing here the stored values (i.e. TSQLRecord inherited class), and the mean of storage (TSQLRest).
IMHO you should not define such an overloaded constructor to TSQLCustomer, but create a factory function in your own TSQLRestServer instance.
Offline
You are mixing here the stored values (i.e. TSQLRecord inherited class), and the mean of storage (TSQLRest).
IMHO you should not define such an overloaded constructor to TSQLCustomer, but create a factory function in your own TSQLRestServer instance.
The problem is that I don't know if a database and a table already exist at the time I want to work with them. Their dynamic names are only known at runtime. So, the mORMot should create them if they not exists. How can I achiche this with mORMot?
Offline
This process should be done at the TSQLRest level, not at TSQLCustomer level.
i.e. should create my own TSQLRestServerDB inherited from the TSQLRestServerDB and call in it VirtualTableExternalRegister and .ExternalDB.MapField?
Offline
Or just define a factory method for your TSQLCustomer class, depending on your needs.
A factory method is a method which returns a new class instance, depending on the current context.
Such a method could be implemented where all the needed context is available, may be TSQLRest inherited class, or whatever class you defined in your own code, which knows how to do the table creation if needed.
Certainly not at TSQLCustomer level IMHO.
This would break the http://synopse.info/files/html/Synopse% … #TITLE_330
Offline
Thank you for your advices! I will do it on the proper and right way! :-)
Offline