Proposed change regarding trimming of strings...
Franck Routier <[email protected]> Thu, 17 Feb 2011 14:55:24 +0100
| Newsgroups | gmane.comp.java.orm.simpleorm |
|---|---|
| Organization | Axège sarl |
| Message-ID | <1297950924.5702.26.camel@franck-laptop> |
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
------------------------------------
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/