RE: Cayenne chain-chank problem

From: ςΡΒΙΓΛΙΚ εΧΗΕΞΙΚ (eryabitski..iasoft.ru)
Date: Fri May 21 2010 - 09:11:53 UTC

  • Next message: Andrus Adamchik: "Re: Cayenne chain-chank problem"

    I took example from http://cayenne.apache.org/doc20/scripting-sqltemplate.html and extend it so it use Boolean fields to show my problem.

    For me problematic that when I am going to filter ARTISTS with id == 1 or id == 10 it is all ok I will got query:

    SELECT * from ARTIST t0 WHERE id = ? [bind: 1 ]

    But if I am filtering with id == 0 (that is absolute valid column value) I got:

    SELECT * from ARTIST t0

    But I was expecting:

    SELECT * from ARTIST t0 WHERE id = ? [bind: 0 ]

    That is my problem.... Same for Boolean values, I just want simple filtering by only passed column values.

    Evgeny.

    -----Original Message-----
    From: Andrus Adamchik [mailto:andru..bjectstyle.org]
    Sent: Friday, May 21, 2010 12:12 PM
    To: de..ayenne.apache.org
    Subject: Re: Cayenne chain-chank problem

    Hi Evgeny,

    Where did you find this example?

    I am checking #chunk directive example here: http://cayenne.apache.org/doc20/scripting-sqltemplate.html
      and everything seems correct to me. IIRC "0 == null" is how Velocity
    evaluates expressions (C-style), so this has to be taken into account
    when building SQLtemplates.

    So I don't understand which parts you find problematic?

    Cheers,
    Andrus

    On May 21, 2010, at 10:36 AM, ςΡΒΙΓΛΙΚ εΧΗΕΞΙΚ wrote:

    > Hello, here is example from tutorial for 2.0:
    >
    > String sql = "SELECT DISTINCT"
    > + " #result('ARTIST_ID' 'int'),"
    > + " #result('ARTIST_NAME' 'String'),"
    > + " #result('DATE_OF_BIRTH' 'java.util.Date')"
    > + " #result('IS_DEAD' 'java.util.Boolean')"
    > + " FROM ARTIST t0"
    > + " #chain('OR' 'WHERE') // start
    > chain prefixed by WHERE,
    > // and joined
    > by OR
    > + " #chunk($name) ARTIST_NAME LIKE #bind($name) #end" //
    > ARTIST_NAMEchunk"
    > + " #chunk($id) ARTIST_ID > #bind($id) #end" // ARTIST_ID
    > chunk"
    > + " #chunk($isDead) IS_DEAD = #bind($isDead) #end" // IS_DEAD
    > chunk"
    > + " #end"; // end of chain
    > SQLTemplate select = new SQLTemplate(Artist.class, sql, true);
    >
    >
    > If I put in isDead true - everything is ok, but if I put false I got
    > chat this condition is skipper because #chunk is actually checking
    > condition of $isDead.
    >
    > Same thing if I put 0 in $id it will be false.
    >
    > So this example of tutorial is bad for Dead Artists or Artists with
    > id == 0.
    > Maybe it's a bug of #chunk directive and it should do only null
    > check??
    >
    > Evgeny.
    >



    This archive was generated by hypermail 2.0.0 : Fri May 21 2010 - 09:12:31 UTC