My inclination would be to think that this is something that the database driver ought to be handling rather than having it in Glorp at all. But, given that it's in there, I suppose it's not unreasonable.
------------------------------------------------------------------------
Mariano Martinez Peck <mailto:marianopeck@gmail.com> 9 November, 2011 8:59 AM
Thanks Sven. We let the repo as global read because we usually receive unintentional commits. Do you think it is worth it to have a kind of DBXTalkInbox ?
Alan, do you think this is useful also for Glorp trunk ?
Thanks!
-- Mariano http://marianopeck.wordpress.com
------------------------------------------------------------------------
Sven Van Caekenberghe <mailto:sven@beta9.be> 8 November, 2011 3:59 AM
Hi,
I have a patch for Glorp(DBX) PostgreSQL to support the newer bytea hex format (see file:///usr/local/pgsql/share/doc/html/datatype-binary.html#AEN5037). I can't write to the repository, so here it is:
PostgreSQLPlatform>>#convertSQLStringToByteArray: aString for: aType aString isNil ifTrue: [ ^ nil ]. ^ (aString beginsWith: '\x') ifTrue: [ self convertHexSQLStringToByteArray: aString ] ifFalse: [ self convertEscapeSQLStringToByteArray: aString ]
PostgreSQLPlatform>>#convertEscapeSQLStringToByteArray: aString | aStream str | aStream := (ByteArray new: aString size // 4) writeStream. str := aString readStream. [str atEnd] whileFalse: [ |nextChar| nextChar := str next. aStream nextPut: (nextChar = $\ ifTrue: [str peek = $\ ifTrue: [str next asInteger] ifFalse: [Number readFrom: (str next: 3) base: 8]] ifFalse: [nextChar asInteger]) ]. aStream close. ^aStream contents
PostgreSQLPlatform>>#convertHexSQLStringToByteArray: aString ^ ByteArray new: (aString size // 2) - 1 streamContents: [ :out | | in | (in := aString readStream) skip: 2. [ in atEnd ] whileFalse: [ out nextPut: (Number readFrom: (in next: 2) base: 16) ] ]
#convertEscapeSQLStringToByteArray: is the old code, unmodified; #convertHexSQLStringToByteArray: is new. This might be of use upstream as well, I don't really know.
If it would help, I could save this as an MC package somewhere.
Regards,
Sven