You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by "I. Venuti" <i....@caribel.it> on 2006/03/30 09:39:39 UTC

Expression returning always 0 rows...

Hi,

I'm costructing an Expression for creating a SelectQuery:

final Expression template = Expression.fromString(
    ("db:dt_start=$data or db:dt_fine=$data "+
    "and db:titolo_ita like $titolo and "+
      "(db:titolo_ita like $chiave "+
      "or db:titolo_eng like $chiave "+
      "or db:abs_ita like $chiave "+
      "or db:abs_eng like $chiave "+
     ")").toLowerCase()
    );

I'm expeting that when there are no parameters I can retreave all the 
rows in the table.
Unfortunatly this isn't the case: I alway retrieve 0 rows.
Here is the line executed (from the logger):

INFO  [http-8090-Processor4 03-30 08:32:42] QueryLogger: SELECT 
t0.abs_eng, t0.abs_ita, t0.codfis, t0.descr_eng, t0.descr_ita, 
t0.dt_fine, t0.dt_ins, t0.dt_start, t0.in_home, t0.mostra_data, 
t0.pubblica, t0.tipo, t0.titolo_eng, t0.titolo_ita, t0.id_news FROM 
db.news t0 WHERE (t0.dt_start = (?)) OR ((t0.dt_fine = (?)) AND 
(t0.titolo_ita LIKE (?)) AND ((t0.titolo_ita LIKE (?)) OR (t0.titolo_eng 
LIKE (?)) OR (t0.abs_ita LIKE (?)) OR (t0.abs_eng LIKE (?)))) [bind: '', 
'', '', '', '', '', ''] - prepared in 20 ms.
INFO  [http-8090-Processor4 03-30 08:32:43] QueryLogger: === returned 0 
rows. - took 40 ms.

Where is my mistake? Thank a lot!

-- Ivan


Re: Expression returning always 0 rows...

Posted by Andrus Adamchik <an...@objectstyle.org>.
Hi Ivan,

On Mar 30, 2006, at 11:39 AM, I. Venuti wrote:

> [bind: '', '', '', '', '', '', '']

This is the cause of the problem. You are using empty strings ("")  
for parameters. For a parameter to be excluded from processing it has  
to be absent from parameter map (null or "" are both considered valid  
parameters).

To achieve the desired result you'll have manually preprocess  
parameter map before passing it to Cayenne, removing all empty string  
values.

Andrus