[Zope] Re: accessing dtml-in SQL variables
Maik Jablonski
maik.jablonski at uni-bielefeld.de
Fri Dec 19 04:49:08 EST 2003
Lalo Castro wrote:
> Hi,
> What is the syntax (if it exists) for accessing SQL fields from a
> <dtml-in>? For example, say you had a SQL method that performed a
> 'select * from data_base'. If you called that SQL method by <dtml-in
> "SQL_method(variables)"> that would return the entries in the database.
> Then you could directly show those entries using the names of the
> database fields as variables.
> But, how could you call those entries (variables) without explicitly
> using the names of the database fields?
Please read the Zope-Book before asking on a list. It's all explained there:
http://zope.org/Documentation/Books/ZopeBook/2_6Edition/RelationalDatabases.stx
""" Other Result Object Methods
Up to now we have just been iterating through the attributes of the
Result object in DTML. The result object does however provide other
methods which can be easier in some situations. These methods can be
accessed from Python scripts, page templates and from DTML. For example
in Python we could write:
len(result)
this will show the number rows returned
result.names()
a list of all the column headings
result.tuples()
returns a list of tuples
result.dictionaries()
will return a list of dictionaries, with one dictionary for each row
result.data_dictionary()
returns a dictionary describing the structure of the results table.
The dictionary has the key name, type, null and width. Name and type are
self explanatory, null is true if that field may contain a null value
and width is the width in characters of the field. Note that null and
width may not be set by some Database Adapters.
result.asRDB()
displays the result in a similar way to a relational database.
result[0][1]
return row 0, column 1 of the result, bob in this example. Be
careful using this method as changes in the schema will cause unexpected
results.
"""
Cheers, Maik
More information about the Zope
mailing list