[Zope-DB] ZSQL Method dictionaries() failing - Please help!
Samir Mishra
SamirMishra@cbuae.gov.ae
Wed, 21 May 2003 08:34:36 +0400
Everyone, thank you for your help on this matter.
Summary
-------
It seems ZODBC is not returning the objects I expected.
After considering all the advice, trying a few things out, I was able to get
the following code (below) to work -
# return results from holidays table in DB
recordset = context.viewHolidays()
header = ""
headul = ""
for varname in recordset.names():
header = header + varname + "\t\t"
headul = headul + "-" * len(varname) + "\t\t"
print header
print headul
nrec = 0
# below will print each row twice, this is sample code,
# meant to show that the same thing can be done in 2 ways
for record in recordset:
nrec = nrec + 1
print "%s\t%s" % (record['date'], record['occasion'])
print "%s\t%s" % (record.date, record.occasion)
print "\n" + "-" * 40 + "\n"
print "Records in Query =", nrec
print "\n" + "-" * 40 + "\n"
return printed
-----Original Message-----
From: Jim Penny [mailto:jpenny@universal-fasteners.com]
Sent: Tuesday, May 20, 2003 19:36
To: zope-db@zope.org
Subject: Re: [Zope-DB] ZSQL Method dictionaries() failing - Please help!
On Tue, May 20, 2003 at 11:27:59AM -0400, jwsacksteder@ramprecision.com
wrote:
> > I connecting to a MS SQL Server using ODBC on Win2000.
>
> A-ha.
>
> > On the other hand, to get the contents of the table 'holidays', when I
> > execute context.getHolidays().dictoinaries(), I get -
> > Error Type: AttributeError
> > Error Value: DatabaseResults instance has no attribute 'dictionaries'
>
> ZODBCDA does not support dictionaries.
> See the following posts.
>
> http://mail.zope.org/pipermail/zope-db/2002-September/000889.html
>
> and more irritatingly...
>
>
http://mail.python.org/pipermail/zope-collector-monitor/2002-August/000894.h
> tml
>
> You can still access your results ordinally by position-
>
> dataset=misc_sql()
> for row in dataset:
> print row[0]
If you need to access by name, and I often do, you can do something like:
dataset=container.misc_sql()
names=dataset.names()
for i in range(len(names)):
names2i[names[i]]=i
Then you can access field name misc_col in row i as
dataset[i][names2i['misc_col']]
Jim Penny
>
> will print the 1st column of each row by position, not name. It works, but
> you must be careful to preserve the order of your result columns. Two
other
> ways to get data from ms-sql are mxODBC(commercial) or the remote ODBC DA
> included in Zdataquerykit.
>
> _______________________________________________
> Zope-DB mailing list
> Zope-DB@zope.org
> http://mail.zope.org/mailman/listinfo/zope-db
>
_______________________________________________
Zope-DB mailing list
Zope-DB@zope.org
http://mail.zope.org/mailman/listinfo/zope-db