I would like to serialize results of the query. Here is my example:
import pypyodbc
import pickle
connection_string ='Driver={SQL Server Native Client 11.0};Server=localhost;' \
'Database=someDB;Uid=someLogin;Pwd=somePassword;'
connection = pypyodbc.connect(connection_string)
sql_query = "SELECT * FROM SomeTable"
cur = connection.cursor()
cur.execute(sql_query)
query_list = list(cur)
with open(r'D:\query_result', 'wb') as f:
pickle.dump(query_list, f)
cur.close()
connection.close()
It generates the following error:
_pickle.PicklingError: Can't pickle <class 'pypyodbc.TupleRow.<locals>.Row'>:
attribute lookup Row on pypyodbc failed
I guess pickle does not fully support pypyodbc objects. What would be a workaround?