[sqlalchemy] Re: the return type of conn.execute(text())
-Original Message- From: sqlalchemy@googlegroups.com [mailto:sqlalch...@googlegroups.com] On Behalf Of Faheem Mitha Sent: 27 January 2009 22:41 To: sqlalchemy@googlegroups.com Subject: [sqlalchemy] the return type of conn.execute(text()) Hi, Today I attempted to serialize the return value of the form result = conn.execute(text()) Till now I thought that the return type was a list of tuples, while in fact it is a list of objects of type class 'sqlalchemy.engine.base.RowProxy'. Hence cPickle refused to serialize till I did some conversion. Just wondering what the reason for this is. Regards, Faheem. The RowProxy object is more intelligent than a plain tuple. As well as accessing the values by index, you can use your original column objects or the name of the column to retrieve the values from it. You can also use attribute access rather than indexing. Eg. row['your_column_name'] row[your_column] row.your_column_name I imagine this would make it harder to pickle. Simon --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: the return type of conn.execute(text())
Doesn't this work? result = conn.execute('some select statement').fetchall() result will be a ResultProxy containing RowProxy's pickleable = [tuple(row) for row in result] Each tuple contains the column data in what should be a pickleable form. This will work for ints, strings, unicodes, etc. Not sure about datetime, but probably ok. If the column types themselves are complex and not pickleable, then all bets are off. Of course when you unpickle this, it will give back raw data not SA objects, you will have to reconstruct those at run time if you need them On Jan 28, 4:47 am, King Simon-NFHD78 simon.k...@motorola.com wrote: -Original Message- From: sqlalchemy@googlegroups.com [mailto:sqlalch...@googlegroups.com] On Behalf Of Faheem Mitha Sent: 27 January 2009 22:41 To: sqlalchemy@googlegroups.com Subject: [sqlalchemy] the return type of conn.execute(text()) Hi, Today I attempted to serialize the return value of the form result = conn.execute(text()) Till now I thought that the return type was a list of tuples, while in fact it is a list of objects of type class 'sqlalchemy.engine.base.RowProxy'. Hence cPickle refused to serialize till I did some conversion. Just wondering what the reason for this is. Regards, Faheem. The RowProxy object is more intelligent than a plain tuple. As well as accessing the values by index, you can use your original column objects or the name of the column to retrieve the values from it. You can also use attribute access rather than indexing. Eg. row['your_column_name'] row[your_column] row.your_column_name I imagine this would make it harder to pickle. Simon --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: the return type of conn.execute(text())
i have recently stumbled on similar - the rowproxy's __hash__ was missing. so i have to tuple() them before usage. Then there was Mike's question, what should the RowProxy emulate? the tuple of the row, or something else? Today I attempted to serialize the return value of the form result = conn.execute(text()) Till now I thought that the return type was a list of tuples, while in fact it is a list of objects of type class 'sqlalchemy.engine.base.RowProxy'. Hence cPickle refused to serialize till I did some conversion. Just wondering what the reason for this is. Regards, Faheem. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: the return type of conn.execute(text())
On Wednesday 28 January 2009 01:34:30 Michael Bayer wrote: On Jan 27, 2009, at 6:28 PM, a...@svilendobrev.com wrote: i have recently stumbled on similar - the rowproxy's __hash__ was missing. so i have to tuple() them before usage. that doesnt strike me as a similar issue. we should apply that patch someone had to detect python 2.6 and place some kind of callable for __hash__. Then there was Mike's question, what should the RowProxy emulate? the tuple of the row, or something else? RowProxy is not a buffered object in the general sense so im not thrilled making it evaluate itself for every tuple() type of access. ah, similar in the sense of some missing implicit protocol. in this case - __getstate__. nevermind, maybe document it that it's not a good thing to play with ... --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: the return type of conn.execute(text())
On Jan 27, 2009, at 6:28 PM, a...@svilendobrev.com wrote: i have recently stumbled on similar - the rowproxy's __hash__ was missing. so i have to tuple() them before usage. that doesnt strike me as a similar issue. we should apply that patch someone had to detect python 2.6 and place some kind of callable for __hash__. Then there was Mike's question, what should the RowProxy emulate? the tuple of the row, or something else? RowProxy is not a buffered object in the general sense so im not thrilled making it evaluate itself for every tuple() type of access. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: the return type of conn.execute(text())
[This message has also been posted.] On Wed, 28 Jan 2009 01:28:31 +0200, a...@svilendobrev.com a...@svilendobrev.com wrote: i have recently stumbled on similar - the rowproxy's __hash__ was missing. so i have to tuple() them before usage. Then there was Mike's question, what should the RowProxy emulate? the tuple of the row, or something else? Er, what question was that? Did I miss something? I'd like to add to my original question a request to make these objects pickleable as tuples. My understanding is that it just involves adding some method to the class. Regards, Faheem. Today I attempted to serialize the return value of the form result = conn.execute(text()) Till now I thought that the return type was a list of tuples, while in fact it is a list of objects of type class 'sqlalchemy.engine.base.RowProxy'. Hence cPickle refused to serialize till I did some conversion. Just wondering what the reason for this is. Regards, Faheem. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---