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? I'm looking for something like the sequence-item tag, where the name of the variable itself isn't needed. Those entry/variables are pushed onto the name space, but I'm not sure how to access the name space to get those variables. Our location is using Zope 2.6 and Python 2.1.3 The context to this is we are building a generic SQL adaptor from scratch using Zope. The modify function (calling an UPDATE SQL method) contains 2 Forms, one to search for applicable entries and the second to narrow down the search of entries to modify. Both use a SQL method that searches the database. The method is called from <dtml-in "SQL_method(variables)". When it returns those entries we have to hand-code all those names/values to be changed into the function itself, for each table, and each database. This would be much easier if there was a way to call the database fields returned from a <dtml-in select_all_method> without explicitly naming the fields. If anyone knows how to call those variables in a generic way, or has a better way for doing this than we've described, please let us know. Thanks in advance. -- Lalo Castro Programmer/Analyst McHenry Library (831) 459-5208
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.... """ 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
participants (2)
-
Lalo Castro -
Maik Jablonski