[Zope] SQL Methods and namespace question

Rik Hoekstra hoekstra@fsw.LeidenUniv.nl
Tue, 14 Dec 1999 15:11:57 +0100


This problem has been bugging for a long time now and I can't seem to find
the answer.

I have a database that is searchable with SQL methods. in simple mode the
SQL method and the Search Interface work well.

Now the problem is when I have a form, which (i thought) would have to be
extensible. So I thought to use record-based input forms, like this

                                            <searchitem.searchterm:records>
# record 1
<searchitem.connector:records (AND/OR/NOT)> <searchitem.searchterm:records>
# record 2
<searchitem.connector:records (AND/OR/NOT)> <searchitem.searchterm:records>
# record 3
                    .
                    .
                    .

At the moment this has only two fields, but it could also be extended to
have a choice of other search fields (Author, Title, Publishing year....),
but let's keep it simple. In theory this would be extensible ad nauseam

The SQL Method then has the following code to build a query string

<dtml-in searchitem>
   <dtml-if sequence-start>TITEL LIKE <dtml-var
          expr="'%s%s%s%s%s' %(chr(39), '%', 'searchterm', '%', chr(39))">
   <dtml-else><dtml-var
        connector> TITEL LIKE <dtml-var
        expr="'%s%s%s%s%s' %(chr(39), '%', searchterm, '%', chr(39))">
   </dtml-if>
</dtml-in>

Whatever I try, this fails with a KeyError for a Key 0

I tracked this down to the dependance of SQL Methods the regular REQUEST
keys. If this is right, it means the 'searchterm' and 'connector' of the
example would not be available which would explain the KeyError. I found
this particularly hard to find out, as using SQL Methods is indirect and
database errors may also get in the way.

A few questions:
- is my analysis correct, or am I way off track
- if it is correct, why does it work this way
- how can I make this work (I can come with workarounds myself, the point is
they all lack flexibility)

Rik