mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-03-02 23:35:46 +03:00
Conver network array types into array of strings by default
This commit is contained in:
parent
86198c1c21
commit
706ad2f177
3
NEWS
3
NEWS
|
@ -19,7 +19,8 @@ New features:
|
|||
- The attributes `~connection.notices` and `~connection.notifies` can be
|
||||
customized replacing them with any object exposing an `!append()` method
|
||||
(:ticket:`#326`).
|
||||
- old ``inet`` adapters deprecated (:ticket:`#343`).
|
||||
- old ``inet`` adapters deprecated, but arrays of network types converted
|
||||
to lists by default (:tickets:`#343, #387`).
|
||||
- Added `~psycopg2.extensions.quote_ident()` function (:ticket:`#359`).
|
||||
- Added `~connection.get_dsn_parameters()` connection method (:ticket:`#364`).
|
||||
|
||||
|
|
|
@ -930,13 +930,20 @@ UUID data type
|
|||
|
||||
.. index::
|
||||
pair: INET; Data types
|
||||
pair: CIDR; Data types
|
||||
pair: MACADDR; Data types
|
||||
|
||||
:sql:`inet` data type
|
||||
^^^^^^^^^^^^^^^^^^^^^^
|
||||
Networking data type
|
||||
^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
.. deprecated:: 2.7
|
||||
these objects will not receive further development and disappear in future
|
||||
versions
|
||||
Psycopg casts the PostgreSQL networking data types (:sql:`inet`, :sql:`cidr`,
|
||||
:sql:`macaddr`) into ordinary strings. However their array are detected as
|
||||
arrays and directly cast into lists.
|
||||
|
||||
.. versionchanged:: 2.7
|
||||
in previous version array of networking types were not treated as arrays
|
||||
|
||||
.. autofunction:: register_inet
|
||||
|
||||
.. doctest::
|
||||
|
||||
|
@ -950,11 +957,16 @@ UUID data type
|
|||
>>> cur.fetchone()[0].addr
|
||||
'192.168.0.1/24'
|
||||
|
||||
.. deprecated:: 2.7
|
||||
this function will not receive further development and disappear in future
|
||||
versions
|
||||
|
||||
.. autofunction:: register_inet
|
||||
|
||||
.. autoclass:: Inet
|
||||
|
||||
.. deprecated:: 2.7
|
||||
this object will not receive further development and disappear in future
|
||||
versions
|
||||
|
||||
|
||||
.. index::
|
||||
|
|
|
@ -25,6 +25,9 @@ static long int typecast_DATEARRAY_types[] = {1182, 0};
|
|||
static long int typecast_INTERVALARRAY_types[] = {1187, 0};
|
||||
static long int typecast_BINARYARRAY_types[] = {1001, 0};
|
||||
static long int typecast_ROWIDARRAY_types[] = {1028, 1013, 0};
|
||||
static long int typecast_INETARRAY_types[] = {1041, 0};
|
||||
static long int typecast_CIDRARRAY_types[] = {651, 0};
|
||||
static long int typecast_MACADDRARRAY_types[] = {1040, 0};
|
||||
static long int typecast_UNKNOWN_types[] = {705, 0};
|
||||
|
||||
|
||||
|
@ -57,6 +60,9 @@ static typecastObject_initlist typecast_builtins[] = {
|
|||
{"BINARYARRAY", typecast_BINARYARRAY_types, typecast_BINARYARRAY_cast, "BINARY"},
|
||||
{"ROWIDARRAY", typecast_ROWIDARRAY_types, typecast_ROWIDARRAY_cast, "ROWID"},
|
||||
{"UNKNOWN", typecast_UNKNOWN_types, typecast_UNKNOWN_cast, NULL},
|
||||
{"INETARRAY", typecast_INETARRAY_types, typecast_STRINGARRAY_cast, "STRING"},
|
||||
{"CIDRARRAY", typecast_CIDRARRAY_types, typecast_STRINGARRAY_cast, "STRING"},
|
||||
{"MACADDRARRAY", typecast_MACADDRARRAY_types, typecast_STRINGARRAY_cast, "STRING"},
|
||||
{NULL, NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
|
|
|
@ -349,6 +349,16 @@ class TypesBasicTests(ConnectingTestCase):
|
|||
a = self.execute("select '{1, 2, NULL}'::int4[]")
|
||||
self.assertEqual(a, [2, 4, 'nada'])
|
||||
|
||||
@testutils.skip_before_postgres(8, 2)
|
||||
def testNetworkArray(self):
|
||||
# we don't know these types, but we know their arrays
|
||||
a = self.execute("select '{192.168.0.1/24}'::inet[]")
|
||||
self.assertEqual(a, ['192.168.0.1/24'])
|
||||
a = self.execute("select '{192.168.0.0/24}'::cidr[]")
|
||||
self.assertEqual(a, ['192.168.0.0/24'])
|
||||
a = self.execute("select '{10:20:30:40:50:60}'::macaddr[]")
|
||||
self.assertEqual(a, ['10:20:30:40:50:60'])
|
||||
|
||||
|
||||
class AdaptSubclassTest(unittest.TestCase):
|
||||
def test_adapt_subtype(self):
|
||||
|
|
Loading…
Reference in New Issue
Block a user