adodbapi 2.4 : not possible to pickle

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

adodbapi 2.4 : not possible to pickle

William Dode
Hi,

Since adodbapi 2.4 it's not more possible to pickle a recordset when
there is a datetime column in the result. I've digged, it's because
PyTime object are kept in _SQLRow

Is there a workaround ?

thanks

--
William Dodé - http://flibuste.net
Informaticien Indépendant

_______________________________________________
DB-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/db-sig
Reply | Threaded
Open this post in threaded view
|

Re: adodbapi 2.4 : not possible to pickle

Vernon D. Cole
Hmmm... pickle was one thing I failed to consider when I changed the adodbapi .fetchxxx methods to return a sequence-like object (_SQLrow) rather than an actual tuple. Since I have never had the need to use pickle, I have never tested it. Frankly, it never occurred to me that one would ever want to serialize data which just came in from a data base.

 As you have noticed, data in an _SQLrow object are not converted into Python types until extracted from the object by its _getValue() method. In previous versions, the conversion was done before you received the data.
 
  The quickest workaround would be (in your code) to simply call tuple() on the returned row object before pickling it.  That should give the same result as before, when tuple() was called internally.

  If this is something which is done frequently, then a perhaps a suitable method should be added to the class definition of _SQLrow() so that pickle would work on it directly.  Is __getstate__() what one uses for this?
--
Vernon

On Tue, Oct 19, 2010 at 7:57 AM, William Dode <[hidden email]> wrote:
Hi,

Since adodbapi 2.4 it's not more possible to pickle a recordset when
there is a datetime column in the result. I've digged, it's because
PyTime object are kept in _SQLRow

Is there a workaround ?

thanks

--
William Dodé - http://flibuste.net
Informaticien Indépendant

_______________________________________________
DB-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/db-sig


_______________________________________________
DB-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/db-sig
Reply | Threaded
Open this post in threaded view
|

Re: adodbapi 2.4 : not possible to pickle

Dieter Maurer
Vernon Cole wrote at 2010-10-19 10:11 -0600:
> ...
>  If this is something which is done frequently, then a perhaps a suitable
>method should be added to the class definition of _SQLrow() so that pickle
>would work on it directly.  Is __getstate__() what one uses for this?

"__getstate__", "__setstate__" and "__new__" (and potentially "__newargs__")
are used for pickling (and unpickling).



--
Dieter
_______________________________________________
DB-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/db-sig
Reply | Threaded
Open this post in threaded view
|

Re: adodbapi 2.4 : not possible to pickle

William Dode
In reply to this post by Vernon D. Cole
On 19-10-2010, Vernon Cole wrote:

> --===============0015925617==
> Content-Type: multipart/alternative; boundary=001485f64746fd50ce0492fa8b98
>
> --001485f64746fd50ce0492fa8b98
> Content-Type: text/plain; charset=ISO-8859-1
> Content-Transfer-Encoding: quoted-printable
>
> Hmmm... pickle was one thing I failed to consider when I changed the
> adodbapi .fetchxxx methods to return a sequence-like object (_SQLrow) rathe=
> r
> than an actual tuple. Since I have never had the need to use pickle, I have
> never tested it. Frankly, it never occurred to me that one would ever want
> to serialize data which just came in from a data base.
>
>  As you have noticed, data in an _SQLrow object are not converted into
> Python types until extracted from the object by its _getValue() method. In
> previous versions, the conversion was done before you received the data.
>
>   The quickest workaround would be (in your code) to simply call tuple() on
> the returned row object before pickling it.  That should give the same
> result as before, when tuple() was called internally.
>
>   If this is something which is done frequently, then a perhaps a suitable
> method should be added to the class definition of _SQLrow() so that pickle
> would work on it directly.  Is __getstate__() what one uses for this?

Thanks, i will try. I use pickle for remote task, it's very usefull.

I use my own class to access the rows, like your SQLRows, maybe it could
be fine to can choose to use it or not ?

--
William Dodé - http://flibuste.net
Informaticien Indépendant

_______________________________________________
DB-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/db-sig