Mailing List Archive

Problem wiith dtml-sqltest variable and multiples values into one parametert ???
Hi,



(Zope 2.8.6-final, python 2.3.5, win32, ZMySQLDA 2.0.8)



I have created a "Z Search Interface" to select some data from MySql
table.



In "search form" (Page Template), I have created a select field (called
"select_keys") to select one or more keys words (from MySQl table). On
submit, with javascript, I fill an hidden field called "ref_fiche" where
I put a list (JS array) of value select in field "select_keys", for
example, value can be : f1 or f1,f4,f2, etc



"Search form" use "result_form" which use a "Z SQL Method" where the SQL
is write like this : SELECT titre, descriptif, gestionnaire, coord_gest,
URL FROM reference_fiche WHERE (<dtml-sqltest ref_Fiche type="string"
multiple>) This Z SQL Method had one parameter called "ref_fiche".



Well, from search form, when I select one key word, all works fine: one
result is found and display, but when I select several keys words, SQL
doesn't works, I get this Zope message :



**********************

SQL used:

SELECT titre, descriptif, gestionnaire, coord_gest, URL FROM
reference_fiche WHERE (ref_Fiche = 'f1, f4')



**********************



Also, I test with "test" tab of "Z SQL method", it's the same, when I
put "f1" in parameter field, that's work but if I put "f1,f2" (list)
that's doesn't work (I get message above) (alos I tried : "f1","f2" and
'f1','f2', etc, etc, but without success)



Zope documentation says about dtml-sqltest variable and multiple
argument;
http://zope.org/Documentation/Books/ZopeBook/2_6Edition/RelationalDataba
ses.stx
<http://zope.org/Documentation/Books/ZopeBook/2_6Edition/RelationalDatab
ases.stx>



**********************

multiple

A flag indicating whether multiple values may be provided. This lets
you test if a column is in a set of variables. For example when name is
a list of strings "Bob" , "Billy" , <dtml-sqltest name type="string"
multiple> renders to this SQL: name in ("Bob", "Billy").

**********************



but, in Zope message above, the SQL used which I see "(ref_Fiche = 'f1,
f4')" and not "ref_Fiche IN ('f1','f4') Why ?



It's a bug ?



How pass one list parameter ?



Any clues (solutions) are welcome,



Thank you,



Thierry
Re: Problem wiith dtml-sqltest variable and multiples values into one parametert ??? [ In reply to ]
Quoting CERETTO Thierry <t.ceretto@chu-nancy.fr>:
> In "search form" (Page Template), I have created a select field (called
> "select_keys") to select one or more keys words (from MySQl table). On
> submit, with javascript, I fill an hidden field called "ref_fiche" where
> I put a list (JS array) of value select in field "select_keys", for
> example, value can be : f1 or f1,f4,f2, etc

...
> but, in Zope message above, the SQL used which I see "(ref_Fiche = 'f1,
> f4')" and not "ref_Fiche IN ('f1','f4') Why ?
>
> How pass one list parameter ?

I can't tell without reading more widely if one could pass a list
parameter but the behavior as you describe it indicates that you
should not be passing a single variable that contains a list. Instead
you should be passing multiple parameters all called ref_Fiche with
different values. For example, if this form were to be sent as a GET
request, you should send ?ref_Fiche=f1&ref_Fiche=f4 rather than
?ref_Fiche=f1,f4 I think the dtml-sqltest is pulling the variables out
of the request object and is seeing a single variable called ref_fiche
and so is constructing the sql that is appropriate to a single
value. To get it to construct something like "ref_Fiche in (f1,f4)"
you will need to have multiple ref_Fiche variables in the request
object.
_______________________________________________
Zope-DB mailing list
Zope-DB@zope.org
http://mail.zope.org/mailman/listinfo/zope-db
Re: Problem wiith dtml-sqltest variable and multiples values into one parametert ??? [ In reply to ]
CERETTO Thierry wrote at 2006-11-29 09:15 +0100:
> ...
>Also, I test with "test" tab of "Z SQL method", it's the same, when I
>put "f1" in parameter field, that's work but if I put "f1,f2" (list)
>that's doesn't work (I get message above) (alos I tried : "f1","f2" and
>'f1','f2', etc, etc, but without success)

"multiple" expects to get a sequence of objects
but HTML/HTTP handles only strings.

Either, you must use Python means to convert the string "f1, f2, ..."
into a list of strings (e.g. "str.split(', ')"),
or use ZPublisher magic (in this concrete case, the ":list" variable
suffix) to let ZPublisher perform the type conversion.

In your special case, using separate "hidden" fields (one for
each list element, all sharing the same name) may be sufficient
(as the ":list" is (almost) the default for this case).

You find a concise description of ZPublisher's magic suffixes in

<http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html>




--
Dieter
_______________________________________________
Zope-DB mailing list
Zope-DB@zope.org
http://mail.zope.org/mailman/listinfo/zope-db