-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Ian,
Thanks for answering.
Ian Bicking wrote:
> On Saturday, August 9, 2003, at 07:25 PM, Javier Ruere wrote:
>
>> How can binary data be stored with SQLObject?
>> I'm trying to pickle something and storing it but caracters are
>> scaped.
>> How can I avoid this?
>>
> This response is a little late, but I don't see another response.
>
> There's an option to Pickle to use a string representation, but that's
> only really a string if all the components can be represented as strings
> (i.e., you don't have any binary instance variables in your objects).
Yes, I already tried this but doesn't seem to work. For example:
>>> pickle.dumps('Hello')
"S'Hello'\np0\n."
The pickle of 'Hello' has a '\n' in it which when passed through
SQLObject returns as '\\n' which cannot be unpickled. I worked around
this be searching for the function which does this modification, copying
the list of tuples and making the inverse operation.
Why is this done? I tried storing strings with '\n' in SQLite and it
seems to work alright. Is there a problem with the other DBs? I will be
using this system with SQLite and Postgress eventually so I would be
very interested in knowing this.
> I haven't really used much binary data, so I'm not sure how to represent
> that to the database. Obviously the data must be escaped somehow. If
> you figure it out for your database, and say make a dbEscape() function
> that creates the SQL version of the value (complete with '' if
> necessary) you could so something like:
>
> class Binary:
> def __init__(self, value):
> self.value = value
> def sqlRepr(self):
> return dbEscape(self.value)
>
> You could also use something like base64, like:
>
> def _set_binaryColumn(self, value):
> self._SO_set_binaryColumn(value.encode('base64'))
> def _get_binaryColumn(self):
> return self._SO_get_binaryColumn().decode('base64')
I have check this possibility as well but they all count on using '\n'
so there would be little benefit.
Later,
Javier
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQE/RD768XQC840MeeoRAnDeAJ4oBXIXhsIzSbV67aLAzsEpZMjwugCdGmXg
eLVSkscsSUnR1Q7vy5Rific=
=AOD/
-----END PGP SIGNATURE-----
|