how to get the fields returned SQL method
Hello, I'm trying to get a list of fields returned by a dynamic SQL query. I've found a howto telling me to write something like : <dtml-in SQL.names> <dtml-var sequence-item> </dtml-in> But it doesn't work : I get the error "Attribute Error : names". I've tried with .items, .keys and .fields too. I'd like to do the same for an LDAP query. Any idea ? I think it's very useful and that an easy way exists but I can't find it. Thanks, EB.
On Fri, 24 Mar 2000, Eric BARROCA wrote:
Hello,
I'm trying to get a list of fields returned by a dynamic SQL query. I've found a howto telling me to write something like : <dtml-in SQL.names> <dtml-var sequence-item> </dtml-in> But it doesn't work : I get the error "Attribute Error : names". I've tried with .items, .keys and .fields too.
I'd like to do the same for an LDAP query.
Any idea ? I think it's very useful and that an easy way exists but I can't find it.
Well, since the SQL will return a list, firsly you would have to index it... also, .keys et al are Python stuff, so...(untested) <dtml-in "SQL[0].keys()"> might be more what you're looking for. Or... <dtml-in SQL> <dtml-in "keys()"> <dtml-var sequence-item> </dtml-in> </dtml-in> should iterate through the keys of each line of the returned table.
Thanks,
EB. -- Have a better one, Curtis.
<dtml-var standard_work_disclaimer>
Okay, a lot depends on what your query is returning. If 'names' is not the name of a column, then ignore the rest of this message ;-) If it is, then try the following: <dtml-in SQL> <dtml-var names><BR> </dtml-in> - If 'SQL' returns a single row and 'names' is a single-valued column, then it should display the value of names. - If 'SQL' returns multiple rows and 'names' is a single-valued column, then it should display the value of names for each row returned on a seperate line. - If names is a multi-valued column then you should get something like [...,...,...] for each row returned. cheers, Chris If names is a single-valued column then the following should work Eric BARROCA wrote:
Hello,
I'm trying to get a list of fields returned by a dynamic SQL query. I've found a howto telling me to write something like : <dtml-in SQL.names> <dtml-var sequence-item> </dtml-in> But it doesn't work : I get the error "Attribute Error : names". I've tried with .items, .keys and .fields too.
I'd like to do the same for an LDAP query.
Any idea ? I think it's very useful and that an easy way exists but I can't find it.
Thanks,
EB.
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
participants (3)
-
Chris Withers -
Curtis Maloney -
Eric BARROCA