3.1.1.2.1 Processing for Maintaining a Hierarchical RecordSet
RecordSets manage multiple tables in the same RecordSet by nesting child RecordSets. This enables scenarios where clients can change parent tables and have dependent changes against child tables and then send the entire list of changes grouped together to the data store.
The tables can be related to each other using the data shaping language. In the RecordSet model, the RecordSet has a parent table. The parent table can have an arbitrary number of child RecordSets.
The data shaping language described in section 3.3.5.2.4 allows the implementer to specify a command that creates a hierarchical RecordSet. For instance, the following Shape command will create a hierarchical RecordSet with a top level table.
-
SHAPE { select EmpID, EmpName from Employee } AS Employee APPEND ( { select EmpID, ProjectName from Projects } AS Projects RELATE EmpID TO EmpID )
This example assumes that the data store contains an Employee table with EmpID and EmpName columns, and a Projects table with EmpID and ProjectName columns. It also assumes that these tables are related by a primary key-foreign key relationship around EmpID. The following diagram shows the table structure.
Figure 2: Table structure example
In this example, the Employee table is the parent table and the Projects table is the child table.
Looking at both the RecordSet that is constructed in memory and the result that is encoded in an adtgTablegram, it is apparent that the RecordSet contains a third column in the Employee table. This third column is the chapter column and contains the necessary syntax from the shape command to define the relationship between the parent table and the child table. For more information, see the RelationConditions description in section 2.2.3.14.3.7.
The parent to child relationship is managed in the RecordSet object, as described in section 3.1.1.2. The column metadata information portion of the adtgTablegram shown in section 2.2.3.14.3 encodes the RelationConditions and CalculationInfo fields. When a column that has the property IsChaptered is set to TRUE, the RecordSet encoding algorithm SHOULD include the RelationConditions and CalculationInfo fields. Setting the IsChaptered property to TRUE is represented in an adtgTablegram by setting the DBCOLUMNFLAGS_ISCHAPTER bit of the column's ColumnFlags to 1. For more information, see section 2.2.3.14.3.6.