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.
This commit is contained in:
Anthony Tuininga 2018-09-21 11:05:40 -06:00
parent 20c930e2e0
commit 74d9d71484
21 changed files with 34 additions and 34 deletions

View File

@ -461,7 +461,7 @@ Connection Object
import cx_Oracle 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) connection.shutdown(mode = cx_Oracle.DBSHUTDOWN_IMMEDIATE)
cursor = connection.cursor() cursor = connection.cursor()
cursor.execute("alter database close normal") cursor.execute("alter database close normal")
@ -484,10 +484,10 @@ Connection Object
import cx_Oracle import cx_Oracle
connection = cx_Oracle.Connection( connection = cx_Oracle.connect(
mode = cx_Oracle.SYSDBA | cx_Oracle.PRELIM_AUTH) mode=cx_Oracle.SYSDBA | cx_Oracle.PRELIM_AUTH)
connection.startup() connection.startup()
connection = cx_Oracle.connect(mode = cx_Oracle.SYSDBA) connection = cx_Oracle.connect(mode=cx_Oracle.SYSDBA)
cursor = connection.cursor() cursor = connection.cursor()
cursor.execute("alter database mount") cursor.execute("alter database mount")
cursor.execute("alter database open") cursor.execute("alter database open")

View File

@ -1251,7 +1251,7 @@ This allows you to use the exceptions for example in the following way:
import cx_Oracle import cx_Oracle
connection = cx_Oracle.Connection("cx_Oracle/dev@localhost/orclpdb") connection = cx_Oracle.connect("cx_Oracle/dev@localhost/orclpdb")
cursor = connection.cursor() cursor = connection.cursor()
try: try:

View File

@ -26,7 +26,7 @@ import SampleEnv
import decimal import decimal
# connect to database # connect to database
connection = cx_Oracle.Connection(SampleEnv.MAIN_CONNECT_STRING) connection = cx_Oracle.connect(SampleEnv.MAIN_CONNECT_STRING)
cursor = connection.cursor() cursor = connection.cursor()
# dequeue all existing messages to ensure the queue is empty, just so that # dequeue all existing messages to ensure the queue is empty, just so that

View File

@ -31,7 +31,7 @@ def callback(message):
print("Queue name:", message.queueName) print("Queue name:", message.queueName)
print("Consumer name:", message.consumerName) 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, sub = connection.subscribe(namespace = cx_Oracle.SUBSCR_NAMESPACE_AQ,
name = "BOOKS", callback = callback, timeout = 300) name = "BOOKS", callback = callback, timeout = 300)
print("Subscription:", sub) print("Subscription:", sub)

View File

@ -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. # Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved.
# #
@ -29,7 +29,7 @@ APP_CTX_ENTRIES = [
( APP_CTX_NAMESPACE, "ATTR3", "VALUE3" ) ( 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) appcontext = APP_CTX_ENTRIES)
cursor = connection.cursor() cursor = connection.cursor()
for namespace, name, value in APP_CTX_ENTRIES: for namespace, name, value in APP_CTX_ENTRIES:

View File

@ -18,7 +18,7 @@ from __future__ import print_function
import cx_Oracle import cx_Oracle
import SampleEnv import SampleEnv
connection = cx_Oracle.Connection(SampleEnv.MAIN_CONNECT_STRING) connection = cx_Oracle.connect(SampleEnv.MAIN_CONNECT_STRING)
cursor = connection.cursor() cursor = connection.cursor()
# show the number of rows for each parent ID as a means of verifying the # show the number of rows for each parent ID as a means of verifying the

View File

@ -50,7 +50,7 @@ def callback(message):
print("-" * 60) print("-" * 60)
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, sub = connection.subscribe(callback = callback, timeout = 1800,
qos = cx_Oracle.SUBSCR_QOS_QUERY | cx_Oracle.SUBSCR_QOS_ROWIDS) qos = cx_Oracle.SUBSCR_QOS_QUERY | cx_Oracle.SUBSCR_QOS_ROWIDS)
print("Subscription:", sub) print("Subscription:", sub)

View File

@ -22,7 +22,7 @@ import datetime
import SampleEnv import SampleEnv
# truncate table first so that script can be rerun # 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() cursor = connection.cursor()
print("Truncating table...") print("Truncating table...")
cursor.execute("truncate table TestTempTable") cursor.execute("truncate table TestTempTable")

View File

@ -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. # Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved.
# #
@ -33,7 +33,7 @@ from __future__ import print_function
import cx_Oracle import cx_Oracle
import SampleEnv 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) purity = cx_Oracle.ATTR_PURITY_SELF)
cursor = conn.cursor() cursor = conn.cursor()
print("Performing query using DRCP...") print("Performing query using DRCP...")

View File

@ -47,7 +47,7 @@ def callback(message):
print("-" * 60) print("-" * 60)
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, sub = connection.subscribe(callback = callback, timeout = 1800,
qos = cx_Oracle.SUBSCR_QOS_ROWIDS) qos = cx_Oracle.SUBSCR_QOS_ROWIDS)
print("Subscription:", sub) print("Subscription:", sub)

View File

@ -24,7 +24,7 @@ import SampleEnv
import os import os
# connect to the editions user and create a procedure # 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:", print("Edition should be None, actual value is:",
repr(connection.edition)) repr(connection.edition))
cursor = connection.cursor() cursor = connection.cursor()
@ -58,7 +58,7 @@ print("Function should return 'Base Procedure', actually returns:",
repr(result)) repr(result))
# the edition can be set upon connection # 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()) edition = SampleEnv.EDITION_NAME.upper())
cursor = connection.cursor() cursor = connection.cursor()
result = cursor.callfunc("TestEditions", str) 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 # it can also be set via the environment variable ORA_EDITION
os.environ["ORA_EDITION"] = SampleEnv.EDITION_NAME.upper() 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()), print("Edition should be", repr(SampleEnv.EDITION_NAME.upper()),
"actual value is:", repr(connection.edition)) "actual value is:", repr(connection.edition))
cursor = connection.cursor() cursor = connection.cursor()

View File

@ -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. # Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved.
# #
@ -21,7 +21,7 @@ import cx_Oracle
import SampleEnv import SampleEnv
# create and populate Oracle objects # 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") typeObj = connection.gettype("MDSYS.SDO_GEOMETRY")
elementInfoTypeObj = connection.gettype("MDSYS.SDO_ELEM_INFO_ARRAY") elementInfoTypeObj = connection.gettype("MDSYS.SDO_ELEM_INFO_ARRAY")
ordinateTypeObj = connection.gettype("MDSYS.SDO_ORDINATE_ARRAY") ordinateTypeObj = connection.gettype("MDSYS.SDO_ORDINATE_ARRAY")

View File

@ -12,7 +12,7 @@ from __future__ import print_function
import cx_Oracle import cx_Oracle
import SampleEnv import SampleEnv
connection = cx_Oracle.Connection(SampleEnv.MAIN_CONNECT_STRING) connection = cx_Oracle.connect(SampleEnv.MAIN_CONNECT_STRING)
cursor = connection.cursor() cursor = connection.cursor()
refCursor = connection.cursor() refCursor = connection.cursor()

View File

@ -29,7 +29,7 @@ def OutputTypeHandler(cursor, name, defaultType, size, precision, scale):
if defaultType == cx_Oracle.BLOB: if defaultType == cx_Oracle.BLOB:
return cursor.var(cx_Oracle.LONG_BINARY, arraysize = cursor.arraysize) 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 connection.outputtypehandler = OutputTypeHandler
cursor = connection.cursor() cursor = connection.cursor()

View File

@ -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: if defaultType == cx_Oracle.NUMBER:
return cursor.var(decimal.Decimal, arraysize = cursor.arraysize) 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 connection.outputtypehandler = OutputTypeHandler
cursor = connection.cursor() cursor = connection.cursor()
cursor.execute("select * from TestNumbers") cursor.execute("select * from TestNumbers")

View File

@ -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. # 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): if defaultType in (cx_Oracle.STRING, cx_Oracle.FIXED_CHAR):
return cursor.var(unicode, size, cursor.arraysize) 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 connection.outputtypehandler = OutputTypeHandler
cursor = connection.cursor() cursor = connection.cursor()
cursor.execute("select * from TestStrings") cursor.execute("select * from TestStrings")

View File

@ -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. # Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved.
# #
@ -28,7 +28,7 @@ class Test(object):
self.b = b self.b = b
self.c = c self.c = c
connection = cx_Oracle.Connection(SampleEnv.MAIN_CONNECT_STRING) connection = cx_Oracle.connect(SampleEnv.MAIN_CONNECT_STRING)
cursor = connection.cursor() cursor = connection.cursor()
# change this to False if you want to create the table yourself using SQL*Plus # change this to False if you want to create the table yourself using SQL*Plus

View File

@ -17,7 +17,7 @@ from __future__ import print_function
import cx_Oracle import cx_Oracle
import SampleEnv 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 # The general recommendation for simple SODA usage is to enable autocommit
connection.autocommit = True connection.autocommit = True

View File

@ -30,7 +30,7 @@ from shapely.wkb import loads
import geopandas as gpd import geopandas as gpd
# create Oracle connection and cursor objects # 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() cursor = connection.cursor()
# enable autocommit to avoid the additional round trip to the database to # enable autocommit to avoid the additional round trip to the database to

View File

@ -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. # Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved.
# #
@ -28,7 +28,7 @@ DATA = [
] ]
# truncate table so sample can be rerun # 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() cursor = connection.cursor()
print("Truncating table...") print("Truncating table...")
cursor.execute("truncate table TestUniversalRowids") cursor.execute("truncate table TestUniversalRowids")

View File

@ -26,7 +26,7 @@ print("File:", cx_Oracle.__file__)
print("Client Version:", ".".join(str(i) for i in cx_Oracle.clientversion())) print("Client Version:", ".".join(str(i) for i in cx_Oracle.clientversion()))
sys.stdout.flush() 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, TestEnv.CONNECT_STRING, encoding = TestEnv.ENCODING,
nencoding = TestEnv.NENCODING) nencoding = TestEnv.NENCODING)
print("Server Version:", connection.version) print("Server Version:", connection.version)
@ -69,7 +69,7 @@ class BaseTestCase(unittest.TestCase):
def getConnection(self, **kwargs): def getConnection(self, **kwargs):
import cx_Oracle import cx_Oracle
import TestEnv 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, TestEnv.CONNECT_STRING, encoding = TestEnv.ENCODING,
nencoding = TestEnv.NENCODING, **kwargs) nencoding = TestEnv.NENCODING, **kwargs)