[Zope] is the return list of an SQL Method a string list

Geir Bækholt Geir Bækholt <geirh@funcom.com>
Thu, 7 Mar 2002 15:28:31 +0100


on or about, Thursday, March 07, 2002, we have reason to believe that Gostn=
err wrote something along the lines of :
G> Hello,
G> i have wirtten a python script like this
G> get_all_cities return a list of cities from a SQL database table:
G> the problem ist, that the if condition is never true ( but there exists =
the Citiy 'new york'  in the table)=20
G> have anybody an idea why this does not work =3F=3F

G> -----------------------------------------------
G> for x in get_all_cities :
G>      if x =3D=3D'New York' :
G>          do something

yes , it is a rather common gotcha when dealing with SQL-results with
only one coloumn..

even if you select only one coloumn with the SQL query , the result
will be a sequence of 'result objects' , not a sequence of strings:

- and , you have to remember to *call* the SQLmethod , not just
address it. .

so , if your database coloumn is called CITY , the script will look
like this :


for x in get_all_cities():
    if x.CITY =3D=3D'New York' :
          do something

:-)

hope to help


--=20
Geir B=E6kholt                      web-developer
geirh@funcom.com             funcom oslo | webdev-team