]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
fixed pickle example, its standard anyway....
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 26 Mar 2006 19:58:08 +0000 (19:58 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 26 Mar 2006 19:58:08 +0000 (19:58 +0000)
doc/build/content/types.myt

index 3df5e75bb3939c19122404fb871ec25cfee5062f..92f5963ba031ac2b8604f1139af7d15224122f94 100644 (file)
        # rowset values, using the unicode encoding 
        # setting on the engine (defaults to 'utf-8')
        class Unicode(String)
+       
+       # uses the pickle protocol to serialize data
+       # in/out of Binary columns
+       class PickleType(Binary)
 </&>
 <p>More specific subclasses of these types are available, which various database engines may choose to implement specifically, allowing finer grained control over types:</p>
 <&|formatting.myt:code&>
@@ -87,16 +91,21 @@ class BOOLEAN(Boolean)
 <&|formatting.myt:code, title="Pickle Type"&>
     import cPickle
 
-    class PickleType(types.Binary):
-          def __init__(self, protocol=cPickle.HIGHEST_PROTOCOL):
+    class PickleType(Binary):
+          def __init__(self, protocol=pickle.HIGHEST_PROTOCOL):
                """allows the pickle protocol to be specified"""
                self.protocol = protocol
           def convert_result_value(self, value, engine):
-                return cpickle.loads(super(PickleType, self).convert_result_value(value, engine), self.protocol)
+              if value is None:
+                  return None
+              buf = Binary.convert_result_value(self, value, engine)
+              return pickle.loads(str(buf))
           def convert_bind_param(self, value, engine):
-                return super(PickleType, self).convert_bind_param(cpickle.dumps(value, self.protocol), engine)
+              if value is None:
+                  return None
+              return Binary.convert_bind_param(self, pickle.dumps(value, self.protocol), engine)
           def get_constructor_args(self):
-                return {'protocol':self.protocol}
+                return {}
 </&>
 <p>Which can be used like:</p>
 <&|formatting.myt:code&>