[Zope] Fw: [Zope] how do I get field names from a query
Jim Sanford
jsanford@atinucleus.com
Wed, 31 May 2000 13:33:13 -0500
I am reposting since I realized that I had some extraneous code on the end of my original dtml.
----- Original Message -----
From: Jim Sanford <jsanford@atinucleus.com>
To: Curtis Maloney <curtis@umd.com.au>; Zope List <zope@zope.org>
Sent: Wednesday, May 31, 2000 10:14 AM
Subject: Re: [Zope] how do I get field names from a query
You need an external method to get the dictionary object that has the field names mapped to column number
Here is the external method:
---------------------------------
def doPySQL(self, zQry) :
tvar1 = 'res=self.'+zQry
exec tvar1
return res._schema.items()
------------------------------------------
Here is a dtml document that uses the external method:
(getRes is what I call the external method in Zope)
This was for proof of idea - it is not pretty
-------------------------------------------------------------------
<html><head><title>Test</title></head><body>
<dtml-with "_.namespace(t1=getRes('Your_Query_Here()'))">
<dtml-var "_.len(t1)"> Columns<br>
<dtml-var "_.str(t1)" html_quote><br><br>
<dtml-in t1>
<dtml-var "_.str(_['sequence-key'])"> = <dtml-var "_.str(_['sequence-item'])"><br>
</dtml-in>
<br><br>
</dtml-with>
</body></html>
---------------------------------------------------------------------------------
----- Original Message -----
From: Curtis Maloney <curtis@umd.com.au>
To: Adam Molyneaux <adam.molyneaux@epfl.ch>
Cc: <zope@zope.org>
Sent: Tuesday, May 30, 2000 11:31 PM
Subject: Re: [Zope] how do I get field names from a query
On Wed, 31 May 2000, Adam Molyneaux wrote:
> how do I get the names of the fields returned from a SQL query ?
> ( I would like to generate stuff using the names automatically)
> I know they must be available because I can use them directly !
>
> I've tried lots of alternatives of the form
>
> <dtml-in "sqlListTable(table_name='personnel')">
> <dtml-in sequence-item>
> <P><dtml-var sequence_item>
> </dtml-in >
Ok... someone may have already answered this, but here's my guess. (Yes,
this is untried, sorry :)
<dtml-in "sqlQueryBlah()">
<dtml-in sequence-item>
<dtml-var sequence-key> = <dtml-var sequence-item>
</dtml-in>
</dtml-in>
>
>
> which give me the values but not the names, and looked through lots of the
> old msgs.
I'm certain this was tackled some time in the past, but yeh, searching the
list logs can sometime be suprisingly fruitless.
>
> Thanks in advance if anyone can help
>
glad i could help. (o8
> adam
> adam.molyneaux@epfl.ch
>
--
Have a better one,
Curtis.
<dtml-var standard_work_disclaimer>
_______________________________________________
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 )