mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-22 08:56:34 +03:00
Allow pickling of cursor.description
This is for people using dtuple.py; a dtuple.DatabaseTuple instance keeps a reference to cursor.description, which is not picklable because psycopg2 doesn't export the Column namedtuple it uses. This commit exports the Column namedtuple, and includes a test to verify the pickle/unpickle works after exporting Column.
This commit is contained in:
parent
66fdaeaf09
commit
28180837bf
|
@ -55,6 +55,7 @@ from psycopg2._psycopg import DateFromTicks, TimeFromTicks, TimestampFromTicks
|
||||||
from psycopg2._psycopg import Error, Warning, DataError, DatabaseError, ProgrammingError
|
from psycopg2._psycopg import Error, Warning, DataError, DatabaseError, ProgrammingError
|
||||||
from psycopg2._psycopg import IntegrityError, InterfaceError, InternalError
|
from psycopg2._psycopg import IntegrityError, InterfaceError, InternalError
|
||||||
from psycopg2._psycopg import NotSupportedError, OperationalError
|
from psycopg2._psycopg import NotSupportedError, OperationalError
|
||||||
|
from psycopg2._psycopg import Column
|
||||||
|
|
||||||
from psycopg2._psycopg import _connect, apilevel, threadsafety, paramstyle
|
from psycopg2._psycopg import _connect, apilevel, threadsafety, paramstyle
|
||||||
from psycopg2._psycopg import __version__
|
from psycopg2._psycopg import __version__
|
||||||
|
|
|
@ -895,6 +895,7 @@ INIT_MODULE(_psycopg)(void)
|
||||||
PyModule_AddObject(module, "Notify", (PyObject*)¬ifyType);
|
PyModule_AddObject(module, "Notify", (PyObject*)¬ifyType);
|
||||||
PyModule_AddObject(module, "Xid", (PyObject*)&xidType);
|
PyModule_AddObject(module, "Xid", (PyObject*)&xidType);
|
||||||
PyModule_AddObject(module, "Diagnostics", (PyObject*)&diagnosticsType);
|
PyModule_AddObject(module, "Diagnostics", (PyObject*)&diagnosticsType);
|
||||||
|
PyModule_AddObject(module, "Column", psyco_DescriptionType);
|
||||||
#ifdef PSYCOPG_EXTENSIONS
|
#ifdef PSYCOPG_EXTENSIONS
|
||||||
PyModule_AddObject(module, "lobject", (PyObject*)&lobjectType);
|
PyModule_AddObject(module, "lobject", (PyObject*)&lobjectType);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
# License for more details.
|
# License for more details.
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
import pickle
|
||||||
import psycopg2
|
import psycopg2
|
||||||
import psycopg2.extensions
|
import psycopg2.extensions
|
||||||
from psycopg2.extensions import b
|
from psycopg2.extensions import b
|
||||||
|
@ -400,6 +401,16 @@ class CursorTests(ConnectingTestCase):
|
||||||
self.assertEqual(c.precision, None)
|
self.assertEqual(c.precision, None)
|
||||||
self.assertEqual(c.scale, None)
|
self.assertEqual(c.scale, None)
|
||||||
|
|
||||||
|
def test_pickle_description(self):
|
||||||
|
curs = self.conn.cursor()
|
||||||
|
curs.execute('SELECT 1 AS foo')
|
||||||
|
description = curs.description
|
||||||
|
|
||||||
|
pickled = pickle.dumps(description, pickle.HIGHEST_PROTOCOL)
|
||||||
|
unpickled = pickle.loads(pickled)
|
||||||
|
|
||||||
|
self.assertEqual(description, unpickled)
|
||||||
|
|
||||||
@skip_before_postgres(8, 0)
|
@skip_before_postgres(8, 0)
|
||||||
def test_named_cursor_stealing(self):
|
def test_named_cursor_stealing(self):
|
||||||
# you can use a named cursor to iterate on a refcursor created
|
# you can use a named cursor to iterate on a refcursor created
|
||||||
|
|
Loading…
Reference in New Issue
Block a user