[Zope] urgent! wrong query results on next/previous urls in ZSQL/Zsearch

k0878290@tiscali.de k0878290@tiscali.de
Thu, 27 Feb 2003 11:01:16 +0100


Hi folks,

I'm 3 days before rollout of my first Zope project and now discover my ZS=
QL
/ Z Search Interface yields wrong query results!
Only the first 20 query results are o.k., navigating around with next/pre=
vious
"forgets" the user search form inputs constructing the SQL WHERE clause.

Details:

1. I Use Zope 2.6.0 with python 2.1.3 and mysql 3.23-48.
2. First I created a zsql method:
select * from usertable
<dtml-sqlgroup where>
   <dtml-sqltest Userid op=3Dlike type=3Dnb optional>
<dtml-and>
   <dtml-sqltest Nachname op=3Dlike type=3Dnb optional>
<dtml-and>
   <dtml-sqltest Vorname op=3Dlike type=3Dnb optional>
</dtml-sqlgroup>

3. Then I added an Z Search Interface, which produced the following
page templates:
##########################################################
...
<form action=3D"fp1b" method=3D"get">
<h2 tal:content=3D"template/title_or_id">Title</h2>
Enter query parameters:<br><table>

<tr><th>Userid</th>
    <td><input name=3D"Userid"
               width=3D30 value=3D""></td></tr>
<tr><th>Nachname</th>
    <td><input name=3D"Nachname"
               width=3D30 value=3D""></td></tr>
<tr><th>Vorname</th>
    <td><input name=3D"Vorname"
               width=3D30 value=3D""></td></tr>
<tr><td colspan=3D2 align=3Dcenter>
<input type=3D"SUBMIT" name=3D"SUBMIT" value=3D"Submit Query">
...
##########################################################
...
  <body tal:define=3D"results here/fp1user_query_sqlmethode_argu;
                    start request/start|python:0;
                    batch python:modules['ZTUtils'].Batch(results,
                                                          size=3D20,
                                                          start=3Dstart);=

                    previous python:batch.previous;
                    next python:batch.next">

  <p>
    <a tal:condition=3D"previous"
       tal:attributes=3D"href string:${request/URL0}?start:int=3D${previo=
us/first}"
       href=3D"previous_url">previous <span tal:replace=3D"previous/lengt=
h">20</span>
results</a>
    <a tal:condition=3D"next"
       tal:attributes=3D"href string:${request/URL0}?start:int=3D${next/f=
irst}"
       href=3D"next_url">next <span tal:replace=3D"next/length">20</span>=
 results</a>
  </p>

  <table border>
        <tr>
          <th>Userid</th>
          <th>Vorname</th>
          <th>Nachname</th>
        </tr>

  <div tal:repeat=3D"result batch" >

         <tr>
          <td><span tal:replace=3D"result/Userid">Userid goes here</span>=
</td>
          <td><span tal:replace=3D"result/Vorname">Vorname goes here</spa=
n></td>
          <td><span tal:replace=3D"result/Nachname">Nachname goes here</s=
pan></td>
        </tr>
...

    <a tal:condition=3D"previous"
       tal:attributes=3D"href string:${request/URL0}?start:int=3D${previo=
us/first}"
       href=3D"previous_url">previous <span tal:replace=3D"previous/lengt=
h">20</span>
results</a>
    <a tal:condition=3D"next"
       tal:attributes=3D"href string:${request/URL0}?start:int=3D${next/f=
irst}"
       href=3D"next_url">next <span tal:replace=3D"next/length">20</span>=
 results</a>
  </p>
...
#########################################################

4. A direct test of the ZSQL in the test tab works perfectly, e.g. search=
ing
all userids starting with C produces 20 results, you click "next 20 resul=
ts"
and get the next 20 hits and so on.

5. When using the Zope-generated Z Search page templates, you can also
choose your query parameter C% and get the first 20 hits correctly.
BUT: IF YOU NOW PRESS NEXT 20 RESULTS, YOU GET THE 20 VERY FIRST ROWS OF
THE WHOLE TABLE!

6. A MySql Trace shows that the first query is
   SELECT * FROM usertable WHERE userid LIKE C%; this is fine

   clicking the "next url" yields another query with
   SELECT * FROM usertable;

7. Obviously something must be wrong with the "next url":
<a tal:condition=3D"next"
       tal:attributes=3D"href string:${request/URL0}?start:int=3D${next/f=
irst}"

It does not know about the SQL query parameters from the first call!?

8. Any ideas how to navigate correctly through this ZSQL result ?
   When I compare to the ZSQL test tab, there a much longer url is compos=
ed
when going to the "next 20 results" link.

Regards

Peter





__________________________________________________________________
Tiscali Mobile
NEU! Die neuesten Klingelt=F6ne, Logos, Mailboxspr=FCche, Bildmitteilunge=
n und
Screensaver f=FCr alle Handytypen.
Einfach und g=FCnstig!
Klicken Sie hier: http://www.tiscali.de/mobile/