[SQLObject] Patch to Support psycopg.Binary
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: J-P L. <sql...@si...> - 2003-12-18 15:31:33
|
<mailto:sql...@li...>This is a patch against v0.5.1. I'm using bytea field types in my tables and this patch makes life easier. In my SQLObject classes, I do: def _set_data(self, val): self._SO_set_data(psycopg.Binary(val)) Seems to work with some preliminary testing. Index: SQLObject/Converters.py =================================================================== RCS file: /usr/local/cvs/depot/sqlobject/SQLObject/Converters.py,v retrieving revision 1.1 retrieving revision 1.2 diff -u -5 -r1.1 -r1.2 --- SQLObject/Converters.py 17 Nov 2003 22:36:02 -0000 1.1 +++ SQLObject/Converters.py 18 Dec 2003 15:03:27 -0000 1.2 @@ -135,10 +135,19 @@ return "(%s)" % ", ".join([sqlrepr(v, db) for v in value]) registerConverter(type(()), SequenceConverter) registerConverter(type([]), SequenceConverter) +try: + import psycopg +except ImportError: pass +else: + def PsycopgBinaryConverter(value, db): + return str(value) + + registerConverter(type(psycopg.Binary('')), PsycopgBinaryConverter) + if hasattr(time, 'struct_time'): def StructTimeConverter(value, db): return time.strftime("'%Y-%m-%d %H:%M:%S'", value) registerConverter(time.struct_time, StructTimeConverter) |