Data Model > Extending the UNICOM Intelligence Data Model > Creating a CDSC > Handling hierarchical data > VDATA and HDATA examples > Implementing SELECT for HDATA
 
Implementing SELECT for HDATA
Selecting columns from HDATA hierarchical tables requires more effort than selecting columns from VDATA. The HDATA tables are on various levels, so the Command and DataBinding objects require a level notation. The Command level indicates on which level of the hierarchical data the Command operates, and similarly the DataBinding level indicates on which level the column is situated. In addition, the Provider can create a Command object only at the root level, and a Command object can create a new Command object only on an immediate child level.
When the Provider wants to retrieve the data for the Area, Age and Transport variables from the data source, the Provider uses the Source object's CreateCommand method to create a new level 0 Command object. It adds two DataBinding objects to this command: one for the variable Area at the root level, and one for the child table representing the Person level. When the CDSC receives the Person table binding, it immediately creates a child Command object to navigate the Person-level data, and stores a pointer to this Command in the Value object for the table binding. The Provider then retrieves this child Command pointer, and adds two bindings to it: one for the variable Age at the Person level, and one for the child table representing the Vehicle level. Again, when the CDSC receives the Vehicle table binding, it immediately creates another child Command object to navigate the Vehicle-level data, and stores a pointer to this Command in the Value object for the table binding. The Provider then adds to this third Command pointer a single binding for the variable Transport at the Vehicle level.
When the Provider calls the MoveFirst method on the root-level Command, the CDSC loads the value North into the Value object from the Area DataBinding, and prepares the Person-level child Command to access the records in the Person table that correspond to the first household. When the Provider then calls MoveFirst on the Person Command, the CDSC loads the value 30 into the Age Value object, and prepares the Vehicle-level child Command to access the records in the Vehicle table that correspond to the first person in the that household. The Provider then calls MoveFirst, then MoveNext repeatedly, on the Vehicle Command object, retrieving the values from its Transport Value object, until its EOF property is True, which means that it has reached the end of the records for the first person in the first household. Next, the Provider calls MoveNext on the Person Command, and the CDSC loads 28 into the Age Value and prepares the Vehicle Command to access the Vehicle records for the second person in the first household. Again, when EOF is True on the Vehicle Command, the Provider calls MoveNext on the Person Command, and when EOF is True on that Command (meaning that all the Person records have been read for the first household), the Provider calls MoveNext on the root-level Command. This is the signal for the CDSC to prepare the Person Command to access records for the people in the second household, and so on.
See also
VDATA and HDATA examples