From 74d9d7148485fbc1a2725931b961fd19212949d5 Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Fri, 21 Sep 2018 11:05:40 -0600 Subject: [PATCH] Use cx_Oracle.connect() in preference to cx_Oracle.Connection() in samples and tests. Although the two are aliases of one another, it makes sense to be consistent and to use the one that the DB API prefers as well. --- doc/src/connection.rst | 8 ++++---- doc/src/module.rst | 2 +- samples/AdvancedQueuing.py | 2 +- samples/AdvancedQueuingNotification.py | 2 +- samples/AppContext.py | 4 ++-- samples/ArrayDMLRowCounts.py | 2 +- samples/CQN.py | 2 +- samples/DMLReturningMultipleRows.py | 2 +- samples/DRCP.py | 4 ++-- samples/DatabaseChangeNotification.py | 2 +- samples/Editioning.py | 6 +++--- samples/InsertGeometry.py | 4 ++-- samples/RefCursor.py | 2 +- samples/ReturnLobsAsStrings.py | 2 +- samples/ReturnNumbersAsDecimals.py | 4 ++-- samples/ReturnUnicode.py | 4 ++-- samples/RowsAsInstance.py | 4 ++-- samples/SodaBasic.py | 2 +- samples/SpatialToGeoPandas.py | 2 +- samples/UniversalRowids.py | 4 ++-- test/test.py | 4 ++-- 21 files changed, 34 insertions(+), 34 deletions(-) diff --git a/doc/src/connection.rst b/doc/src/connection.rst index 6a00d81..ac3e081 100644 --- a/doc/src/connection.rst +++ b/doc/src/connection.rst @@ -461,7 +461,7 @@ Connection Object import cx_Oracle - connection = cx_Oracle.Connection(mode = cx_Oracle.SYSDBA) + connection = cx_Oracle.connect(mode = cx_Oracle.SYSDBA) connection.shutdown(mode = cx_Oracle.DBSHUTDOWN_IMMEDIATE) cursor = connection.cursor() cursor.execute("alter database close normal") @@ -484,10 +484,10 @@ Connection Object import cx_Oracle - connection = cx_Oracle.Connection( - mode = cx_Oracle.SYSDBA | cx_Oracle.PRELIM_AUTH) + connection = cx_Oracle.connect( + mode=cx_Oracle.SYSDBA | cx_Oracle.PRELIM_AUTH) connection.startup() - connection = cx_Oracle.connect(mode = cx_Oracle.SYSDBA) + connection = cx_Oracle.connect(mode=cx_Oracle.SYSDBA) cursor = connection.cursor() cursor.execute("alter database mount") cursor.execute("alter database open") diff --git a/doc/src/module.rst b/doc/src/module.rst index 80b4a2d..ae9f4cc 100644 --- a/doc/src/module.rst +++ b/doc/src/module.rst @@ -1251,7 +1251,7 @@ This allows you to use the exceptions for example in the following way: import cx_Oracle - connection = cx_Oracle.Connection("cx_Oracle/dev@localhost/orclpdb") + connection = cx_Oracle.connect("cx_Oracle/dev@localhost/orclpdb") cursor = connection.cursor() try: diff --git a/samples/AdvancedQueuing.py b/samples/AdvancedQueuing.py index 2ad34c9..67f8bb7 100644 --- a/samples/AdvancedQueuing.py +++ b/samples/AdvancedQueuing.py @@ -26,7 +26,7 @@ import SampleEnv import decimal # connect to database -connection = cx_Oracle.Connection(SampleEnv.MAIN_CONNECT_STRING) +connection = cx_Oracle.connect(SampleEnv.MAIN_CONNECT_STRING) cursor = connection.cursor() # dequeue all existing messages to ensure the queue is empty, just so that diff --git a/samples/AdvancedQueuingNotification.py b/samples/AdvancedQueuingNotification.py index 992ecea..7df4b6e 100644 --- a/samples/AdvancedQueuingNotification.py +++ b/samples/AdvancedQueuingNotification.py @@ -31,7 +31,7 @@ def callback(message): print("Queue name:", message.queueName) print("Consumer name:", message.consumerName) -connection = cx_Oracle.Connection(SampleEnv.MAIN_CONNECT_STRING, events = True) +connection = cx_Oracle.connect(SampleEnv.MAIN_CONNECT_STRING, events = True) sub = connection.subscribe(namespace = cx_Oracle.SUBSCR_NAMESPACE_AQ, name = "BOOKS", callback = callback, timeout = 300) print("Subscription:", sub) diff --git a/samples/AppContext.py b/samples/AppContext.py index d55261e..819ffea 100644 --- a/samples/AppContext.py +++ b/samples/AppContext.py @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------ -# Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. # # Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved. # @@ -29,7 +29,7 @@ APP_CTX_ENTRIES = [ ( APP_CTX_NAMESPACE, "ATTR3", "VALUE3" ) ] -connection = cx_Oracle.Connection(SampleEnv.MAIN_CONNECT_STRING, +connection = cx_Oracle.connect(SampleEnv.MAIN_CONNECT_STRING, appcontext = APP_CTX_ENTRIES) cursor = connection.cursor() for namespace, name, value in APP_CTX_ENTRIES: diff --git a/samples/ArrayDMLRowCounts.py b/samples/ArrayDMLRowCounts.py index 59ec4eb..88f07e0 100644 --- a/samples/ArrayDMLRowCounts.py +++ b/samples/ArrayDMLRowCounts.py @@ -18,7 +18,7 @@ from __future__ import print_function import cx_Oracle import SampleEnv -connection = cx_Oracle.Connection(SampleEnv.MAIN_CONNECT_STRING) +connection = cx_Oracle.connect(SampleEnv.MAIN_CONNECT_STRING) cursor = connection.cursor() # show the number of rows for each parent ID as a means of verifying the diff --git a/samples/CQN.py b/samples/CQN.py index 30829a2..29c1bdb 100644 --- a/samples/CQN.py +++ b/samples/CQN.py @@ -50,7 +50,7 @@ def callback(message): print("-" * 60) print("=" * 60) -connection = cx_Oracle.Connection(SampleEnv.MAIN_CONNECT_STRING, events = True) +connection = cx_Oracle.connect(SampleEnv.MAIN_CONNECT_STRING, events = True) sub = connection.subscribe(callback = callback, timeout = 1800, qos = cx_Oracle.SUBSCR_QOS_QUERY | cx_Oracle.SUBSCR_QOS_ROWIDS) print("Subscription:", sub) diff --git a/samples/DMLReturningMultipleRows.py b/samples/DMLReturningMultipleRows.py index 62adfcd..ebb1267 100644 --- a/samples/DMLReturningMultipleRows.py +++ b/samples/DMLReturningMultipleRows.py @@ -22,7 +22,7 @@ import datetime import SampleEnv # truncate table first so that script can be rerun -connection = cx_Oracle.Connection(SampleEnv.MAIN_CONNECT_STRING) +connection = cx_Oracle.connect(SampleEnv.MAIN_CONNECT_STRING) cursor = connection.cursor() print("Truncating table...") cursor.execute("truncate table TestTempTable") diff --git a/samples/DRCP.py b/samples/DRCP.py index 7d67e9f..8d95e0e 100644 --- a/samples/DRCP.py +++ b/samples/DRCP.py @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------ -# Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. # # Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved. # @@ -33,7 +33,7 @@ from __future__ import print_function import cx_Oracle import SampleEnv -conn = cx_Oracle.Connection(SampleEnv.DRCP_CONNECT_STRING, cclass = "PYCLASS", +conn = cx_Oracle.connect(SampleEnv.DRCP_CONNECT_STRING, cclass = "PYCLASS", purity = cx_Oracle.ATTR_PURITY_SELF) cursor = conn.cursor() print("Performing query using DRCP...") diff --git a/samples/DatabaseChangeNotification.py b/samples/DatabaseChangeNotification.py index e18e30c..2f1dde5 100644 --- a/samples/DatabaseChangeNotification.py +++ b/samples/DatabaseChangeNotification.py @@ -47,7 +47,7 @@ def callback(message): print("-" * 60) print("=" * 60) -connection = cx_Oracle.Connection(SampleEnv.MAIN_CONNECT_STRING, events = True) +connection = cx_Oracle.connect(SampleEnv.MAIN_CONNECT_STRING, events = True) sub = connection.subscribe(callback = callback, timeout = 1800, qos = cx_Oracle.SUBSCR_QOS_ROWIDS) print("Subscription:", sub) diff --git a/samples/Editioning.py b/samples/Editioning.py index e90495e..7cc09a1 100644 --- a/samples/Editioning.py +++ b/samples/Editioning.py @@ -24,7 +24,7 @@ import SampleEnv import os # connect to the editions user and create a procedure -connection = cx_Oracle.Connection(SampleEnv.EDITION_CONNECT_STRING) +connection = cx_Oracle.connect(SampleEnv.EDITION_CONNECT_STRING) print("Edition should be None, actual value is:", repr(connection.edition)) cursor = connection.cursor() @@ -58,7 +58,7 @@ print("Function should return 'Base Procedure', actually returns:", repr(result)) # the edition can be set upon connection -connection = cx_Oracle.Connection(SampleEnv.EDITION_CONNECT_STRING, +connection = cx_Oracle.connect(SampleEnv.EDITION_CONNECT_STRING, edition = SampleEnv.EDITION_NAME.upper()) cursor = connection.cursor() result = cursor.callfunc("TestEditions", str) @@ -67,7 +67,7 @@ print("Function should return 'Edition 1 Procedure', actually returns:", # it can also be set via the environment variable ORA_EDITION os.environ["ORA_EDITION"] = SampleEnv.EDITION_NAME.upper() -connection = cx_Oracle.Connection(SampleEnv.EDITION_CONNECT_STRING) +connection = cx_Oracle.connect(SampleEnv.EDITION_CONNECT_STRING) print("Edition should be", repr(SampleEnv.EDITION_NAME.upper()), "actual value is:", repr(connection.edition)) cursor = connection.cursor() diff --git a/samples/InsertGeometry.py b/samples/InsertGeometry.py index 39008c9..cd3bfe9 100644 --- a/samples/InsertGeometry.py +++ b/samples/InsertGeometry.py @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------ -# Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. # # Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved. # @@ -21,7 +21,7 @@ import cx_Oracle import SampleEnv # create and populate Oracle objects -connection = cx_Oracle.Connection(SampleEnv.MAIN_CONNECT_STRING) +connection = cx_Oracle.connect(SampleEnv.MAIN_CONNECT_STRING) typeObj = connection.gettype("MDSYS.SDO_GEOMETRY") elementInfoTypeObj = connection.gettype("MDSYS.SDO_ELEM_INFO_ARRAY") ordinateTypeObj = connection.gettype("MDSYS.SDO_ORDINATE_ARRAY") diff --git a/samples/RefCursor.py b/samples/RefCursor.py index 2e013ac..bf3fcfd 100644 --- a/samples/RefCursor.py +++ b/samples/RefCursor.py @@ -12,7 +12,7 @@ from __future__ import print_function import cx_Oracle import SampleEnv -connection = cx_Oracle.Connection(SampleEnv.MAIN_CONNECT_STRING) +connection = cx_Oracle.connect(SampleEnv.MAIN_CONNECT_STRING) cursor = connection.cursor() refCursor = connection.cursor() diff --git a/samples/ReturnLobsAsStrings.py b/samples/ReturnLobsAsStrings.py index 9ece548..d17a55b 100644 --- a/samples/ReturnLobsAsStrings.py +++ b/samples/ReturnLobsAsStrings.py @@ -29,7 +29,7 @@ def OutputTypeHandler(cursor, name, defaultType, size, precision, scale): if defaultType == cx_Oracle.BLOB: return cursor.var(cx_Oracle.LONG_BINARY, arraysize = cursor.arraysize) -connection = cx_Oracle.Connection(SampleEnv.MAIN_CONNECT_STRING) +connection = cx_Oracle.connect(SampleEnv.MAIN_CONNECT_STRING) connection.outputtypehandler = OutputTypeHandler cursor = connection.cursor() diff --git a/samples/ReturnNumbersAsDecimals.py b/samples/ReturnNumbersAsDecimals.py index 1a8d883..a738677 100644 --- a/samples/ReturnNumbersAsDecimals.py +++ b/samples/ReturnNumbersAsDecimals.py @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------ -# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. #------------------------------------------------------------------------------ #------------------------------------------------------------------------------ @@ -24,7 +24,7 @@ def OutputTypeHandler(cursor, name, defaultType, size, precision, scale): if defaultType == cx_Oracle.NUMBER: return cursor.var(decimal.Decimal, arraysize = cursor.arraysize) -connection = cx_Oracle.Connection(SampleEnv.MAIN_CONNECT_STRING) +connection = cx_Oracle.connect(SampleEnv.MAIN_CONNECT_STRING) connection.outputtypehandler = OutputTypeHandler cursor = connection.cursor() cursor.execute("select * from TestNumbers") diff --git a/samples/ReturnUnicode.py b/samples/ReturnUnicode.py index bef61e9..02767fe 100644 --- a/samples/ReturnUnicode.py +++ b/samples/ReturnUnicode.py @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------ -# Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. # # Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved. # @@ -24,7 +24,7 @@ def OutputTypeHandler(cursor, name, defaultType, size, precision, scale): if defaultType in (cx_Oracle.STRING, cx_Oracle.FIXED_CHAR): return cursor.var(unicode, size, cursor.arraysize) -connection = cx_Oracle.Connection(SampleEnv.MAIN_CONNECT_STRING) +connection = cx_Oracle.connect(SampleEnv.MAIN_CONNECT_STRING) connection.outputtypehandler = OutputTypeHandler cursor = connection.cursor() cursor.execute("select * from TestStrings") diff --git a/samples/RowsAsInstance.py b/samples/RowsAsInstance.py index 9719431..e87becb 100644 --- a/samples/RowsAsInstance.py +++ b/samples/RowsAsInstance.py @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------ -# Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. # # Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved. # @@ -28,7 +28,7 @@ class Test(object): self.b = b self.c = c -connection = cx_Oracle.Connection(SampleEnv.MAIN_CONNECT_STRING) +connection = cx_Oracle.connect(SampleEnv.MAIN_CONNECT_STRING) cursor = connection.cursor() # change this to False if you want to create the table yourself using SQL*Plus diff --git a/samples/SodaBasic.py b/samples/SodaBasic.py index 434829c..de73c26 100644 --- a/samples/SodaBasic.py +++ b/samples/SodaBasic.py @@ -17,7 +17,7 @@ from __future__ import print_function import cx_Oracle import SampleEnv -connection = cx_Oracle.Connection(SampleEnv.MAIN_CONNECT_STRING) +connection = cx_Oracle.connect(SampleEnv.MAIN_CONNECT_STRING) # The general recommendation for simple SODA usage is to enable autocommit connection.autocommit = True diff --git a/samples/SpatialToGeoPandas.py b/samples/SpatialToGeoPandas.py index 0e6b681..4a0bc5a 100644 --- a/samples/SpatialToGeoPandas.py +++ b/samples/SpatialToGeoPandas.py @@ -30,7 +30,7 @@ from shapely.wkb import loads import geopandas as gpd # create Oracle connection and cursor objects -connection = cx_Oracle.Connection(SampleEnv.MAIN_CONNECT_STRING) +connection = cx_Oracle.connect(SampleEnv.MAIN_CONNECT_STRING) cursor = connection.cursor() # enable autocommit to avoid the additional round trip to the database to diff --git a/samples/UniversalRowids.py b/samples/UniversalRowids.py index b523886..18d4cb5 100644 --- a/samples/UniversalRowids.py +++ b/samples/UniversalRowids.py @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------ -# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. # # Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved. # @@ -28,7 +28,7 @@ DATA = [ ] # truncate table so sample can be rerun -connection = cx_Oracle.Connection(SampleEnv.MAIN_CONNECT_STRING) +connection = cx_Oracle.connect(SampleEnv.MAIN_CONNECT_STRING) cursor = connection.cursor() print("Truncating table...") cursor.execute("truncate table TestUniversalRowids") diff --git a/test/test.py b/test/test.py index 8b8e18b..2e9c429 100644 --- a/test/test.py +++ b/test/test.py @@ -26,7 +26,7 @@ print("File:", cx_Oracle.__file__) print("Client Version:", ".".join(str(i) for i in cx_Oracle.clientversion())) sys.stdout.flush() -connection = cx_Oracle.Connection(TestEnv.MAIN_USER, TestEnv.MAIN_PASSWORD, +connection = cx_Oracle.connect(TestEnv.MAIN_USER, TestEnv.MAIN_PASSWORD, TestEnv.CONNECT_STRING, encoding = TestEnv.ENCODING, nencoding = TestEnv.NENCODING) print("Server Version:", connection.version) @@ -69,7 +69,7 @@ class BaseTestCase(unittest.TestCase): def getConnection(self, **kwargs): import cx_Oracle import TestEnv - return cx_Oracle.Connection(TestEnv.MAIN_USER, TestEnv.MAIN_PASSWORD, + return cx_Oracle.connect(TestEnv.MAIN_USER, TestEnv.MAIN_PASSWORD, TestEnv.CONNECT_STRING, encoding = TestEnv.ENCODING, nencoding = TestEnv.NENCODING, **kwargs)