[Zope] connet to MS-SQL database with ython script from with
in zope
Stuart Nicholson
stuart.nicholson@wirelessdatanz.com
Tue, 19 Feb 2002 08:30:30 +1300
I think you'll find these are 'r for Record' instances returned from the sql object. From memory you should be able to do things like
for r in results:
print r['MySQLFieldName']
print r[0]
or alternately r[0]['MySQLFieldName'] or r[0][0] to access the first record field values.
Where each record contains a field called 'MySQLFieldName' and r[0] gets you the 'first' SQL field value returned from your query as a string, r[1] gets the second SQL field
value etc. etc.
So to print every field of every record you could do something like:
for rec in results:
for fieldName in rec.keys():
print fieldName, ' = ', rec[ 'fieldName' ]
Hope that helps (and I may be wrong, been a couple of months since I've worked with Zope SQL interface).
Stuart Nicholson
-----Original Message-----
From: Tim Hicks [mailto:tim@sitefusion.co.uk]
Sent: Tuesday, 19 February 2002 8:20 AM
To: mbagepll@memphis.edu
Cc: zope@zope.org
Subject: Re: [Zope] connet to MS-SQL database with ython script from
with in zope
> Hi Tim,
> I did exactly as you told me to do. The following is the python script
>
> sql="Select * from LinkArea"
> results = container.sql_method(the_sql=sql)
> for i in results:
> print i
> return printed
>
> and below is the ZSQL method:
> <dtml-var the_sql>
>
> when i do this, it gives me the instances, something like this..
> <r instance at 01674978>
> <r instance at 015DAED0>
> <r instance at 01674978>
> <r instance at 015DAED0>
>
> I do not understand this.
ZSQL methods return special objects ('pluggable brains' I believe they are
called - I'm sure someone will correct me if I'm wrong). Try this to see
how to use them from python scripts (dtml docs/methods have some magic that
makes it easy transparent)...
-------
sql="Select * from LinkArea"
results = container.sql_method(the_sql=sql)
headings = results.names() # names() gives you the column headings
print headings
for row in results:
for heading in headings:
print row[heading]
return printed
--------
There's also a dictionaries() method on the result object that is very
helpful. I know there are more posts on this in the list archives as well.
hth
tim
_______________________________________________
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 )
----------------------------------------------------------------------
The information contained in this communication is intended solely for the use of the individual or entity to whom it is addressed and others authorised to receive it. It may
contain confidential or legally privileged information.
If you are not the intended recipient you are hereby notified that any disclosure, copying, distribution or taking any action in reliance on the contents of this information is
strictly prohibited and may be unlawful.
If you have received this communication in error, please notify us immediately by responding to this email and then delete it from your system.
Wirelessdata Ltd is neither liable for the proper and complete transmission of the information contained in this communication nor for any delay in its receipt.
----------------------------------------------------------------------