[Opensource] Fix for quoteIfNeeded method in DBObject

Kris Thompson kris.thompson at seurat.com
Mon Aug 5 08:19:10 PDT 2002


Here the senerio

1.  I have a NUMBER field which is a nullable field.
2.  The field is null in the DB.  
3.  I call update on the Object
4.  DBObject update method calls quoteIfNeeded
5.  This code is called
        if (isNumericType(oneField.getTypeString())) {
            if (fieldValue.equals("")) {
                return "0";
            }
            return fieldValue.trim();
6.  The quoteIfNeeded method returns 0.  
7. Developer is yelling "NO NO NO NO NO   make it null"


Solution  This code

                if (isNumericType(oneField.getTypeString()))
        {
            if(fieldValue.equals("") && oneField.allowsNull())
                return null;
            else
            {
                if (fieldValue.equals("")) {
                    return "0";
                }
                return fieldValue.trim();
            }
        }

Other possible solution.... but I don't recommend it is to removed the 
StringUtil.notNull method in getField of DBObject....but I think we 
might have some problems with other stuff if we did that......

Kris Thompson




More information about the Opensource mailing list