Search the web
Sign In
New User? Sign Up
SimpleORM
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Show off your group to the world. Share a photo of your group with us.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Handling of "" when it means NULL in the database   Message List  
Reply | Forward Message #1545 of 1851 |
Hi,
I use SimpleOrm quite a lot, and I have this annoyance that "" is not
treated
as NULL when it should be. In Oracle (and also Informix and maybe others),
"" is the same as NULL, whereas in other databases, "" is distinct
from NULL.

So what I propose is to add the following method in SDriver :

/** method to indicate if the database treats empty strings as null
(default : false) */
public boolean emptyStringIsNull() { return false; }

and to overload it in SDriverOracle :

/** Oracle treats empty strings as null */
public boolean emptyStringIsNull() { return true; }

we can now check for empty strings when we store them, and replace
them with
NULL accordingly. The convertToField in the SFieldString becomes :

//(hk) changed to handle the case where "raw" is "", and empty
strings are
//equivalent to null
Object convertToField(Object raw) {
if (raw == null) return null;
String str = raw.toString();
//Convert the empty string to NULL if this is the internal
representation
//for empty strings (this is the case for Oracle and SQLBase (Unify).
if (SConnection.getDriver().emptyStringIsNull() &&
"".equals(str)) {
str = null;
}
return str;
}

This will avoid missed results because Simpleorm issues "=?" with
values of
"", where it should emit "IS NULL".


Best regards,





Wed Apr 9, 2008 9:39 am

hkara1
Offline Offline
Send Email Send Email

Forward
Message #1545 of 1851 |
Expand Messages Author Sort by Date

Hi, I use SimpleOrm quite a lot, and I have this annoyance that "" is not treated as NULL when it should be. In Oracle (and also Informix and maybe others), ""...
hkara1
Offline Send Email
Apr 9, 2008
9:39 am

Your approach sounds reasonable. There is an isEmpty test in SField. Anthony ... Spreadsheet Detective, Southern Cross Software Queensland Pty Limited 54...
Anthony & Melissa Ber...
berglas@...
Send Email
Apr 14, 2008
3:30 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help