I think I might have asked the question a little bit vaguely.
My goal is to simplify the API of the server
I have these tables :
ENTITY (ID)
PERSON (ID, BIRTH, DEATH, GENDER) (FK on ENTITY)
ORGANISATION (ID, CONSTITUTIONDATE) (FK on ENTITY)
LOCATOR (ID, ENTITYID, DATEACTIVE, DATEINACTIVE) (FK on ENTITY)
ADDRESSLOCATOR (ID, ADDRESSID, ADDRESSTYPEID) (FK on LOCATOR, FK on ADDRESS, FK on ADDRESSTYPE)
ADDRESS (ID, LINES, COUNTRY)
Inheritance
--------------------
PERSON is a ENTITY
ORGANISATION is a ENTITY
ADDRESSLOCATOR is a LOCATOR
Each time I want to add a ADDRESSLOCATOR, I also need to add a corresponding LOCATOR. ( It’s a table-per-class hierarchy). (like so Tech Journal: Image)
Similary, each time I want to add a PERSON or ORGANISATION, I have to create the corresponding ENTITY.
For now, the only way I got this to work, is to add, on the client, DAMemDataTables for each of these tables, and define the Master-Child relationships. These DAMemDataTables lie in a DataModule. My form will simply call the Insert / Post / Delete / FieldByName methods to interact with these DAMemDataTables.
To enable the client to add a new PERSON, I have to
1. DAEntityTable.Insert;
2. DAEntityTable.FieldByName ...
3. DAEntityTable.Post
4. DAPersonTable.Insert;
5. DAPersonTable.FieldByName ...
6. DAPersonTable.Post;
7. RDA.ApplyUpdates
------------ CLIENT/SERVER Boundary --------------
8. Server receives updates and apply them
But this is complicated for the client. I would prefer to handle that logic in the server, by having a single “Condensed” table. If I define a table in SchemaModeler like so
// TABLE FULLPERSONTABLE
SELECT ENTITY.ID, PERSON.BIRTH, PERSON.DEATH, PERSON.GENDER
FROM ENTITY
INNER JOIN PERSON ON PERSON.ID = ENTITY.ID
Then, on the INSERT statement somehow updating two tables :
INSERT INTO ENTITY (ID) VALUES (:ID);
INSERT INTO PERSON(ID, BIRTH, DEATH, GENDER) VALUES(:ID, :BIRTH, :DEATH, :GENDER);
Then, the client using this “Interface” would only have to :
1. DAFullPersonTable.Insert;
2. DAFullPersonTable.FieldByName ...
3. DAFullPersonTable.Post;
4. RDA.ApplyUpdate
--------- CLIENT / SERVER Boundary ----------
5. Server handles request
6. Add record in ENTITY table
7. Add record in PERSON table
When you are saying :
Scripts are supported by FireDAC’s TFDScript, but not TFDQuery for example. Is it possible to use this ?
I would really prefer avoiding stored procedures altogether.
In this case at hand, when inserting a record into FullPersonTable, I would have to insert a record in both ENTITY and PERSON table. But that can only happen
- Within a SQL script
- Within a SQL transaction
So,
- With FireDAC, is it possible to use the TFDScript component to be used with SchemaModeler’s Delta commands ?
- Is it possible to override a DeltaCommand by Code (InsertPersonCommand) , so that I could update the two different tables in a single transaction ?