[Zope-DB] Bug: ZopeRDB does not handle empty column names

Thomas_Janke@prisma-edv.de Thomas_Janke@prisma-edv.de
Fri, 23 Nov 2001 17:16:19 +0100

I think, I found a bug. Hopefully somebody will forward this report to the
responsible person.

I executed the following statement successfully with Sybase-isql

SELECT topic_name, count(topic_name)
FROM topics, problems
WHERE topics.topic_id = problems.topic_id
GROUP BY topics.topic_name

This prints a table like this:

 -------------------------------------------------- -----------
 Sybase                                                       1
 Windows2000                                                  2
 ZOPE                                                         7
 test                                                         2
 tre                                                          2

The second column has no name, because it's a calculated column. When executing
the same code within an ZSQL-Method, I get the error

Error: ... : Empty column name,

I also found the snipped of code, which causes the error:
Its in zope/lib/python/Shared/DC/ZRDB/Results.py
in Class Results
in def __init__
        for item in items:
            if not name:
                raise ValueError, 'Empty column name, %s' % name   /* <=== This
is the problem */
            if schema.has_key(name):
                raise ValueError, 'Duplicate column name, %s' % name
            if n != name: aliases.append((n, SQLAlias(name)))
            if n != name: aliases.append((n, SQLAlias(name)))

After testing for a while and trying to persuate ZRDB to accept empty column
names, I found a better way. I changed the first line of my code into:
SELECT topic_name, problems = count(topic_name)

so I gave it a name and worked arround the problem.

Just one question remaines. Why is it not possible to have the number of the
column as the column name, if there is none?
I hope, this really is seen as a problem too and somebody will go and find a
more flexible solution for it.


PS: WHOW!! Did I really write that much stuff? 8)