[Opensource] problem when saving string containing newline strings

Michael Rimov rimovm at centercomp.com
Tue Nov 11 13:10:06 PST 2003


At 04:16 AM 11/11/2003, you wrote:

>Hi,
>
>When I try to save a String to a DBObject toa VARCHAR field which
>contains the newline character (\n) the newline character gets lost.
>
>I.e., if dbo is a DBobject, and field is the name of the VARCHAR field:
>
>String myString = "Test\nthis";
>dbo.setStringFilter(field, FilterManager.RAW_FILTER);
>dbo.setField(field, value);
>result = dbo.getField(field);
>
>result == "Testthis";
>
>Interestingly, if I use LONGVARCHAR (which I map to PostgreSQL "text"
>type) the phenomenon does not occur.
>
>Does anyone else experience this? Is that a normal behaviour for VARCHARs?

Correct.  Many databases HATE newlines in VARCHAR fields, so we strip them 
before sending it off to the database.  Because we use PreparedStatements 
for LONGVARCHAR, that is why you can use newlines inside the field.

HTH!

                                                 -Mike 





More information about the Opensource mailing list