Re : Proposed change regarding trimming of strings...
Hoang-Vu PHUNG <[email protected]> Fri, 18 Feb 2011 10:15:46 +0000 (GMT)
| Newsgroups | gmane.comp.java.orm.simpleorm |
|---|---|
| Message-ID | <[email protected]> |
--0-2035601374-1298024146=:13181 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi Frank, =C2=A0 Wondering why you can't override the methods depending on different Databas= e drivers. =C2=A0 Forget if it is a stupid suggestion. =C2=A0 Regards, --- En date de=C2=A0: Jeu 17.2.11, Franck Routier <[email protected]= > a =C3=A9crit=C2=A0: De: Franck Routier <[email protected]> Objet: [SimpleORM] Proposed change regarding trimming of strings... =C3=80: [email protected] Date: Jeudi 17 f=C3=A9vrier 2011, 15h55 =C2=A0=20 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 =3D field.convertToDataSetFieldType(value); if (field instanceof SFieldString && isNewRow()) { // optionaly && field.isPrimayKey() convValue =3D 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 =20=20=20=20=20=20 --0-2035601374-1298024146=:13181 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <head> <style type=3D"text/css"> <!-- /* start of attachment style */ .ygrp-photo-title{ clear: both; font-size: smaller; height: 15px; overflow: hidden; text-align: center; width: 75px; } div.ygrp-photo{ background-position: center; background-repeat: no-repeat; background-color: white; border: 1px solid black; height: 62px; width: 62px; } div.photo-title=20 a, div.photo-title a:active, div.photo-title a:hover, div.photo-title a:visited { text-decoration: none;=20 } div.attach-table div.attach-row { clear: both; } div.attach-table div.attach-row div { float: left; /* margin: 2px;*/ } p { clear: both; padding: 15px 0 3px 0; overflow: hidden; } div.ygrp-file { width: 30px; valign: middle; } div.attach-table div.attach-row div div a { text-decoration: none; } div.attach-table div.attach-row div div span { font-weight: normal; } div.ygrp-file-title { font-weight: bold; } /* end of attachment style */ --> </style> </head> <html> <head> <style type=3D"text/css"> <!-- #ygrp-mkp { border: 1px solid #d8d8d8; font-family: Arial; margin: 10px 0; padding: 0 10px; } #ygrp-mkp hr { border: 1px solid #d8d8d8; } #ygrp-mkp #hd { color: #628c2a; font-size: 85%; font-weight: 700; line-height: 122%; margin: 10px 0; } #ygrp-mkp #ads { margin-bottom: 10px; } #ygrp-mkp .ad { padding: 0 0; } #ygrp-mkp .ad p { margin: 0; } #ygrp-mkp .ad a { color: #0000ff; text-decoration: none; } --> </style> </head> <body> <table cellspacing=3D"0" cellpadding=3D"0" border=3D"0" ><tr><td valign=3D"= top" style=3D"font: inherit;"><DIV>Hi Frank,</DIV> <DIV> </DIV> <DIV>Wondering why you can't override the methods depending on different Da= tabase drivers.</DIV> <DIV> </DIV> <DIV>Forget if it is a stupid suggestion.</DIV> <DIV> </DIV> <DIV>Regards,</DIV> <DIV><BR><BR>--- En date de : <B>Jeu 17.2.11, Franck Routier <I><fr= [email protected]></I></B> a =C3=A9crit :<BR></DIV> <BLOCKQUOTE style=3D"PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: rgb(= 16,16,255) 2px solid"><BR>De: Franck Routier <[email protected]&g= t;<BR>Objet: [SimpleORM] Proposed change regarding trimming of strings...<B= R>=C3=80: [email protected]<BR>Date: Jeudi 17 f=C3=A9vrier 2011, 15= h55<BR><BR> <DIV id=3Dyiv1328011638><SPAN style=3D"DISPLAY: none"> </SPAN>=20 <DIV id=3Dyiv1328011638ygrp-text> <DIV>Hi,<BR><BR>there is a known problem in Simpleorm right now regarding c= onsistency<BR>when dealing with String:<BR><BR>- getString(field) will righ= t trim String before returning them.<BR>Comments in SRecordInstance.getStri= ng() suggest that otherwise there are<BR>problems with some databases and c= haracter() (not varrying) sql<BR>datatype.<BR><BR>- on the other end, setOb= ject will never trim<BR><BR>- if you happen to have a foreign key on a Stri= ng primary key that<BR>happens to have spaces at the end, findReference won= 't work, although<BR>the foreign key is valid in the database...<BR><BR>I h= ave no simple solution to this. We have to deal with existing data<BR>and w= e have to deal with character sql datatype and inconsistencies<BR>accross d= atabases.<BR><BR>What I suggest will solve at least a few cases, and especi= ally one that<BR>bites me: if a record is a new row (not existing in databa= se) and field<BR>is a SFieldString, then right trim the value.<BR><BR>What this means is that every String you _insert_ using Simp= leorm will<BR>be right trimmed. Existing data won't be touched, and will be= read just<BR>as before.<BR>Optionaly, I could add a test on the field to t= rim only if it is part of<BR>a primary key (who would want to have a primar= y key ended with<BR>spaces ??).<BR><BR>The code would look like this (in SR= ecordInstance.setObject) :<BR><BR>try {<BR>convValue =3D field.convertToDat= aSetFieldType(value);<BR>if (field instanceof SFieldString && isNew= Row()) { // optionaly &&<BR>field.isPrimayKey()<BR>convValue =3D co= nvertToString(convValue);<BR>}<BR>}<BR><BR>This seems like a workaround, bu= t I'm not sure what the right solution<BR>would be... What do you think of = this ?<BR><BR>Franck<BR><BR></DIV></DIV></DIV></BLOCKQUOTE></td></tr></tabl= e><br> =20=20=20=20=20=20 <!-- |**|begin egp html banner|**| --> <br> =20=20=20=20 =20=20=20=20 <br> <!-- |**|end egp html banner|**| --> <div width=3D"1" style=3D"color: white; clear: both;"/>__._,_.___</div> <!-- Start Recommendations --> <!-- End Recommendations --> <!-- |**|begin egp html banner|**| --> <img src=3D"http://geo.yahoo.com/serv?s=3D97476590/grpId=3D7360226/grpspI= d=3D1705006905/msgId=3D2018/stime=3D1298024150" width=3D"1" height=3D"1"> <= br> <!-- |**|end egp html banner|**| --> =20=20 <!-- |**|begin egp html banner|**| --> <br> <div style=3D"font-family: verdana; font-size: 77%; border-top: 1px s= olid #666; padding: 5px 0;" > Your email settings: Individual Email|Traditional <br> <a href=3D"http://groups.yahoo.com/group/SimpleORM/join;_ylc=3DX3oDMT= JmMWM4bmtkBF9TAzk3NDc2NTkwBGdycElkAzczNjAyMjYEZ3Jwc3BJZAMxNzA1MDA2OTA1BHNlY= wNmdHIEc2xrA3N0bmdzBHN0aW1lAzEyOTgwMjQxNTA-">Change settings via the Web</a= > (Yahoo! ID required) <br> Change settings via email: <a href=3D"mailto:SimpleORM-digest@yahoogr= oups.com?subject=3DEmail Delivery: Digest">Switch delivery to Daily Digest<= /a> | <a href =3D "mailto:[email protected]?subject=3D= Change Delivery Format: Fully Featured">Switch to Fully Featured</a> <br> <a href=3D"http://groups.yahoo.com/group/SimpleORM;_ylc=3DX3oDMT= JkN2hia3BoBF9TAzk3NDc2NTkwBGdycElkAzczNjAyMjYEZ3Jwc3BJZAMxNzA1MDA2OTA1BHNlY= wNmdHIEc2xrA2hwZgRzdGltZQMxMjk4MDI0MTUw"> Visit Your Group=20 </a> | <a href=3D"http://docs.yahoo.com/info/terms/"> Yahoo! Groups Terms of Use </a> | <a href=3D"mailto:[email protected]?subject=3DUns= ubscribe"> Unsubscribe=20 </a>=20 <br> </div> <br> <!-- |**|end egp html banner|**| --> <div style=3D"color: white; clear: both;"/>__,_._,___</div> </body> </html> --0-2035601374-1298024146=:13181--