[Zope-DB] TAL and empty sql-list

Jonas Nielsen jonasn at mail.tele.dk
Mon Mar 20 06:01:55 EST 2006

I have an sql statement that given a username it returns a project.

So my first question is: Is it possible to let the statement return a 
string instead of a list. i.e. 'project' instead of ['project'] ?

So, if call it from a page template, I can use

<div tal:content="python:here.project(uname=username)[0].project" />

But if the project method returns an empty list, this statement will 
fail (because of [0]).

So what is a smart solution to this ? I've tried putting a repeat 
statement around this, and tried defining a variable called projectExist 
using len on the function. This however makes the page template very 
complex when calling another sql method such as:

                                project=projectList[0].project)" />

if I'm using, say, the Python Database API I would just call fetchone() 
on the cursor object. It is that functionality I am looking for.

More information about the Zope-DB mailing list