mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-01-31 17:34:08 +03:00
Added schema attribute to CompositeCaster
This commit is contained in:
parent
26cfdc1234
commit
9949e04c70
|
@ -247,6 +247,12 @@ requires no adapter registration.
|
|||
|
||||
The name of the PostgreSQL type.
|
||||
|
||||
.. attribute:: schema
|
||||
|
||||
The schema where the type is defined.
|
||||
|
||||
.. versionadded:: 2.4.6
|
||||
|
||||
.. attribute:: oid
|
||||
|
||||
The oid of the PostgreSQL type.
|
||||
|
|
|
@ -803,8 +803,9 @@ class CompositeCaster(object):
|
|||
using an :ref:`asynchronous connections <async-support>`).
|
||||
|
||||
"""
|
||||
def __init__(self, name, oid, attrs, array_oid=None):
|
||||
def __init__(self, name, oid, attrs, array_oid=None, schema=None):
|
||||
self.name = name
|
||||
self.schema = schema
|
||||
self.oid = oid
|
||||
self.array_oid = array_oid
|
||||
|
||||
|
@ -926,7 +927,7 @@ ORDER BY attnum;
|
|||
type_attrs = [ (r[2], r[3]) for r in recs ]
|
||||
|
||||
return self(tname, type_oid, type_attrs,
|
||||
array_oid=array_oid)
|
||||
array_oid=array_oid, schema=schema)
|
||||
|
||||
def register_composite(name, conn_or_curs, globally=False, factory=None):
|
||||
"""Register a typecaster to convert a composite type into a tuple.
|
||||
|
|
|
@ -532,6 +532,7 @@ class AdaptTypeTestCase(unittest.TestCase):
|
|||
|
||||
t = psycopg2.extras.register_composite("type_isd", self.conn)
|
||||
self.assertEqual(t.name, 'type_isd')
|
||||
self.assertEqual(t.schema, 'public')
|
||||
self.assertEqual(t.oid, oid)
|
||||
self.assert_(issubclass(t.type, tuple))
|
||||
self.assertEqual(t.attnames, ['anint', 'astring', 'adate'])
|
||||
|
@ -655,6 +656,7 @@ class AdaptTypeTestCase(unittest.TestCase):
|
|||
[("a", "integer"), ("b", "integer")])
|
||||
t = psycopg2.extras.register_composite(
|
||||
"typens.typens_ii", self.conn)
|
||||
self.assertEqual(t.schema, 'typens')
|
||||
curs.execute("select (4,8)::typens.typens_ii")
|
||||
self.assertEqual(curs.fetchone()[0], (4,8))
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user