[Zope] SQL query from "Multiple Selection Field"(was: [Zope] [Newbie] ZSQL problem) (was: [Zope] [Newbie] ZSQL problem)

2001-01-04 Thread Dieter Maurer

Hi Michal,

Michal Seta writes:
 > ... query
 >"select ... where col = "
 > works for single value but not for multiple selection ...

This is difficult indeed, as you have to fight
various strange behaviours.

First, it is easy to explain, why your query does not work:

  When you select more then one value from the selection
  list, then "multiple_section" will be a list.
  Your "sqlvar ... type=string" converts this into a string
  that looks like "[ 'a', 'b', 'c']".
  This string is then compared to your database column.
  You easily see, the result will be false.

Your SQL query is not correct to search for a value
in a list of possible values. You must use something
like

 select ... where col in ( 'a', 'b', 'c' )

How to construct such a query?
If you know, that your values do not contain quotes (i.e. '),
then you can use "_.string.join" like this:

 select ... where
 col in (  )

Now, your code will work, when you select more than one value
from the list. It will fail, if you select a single item
(or none at all).

It fails for a single selected value, because in this case
"multiple_selection" is not a list but a single value.
Fortunately, if you put the ":list" suffix at the form
variable name (like ""),
then you tell ZPublisher, that you want this to be a list.
In this case, you will get a list with one value.
This works well...

... up to the case, where no value is selected.


In this case, the variable is completely missing from the
request. You probably will get a "Bad request; missing
arguments ['multiple_selection']" from your ZSQL method.

In your case, it is probably best, to catch this case
in the DTML code that handles your form and report a nice
error.


After you became more familiar with Zope and the rough edges
of HTML form processing, you will hit cases where the above
approach is not adequate.
You can then ask again in the list (or search the searchable
list archive).


Dieter

___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




[Zope] [Newbie] ZSQL problem

2001-01-03 Thread Michal Seta

Hello all.

I'm a total newbie to Zope (a few days).

I have a problem with getting some results throuh a ZSQL method.
(I've been playing with a sample baseball database that came with
PyGreSQL.)


I have a form that accepts multiple choice:  (generated by the wizard)



Home team

Indians
Blue Jays
White Sox
Red Sox







My ZSQL method, called get_all_from_game is the following:

select * from game
where home_team=


and I have specified 1 argument: home_team
--
the output page: search_data_result looks like that:  (it's been
generated by the wizard)



   

  


(Previous  results)


  

  

  Home team
  Visiting team
  Home team runs
  Visiting team runs
  Game date
  Game number


   


  
  
  
  
  
  


   

  
  

 
 (Next  results)
 

  
   



  There was no data matching this  query.



---

When I select one item in the list I get the results as specified in the
SQL query.  However, I get nothing when I select more than one item.
What am I doing wrong?

Thanks in advance.

MiS


___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )