diff options
author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2016-10-11 02:31:45 +0100 |
---|---|---|
committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2016-10-11 02:31:45 +0100 |
commit | 706ad2f177d5e3250643765446e66b82e9849648 (patch) | |
tree | 123fde2c2987d63bd312bc2901a2c57baedca3eb | |
parent | 86198c1c21e959030cf5710a6d4d2fcb3337596b (diff) | |
download | psycopg2-706ad2f177d5e3250643765446e66b82e9849648.tar.gz |
Conver network array types into array of strings by default
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | doc/src/extras.rst | 24 | ||||
-rw-r--r-- | psycopg/typecast_builtins.c | 6 | ||||
-rwxr-xr-x | tests/test_types_basic.py | 10 |
4 files changed, 36 insertions, 7 deletions
@@ -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`). diff --git a/doc/src/extras.rst b/doc/src/extras.rst index 3a3d232..cf871af 100644 --- a/doc/src/extras.rst +++ b/doc/src/extras.rst @@ -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:: diff --git a/psycopg/typecast_builtins.c b/psycopg/typecast_builtins.c index a104b7c..fa548a7 100644 --- a/psycopg/typecast_builtins.c +++ b/psycopg/typecast_builtins.c @@ -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} }; diff --git a/tests/test_types_basic.py b/tests/test_types_basic.py index b43ea53..bee23d5 100755 --- a/tests/test_types_basic.py +++ b/tests/test_types_basic.py @@ -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): |