Several users having problem accessing field names of a ZSQL Method
I am a new Zope user and am attempting to access field names of a ZSQL method. I have read and tried to use the How-To : "Access the field names and fields of any arbitrary ZQSL query" by teyc. The code suggested there has not worked. For example, when I use the code: <dtml-in SQL.names> <dtml-let vname=sequence-item vvalue="SQL()[0][_['sequence-index']]"> <dtml-var vname>, <dtml-var vvalue><br> </dtml-let> </dtml-in> I get the error: Error Type: KeyError Error Value: SQL.names I have nested the above code in code that references a ZSQL method, as well as trying several other permutations, but nothing has worked. I'm wondering if this is a name lookup problem. In checking this news group I see that several others have had similar problems. See: http://zope.nipltd.com/public/lists/zope-archive.nsf/Main?SearchView=++&Star... Can anyone tell me (us) how to correctly do this, or what mistake I (we) am making. Version information: Zope version: Zope 2.1.6 (binary release, python 1.5.2, win32-x86) Python version: 1.5.2 (#0, Jul 30 1999, 09:52:18) [MSC 32 bit (Intel)] Regards, David H. Jones Boeing Phantom Works, Mathematics and Computing Technology 425-865-6924 425-865-2964 (FAX) david.h.jones@boeing.com
~ ~ I am a new Zope user and am attempting to access field names of a ~ ZSQL method. I have read and tried to use the How-To : "Access ~ the field names and fields of any arbitrary ZQSL query" by teyc. ~ The code suggested there has not worked. ~ ~ For example, when I use the code: ~ ~ <dtml-in SQL.names> ~ <dtml-let vname=sequence-item ~ vvalue="SQL()[0][_['sequence-index']]"> ~ <dtml-var vname>, ~ <dtml-var vvalue><br> ~ </dtml-let> ~ </dtml-in> ~ ~ I get the error: ~ Error Type: KeyError ~ Error Value: SQL.names ~ ~ I have nested the above code in code that references a ZSQL ~ method, as well as trying several other permutations, but nothing ~ has worked. I'm wondering if this is a name lookup problem. ~ ~ In checking this news group I see that several others have had ~ similar problems. See: ~ ~ http://zope.nipltd.com/public/lists/zope-archive.nsf/Main?SearchVi ew=++&Start=1&Count=20&SearchOrder=1&ExactMatch=&SearchOrder=1&Query=sql.nam es Can anyone tell me (us) how to correctly do this, or what mistake I (we) am making. I think i can tell you. When zope encounters something inside quotes, it generally treats it as a python expression. Python is treating what you thought was a hyphen as a minus sign and trying to subtract the variable "index" from the variable "sequence" in this line of code: <dtml-let vname=sequence-item vvalue="SQL()[0][_['sequence-index']]"> The easy solution is to name your variable sequence_item instead of sequence-item. I think there's also a way to actually name a variable sequence-item, but it involves an underscore and parens _( ) and some more funky syntax, but it's a lot easier to just stop using hyphens in variable names. hth, ~c Version information: Zope version: Zope 2.1.6 (binary release, python 1.5.2, win32-x86) Python version: 1.5.2 (#0, Jul 30 1999, 09:52:18) [MSC 32 bit (Intel)] Regards, David H. Jones Boeing Phantom Works, Mathematics and Computing Technology 425-865-6924 425-865-2964 (FAX) david.h.jones@boeing.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 )
Below is the dtml code for a DTML document I have written to return the results of any SQL query as an html table in groups of 50. Query.QuickSQL() takes as an argument a complete SQL statement. "sqlStatement" is the REQUEST variable with the SQL statement. You can replace the query with your own ZSQL query. getRes is an external python method, here it is: ------------------------------------ def getRes(self, zQry) : tvar1 = 'res=self.'+zQry exec tvar1 tc1=res._schema.items() return tc1 ---------------------------------------- this came out of a function module I wrote that has all the imports at the top. You may need to "import sys" for this to work. I don not recall. __________________________________________________________________ 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 __________________________________________________________________ DTML Document Code below _________________________________________________________________ <html><head><title>SQLResult</title></head><body> <dtml-var sqlStatement><br><br> <dtml-with "_.namespace(t1=getRes('Query.QuickSQL()'), t2=Query.QuickSQL())"> <dtml-call "REQUEST.set('colList',[])"> <dtml-in t1> <dtml-call "colList.append([_['sequence-item'],_['sequence-key']])"> </dtml-in> <dtml-call "colList.sort()"> <dtml-in t2 size=50 start=query_start> <dtml-if sequence-start> <dtml-if previous-sequence> <a href="<dtml-var URL><dtml-var sequence-query
query_start=<dtml-var previous-sequence-start-number>"> (Previous <dtml-var previous-sequence-size> results) </a> </dtml-if previous-sequence> <table border=1> <tr> <dtml-in colList> <dtml-let tlist="_['sequence-item']" tname="tlist[1]"> <th><dtml-var tname html_quote></th> </dtml-let> </dtml-in> </tr> </dtml-if> <tr> <dtml-let titem="_['sequence-item']"> <dtml-in colList> <dtml-let tlist="_['sequence-item']" tcol="tlist[0]"> <td><dtml-var "titem[tcol]" html_quote newline_to_br></td> </dtml-let> </dtml-in> </dtml-let> </tr> <dtml-if sequence-end> </table> <dtml-if next-sequence> <a href="<dtml-var URL><dtml-var sequence-query query_start=<dtml-var next-sequence-start-number>"> (Next <dtml-var next-sequence-size> results) </a> </dtml-if next-sequence> </dtml-if sequence-end> </dtml-in> </dtml-with> </body></html>
participants (3)
-
Charlie Derr -
Jim Sanford -
Jones, David H