Skip to content

Commit

Permalink
Use cx_Oracle.connect() in preference to cx_Oracle.Connection() in sa…
Browse files Browse the repository at this point in the history
…mples 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.
  • Loading branch information
anthony-tuininga committed Sep 21, 2018
1 parent 20c930e commit 74d9d71
Show file tree
Hide file tree
Showing 21 changed files with 34 additions and 34 deletions.
8 changes: 4 additions & 4 deletions doc/src/connection.rst
Expand Up @@ -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")
Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion doc/src/module.rst
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion samples/AdvancedQueuing.py
Expand Up @@ -26,7 +26,7 @@
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
Expand Down
2 changes: 1 addition & 1 deletion samples/AdvancedQueuingNotification.py
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions 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.
#
Expand Down Expand Up @@ -29,7 +29,7 @@
( 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:
Expand Down
2 changes: 1 addition & 1 deletion samples/ArrayDMLRowCounts.py
Expand Up @@ -18,7 +18,7 @@
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
Expand Down
2 changes: 1 addition & 1 deletion samples/CQN.py
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion samples/DMLReturningMultipleRows.py
Expand Up @@ -22,7 +22,7 @@
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")
Expand Down
4 changes: 2 additions & 2 deletions 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.
#
Expand Down Expand Up @@ -33,7 +33,7 @@
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...")
Expand Down
2 changes: 1 addition & 1 deletion samples/DatabaseChangeNotification.py
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions samples/Editioning.py
Expand Up @@ -24,7 +24,7 @@
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()
Expand Down Expand Up @@ -58,7 +58,7 @@
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)
Expand All @@ -67,7 +67,7 @@

# 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()
Expand Down
4 changes: 2 additions & 2 deletions 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.
#
Expand All @@ -21,7 +21,7 @@
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")
Expand Down
2 changes: 1 addition & 1 deletion samples/RefCursor.py
Expand Up @@ -12,7 +12,7 @@
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()
Expand Down
2 changes: 1 addition & 1 deletion samples/ReturnLobsAsStrings.py
Expand Up @@ -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()

Expand Down
4 changes: 2 additions & 2 deletions 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.
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
Expand All @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions 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.
#
Expand All @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions 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.
#
Expand Down Expand Up @@ -28,7 +28,7 @@ def __init__(self, a, b, c):
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
Expand Down
2 changes: 1 addition & 1 deletion samples/SodaBasic.py
Expand Up @@ -17,7 +17,7 @@
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
Expand Down
2 changes: 1 addition & 1 deletion samples/SpatialToGeoPandas.py
Expand Up @@ -30,7 +30,7 @@
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
Expand Down
4 changes: 2 additions & 2 deletions 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.
#
Expand Down Expand Up @@ -28,7 +28,7 @@
]

# 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")
Expand Down
4 changes: 2 additions & 2 deletions test/test.py
Expand Up @@ -26,7 +26,7 @@
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)
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 74d9d71

Please sign in to comment.