[Zope] how do I get field names from a query

Jim Sanford jsanford@atinucleus.com
Wed, 31 May 2000 10:14:59 -0500


You need an external method to get the dictionary object that has the field name 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>
</dtml-comment>
<html><head><title>Test</title></head><body>

<dtml-with "_.namespace(t1=Your_Query_Here(),t2=getRes('Your_Query_Here()'))">
<hr>
<dtml-in t1>
  <dtml-in t2 sort=sequence-item>
    <dtml-var "_['sequence-key']"> = <dtml-var "_.getitem(_['sequence-key'])" html_quote><br>
  </dtml-in><hr>
</dtml-in>
</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 )