Next Chapter | Up | Next Section | Contents

The relational data object model


Data that are returned from relational database queries as sequences of Python objects. Because each query result is a sequence, the DTML in tag and the Python for statement may be used to iterate over results. Each element in a result sequence is a Python object that encapsulates a single record of a result table. The Python objects that encapsulates result records are called record objects.

Record objects provide access to result data by column name. Result columns are available as both attributes and as mapping keys of record objects. This allows columns to be accessed with simple DTML var tags inside in tags when iterating over query results. For example, consider a Z SQL Method named customers that returns columns CUSTOMER_ID , NAME , and PLANET . From DTML, the customer names can be accessed with:

<!--#in customers-->

<!--#var NAME-->

<!--#/in-->

and from Python, the customer names can be accessed with:

for customer in customers():

print customer.NAME

or

for customer in customers():

print customer[`NAME']

Column data can also be accessed using integer column numbers. Each record object is a sequence of column values. For example, the data for a record can be output without use of column names in DTML:

<table>

<!--#in customers-->

<tr>

<!--#in sequence-item-->

<td><!--#var sequence-item--></td>

<!--#/in-->

</tr>

<!--#/in-->

</table>

and in Python:

for customer in customers():

for data in customer:

print data

Next Chapter | Up | Next Section | Contents