Re: Proposed change regarding trimming of strings...

[email protected] Sun, 20 Feb 2011 09:41:12 +1000
Newsgroups gmane.comp.java.orm.simpleorm
Message-ID <[email protected]>
--=====================_62099754==_
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

Hello Franck,

This has always been on the list, and would be good to do nicely.

Char vs Varchar was the driver, but not the only problem.  Depending on circumstances and database CHAR returns space filled strings, and compare (not) ignoring spaces.  I seem to recall that Oracle was inconsistent with comparisons -- they needed to have the right number of trailing spaces.

(This is an old COBOL idea -- space filled strings come from punch cards that way into fixed size records.  Which is how major systems could be built in a few Kilobytes (not gigabytes) of memory.  But Cobol always consistently ignored trailing spaces for comparisons.)

But for ordinary Varchar fields, if you ever did accidentally have trailing spaces in a key for a VARCHAR it would be a pretty horrible bug.  A user could simply accidentally add a space to an input field, for example.

A related issue is "" vs NULL. Depending on the database and style one or the other should always be used.  Mixing them can reek havoc.  And classic JSPs can return "" or NULL for inputs depending on circumstances.  (Most systems use NULL, LAMP systems use "", Oralce db treats "" as NULLS.)  There should be a property default from Driver to Field that specifies the behavior.

Two options, be helpful or strict.  I think we need both.

So to be helpful, have setString and getString trim, and NULL convert.  And then have get|setStringExact which do not.  SetObject should not.   Thus we provide basic protection.   For queries, do not do any conversion of ? parameters -- it is up to the user to pad with spaces if that is required by the db if they insist on using CHARs.  (Queries are less important because they values are not persisted.)

FindReference then uses getObject or getStringExact.  So a read of a record followed by a findReference will always work.  (No conversions should be made as data is actually being selected from the database.)  Beyond that, it is up to the user to pad with spaces appropriately and use setStringExact in the rare situations where that is what is really required.

I think that Hibernate just ignores all these problems.  CHARS return space filled strings which just do not work properly.  NULLs vs "" is just a user problem -- and a nasty one when it arises.

Inicentally, this is a nice part about NOT using pseudo POJOs.  We can provide a variety of methods to work on fields to be used in different circumstances.  But Hibernate has only two, get and set, and thus needs to make unfortunate compromises.

Regards,

Anthony

At 11:55 PM 17/02/2011, Franck Routier wrote:
>  
>
>Hi,
>
>there is a known problem in Simpleorm right now regarding consistency
>when dealing with String:
>
>- getString(field) will right trim String before returning them.
>Comments in SRecordInstance.getString() suggest that otherwise there are
>problems with some databases and character() (not varrying) sql
>datatype.
>
>- on the other end, setObject will never trim
>
>- if you happen to have a foreign key on a String primary key that
>happens to have spaces at the end, findReference won't work, although
>the foreign key is valid in the database...
>
>I have no simple solution to this. We have to deal with existing data
>and we have to deal with character sql datatype and inconsistencies
>accross databases.
>
>What I suggest will solve at least a few cases, and especially one that
>bites me: if a record is a new row (not existing in database) and field
>is a SFieldString, then right trim the value.
>
>What this means is that every String you _insert_ using Simpleorm will
>be right trimmed. Existing data won't be touched, and will be read just
>as before.
>Optionaly, I could add a test on the field to trim only if it is part of
>a primary key (who would want to have a primary key ended with
>spaces ??).
>
>The code would look like this (in SRecordInstance.setObject) :
>
>try {
>convValue = field.convertToDataSetFieldType(value);
>if (field instanceof SFieldString && isNewRow()) { // optionaly &&
>field.isPrimayKey()
>convValue = convertToString(convValue);
>}
>}
>
>This seems like a workaround, but I'm not sure what the right solution
>would be... What do you think of this ?
>
>Franck
>
>


Spreadsheet Detective,
Southern Cross Software Queensland Pty Limited
54 Gerler Street, Bardon, Queensland 4065, Australia.
www.SpreadsheetDetective.com
"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:
    [email protected] 
    [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/


--=====================_62099754==_
Content-Type: image/jpeg; name="3b390ad.jpg";
 x-mac-type="4A504547"; x-mac-creator="4A565752"
Content-ID: <.0>
Content-Transfer-Encoding: base64
Content-Disposition: inline; filename="3b390ad.jpg"

/9j/4AAQSkZJRgABAQAAAQABAAD/2w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