Re: Handling of "" when it means NULL in the database

Anthony & Melissa Berglas <[email protected]>
Newsgroups gmane.comp.java.orm.simpleorm
Message-ID <[email protected]>
Your approach sounds reasonable.

There is an isEmpty test in SField.

Anthony

At 07:39 PM 9/04/2008, hkara1 wrote:

>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,
>
>


Spreadsheet Detective,
Southern Cross Software Queensland Pty Limited
54 Gerler Street
Bardon, Queensland 4065, Australia.

Email: [email protected]
www.SpreadsheetDetective.com
Ph: +61 427 830248 (Australian Eastern Standard Time)

"If the model seems correct only because the numbers look right,
then why build the model in the first place?"


------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/SimpleORM/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/SimpleORM/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:[email protected] 
    mailto:[email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.