Postgres / Glorp

Ramiro Diaz Trepat ramirodt at gmail.com
Mon May 14 10:55:20 UTC 2007


Thank you very much Norbert.
It would be great if someone with an important blog (Ramon/Lukas)
posted an article about how to get around the current limitations of
Squeak/Seaside to work with UTF8 and the possible work arounds, like
this.
Cheers, and thanks again.


On 5/14/07, Norbert Hartl <norbert at hartl.name> wrote:
> On Sun, 2007-05-13 at 18:28 -0300, Ramiro Diaz Trepat wrote:
> > Sorry, it does work.
> > I don´t know what happend.
> >
> >
> Try more to be sure :) I had luck for a few weeks but then...
> I post the message I send you in private to the list so
> it is archived.
>
> ---
>
> There are four places where encoding plays a role:
>
> 1. getting data from the web into squeak
> 2. putting data from squeak into a database
> 3. getting data from the database into squeak
> 4. putting the data into the web.
>
>
> 1. from the web
>
> works usually quite well but not for multipart forms (if you
> have something for upload). I exchanged a WAKom method:
>
> WAKom>>processMultipartFields: aRequest
>         aRequest multipartFormFieldsDo:
>                 [:chunk |
>                 chunk fileName isEmptyOrNil ifFalse:
>                         [|stream file|
>                         stream := WriteStream on: String new.
>                         chunk saveToStream: stream.
>                         file := WAFile new
>                                 fileName: chunk fileName;
>                                 contents: stream contents;
>                                 contentType: chunk contentType;
>                                 yourself.
>                         aRequest postFields at: chunk fieldName put:
> file]
>                 ifTrue: [
>                         |stream|
>                         stream := WriteStream on: String new.
>                         chunk saveToStream: stream.
>
>                         aRequest postFields at: chunk fieldName
> put:( (stream contents)
> convertFromEncoding: #utf8)]
>                 ].
>
> 2. squeak to database
>
> herefor I assume that the client encoding between squeak and postgres
> is UTF-8. I just encode the complete outgoing SQL string to utf-8.
>
> SqueakDatabaseAccessor>>basicExecuteSQLString: aString
>         | result rowCollection |
>         "self log: aString."
>         result := connection execute: (aString convertToEncoding:
> #utf8).
>         "result := connection execute: aString."
>         result errorResponse notNil
>                 ifTrue:
>                         [self externalDatabaseErrorSignal signal: result
> errorResponse
> value].
>         rowCollection := OrderedCollection new.
>         result rows do: [:ea | rowCollection add: ea data asArray].
>         ^ReadStream on: rowCollection asArray
>
> 3. database to squeak
>
> here the same client encoding applies. To convert these you have
> to register type converters. I did this for varchar and text fields.
>
> Add
>         #(1043 25)
>                 do: [:each| converters at: each put: [:s | s
> convertFromEncoding:
> #utf8]].
>
> somewhere in PGConnection class>>buildDefaultFieldConverters
>
>
> 4. squeak to web
>
> is the easiest as it is solved by using WAKomEncoded39 instead
> of WAKom.
>
>
> This approach solves all four ends where encoding plays a role. It
> means there happens a lot of conversion but the approach is clean
> in a way that you use inside squeak its own encoding. You're able
> to use special spanisch characters inside squeak and they are displayed
> properly in squeak and on the web pages.
>
> Hope this helps,
>
> Norbert
>
>
>
>



More information about the Squeak-dev mailing list