I had the problem of wanting case insensitive OQL, such as:

SELECT o com.project.User o WHERE lower(login) = $1;

but placing the lower() (or equivilent database call -- I'm using
postgresql for this) around the field resulted in the ParseTreeWalker
barfing, because it couldn't resolve the field "lower(login)".

I noticed this same issue mentioned in 
http://castor.exolab.org/list-archive/msg08762.html
but the eventual solution didn't seem to work. The LPARENS case was
never being reached.

So, my solution was to modify org/exolab/castor/jdo/oql/ParseTreeWalker.java
to check for a field being a database function in the form function(field),
and then returning the JDOFieldDescriptor for the "field" part of this.

Is there a more appropriate way of doing this?

Patch against todays cvs is attached.

D.
-- 
Dale Harrison         |
Angry Camel Software  |     "From now on, I'll connect the dots my own way."
< [EMAIL PROTECTED] >  |                                            -- Calvin
diff -c -r castor/src/main/org/exolab/castor/jdo/oql/ParseTreeWalker.java 
castor-iwn/src/main/org/exolab/castor/jdo/oql/ParseTreeWalker.java
*** castor/src/main/org/exolab/castor/jdo/oql/ParseTreeWalker.java      Wed Sep 19 
10:04:57 2001
--- castor-iwn/src/main/org/exolab/castor/jdo/oql/ParseTreeWalker.java  Thu Sep 27 
13:27:47 2001
***************
*** 579,586 ****
    private JDOFieldDescriptor checkField(ParseTreeNode fieldTree)
          throws QueryException {
  
!     //see if we've checked this field before.
!     JDOFieldDescriptor field = (JDOFieldDescriptor)_fieldInfo.get(fieldTree);
      if ( field != null )
        return field;
  
--- 579,597 ----
    private JDOFieldDescriptor checkField(ParseTreeNode fieldTree)
          throws QueryException {
  
!     JDOFieldDescriptor field = null;
! 
!     // we have children, so we might be in the form "... function(field)"
!     // this allows database specific functions to be called within the OQL
!     // such as "SELECT o FROM com.project.User o WHERE lower(login) = $1"
!     if(fieldTree.children().hasMoreElements() && 
fieldTree.getChild(0).getToken().getTokenValue().equals("(")) {
!       // get the field part of "function(field)", if exists.
!       field = (JDOFieldDescriptor)_fieldInfo.get(fieldTree.getChild(0).getChild(0));
!     } else {
!       //see if we've checked this field before.
!       field = (JDOFieldDescriptor)_fieldInfo.get(fieldTree);
!     }
! 
      if ( field != null )
        return field;
  

Reply via email to