[Zope] Fw: [Zope] How can I get the fieldname in a dtml-in sqlquery tag

Jim Sanford jsanford@atinucleus.com
Fri, 24 Mar 2000 15:43:52 -0600


I use an external python function to return the SQL result set.

here it is: ( I reference it as an external method called getRes in Zope)
---------------------------------------
def doPySQL(self, zQry) :
    tvar1 = 'res=self.'+zQry
    exec tvar1
    return res._schema.items()
----------------------------------------

This function returns a set of key/value pairs that are the column_name/column number

Here is the dtml document I used for testing: (UserSettings returns info for a user)

-------------------------

<html><head><title>Test</title></head><body>
<dtml-with "_.namespace(t1=getRes('Your_Query_Name_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>
______________________________

This code will give you a listing of column names and values
sorted by column name for every record returned by the SQL Query:

--------------------------

<html><head><title>Test</title></head><body>
<dtml-with "_.namespace(t1=Your_Query_Name_Here(),t2=getRes('Your_Query_Name_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>

__________________________________________________________________

              Jim Sanford
      .       Database Engineer
     / \  /   Accelerated Technology, Inc.
    /   /     720 Oak Circle Drive East
   /  /  \    Mobile, AL 36609
  / /     \   Voice: 334-661-5770  fax: 334-661-5788
 /         \  E-Mail: jsanford@atinucleus.com
              Web: http://www.atinucleus.com

 Nucleus.  All You NEED in an RTOS.  Royalty Free
 __________________________________________________________________




----- Original Message -----
From: jens ebaer <jensebaer@hotmail.com>
To: <zope@zope.org>
Sent: Friday, March 24, 2000 11:04 AM
Subject: [Zope] How can I get the fieldname in a dtml-in sqlquery tag


Hello all


I have the problem that i want to get the fieldnames of database.

code is like this

<dtml-in sqlquery>
Here i want to read out the fieldnames (colums)
</dtml-in>
--------------------------------------------------------------------
database:
Fieldnames: Name Age Birthday ....... <- how can get the fieldnames?
            Peter 21   1979   ........
--------------------------------------------------------------------

maybe that doesn´t work with the dtml-in tag but maybe someone know a simple
solution.

Thank you
Jens
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com


_______________________________________________
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 )