RE: Cayenne, Oracle and Date-based queries...

From: Gentry, Michael (michael_gentr..anniemae.com)
Date: Tue Oct 12 2004 - 10:55:32 EDT

  • Next message: Mike Kienenberger: "Re: Bug: Committed object considered transient by validation -- how could it happen?"

    I don't have Oracle, so I can't test this, but have you tried using a
    regular Cayenne expression/etc? Something similar to this (I haven't
    tested this at all and there are probably cleaner ways to do it):

    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    Expression expression = Expression.fromString("birthday >= $start and
    birthday < $end");
    Map parameters = new HashMap();

    // The following is kind of convoluted, but should handle timezone
    switches/etc
    Date start = dateFormat.parse("1953-05-31");
    Calendar calendar = new GregorainCalendar();
    calendar.setTime(start); // setTime takes a Date ...
    calendar.add(GregorianCalendar.DATE, 1);
    Date end = calendar.getTime(); // getTime returns a Date ...
    parameters.put("start", start);
    parameters.put("end", end);

    SelectQuery query = new SelectQuery(Patients.class,
    expression.expWithParameters(parameters));
    ...

    /dev/mrg

    -----Original Message-----
    From: Julien Vignali [mailto:julien.vignal..im.hcuge.ch]
    Sent: Tuesday, October 12, 2004 8:29 AM
    To: cayenne-use..bjectstyle.org
    Subject: Cayenne, Oracle and Date-based queries...

    Hello everybody,
    I recently switched to Cayenne for our medical query application on a
    Oracle
    9i DB, so my Cayenne's knowledge is still limited. So far, everything is
    working great and smoothly except when it comes date-based queries.

    For example :

    // doesn't work (i.e. no rows returned)
    SELECT t0.patientsname FROM imagedev.patients t0 WHERE (t0.birthdt =
    '1953-05-31')

    // works (x rows returned)
    SELECT t0.patientsname FROM imagedev.patients t0 WHERE (t0.birthdt =
    TO_DATE('1953-05-31','YYYY-MM-DD'))

    Is there a way to add some oracle SQL functions such as "TO_DATE()" in
    an
    Qualifier or should I use SQLTemplate instead since it is db
    vendor-dependant functionality ? Does Cayenne can be aware of the
    NLS_PARAMETERS and use them ?

    Thanks :-)
    Julien



    This archive was generated by hypermail 2.0.0 : Tue Oct 12 2004 - 10:55:41 EDT