|
From: Ian B. <ia...@co...> - 2003-08-20 17:09:26
|
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).
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')
Ian
|