Rework test suite further to use PEP 8 style guidelines.
This commit is contained in:
parent
ef3d84318e
commit
229f9f5533
|
@ -44,7 +44,8 @@
|
|||
# user for on premises databases is SYSTEM.
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
import cx_Oracle
|
||||
import cx_Oracle as oracledb
|
||||
|
||||
import getpass
|
||||
import os
|
||||
import sys
|
||||
|
@ -60,136 +61,137 @@ DEFAULT_CONNECT_STRING = "localhost/orclpdb1"
|
|||
# directly) and then stored so that a value is not requested more than once
|
||||
PARAMETERS = {}
|
||||
|
||||
def GetValue(name, label, defaultValue=""):
|
||||
def get_value(name, label, default_value=""):
|
||||
value = PARAMETERS.get(name)
|
||||
if value is not None:
|
||||
return value
|
||||
envName = "CX_ORACLE_TEST_" + name
|
||||
value = os.environ.get(envName)
|
||||
env_name = "CX_ORACLE_TEST_" + name
|
||||
value = os.environ.get(env_name)
|
||||
if value is None:
|
||||
if defaultValue:
|
||||
label += " [%s]" % defaultValue
|
||||
if default_value:
|
||||
label += " [%s]" % default_value
|
||||
label += ": "
|
||||
if defaultValue:
|
||||
if default_value:
|
||||
value = input(label).strip()
|
||||
else:
|
||||
value = getpass.getpass(label)
|
||||
if not value:
|
||||
value = defaultValue
|
||||
value = default_value
|
||||
PARAMETERS[name] = value
|
||||
return value
|
||||
|
||||
def GetMainUser():
|
||||
return GetValue("MAIN_USER", "Main User Name", DEFAULT_MAIN_USER)
|
||||
def get_admin_connect_string():
|
||||
admin_user = get_value("ADMIN_USER", "Administrative user", "admin")
|
||||
admin_password = get_value("ADMIN_PASSWORD",
|
||||
"Password for %s" % admin_user)
|
||||
return "%s/%s@%s" % (admin_user, admin_password, get_connect_string())
|
||||
|
||||
def GetMainPassword():
|
||||
return GetValue("MAIN_PASSWORD", "Password for %s" % GetMainUser())
|
||||
|
||||
def GetProxyUser():
|
||||
return GetValue("PROXY_USER", "Proxy User Name", DEFAULT_PROXY_USER)
|
||||
|
||||
def GetProxyPassword():
|
||||
return GetValue("PROXY_PASSWORD", "Password for %s" % GetProxyUser())
|
||||
|
||||
def GetConnectString():
|
||||
return GetValue("CONNECT_STRING", "Connect String", DEFAULT_CONNECT_STRING)
|
||||
|
||||
def GetCharSetRatio():
|
||||
def get_charset_ratio():
|
||||
value = PARAMETERS.get("CS_RATIO")
|
||||
if value is None:
|
||||
connection = GetConnection()
|
||||
connection = get_connection()
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("select 'X' from dual")
|
||||
col, = cursor.description
|
||||
value = col[3]
|
||||
PARAMETERS["CS_RATIO"] = value
|
||||
column_info, = cursor.description
|
||||
value = PARAMETERS["CS_RATIO"] = column_info[3]
|
||||
return value
|
||||
|
||||
def GetAdminConnectString():
|
||||
adminUser = GetValue("ADMIN_USER", "Administrative user", "admin")
|
||||
adminPassword = GetValue("ADMIN_PASSWORD", "Password for %s" % adminUser)
|
||||
return "%s/%s@%s" % (adminUser, adminPassword, GetConnectString())
|
||||
def get_client_version():
|
||||
name = "CLIENT_VERSION"
|
||||
value = PARAMETERS.get(name)
|
||||
if value is None:
|
||||
value = oracledb.clientversion()[:2]
|
||||
PARAMETERS[name] = value
|
||||
return value
|
||||
|
||||
def RunSqlScript(conn, scriptName, **kwargs):
|
||||
statementParts = []
|
||||
def get_connection(**kwargs):
|
||||
return oracledb.connect(dsn=get_connect_string(), user=get_main_user(),
|
||||
password=get_main_password(), **kwargs)
|
||||
|
||||
def get_connect_string():
|
||||
return get_value("CONNECT_STRING", "Connect String",
|
||||
DEFAULT_CONNECT_STRING)
|
||||
|
||||
def get_main_password():
|
||||
return get_value("MAIN_PASSWORD", "Password for %s" % get_main_user())
|
||||
|
||||
def get_main_user():
|
||||
return get_value("MAIN_USER", "Main User Name", DEFAULT_MAIN_USER)
|
||||
|
||||
def get_pool(user=None, password=None, **kwargs):
|
||||
if user is None:
|
||||
user = get_main_user()
|
||||
if password is None:
|
||||
password = get_main_password()
|
||||
return oracledb.SessionPool(user, password, get_connect_string(),
|
||||
**kwargs)
|
||||
|
||||
def get_proxy_password():
|
||||
return get_value("PROXY_PASSWORD", "Password for %s" % get_proxy_user())
|
||||
|
||||
def get_proxy_user():
|
||||
return get_value("PROXY_USER", "Proxy User Name", DEFAULT_PROXY_USER)
|
||||
|
||||
def get_server_version():
|
||||
name = "SERVER_VERSION"
|
||||
value = PARAMETERS.get(name)
|
||||
if value is None:
|
||||
conn = get_connection()
|
||||
value = tuple(int(s) for s in conn.version.split("."))[:2]
|
||||
PARAMETERS[name] = value
|
||||
return value
|
||||
|
||||
def run_sql_script(conn, script_name, **kwargs):
|
||||
statement_parts = []
|
||||
cursor = conn.cursor()
|
||||
replaceValues = [("&" + k + ".", v) for k, v in kwargs.items()] + \
|
||||
[("&" + k, v) for k, v in kwargs.items()]
|
||||
scriptDir = os.path.dirname(os.path.abspath(sys.argv[0]))
|
||||
fileName = os.path.join(scriptDir, "sql", scriptName + "Exec.sql")
|
||||
for line in open(fileName):
|
||||
replace_values = [("&" + k + ".", v) for k, v in kwargs.items()] + \
|
||||
[("&" + k, v) for k, v in kwargs.items()]
|
||||
script_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
|
||||
file_name = os.path.join(script_dir, "sql", script_name + "Exec.sql")
|
||||
for line in open(file_name):
|
||||
if line.strip() == "/":
|
||||
statement = "".join(statementParts).strip()
|
||||
statement = "".join(statement_parts).strip()
|
||||
if statement:
|
||||
for searchValue, replaceValue in replaceValues:
|
||||
statement = statement.replace(searchValue, replaceValue)
|
||||
for search_value, replace_value in replace_values:
|
||||
statement = statement.replace(search_value, replace_value)
|
||||
try:
|
||||
cursor.execute(statement)
|
||||
except:
|
||||
print("Failed to execute SQL:", statement)
|
||||
raise
|
||||
statementParts = []
|
||||
statement_parts = []
|
||||
else:
|
||||
statementParts.append(line)
|
||||
statement_parts.append(line)
|
||||
cursor.execute("""
|
||||
select name, type, line, position, text
|
||||
from dba_errors
|
||||
where owner = upper(:owner)
|
||||
order by name, type, line, position""",
|
||||
owner = GetMainUser())
|
||||
prevName = prevObjType = None
|
||||
for name, objType, lineNum, position, text in cursor:
|
||||
if name != prevName or objType != prevObjType:
|
||||
print("%s (%s)" % (name, objType))
|
||||
prevName = name
|
||||
prevObjType = objType
|
||||
print(" %s/%s %s" % (lineNum, position, text))
|
||||
owner = get_main_user())
|
||||
prev_name = prev_obj_type = None
|
||||
for name, obj_type, line_num, position, text in cursor:
|
||||
if name != prev_name or obj_type != prev_obj_type:
|
||||
print("%s (%s)" % (name, obj_type))
|
||||
prev_name = name
|
||||
prev_obj_type = obj_type
|
||||
print(" %s/%s %s" % (line_num, position, text))
|
||||
|
||||
def RunTestCases():
|
||||
print("Running tests for cx_Oracle version", cx_Oracle.version,
|
||||
"built at", cx_Oracle.buildtime)
|
||||
print("File:", cx_Oracle.__file__)
|
||||
def run_test_cases():
|
||||
print("Running tests for cx_Oracle version", oracledb.version,
|
||||
"built at", oracledb.buildtime)
|
||||
print("File:", oracledb.__file__)
|
||||
print("Client Version:",
|
||||
".".join(str(i) for i in cx_Oracle.clientversion()))
|
||||
with GetConnection() as connection:
|
||||
".".join(str(i) for i in oracledb.clientversion()))
|
||||
with get_connection() as connection:
|
||||
print("Server Version:", connection.version)
|
||||
print()
|
||||
unittest.main(testRunner=unittest.TextTestRunner(verbosity=2))
|
||||
|
||||
def GetConnection(**kwargs):
|
||||
return cx_Oracle.connect(GetMainUser(), GetMainPassword(),
|
||||
GetConnectString(), encoding="UTF-8", nencoding="UTF-8", **kwargs)
|
||||
|
||||
def GetPool(user=None, password=None, **kwargs):
|
||||
if user is None:
|
||||
user = GetMainUser()
|
||||
if password is None:
|
||||
password = GetMainPassword()
|
||||
return cx_Oracle.SessionPool(user, password, GetConnectString(),
|
||||
encoding="UTF-8", nencoding="UTF-8", **kwargs)
|
||||
|
||||
def GetClientVersion():
|
||||
name = "CLIENT_VERSION"
|
||||
value = PARAMETERS.get(name)
|
||||
if value is None:
|
||||
value = cx_Oracle.clientversion()[:2]
|
||||
PARAMETERS[name] = value
|
||||
return value
|
||||
|
||||
def GetServerVersion():
|
||||
name = "SERVER_VERSION"
|
||||
value = PARAMETERS.get(name)
|
||||
if value is None:
|
||||
conn = GetConnection()
|
||||
value = tuple(int(s) for s in conn.version.split("."))[:2]
|
||||
PARAMETERS[name] = value
|
||||
return value
|
||||
|
||||
def SkipSodaTests():
|
||||
client = GetClientVersion()
|
||||
def skip_soda_tests():
|
||||
client = get_client_version()
|
||||
if client < (18, 3):
|
||||
return True
|
||||
server = GetServerVersion()
|
||||
server = get_server_version()
|
||||
if server < (18, 0):
|
||||
return True
|
||||
if server > (20, 1) and client < (20, 1):
|
||||
|
@ -199,68 +201,65 @@ def SkipSodaTests():
|
|||
class RoundTripInfo:
|
||||
|
||||
def __init__(self, connection):
|
||||
self.prevRoundTrips = 0
|
||||
self.adminConn = cx_Oracle.connect(GetAdminConnectString())
|
||||
self.prev_round_trips = 0
|
||||
self.admin_conn = oracledb.connect(get_admin_connect_string())
|
||||
with connection.cursor() as cursor:
|
||||
cursor.execute("select sys_context('userenv', 'sid') from dual")
|
||||
self.sid, = cursor.fetchone()
|
||||
self.getRoundTrips()
|
||||
self.get_round_trips()
|
||||
|
||||
def getRoundTrips(self):
|
||||
with self.adminConn.cursor() as cursor:
|
||||
def get_round_trips(self):
|
||||
with self.admin_conn.cursor() as cursor:
|
||||
cursor.execute("""
|
||||
select ss.value
|
||||
from v$sesstat ss, v$statname sn
|
||||
where ss.sid = :sid
|
||||
and ss.statistic# = sn.statistic#
|
||||
and sn.name like '%roundtrip%client%'""", sid=self.sid)
|
||||
currentRoundTrips, = cursor.fetchone()
|
||||
diffRoundTrips = currentRoundTrips - self.prevRoundTrips
|
||||
self.prevRoundTrips = currentRoundTrips
|
||||
return diffRoundTrips
|
||||
current_round_trips, = cursor.fetchone()
|
||||
diff_round_trips = current_round_trips - self.prev_round_trips
|
||||
self.prev_round_trips = current_round_trips
|
||||
return diff_round_trips
|
||||
|
||||
class BaseTestCase(unittest.TestCase):
|
||||
requires_connection = True
|
||||
|
||||
def assertRoundTrips(self, n):
|
||||
self.assertEqual(self.roundTripInfo.getRoundTrips(), n)
|
||||
self.assertEqual(self.round_trip_info.get_round_trips(), n)
|
||||
|
||||
def getSodaDatabase(self, minclient=(18, 3), minserver=(18, 0),
|
||||
message="not supported with this client/server combination"):
|
||||
client = cx_Oracle.clientversion()[:2]
|
||||
def get_soda_database(self, minclient=(18, 3), minserver=(18, 0),
|
||||
message="not supported with this client/server " \
|
||||
"combination"):
|
||||
client = get_client_version()
|
||||
if client < minclient:
|
||||
self.skipTest(message)
|
||||
server = tuple(int(s) for s in self.connection.version.split("."))[:2]
|
||||
server = get_server_version()
|
||||
if server < minserver:
|
||||
self.skipTest(message)
|
||||
if server > (20, 1) and client < (20, 1):
|
||||
self.skipTest(message)
|
||||
return self.connection.getSodaDatabase()
|
||||
|
||||
def isOnOracleCloud(self, connection=None):
|
||||
def is_on_oracle_cloud(self, connection=None):
|
||||
if connection is None:
|
||||
connection = self.connection
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("""
|
||||
select sys_context('userenv', 'service_name')
|
||||
from dual""")
|
||||
serviceName, = cursor.fetchone()
|
||||
return serviceName.endswith("oraclecloud.com")
|
||||
service_name, = cursor.fetchone()
|
||||
return service_name.endswith("oraclecloud.com")
|
||||
|
||||
def setUp(self):
|
||||
self.connection = GetConnection()
|
||||
self.cursor = self.connection.cursor()
|
||||
if self.requires_connection:
|
||||
self.connection = get_connection()
|
||||
self.cursor = self.connection.cursor()
|
||||
|
||||
def setUpRoundTripChecker(self):
|
||||
self.roundTripInfo = RoundTripInfo(self.connection)
|
||||
def setup_round_trip_checker(self):
|
||||
self.round_trip_info = RoundTripInfo(self.connection)
|
||||
|
||||
def tearDown(self):
|
||||
self.connection.close()
|
||||
del self.cursor
|
||||
del self.connection
|
||||
|
||||
|
||||
def load_tests(loader, standard_tests, pattern):
|
||||
return loader.discover(os.path.dirname(__file__))
|
||||
|
||||
if __name__ == "__main__":
|
||||
RunTestCases()
|
||||
if self.requires_connection:
|
||||
self.connection.close()
|
||||
del self.cursor
|
||||
del self.connection
|
|
@ -6,40 +6,40 @@
|
|||
1000 - Module for testing top-level module methods
|
||||
"""
|
||||
|
||||
import TestEnv
|
||||
import base
|
||||
|
||||
import cx_Oracle
|
||||
import cx_Oracle as oracledb
|
||||
import datetime
|
||||
import time
|
||||
|
||||
class TestCase(TestEnv.BaseTestCase):
|
||||
class TestCase(base.BaseTestCase):
|
||||
requires_connection = False
|
||||
|
||||
def test_1000_DateFromTicks(self):
|
||||
def test_1000_date_from_ticks(self):
|
||||
"1000 - test DateFromTicks()"
|
||||
today = datetime.datetime.today()
|
||||
timestamp = time.mktime(today.timetuple())
|
||||
date = cx_Oracle.DateFromTicks(timestamp)
|
||||
date = oracledb.DateFromTicks(timestamp)
|
||||
self.assertEqual(date, today.date())
|
||||
|
||||
def test_1001_FutureObj(self):
|
||||
def test_1001_future_obj(self):
|
||||
"1001 - test management of __future__ object"
|
||||
self.assertEqual(cx_Oracle.__future__.dummy, None)
|
||||
cx_Oracle.__future__.dummy = "Unimportant"
|
||||
self.assertEqual(cx_Oracle.__future__.dummy, None)
|
||||
self.assertEqual(oracledb.__future__.dummy, None)
|
||||
oracledb.__future__.dummy = "Unimportant"
|
||||
self.assertEqual(oracledb.__future__.dummy, None)
|
||||
|
||||
def test_1002_TimestampFromTicks(self):
|
||||
def test_1002_timestamp_from_ticks(self):
|
||||
"1002 - test TimestampFromTicks()"
|
||||
timestamp = time.mktime(datetime.datetime.today().timetuple())
|
||||
today = datetime.datetime.fromtimestamp(timestamp)
|
||||
date = cx_Oracle.TimestampFromTicks(timestamp)
|
||||
date = oracledb.TimestampFromTicks(timestamp)
|
||||
self.assertEqual(date, today)
|
||||
|
||||
def test_1003_UnsupportedFunctions(self):
|
||||
def test_1003_unsupported_functions(self):
|
||||
"1003 - test unsupported time functions"
|
||||
self.assertRaises(cx_Oracle.NotSupportedError, cx_Oracle.Time,
|
||||
12, 0, 0)
|
||||
self.assertRaises(cx_Oracle.NotSupportedError, cx_Oracle.TimeFromTicks,
|
||||
100)
|
||||
self.assertRaises(oracledb.NotSupportedError, oracledb.Time, 12, 0, 0)
|
||||
self.assertRaises(oracledb.NotSupportedError, oracledb.TimeFromTicks,
|
||||
100)
|
||||
|
||||
if __name__ == "__main__":
|
||||
TestEnv.RunTestCases()
|
||||
base.run_test_cases()
|
||||
|
|
|
@ -11,314 +11,317 @@
|
|||
1100 - Module for testing connections
|
||||
"""
|
||||
|
||||
import TestEnv
|
||||
import base
|
||||
|
||||
import cx_Oracle
|
||||
import cx_Oracle as oracledb
|
||||
import random
|
||||
import string
|
||||
import threading
|
||||
|
||||
class TestCase(TestEnv.BaseTestCase):
|
||||
class TestCase(base.BaseTestCase):
|
||||
requires_connection = False
|
||||
|
||||
def __ConnectAndDrop(self):
|
||||
def __connect_and_drop(self):
|
||||
"""Connect to the database, perform a query and drop the connection."""
|
||||
connection = TestEnv.GetConnection(threaded=True)
|
||||
connection = base.get_connection(threaded=True)
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("select count(*) from TestNumbers")
|
||||
count, = cursor.fetchone()
|
||||
self.assertEqual(count, 10)
|
||||
|
||||
def __VerifyAttributes(self, connection, attrName, value, sql):
|
||||
def __verify_args(self, connection):
|
||||
self.assertEqual(connection.username, base.get_main_user(),
|
||||
"user name differs")
|
||||
self.assertEqual(connection.tnsentry, base.get_connect_string(),
|
||||
"tnsentry differs")
|
||||
self.assertEqual(connection.dsn, base.get_connect_string(),
|
||||
"dsn differs")
|
||||
|
||||
def __verify_attributes(self, connection, attrName, value, sql):
|
||||
setattr(connection, attrName, value)
|
||||
cursor = connection.cursor()
|
||||
cursor.execute(sql)
|
||||
result, = cursor.fetchone()
|
||||
self.assertEqual(result, value, "%s value mismatch" % attrName)
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def verifyArgs(self, connection):
|
||||
self.assertEqual(connection.username, TestEnv.GetMainUser(),
|
||||
"user name differs")
|
||||
self.assertEqual(connection.tnsentry, TestEnv.GetConnectString(),
|
||||
"tnsentry differs")
|
||||
self.assertEqual(connection.dsn, TestEnv.GetConnectString(),
|
||||
"dsn differs")
|
||||
|
||||
def test_1100_AllArgs(self):
|
||||
def test_1100_all_args(self):
|
||||
"1100 - connection to database with user, password, TNS separate"
|
||||
connection = TestEnv.GetConnection()
|
||||
self.verifyArgs(connection)
|
||||
connection = base.get_connection()
|
||||
self.__verify_args(connection)
|
||||
|
||||
def test_1101_AppContext(self):
|
||||
def test_1101_app_context(self):
|
||||
"1101 - test use of application context"
|
||||
namespace = "CLIENTCONTEXT"
|
||||
appContextEntries = [
|
||||
app_context_entries = [
|
||||
( namespace, "ATTR1", "VALUE1" ),
|
||||
( namespace, "ATTR2", "VALUE2" ),
|
||||
( namespace, "ATTR3", "VALUE3" )
|
||||
]
|
||||
connection = TestEnv.GetConnection(appcontext=appContextEntries)
|
||||
connection = base.get_connection(appcontext=app_context_entries)
|
||||
cursor = connection.cursor()
|
||||
for namespace, name, value in appContextEntries:
|
||||
for namespace, name, value in app_context_entries:
|
||||
cursor.execute("select sys_context(:1, :2) from dual",
|
||||
(namespace, name))
|
||||
actualValue, = cursor.fetchone()
|
||||
self.assertEqual(actualValue, value)
|
||||
actual_value, = cursor.fetchone()
|
||||
self.assertEqual(actual_value, value)
|
||||
|
||||
def test_1102_AppContextNegative(self):
|
||||
def test_1102_app_context_negative(self):
|
||||
"1102 - test invalid use of application context"
|
||||
self.assertRaises(TypeError, cx_Oracle.connect, TestEnv.GetMainUser(),
|
||||
TestEnv.GetMainPassword(), TestEnv.GetConnectString(),
|
||||
appcontext=[('userenv', 'action')])
|
||||
self.assertRaises(TypeError, oracledb.connect, base.get_main_user(),
|
||||
base.get_main_password(), base.get_connect_string(),
|
||||
appcontext=[('userenv', 'action')])
|
||||
|
||||
def test_1103_Attributes(self):
|
||||
def test_1103_attributes(self):
|
||||
"1103 - test connection end-to-end tracing attributes"
|
||||
connection = TestEnv.GetConnection()
|
||||
if TestEnv.GetClientVersion() >= (12, 1) \
|
||||
and not self.isOnOracleCloud(connection):
|
||||
self.__VerifyAttributes(connection, "dbop", "cx_OracleTest_DBOP",
|
||||
"select dbop_name from v$sql_monitor "
|
||||
"where sid = sys_context('userenv', 'sid')"
|
||||
"and status = 'EXECUTING'")
|
||||
self.__VerifyAttributes(connection, "action", "cx_OracleTest_Action",
|
||||
"select sys_context('userenv', 'action') from dual")
|
||||
self.__VerifyAttributes(connection, "module", "cx_OracleTest_Module",
|
||||
"select sys_context('userenv', 'module') from dual")
|
||||
self.__VerifyAttributes(connection, "clientinfo",
|
||||
"cx_OracleTest_CInfo",
|
||||
"select sys_context('userenv', 'client_info') from dual")
|
||||
self.__VerifyAttributes(connection, "client_identifier",
|
||||
"cx_OracleTest_CID",
|
||||
"select sys_context('userenv', 'client_identifier') from dual")
|
||||
connection = base.get_connection()
|
||||
if base.get_client_version() >= (12, 1) \
|
||||
and not self.is_on_oracle_cloud(connection):
|
||||
sql = "select dbop_name from v$sql_monitor " \
|
||||
"where sid = sys_context('userenv', 'sid')" \
|
||||
"and status = 'EXECUTING'"
|
||||
self.__verify_attributes(connection, "dbop", "oracledb_dbop", sql)
|
||||
sql = "select sys_context('userenv', 'action') from dual"
|
||||
self.__verify_attributes(connection, "action", "oracledb_Action", sql)
|
||||
sql = "select sys_context('userenv', 'module') from dual"
|
||||
self.__verify_attributes(connection, "module", "oracledb_Module", sql)
|
||||
sql = "select sys_context('userenv', 'client_info') from dual"
|
||||
self.__verify_attributes(connection, "clientinfo", "oracledb_cinfo",
|
||||
sql)
|
||||
sql = "select sys_context('userenv', 'client_identifier') from dual"
|
||||
self.__verify_attributes(connection, "client_identifier",
|
||||
"oracledb_cid", sql)
|
||||
|
||||
def test_1104_AutoCommit(self):
|
||||
def test_1104_autocommit(self):
|
||||
"1104 - test use of autocommit"
|
||||
connection = TestEnv.GetConnection()
|
||||
connection = base.get_connection()
|
||||
cursor = connection.cursor()
|
||||
otherConnection = TestEnv.GetConnection()
|
||||
otherCursor = otherConnection.cursor()
|
||||
other_connection = base.get_connection()
|
||||
other_cursor = other_connection.cursor()
|
||||
cursor.execute("truncate table TestTempTable")
|
||||
cursor.execute("insert into TestTempTable (IntCol) values (1)")
|
||||
otherCursor.execute("select IntCol from TestTempTable")
|
||||
rows = otherCursor.fetchall()
|
||||
other_cursor.execute("select IntCol from TestTempTable")
|
||||
rows = other_cursor.fetchall()
|
||||
self.assertEqual(rows, [])
|
||||
connection.autocommit = True
|
||||
cursor.execute("insert into TestTempTable (IntCol) values (2)")
|
||||
otherCursor.execute("select IntCol from TestTempTable order by IntCol")
|
||||
rows = otherCursor.fetchall()
|
||||
other_cursor.execute("select IntCol from TestTempTable order by IntCol")
|
||||
rows = other_cursor.fetchall()
|
||||
self.assertEqual(rows, [(1,), (2,)])
|
||||
|
||||
def test_1105_BadConnectString(self):
|
||||
def test_1105_bad_connect_string(self):
|
||||
"1105 - connection to database with bad connect string"
|
||||
self.assertRaises(cx_Oracle.DatabaseError, cx_Oracle.connect,
|
||||
TestEnv.GetMainUser())
|
||||
self.assertRaises(cx_Oracle.DatabaseError, cx_Oracle.connect,
|
||||
TestEnv.GetMainUser() + "@" + TestEnv.GetConnectString())
|
||||
self.assertRaises(cx_Oracle.DatabaseError, cx_Oracle.connect,
|
||||
TestEnv.GetMainUser() + "@" + \
|
||||
TestEnv.GetConnectString() + "/" + TestEnv.GetMainPassword())
|
||||
self.assertRaises(oracledb.DatabaseError, oracledb.connect,
|
||||
base.get_main_user())
|
||||
self.assertRaises(oracledb.DatabaseError, oracledb.connect,
|
||||
base.get_main_user() + "@" + \
|
||||
base.get_connect_string())
|
||||
self.assertRaises(oracledb.DatabaseError, oracledb.connect,
|
||||
base.get_main_user() + "@" + \
|
||||
base.get_connect_string() + "/" + \
|
||||
base.get_main_password())
|
||||
|
||||
def test_1106_BadPassword(self):
|
||||
def test_1106_bad_password(self):
|
||||
"1106 - connection to database with bad password"
|
||||
self.assertRaises(cx_Oracle.DatabaseError, cx_Oracle.connect,
|
||||
TestEnv.GetMainUser(), TestEnv.GetMainPassword() + "X",
|
||||
TestEnv.GetConnectString())
|
||||
self.assertRaises(oracledb.DatabaseError, oracledb.connect,
|
||||
base.get_main_user(), base.get_main_password() + "X",
|
||||
base.get_connect_string())
|
||||
|
||||
def test_1107_ChangePassword(self):
|
||||
def test_1107_change_password(self):
|
||||
"1107 - test changing password"
|
||||
connection = TestEnv.GetConnection()
|
||||
if self.isOnOracleCloud(connection):
|
||||
connection = base.get_connection()
|
||||
if self.is_on_oracle_cloud(connection):
|
||||
self.skipTest("passwords on Oracle Cloud are strictly controlled")
|
||||
sysRandom = random.SystemRandom()
|
||||
newPassword = "".join(sysRandom.choice(string.ascii_letters) \
|
||||
for i in range(20))
|
||||
connection.changepassword(TestEnv.GetMainPassword(), newPassword)
|
||||
cconnection = cx_Oracle.connect(TestEnv.GetMainUser(), newPassword,
|
||||
TestEnv.GetConnectString())
|
||||
connection.changepassword(newPassword, TestEnv.GetMainPassword())
|
||||
sys_random = random.SystemRandom()
|
||||
new_password = "".join(sys_random.choice(string.ascii_letters) \
|
||||
for i in range(20))
|
||||
connection.changepassword(base.get_main_password(), new_password)
|
||||
cconnection = oracledb.connect(base.get_main_user(), new_password,
|
||||
base.get_connect_string())
|
||||
connection.changepassword(new_password, base.get_main_password())
|
||||
|
||||
def test_1108_ChangePasswordNegative(self):
|
||||
def test_1108_change_password_negative(self):
|
||||
"1108 - test changing password to an invalid value"
|
||||
connection = TestEnv.GetConnection()
|
||||
if self.isOnOracleCloud(connection):
|
||||
connection = base.get_connection()
|
||||
if self.is_on_oracle_cloud(connection):
|
||||
self.skipTest("passwords on Oracle Cloud are strictly controlled")
|
||||
newPassword = "1" * 150
|
||||
self.assertRaises(cx_Oracle.DatabaseError, connection.changepassword,
|
||||
TestEnv.GetMainPassword(), newPassword)
|
||||
new_password = "1" * 150
|
||||
self.assertRaises(oracledb.DatabaseError, connection.changepassword,
|
||||
base.get_main_password(), new_password)
|
||||
|
||||
def test_1109_ParsePassword(self):
|
||||
def test_1109_parse_password(self):
|
||||
"1109 - test connecting with password containing / and @ symbols"
|
||||
connection = TestEnv.GetConnection()
|
||||
if self.isOnOracleCloud(connection):
|
||||
connection = base.get_connection()
|
||||
if self.is_on_oracle_cloud(connection):
|
||||
self.skipTest("passwords on Oracle Cloud are strictly controlled")
|
||||
sysRandom = random.SystemRandom()
|
||||
chars = list(sysRandom.choice(string.ascii_letters) for i in range(20))
|
||||
sys_random = random.SystemRandom()
|
||||
chars = list(sys_random.choice(string.ascii_letters) for i in range(20))
|
||||
chars[4] = "/"
|
||||
chars[8] = "@"
|
||||
newPassword = "".join(chars)
|
||||
connection.changepassword(TestEnv.GetMainPassword(), newPassword)
|
||||
new_password = "".join(chars)
|
||||
connection.changepassword(base.get_main_password(), new_password)
|
||||
try:
|
||||
arg = "%s/%s@%s" % (TestEnv.GetMainUser(), newPassword,
|
||||
TestEnv.GetConnectString())
|
||||
cx_Oracle.connect(arg)
|
||||
arg = "%s/%s@%s" % (base.get_main_user(), new_password,
|
||||
base.get_connect_string())
|
||||
oracledb.connect(arg)
|
||||
finally:
|
||||
connection.changepassword(newPassword, TestEnv.GetMainPassword())
|
||||
connection.changepassword(new_password, base.get_main_password())
|
||||
|
||||
def test_1110_Encodings(self):
|
||||
def test_1110_encodings(self):
|
||||
"1110 - connection with only encoding/nencoding specified should work"
|
||||
connection = cx_Oracle.connect(TestEnv.GetMainUser(),
|
||||
TestEnv.GetMainPassword(), TestEnv.GetConnectString())
|
||||
connection = oracledb.connect(base.get_main_user(),
|
||||
base.get_main_password(),
|
||||
base.get_connect_string())
|
||||
encoding = connection.encoding
|
||||
nencoding = connection.nencoding
|
||||
altEncoding = "ISO-8859-1"
|
||||
connection = cx_Oracle.connect(TestEnv.GetMainUser(),
|
||||
TestEnv.GetMainPassword(), TestEnv.GetConnectString(),
|
||||
encoding=altEncoding)
|
||||
self.assertEqual(connection.encoding, altEncoding)
|
||||
alt_encoding = "ISO-8859-1"
|
||||
connection = oracledb.connect(base.get_main_user(),
|
||||
base.get_main_password(),
|
||||
base.get_connect_string(),
|
||||
encoding=alt_encoding)
|
||||
self.assertEqual(connection.encoding, alt_encoding)
|
||||
self.assertEqual(connection.nencoding, nencoding)
|
||||
connection = cx_Oracle.connect(TestEnv.GetMainUser(),
|
||||
TestEnv.GetMainPassword(), TestEnv.GetConnectString(),
|
||||
nencoding=altEncoding)
|
||||
connection = oracledb.connect(base.get_main_user(),
|
||||
base.get_main_password(),
|
||||
base.get_connect_string(),
|
||||
nencoding=alt_encoding)
|
||||
self.assertEqual(connection.encoding, encoding)
|
||||
self.assertEqual(connection.nencoding, altEncoding)
|
||||
self.assertEqual(connection.nencoding, alt_encoding)
|
||||
|
||||
def test_1111_DifferentEncodings(self):
|
||||
def test_1111_different_encodings(self):
|
||||
"1111 - different encodings can be specified for encoding/nencoding"
|
||||
connection = cx_Oracle.connect(TestEnv.GetMainUser(),
|
||||
TestEnv.GetMainPassword(), TestEnv.GetConnectString(),
|
||||
encoding="UTF-8", nencoding="UTF-16")
|
||||
connection = oracledb.connect(base.get_main_user(),
|
||||
base.get_main_password(),
|
||||
base.get_connect_string(),
|
||||
encoding="UTF-8", nencoding="UTF-16")
|
||||
value = "\u03b4\u4e2a"
|
||||
cursor = connection.cursor()
|
||||
ncharVar = cursor.var(cx_Oracle.DB_TYPE_NVARCHAR, 100)
|
||||
ncharVar.setvalue(0, value)
|
||||
cursor.execute("select :value from dual", value = ncharVar)
|
||||
nchar_var = cursor.var(oracledb.DB_TYPE_NVARCHAR, 100)
|
||||
nchar_var.setvalue(0, value)
|
||||
cursor.execute("select :value from dual", value=nchar_var)
|
||||
result, = cursor.fetchone()
|
||||
self.assertEqual(result, value)
|
||||
|
||||
def test_1112_ExceptionOnClose(self):
|
||||
def test_1112_exception_on_close(self):
|
||||
"1112 - confirm an exception is raised after closing a connection"
|
||||
connection = TestEnv.GetConnection()
|
||||
connection = base.get_connection()
|
||||
connection.close()
|
||||
self.assertRaises(cx_Oracle.InterfaceError, connection.rollback)
|
||||
self.assertRaises(oracledb.InterfaceError, connection.rollback)
|
||||
|
||||
def test_1113_ConnectWithHandle(self):
|
||||
def test_1113_connect_with_handle(self):
|
||||
"1113 - test creating a connection using a handle"
|
||||
connection = TestEnv.GetConnection()
|
||||
connection = base.get_connection()
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("truncate table TestTempTable")
|
||||
intValue = random.randint(1, 32768)
|
||||
int_value = random.randint(1, 32768)
|
||||
cursor.execute("""
|
||||
insert into TestTempTable (IntCol, StringCol)
|
||||
values (:val, null)""", val = intValue)
|
||||
connection2 = cx_Oracle.connect(handle = connection.handle)
|
||||
values (:val, null)""", val=int_value)
|
||||
connection2 = oracledb.connect(handle = connection.handle)
|
||||
cursor = connection2.cursor()
|
||||
cursor.execute("select IntCol from TestTempTable")
|
||||
fetchedIntValue, = cursor.fetchone()
|
||||
self.assertEqual(fetchedIntValue, intValue)
|
||||
fetched_int_value, = cursor.fetchone()
|
||||
self.assertEqual(fetched_int_value, int_value)
|
||||
cursor.close()
|
||||
self.assertRaises(cx_Oracle.DatabaseError, connection2.close)
|
||||
self.assertRaises(oracledb.DatabaseError, connection2.close)
|
||||
connection.close()
|
||||
cursor = connection2.cursor()
|
||||
self.assertRaises(cx_Oracle.DatabaseError, cursor.execute,
|
||||
self.assertRaises(oracledb.DatabaseError, cursor.execute,
|
||||
"select count(*) from TestTempTable")
|
||||
|
||||
def test_1114_MakeDSN(self):
|
||||
def test_1114_make_dsn(self):
|
||||
"1114 - test making a data source name from host, port and sid"
|
||||
formatString = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)" + \
|
||||
"(HOST=%s)(PORT=%d))(CONNECT_DATA=(SID=%s)))"
|
||||
format_string = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)" + \
|
||||
"(HOST=%s)(PORT=%d))(CONNECT_DATA=(SID=%s)))"
|
||||
args = ("hostname", 1521, "TEST")
|
||||
result = cx_Oracle.makedsn(*args)
|
||||
self.assertEqual(result, formatString % args)
|
||||
result = oracledb.makedsn(*args)
|
||||
self.assertEqual(result, format_string % args)
|
||||
|
||||
def test_1115_SingleArg(self):
|
||||
def test_1115_single_arg(self):
|
||||
"1115 - connection to database with user, password, DSN together"
|
||||
connection = cx_Oracle.connect("%s/%s@%s" % \
|
||||
(TestEnv.GetMainUser(), TestEnv.GetMainPassword(),
|
||||
TestEnv.GetConnectString()))
|
||||
self.verifyArgs(connection)
|
||||
arg = "%s/%s@%s" % (base.get_main_user(), base.get_main_password(),
|
||||
base.get_connect_string())
|
||||
connection = oracledb.connect(arg)
|
||||
self.__verify_args(connection)
|
||||
|
||||
def test_1116_Version(self):
|
||||
def test_1116_version(self):
|
||||
"1116 - connection version is a string"
|
||||
connection = TestEnv.GetConnection()
|
||||
connection = base.get_connection()
|
||||
self.assertTrue(isinstance(connection.version, str))
|
||||
|
||||
def test_1117_RollbackOnClose(self):
|
||||
def test_1117_rollback_on_close(self):
|
||||
"1117 - connection rolls back before close"
|
||||
connection = TestEnv.GetConnection()
|
||||
connection = base.get_connection()
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("truncate table TestTempTable")
|
||||
otherConnection = TestEnv.GetConnection()
|
||||
otherCursor = otherConnection.cursor()
|
||||
otherCursor.execute("insert into TestTempTable (IntCol) values (1)")
|
||||
otherCursor.close()
|
||||
otherConnection.close()
|
||||
other_connection = base.get_connection()
|
||||
other_cursor = other_connection.cursor()
|
||||
other_cursor.execute("insert into TestTempTable (IntCol) values (1)")
|
||||
other_cursor.close()
|
||||
other_connection.close()
|
||||
cursor.execute("select count(*) from TestTempTable")
|
||||
count, = cursor.fetchone()
|
||||
self.assertEqual(count, 0)
|
||||
|
||||
def test_1118_RollbackOnDel(self):
|
||||
def test_1118_rollback_on_del(self):
|
||||
"1118 - connection rolls back before destruction"
|
||||
connection = TestEnv.GetConnection()
|
||||
connection = base.get_connection()
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("truncate table TestTempTable")
|
||||
otherConnection = TestEnv.GetConnection()
|
||||
otherCursor = otherConnection.cursor()
|
||||
otherCursor.execute("insert into TestTempTable (IntCol) values (1)")
|
||||
del otherCursor
|
||||
del otherConnection
|
||||
other_connection = base.get_connection()
|
||||
other_cursor = other_connection.cursor()
|
||||
other_cursor.execute("insert into TestTempTable (IntCol) values (1)")
|
||||
del other_cursor
|
||||
del other_connection
|
||||
cursor.execute("select count(*) from TestTempTable")
|
||||
count, = cursor.fetchone()
|
||||
self.assertEqual(count, 0)
|
||||
|
||||
def test_1119_Threading(self):
|
||||
def test_1119_threading(self):
|
||||
"1119 - connection to database with multiple threads"
|
||||
threads = []
|
||||
for i in range(20):
|
||||
thread = threading.Thread(None, self.__ConnectAndDrop)
|
||||
thread = threading.Thread(None, self.__connect_and_drop)
|
||||
threads.append(thread)
|
||||
thread.start()
|
||||
for thread in threads:
|
||||
thread.join()
|
||||
|
||||
def test_1120_StringFormat(self):
|
||||
def test_1120_string_format(self):
|
||||
"1120 - test string format of connection"
|
||||
connection = TestEnv.GetConnection()
|
||||
expectedValue = "<cx_Oracle.Connection to %s@%s>" % \
|
||||
(TestEnv.GetMainUser(), TestEnv.GetConnectString())
|
||||
self.assertEqual(str(connection), expectedValue)
|
||||
connection = base.get_connection()
|
||||
expected_value = "<cx_Oracle.Connection to %s@%s>" % \
|
||||
(base.get_main_user(), base.get_connect_string())
|
||||
self.assertEqual(str(connection), expected_value)
|
||||
|
||||
def test_1121_CtxMgrClose(self):
|
||||
def test_1121_ctx_mgr_close(self):
|
||||
"1121 - test context manager - close"
|
||||
connection = TestEnv.GetConnection()
|
||||
connection = base.get_connection()
|
||||
with connection:
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("truncate table TestTempTable")
|
||||
cursor.execute("insert into TestTempTable (IntCol) values (1)")
|
||||
connection.commit()
|
||||
cursor.execute("insert into TestTempTable (IntCol) values (2)")
|
||||
self.assertRaises(cx_Oracle.InterfaceError, connection.ping)
|
||||
connection = TestEnv.GetConnection()
|
||||
self.assertRaises(oracledb.InterfaceError, connection.ping)
|
||||
connection = base.get_connection()
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("select count(*) from TestTempTable")
|
||||
count, = cursor.fetchone()
|
||||
self.assertEqual(count, 1)
|
||||
|
||||
def test_1122_ConnectionAttributes(self):
|
||||
def test_1122_connection_attributes(self):
|
||||
"1122 - test connection attribute values"
|
||||
connection = cx_Oracle.connect(TestEnv.GetMainUser(),
|
||||
TestEnv.GetMainPassword(), TestEnv.GetConnectString(),
|
||||
encoding="ASCII")
|
||||
connection = oracledb.connect(base.get_main_user(),
|
||||
base.get_main_password(),
|
||||
base.get_connect_string(),
|
||||
encoding="ASCII")
|
||||
self.assertEqual(connection.maxBytesPerCharacter, 1)
|
||||
connection = cx_Oracle.connect(TestEnv.GetMainUser(),
|
||||
TestEnv.GetMainPassword(), TestEnv.GetConnectString(),
|
||||
encoding="UTF-8")
|
||||
connection = oracledb.connect(base.get_main_user(),
|
||||
base.get_main_password(),
|
||||
base.get_connect_string(),
|
||||
encoding="UTF-8")
|
||||
self.assertEqual(connection.maxBytesPerCharacter, 4)
|
||||
if TestEnv.GetClientVersion() >= (12, 1):
|
||||
if base.get_client_version() >= (12, 1):
|
||||
self.assertEqual(connection.ltxid, b'')
|
||||
self.assertEqual(connection.current_schema, None)
|
||||
connection.current_schema = "test_schema"
|
||||
|
@ -333,26 +336,26 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
self.assertRaises(TypeError, connection.stmtcachesize, 20.5)
|
||||
self.assertRaises(TypeError, connection.stmtcachesize, "value")
|
||||
|
||||
def test_1123_ClosedConnectionAttributes(self):
|
||||
def test_1123_closed_connection_attributes(self):
|
||||
"1123 - test closed connection attribute values"
|
||||
connection = TestEnv.GetConnection()
|
||||
connection = base.get_connection()
|
||||
connection.close()
|
||||
attrNames = ["current_schema", "edition", "external_name",
|
||||
"internal_name", "stmtcachesize"]
|
||||
if TestEnv.GetClientVersion() >= (12, 1):
|
||||
attrNames.append("ltxid")
|
||||
for name in attrNames:
|
||||
self.assertRaises(cx_Oracle.InterfaceError, getattr, connection,
|
||||
attr_names = ["current_schema", "edition", "external_name",
|
||||
"internal_name", "stmtcachesize"]
|
||||
if base.get_client_version() >= (12, 1):
|
||||
attr_names.append("ltxid")
|
||||
for name in attr_names:
|
||||
self.assertRaises(oracledb.InterfaceError, getattr, connection,
|
||||
name)
|
||||
|
||||
def test_1124_Ping(self):
|
||||
def test_1124_ping(self):
|
||||
"1124 - test connection ping"
|
||||
connection = TestEnv.GetConnection()
|
||||
connection = base.get_connection()
|
||||
connection.ping()
|
||||
|
||||
def test_1125_TransactionBegin(self):
|
||||
def test_1125_transaction_begin(self):
|
||||
"1125 - test begin, prepare, cancel transaction"
|
||||
connection = TestEnv.GetConnection()
|
||||
connection = base.get_connection()
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("truncate table TestTempTable")
|
||||
connection.begin(10, 'trxnId', 'branchId')
|
||||
|
@ -369,4 +372,4 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
self.assertEqual(count, 0)
|
||||
|
||||
if __name__ == "__main__":
|
||||
TestEnv.RunTestCases()
|
||||
base.run_test_cases()
|
||||
|
|
|
@ -11,139 +11,140 @@
|
|||
1200 - Module for testing cursors
|
||||
"""
|
||||
|
||||
import TestEnv
|
||||
|
||||
import cx_Oracle
|
||||
import base
|
||||
import cx_Oracle as oracledb
|
||||
import decimal
|
||||
import sys
|
||||
|
||||
class TestCase(TestEnv.BaseTestCase):
|
||||
class TestCase(base.BaseTestCase):
|
||||
|
||||
def test_1200_CreateScrollableCursor(self):
|
||||
def test_1200_create_scrollable_cursor(self):
|
||||
"1200 - test creating a scrollable cursor"
|
||||
cursor = self.connection.cursor()
|
||||
self.assertEqual(cursor.scrollable, False)
|
||||
cursor = self.connection.cursor(True)
|
||||
self.assertEqual(cursor.scrollable, True)
|
||||
cursor = self.connection.cursor(scrollable = True)
|
||||
cursor = self.connection.cursor(scrollable=True)
|
||||
self.assertEqual(cursor.scrollable, True)
|
||||
cursor.scrollable = False
|
||||
self.assertEqual(cursor.scrollable, False)
|
||||
|
||||
def test_1201_ExecuteNoArgs(self):
|
||||
def test_1201_execute_no_args(self):
|
||||
"1201 - test executing a statement without any arguments"
|
||||
result = self.cursor.execute("begin null; end;")
|
||||
self.assertEqual(result, None)
|
||||
|
||||
def test_1202_ExecuteNoStatementWithArgs(self):
|
||||
def test_1202_execute_no_statement_with_args(self):
|
||||
"1202 - test executing a None statement with bind variables"
|
||||
self.assertRaises(cx_Oracle.ProgrammingError, self.cursor.execute,
|
||||
None, x = 5)
|
||||
self.assertRaises(oracledb.ProgrammingError, self.cursor.execute, None,
|
||||
x=5)
|
||||
|
||||
def test_1203_ExecuteEmptyKeywordArgs(self):
|
||||
def test_1203_execute_empty_keyword_args(self):
|
||||
"1203 - test executing a statement with args and empty keyword args"
|
||||
simpleVar = self.cursor.var(cx_Oracle.NUMBER)
|
||||
args = [simpleVar]
|
||||
kwArgs = {}
|
||||
result = self.cursor.execute("begin :1 := 25; end;", args, **kwArgs)
|
||||
simple_var = self.cursor.var(oracledb.NUMBER)
|
||||
args = [simple_var]
|
||||
kwargs = {}
|
||||
result = self.cursor.execute("begin :1 := 25; end;", args, **kwargs)
|
||||
self.assertEqual(result, None)
|
||||
self.assertEqual(simpleVar.getvalue(), 25)
|
||||
self.assertEqual(simple_var.getvalue(), 25)
|
||||
|
||||
def test_1204_ExecuteKeywordArgs(self):
|
||||
def test_1204_execute_keyword_args(self):
|
||||
"1204 - test executing a statement with keyword arguments"
|
||||
simpleVar = self.cursor.var(cx_Oracle.NUMBER)
|
||||
simple_var = self.cursor.var(oracledb.NUMBER)
|
||||
result = self.cursor.execute("begin :value := 5; end;",
|
||||
value = simpleVar)
|
||||
value=simple_var)
|
||||
self.assertEqual(result, None)
|
||||
self.assertEqual(simpleVar.getvalue(), 5)
|
||||
self.assertEqual(simple_var.getvalue(), 5)
|
||||
|
||||
def test_1205_ExecuteDictionaryArg(self):
|
||||
def test_1205_execute_dictionary_arg(self):
|
||||
"1205 - test executing a statement with a dictionary argument"
|
||||
simpleVar = self.cursor.var(cx_Oracle.NUMBER)
|
||||
dictArg = { "value" : simpleVar }
|
||||
result = self.cursor.execute("begin :value := 10; end;", dictArg)
|
||||
simple_var = self.cursor.var(oracledb.NUMBER)
|
||||
dict_arg = dict(value=simple_var)
|
||||
result = self.cursor.execute("begin :value := 10; end;", dict_arg)
|
||||
self.assertEqual(result, None)
|
||||
self.assertEqual(simpleVar.getvalue(), 10)
|
||||
self.assertEqual(simple_var.getvalue(), 10)
|
||||
|
||||
def test_1206_ExecuteMultipleMethod(self):
|
||||
def test_1206_execute_multiple_arg_types(self):
|
||||
"1206 - test executing a statement with both a dict and keyword args"
|
||||
simpleVar = self.cursor.var(cx_Oracle.NUMBER)
|
||||
dictArg = { "value" : simpleVar }
|
||||
self.assertRaises(cx_Oracle.InterfaceError, self.cursor.execute,
|
||||
"begin :value := 15; end;", dictArg, value = simpleVar)
|
||||
simple_var = self.cursor.var(oracledb.NUMBER)
|
||||
dict_arg = dict(value=simple_var)
|
||||
self.assertRaises(oracledb.InterfaceError, self.cursor.execute,
|
||||
"begin :value := 15; end;", dict_arg,
|
||||
value=simple_var)
|
||||
|
||||
def test_1207_ExecuteAndModifyArraySize(self):
|
||||
def test_1207_execute_and_modify_array_size(self):
|
||||
"1207 - test executing a statement and then changing the array size"
|
||||
self.cursor.execute("select IntCol from TestNumbers")
|
||||
self.cursor.arraysize = 20
|
||||
self.assertEqual(len(self.cursor.fetchall()), 10)
|
||||
|
||||
def test_1208_CallProc(self):
|
||||
def test_1208_callproc(self):
|
||||
"1208 - test executing a stored procedure"
|
||||
var = self.cursor.var(cx_Oracle.NUMBER)
|
||||
var = self.cursor.var(oracledb.NUMBER)
|
||||
results = self.cursor.callproc("proc_Test", ("hi", 5, var))
|
||||
self.assertEqual(results, ["hi", 10, 2.0])
|
||||
|
||||
def test_1209_CallProcAllKeywords(self):
|
||||
"1209 - test executing a stored procedure with keyword args"
|
||||
kwargs = dict(a_InOutValue=self.cursor.var(cx_Oracle.NUMBER),
|
||||
a_InValue="hi", a_OutValue=self.cursor.var(cx_Oracle.NUMBER))
|
||||
kwargs['a_InOutValue'].setvalue(0, 5)
|
||||
results = self.cursor.callproc("proc_Test", keywordParameters=kwargs)
|
||||
def test_1209_callproc_all_keywords(self):
|
||||
"1209 - test executing a stored procedure with all args keyword args"
|
||||
inout_value = self.cursor.var(oracledb.NUMBER)
|
||||
inout_value.setvalue(0, 5)
|
||||
out_value = self.cursor.var(oracledb.NUMBER)
|
||||
kwargs = dict(a_InOutValue=inout_value, a_InValue="hi",
|
||||
a_OutValue=out_value)
|
||||
results = self.cursor.callproc("proc_Test", [], kwargs)
|
||||
self.assertEqual(results, [])
|
||||
self.assertEqual(kwargs['a_InOutValue'].getvalue(), 10)
|
||||
self.assertEqual(kwargs['a_OutValue'].getvalue(), 2.0)
|
||||
self.assertEqual(inout_value.getvalue(), 10)
|
||||
self.assertEqual(out_value.getvalue(), 2.0)
|
||||
|
||||
def test_1210_CallProcOnlyLastKeyword(self):
|
||||
def test_1210_callproc_only_last_keyword(self):
|
||||
"1210 - test executing a stored procedure with last arg as keyword arg"
|
||||
kwargs = dict(a_OutValue = self.cursor.var(cx_Oracle.NUMBER))
|
||||
out_value = self.cursor.var(oracledb.NUMBER)
|
||||
kwargs = dict(a_OutValue=out_value)
|
||||
results = self.cursor.callproc("proc_Test", ("hi", 5), kwargs)
|
||||
self.assertEqual(results, ["hi", 10])
|
||||
self.assertEqual(kwargs['a_OutValue'].getvalue(), 2.0)
|
||||
self.assertEqual(out_value.getvalue(), 2.0)
|
||||
|
||||
def test_1211_CallProcRepeatedKeywordParameters(self):
|
||||
def test_1211_callproc_repeated_keyword_parameters(self):
|
||||
"1211 - test executing a stored procedure, repeated keyword arg"
|
||||
kwargs = dict(a_InValue="hi",
|
||||
a_OutValue=self.cursor.var(cx_Oracle.NUMBER))
|
||||
self.assertRaises(cx_Oracle.DatabaseError, self.cursor.callproc,
|
||||
"proc_Test", parameters=("hi", 5), keywordParameters=kwargs)
|
||||
a_OutValue=self.cursor.var(oracledb.NUMBER))
|
||||
self.assertRaises(oracledb.DatabaseError, self.cursor.callproc,
|
||||
"proc_Test", ("hi", 5), kwargs)
|
||||
|
||||
def test_1212_CallProcNoArgs(self):
|
||||
def test_1212_callproc_no_args(self):
|
||||
"1212 - test executing a stored procedure without any arguments"
|
||||
results = self.cursor.callproc("proc_TestNoArgs")
|
||||
self.assertEqual(results, [])
|
||||
|
||||
def test_1213_CallFunc(self):
|
||||
def test_1213_callfunc(self):
|
||||
"1213 - test executing a stored function"
|
||||
results = self.cursor.callfunc("func_Test", cx_Oracle.NUMBER,
|
||||
("hi", 5))
|
||||
results = self.cursor.callfunc("func_Test", oracledb.NUMBER, ("hi", 5))
|
||||
self.assertEqual(results, 7)
|
||||
|
||||
def test_1214_CallFuncNoArgs(self):
|
||||
def test_1214_callfunc_no_args(self):
|
||||
"1214 - test executing a stored function without any arguments"
|
||||
results = self.cursor.callfunc("func_TestNoArgs", cx_Oracle.NUMBER)
|
||||
results = self.cursor.callfunc("func_TestNoArgs", oracledb.NUMBER)
|
||||
self.assertEqual(results, 712)
|
||||
|
||||
def test_1215_CallFuncNegative(self):
|
||||
def test_1215_callfunc_negative(self):
|
||||
"1215 - test executing a stored function with wrong parameters"
|
||||
funcName = "func_Test"
|
||||
self.assertRaises(TypeError, self.cursor.callfunc, cx_Oracle.NUMBER,
|
||||
funcName, ("hi", 5))
|
||||
self.assertRaises(cx_Oracle.DatabaseError, self.cursor.callfunc,
|
||||
funcName, cx_Oracle.NUMBER, ("hi", 5, 7))
|
||||
self.assertRaises(TypeError, self.cursor.callfunc, funcName,
|
||||
cx_Oracle.NUMBER, "hi", 7)
|
||||
self.assertRaises(cx_Oracle.DatabaseError, self.cursor.callfunc,
|
||||
funcName, cx_Oracle.NUMBER, [5, "hi"])
|
||||
self.assertRaises(cx_Oracle.DatabaseError, self.cursor.callfunc,
|
||||
funcName, cx_Oracle.NUMBER)
|
||||
self.assertRaises(TypeError, self.cursor.callfunc, funcName,
|
||||
cx_Oracle.NUMBER, 5)
|
||||
func_name = "func_Test"
|
||||
self.assertRaises(TypeError, self.cursor.callfunc, oracledb.NUMBER,
|
||||
func_name, ("hi", 5))
|
||||
self.assertRaises(oracledb.DatabaseError, self.cursor.callfunc,
|
||||
func_name, oracledb.NUMBER, ("hi", 5, 7))
|
||||
self.assertRaises(TypeError, self.cursor.callfunc, func_name,
|
||||
oracledb.NUMBER, "hi", 7)
|
||||
self.assertRaises(oracledb.DatabaseError, self.cursor.callfunc,
|
||||
func_name, oracledb.NUMBER, [5, "hi"])
|
||||
self.assertRaises(oracledb.DatabaseError, self.cursor.callfunc,
|
||||
func_name, oracledb.NUMBER)
|
||||
self.assertRaises(TypeError, self.cursor.callfunc, func_name,
|
||||
oracledb.NUMBER, 5)
|
||||
|
||||
def test_1216_ExecuteManyByName(self):
|
||||
def test_1216_executemany_by_name(self):
|
||||
"1216 - test executing a statement multiple times (named args)"
|
||||
self.cursor.execute("truncate table TestTempTable")
|
||||
rows = [ { "value" : n } for n in range(250) ]
|
||||
rows = [{"value": n} for n in range(250)]
|
||||
self.cursor.arraysize = 100
|
||||
statement = "insert into TestTempTable (IntCol) values (:value)"
|
||||
self.cursor.executemany(statement, rows)
|
||||
|
@ -152,10 +153,10 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
count, = self.cursor.fetchone()
|
||||
self.assertEqual(count, len(rows))
|
||||
|
||||
def test_1217_ExecuteManyByPosition(self):
|
||||
def test_1217_executemany_by_position(self):
|
||||
"1217 - test executing a statement multiple times (positional args)"
|
||||
self.cursor.execute("truncate table TestTempTable")
|
||||
rows = [ [n] for n in range(230) ]
|
||||
rows = [[n] for n in range(230)]
|
||||
self.cursor.arraysize = 100
|
||||
statement = "insert into TestTempTable (IntCol) values (:1)"
|
||||
self.cursor.executemany(statement, rows)
|
||||
|
@ -164,10 +165,10 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
count, = self.cursor.fetchone()
|
||||
self.assertEqual(count, len(rows))
|
||||
|
||||
def test_1218_ExecuteManyWithPrepare(self):
|
||||
def test_1218_executemany_with_prepare(self):
|
||||
"1218 - test executing a statement multiple times (with prepare)"
|
||||
self.cursor.execute("truncate table TestTempTable")
|
||||
rows = [ [n] for n in range(225) ]
|
||||
rows = [[n] for n in range(225)]
|
||||
self.cursor.arraysize = 100
|
||||
statement = "insert into TestTempTable (IntCol) values (:1)"
|
||||
self.cursor.prepare(statement)
|
||||
|
@ -177,10 +178,10 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
count, = self.cursor.fetchone()
|
||||
self.assertEqual(count, len(rows))
|
||||
|
||||
def test_1219_ExecuteManyWithRebind(self):
|
||||
def test_1219_executemany_with_rebind(self):
|
||||
"1219 - test executing a statement multiple times (with rebind)"
|
||||
self.cursor.execute("truncate table TestTempTable")
|
||||
rows = [ [n] for n in range(235) ]
|
||||
rows = [[n] for n in range(235)]
|
||||
self.cursor.arraysize = 100
|
||||
statement = "insert into TestTempTable (IntCol) values (:1)"
|
||||
self.cursor.executemany(statement, rows[:50])
|
||||
|
@ -190,25 +191,30 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
count, = self.cursor.fetchone()
|
||||
self.assertEqual(count, len(rows))
|
||||
|
||||
def test_1220_ExecuteManyWithInputSizesWrong(self):
|
||||
def test_1220_executemany_with_input_sizes_wrong(self):
|
||||
"1220 - test executing multiple times (with input sizes wrong)"
|
||||
cursor = self.connection.cursor()
|
||||
cursor.setinputsizes(cx_Oracle.NUMBER)
|
||||
cursor.setinputsizes(oracledb.NUMBER)
|
||||
data = [[decimal.Decimal("25.8")], [decimal.Decimal("30.0")]]
|
||||
cursor.executemany("declare t number; begin t := :1; end;", data)
|
||||
|
||||
def test_1221_ExecuteManyMultipleBatches(self):
|
||||
def test_1221_executemany_with_multiple_batches(self):
|
||||
"1221 - test executing multiple times (with multiple batches)"
|
||||
self.cursor.execute("truncate table TestTempTable")
|
||||
sql = "insert into TestTempTable (IntCol, StringCol) values (:1, :2)"
|
||||
self.cursor.executemany(sql, [(1, None), (2, None)])
|
||||
self.cursor.executemany(sql, [(3, None), (4, "Testing")])
|
||||
|
||||
def test_1222_ExecuteManyNumeric(self):
|
||||
def test_1222_executemany_numeric(self):
|
||||
"1222 - test executemany() with various numeric types"
|
||||
self.cursor.execute("truncate table TestTempTable")
|
||||
data = [(1, 5), (2, 7.0), (3, 6.5), (4, 2 ** 65),
|
||||
(5, decimal.Decimal("24.5"))]
|
||||
data = [
|
||||
(1, 5),
|
||||
(2, 7.0),
|
||||
(3, 6.5),
|
||||
(4, 2 ** 65),
|
||||
(5, decimal.Decimal("24.5"))
|
||||
]
|
||||
sql = "insert into TestTempTable (IntCol, NumberCol) values (:1, :2)"
|
||||
self.cursor.executemany(sql, data)
|
||||
self.cursor.execute("""
|
||||
|
@ -217,43 +223,45 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
order by IntCol""")
|
||||
self.assertEqual(self.cursor.fetchall(), data)
|
||||
|
||||
def test_1223_ExecuteManyWithResize(self):
|
||||
def test_1223_executemany_with_resize(self):
|
||||
"1223 - test executing a statement multiple times (with resize)"
|
||||
self.cursor.execute("truncate table TestTempTable")
|
||||
rows = [ ( 1, "First" ),
|
||||
( 2, "Second" ),
|
||||
( 3, "Third" ),
|
||||
( 4, "Fourth" ),
|
||||
( 5, "Fifth" ),
|
||||
( 6, "Sixth" ),
|
||||
( 7, "Seventh and the longest one" ) ]
|
||||
rows = [
|
||||
(1, "First"),
|
||||
(2, "Second"),
|
||||
(3, "Third"),
|
||||
(4, "Fourth"),
|
||||
(5, "Fifth"),
|
||||
(6, "Sixth"),
|
||||
(7, "Seventh and the longest one")
|
||||
]
|
||||
sql = "insert into TestTempTable (IntCol, StringCol) values (:1, :2)"
|
||||
self.cursor.executemany(sql, rows)
|
||||
self.cursor.execute("""
|
||||
select IntCol, StringCol
|
||||
from TestTempTable
|
||||
order by IntCol""")
|
||||
fetchedRows = self.cursor.fetchall()
|
||||
self.assertEqual(fetchedRows, rows)
|
||||
fetched_rows = self.cursor.fetchall()
|
||||
self.assertEqual(fetched_rows, rows)
|
||||
|
||||
def test_1224_ExecuteManyWithExecption(self):
|
||||
def test_1224_executemany_with_exception(self):
|
||||
"1224 - test executing a statement multiple times (with exception)"
|
||||
self.cursor.execute("truncate table TestTempTable")
|
||||
rows = [ { "value" : n } for n in (1, 2, 3, 2, 5) ]
|
||||
rows = [{"value": n} for n in (1, 2, 3, 2, 5)]
|
||||
statement = "insert into TestTempTable (IntCol) values (:value)"
|
||||
self.assertRaises(cx_Oracle.DatabaseError, self.cursor.executemany,
|
||||
statement, rows)
|
||||
self.assertRaises(oracledb.DatabaseError, self.cursor.executemany,
|
||||
statement, rows)
|
||||
self.assertEqual(self.cursor.rowcount, 3)
|
||||
|
||||
def test_1225_ExecuteManyWithInvalidParameters(self):
|
||||
def test_1225_executemany_with_invalid_parameters(self):
|
||||
"1225 - test calling executemany() with invalid parameters"
|
||||
self.assertRaises(TypeError, self.cursor.executemany,
|
||||
"insert into TestTempTable (IntCol, StringCol) values (:1, :2)",
|
||||
"These are not valid parameters")
|
||||
sql = "insert into TestTempTable (IntCol, StringCol) values (:1, :2)"
|
||||
self.assertRaises(TypeError, self.cursor.executemany, sql,
|
||||
"These are not valid parameters")
|
||||
|
||||
def test_1226_ExecuteManyNoParameters(self):
|
||||
def test_1226_executemany_no_parameters(self):
|
||||
"1226 - test calling executemany() without any bind parameters"
|
||||
numRows = 5
|
||||
num_rows = 5
|
||||
self.cursor.execute("truncate table TestTempTable")
|
||||
self.cursor.executemany("""
|
||||
declare
|
||||
|
@ -264,17 +272,17 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
|
||||
insert into TestTempTable (IntCol, StringCol)
|
||||
values (t_Id, 'Test String ' || t_Id);
|
||||
end;""", numRows)
|
||||
self.assertEqual(self.cursor.rowcount, numRows)
|
||||
end;""", num_rows)
|
||||
self.assertEqual(self.cursor.rowcount, num_rows)
|
||||
self.cursor.execute("select count(*) from TestTempTable")
|
||||
count, = self.cursor.fetchone()
|
||||
self.assertEqual(count, numRows)
|
||||
self.assertEqual(count, num_rows)
|
||||
|
||||
def test_1227_ExecuteManyBoundEarlier(self):
|
||||
def test_1227_executemany_bound_earlier(self):
|
||||
"1227 - test calling executemany() with binds performed earlier"
|
||||
numRows = 9
|
||||
num_rows = 9
|
||||
self.cursor.execute("truncate table TestTempTable")
|
||||
var = self.cursor.var(int, arraysize = numRows)
|
||||
var = self.cursor.var(int, arraysize=num_rows)
|
||||
self.cursor.setinputsizes(var)
|
||||
self.cursor.executemany("""
|
||||
declare
|
||||
|
@ -288,17 +296,17 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
|
||||
select sum(IntCol) into :1
|
||||
from TestTempTable;
|
||||
end;""", numRows)
|
||||
self.assertEqual(self.cursor.rowcount, numRows)
|
||||
expectedData = [1, 3, 6, 10, 15, 21, 28, 36, 45]
|
||||
self.assertEqual(var.values, expectedData)
|
||||
end;""", num_rows)
|
||||
self.assertEqual(self.cursor.rowcount, num_rows)
|
||||
expected_data = [1, 3, 6, 10, 15, 21, 28, 36, 45]
|
||||
self.assertEqual(var.values, expected_data)
|
||||
|
||||
def test_1228_Prepare(self):
|
||||
def test_1228_prepare(self):
|
||||
"1228 - test preparing a statement and executing it multiple times"
|
||||
self.assertEqual(self.cursor.statement, None)
|
||||
statement = "begin :value := :value + 5; end;"
|
||||
self.cursor.prepare(statement)
|
||||
var = self.cursor.var(cx_Oracle.NUMBER)
|
||||
var = self.cursor.var(oracledb.NUMBER)
|
||||
self.assertEqual(self.cursor.statement, statement)
|
||||
var.setvalue(0, 2)
|
||||
self.cursor.execute(None, value = var)
|
||||
|
@ -308,25 +316,23 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
self.cursor.execute("begin :value2 := 3; end;", value2 = var)
|
||||
self.assertEqual(var.getvalue(), 3)
|
||||
|
||||
def test_1229_ExceptionOnClose(self):
|
||||
def test_1229_exception_on_close(self):
|
||||
"1229 - confirm an exception is raised after closing a cursor"
|
||||
self.cursor.close()
|
||||
self.assertRaises(cx_Oracle.InterfaceError, self.cursor.execute,
|
||||
"select 1 from dual")
|
||||
self.assertRaises(oracledb.InterfaceError, self.cursor.execute,
|
||||
"select 1 from dual")
|
||||
|
||||
def test_1230_Iterators(self):
|
||||
def test_1230_iterators(self):
|
||||
"1230 - test iterators"
|
||||
self.cursor.execute("""
|
||||
select IntCol
|
||||
from TestNumbers
|
||||
where IntCol between 1 and 3
|
||||
order by IntCol""")
|
||||
rows = []
|
||||
for row in self.cursor:
|
||||
rows.append(row[0])
|
||||
rows = [v for v, in self.cursor]
|
||||
self.assertEqual(rows, [1, 2, 3])
|
||||
|
||||
def test_1231_IteratorsInterrupted(self):
|
||||
def test_1231_iterators_interrupted(self):
|
||||
"1231 - test iterators (with intermediate execute)"
|
||||
self.cursor.execute("truncate table TestTempTable")
|
||||
self.cursor.execute("""
|
||||
|
@ -334,20 +340,14 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
from TestNumbers
|
||||
where IntCol between 1 and 3
|
||||
order by IntCol""")
|
||||
testIter = iter(self.cursor)
|
||||
if sys.version_info[0] >= 3:
|
||||
value, = next(testIter)
|
||||
else:
|
||||
value, = testIter.next()
|
||||
test_iter = iter(self.cursor)
|
||||
value, = next(test_iter)
|
||||
self.cursor.execute("insert into TestTempTable (IntCol) values (1)")
|
||||
if sys.version_info[0] >= 3:
|
||||
self.assertRaises(cx_Oracle.InterfaceError, next, testIter)
|
||||
else:
|
||||
self.assertRaises(cx_Oracle.InterfaceError, testIter.next)
|
||||
self.assertRaises(oracledb.InterfaceError, next, test_iter)
|
||||
|
||||
def test_1232_BindNames(self):
|
||||
def test_1232_bind_names(self):
|
||||
"1232 - test that bindnames() works correctly."
|
||||
self.assertRaises(cx_Oracle.ProgrammingError, self.cursor.bindnames)
|
||||
self.assertRaises(oracledb.ProgrammingError, self.cursor.bindnames)
|
||||
self.cursor.prepare("begin null; end;")
|
||||
self.assertEqual(self.cursor.bindnames(), [])
|
||||
self.cursor.prepare("begin :retval := :inval + 5; end;")
|
||||
|
@ -355,40 +355,39 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
self.cursor.prepare("begin :retval := :a * :a + :b * :b; end;")
|
||||
self.assertEqual(self.cursor.bindnames(), ["RETVAL", "A", "B"])
|
||||
self.cursor.prepare("begin :a := :b + :c + :d + :e + :f + :g + " + \
|
||||
":h + :i + :j + :k + :l; end;")
|
||||
self.assertEqual(self.cursor.bindnames(),
|
||||
["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"])
|
||||
":h + :i + :j + :k + :l; end;")
|
||||
names = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"]
|
||||
self.assertEqual(self.cursor.bindnames(), names)
|
||||
self.cursor.prepare("select :a * :a + :b * :b from dual")
|
||||
self.assertEqual(self.cursor.bindnames(), ["A", "B"])
|
||||
|
||||
def test_1233_BadPrepare(self):
|
||||
"1233 - test that subsequent executes succeed after bad prepare"
|
||||
self.assertRaises(cx_Oracle.DatabaseError,
|
||||
self.cursor.execute,
|
||||
"begin raise_application_error(-20000, 'this); end;")
|
||||
def test_1233_bad_execute(self):
|
||||
"1233 - test that subsequent executes succeed after bad execute"
|
||||
self.assertRaises(oracledb.DatabaseError,
|
||||
self.cursor.execute,
|
||||
"begin raise_application_error(-20000, 'this); end;")
|
||||
self.cursor.execute("begin null; end;")
|
||||
|
||||
def test_1234_BadExecute(self):
|
||||
def test_1234_fetch_after_bad_execute(self):
|
||||
"1234 - test that subsequent fetches fail after bad execute"
|
||||
self.assertRaises(cx_Oracle.DatabaseError,
|
||||
self.cursor.execute, "select y from dual")
|
||||
self.assertRaises(cx_Oracle.InterfaceError,
|
||||
self.cursor.fetchall)
|
||||
self.assertRaises(oracledb.DatabaseError,
|
||||
self.cursor.execute, "select y from dual")
|
||||
self.assertRaises(oracledb.InterfaceError, self.cursor.fetchall)
|
||||
|
||||
def test_1235_ScrollAbsoluteExceptionAfter(self):
|
||||
def test_1235_scroll_absolute_exception_after(self):
|
||||
"1235 - test scrolling absolute yields an exception (after result set)"
|
||||
cursor = self.connection.cursor(scrollable = True)
|
||||
cursor = self.connection.cursor(scrollable=True)
|
||||
cursor.arraysize = self.cursor.arraysize
|
||||
cursor.execute("""
|
||||
select NumberCol
|
||||
from TestNumbers
|
||||
order by IntCol""")
|
||||
self.assertRaises(cx_Oracle.DatabaseError, cursor.scroll, 12,
|
||||
"absolute")
|
||||
self.assertRaises(oracledb.DatabaseError, cursor.scroll, 12,
|
||||
"absolute")
|
||||
|
||||
def test_1236_ScrollAbsoluteInBuffer(self):
|
||||
def test_1236_scroll_absolute_in_buffer(self):
|
||||
"1236 - test scrolling absolute (when in buffers)"
|
||||
cursor = self.connection.cursor(scrollable = True)
|
||||
cursor = self.connection.cursor(scrollable=True)
|
||||
cursor.arraysize = self.cursor.arraysize
|
||||
cursor.execute("""
|
||||
select NumberCol
|
||||
|
@ -402,9 +401,9 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
self.assertEqual(row[0], 1.25)
|
||||
self.assertEqual(cursor.rowcount, 1)
|
||||
|
||||
def test_1237_ScrollAbsoluteNotInBuffer(self):
|
||||
def test_1237_scroll_absolute_not_in_buffer(self):
|
||||
"1237 - test scrolling absolute (when not in buffers)"
|
||||
cursor = self.connection.cursor(scrollable = True)
|
||||
cursor = self.connection.cursor(scrollable=True)
|
||||
cursor.arraysize = self.cursor.arraysize
|
||||
cursor.execute("""
|
||||
select NumberCol
|
||||
|
@ -415,23 +414,23 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
self.assertEqual(row[0], 7.5)
|
||||
self.assertEqual(cursor.rowcount, 6)
|
||||
|
||||
def test_1238_ScrollFirstInBuffer(self):
|
||||
def test_1238_scroll_first_in_buffer(self):
|
||||
"1238 - test scrolling to first row in result set (in buffers)"
|
||||
cursor = self.connection.cursor(scrollable = True)
|
||||
cursor = self.connection.cursor(scrollable=True)
|
||||
cursor.arraysize = self.cursor.arraysize
|
||||
cursor.execute("""
|
||||
select NumberCol
|
||||
from TestNumbers
|
||||
order by IntCol""")
|
||||
cursor.fetchmany()
|
||||
cursor.scroll(mode = "first")
|
||||
cursor.scroll(mode="first")
|
||||
row = cursor.fetchone()
|
||||
self.assertEqual(row[0], 1.25)
|
||||
self.assertEqual(cursor.rowcount, 1)
|
||||
|
||||
def test_1239_ScrollFirstNotInBuffer(self):
|
||||
def test_1239_scroll_first_not_in_buffer(self):
|
||||
"1239 - test scrolling to first row in result set (not in buffers)"
|
||||
cursor = self.connection.cursor(scrollable = True)
|
||||
cursor = self.connection.cursor(scrollable=True)
|
||||
cursor.arraysize = self.cursor.arraysize
|
||||
cursor.execute("""
|
||||
select NumberCol
|
||||
|
@ -439,63 +438,63 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
order by IntCol""")
|
||||
cursor.fetchmany()
|
||||
cursor.fetchmany()
|
||||
cursor.scroll(mode = "first")
|
||||
cursor.scroll(mode="first")
|
||||
row = cursor.fetchone()
|
||||
self.assertEqual(row[0], 1.25)
|
||||
self.assertEqual(cursor.rowcount, 1)
|
||||
|
||||
def test_1240_ScrollLast(self):
|
||||
def test_1240_scroll_last(self):
|
||||
"1240 - test scrolling to last row in result set"
|
||||
cursor = self.connection.cursor(scrollable = True)
|
||||
cursor = self.connection.cursor(scrollable=True)
|
||||
cursor.arraysize = self.cursor.arraysize
|
||||
cursor.execute("""
|
||||
select NumberCol
|
||||
from TestNumbers
|
||||
order by IntCol""")
|
||||
cursor.scroll(mode = "last")
|
||||
cursor.scroll(mode="last")
|
||||
row = cursor.fetchone()
|
||||
self.assertEqual(row[0], 12.5)
|
||||
self.assertEqual(cursor.rowcount, 10)
|
||||
|
||||
def test_1241_ScrollRelativeExceptionAfter(self):
|
||||
def test_1241_scroll_relative_exception_after(self):
|
||||
"1241 - test scrolling relative yields an exception (after result set)"
|
||||
cursor = self.connection.cursor(scrollable = True)
|
||||
cursor = self.connection.cursor(scrollable=True)
|
||||
cursor.arraysize = self.cursor.arraysize
|
||||
cursor.execute("""
|
||||
select NumberCol
|
||||
from TestNumbers
|
||||
order by IntCol""")
|
||||
self.assertRaises(cx_Oracle.DatabaseError, cursor.scroll, 15)
|
||||
self.assertRaises(oracledb.DatabaseError, cursor.scroll, 15)
|
||||
|
||||
def test_1242_ScrollRelativeExceptionBefore(self):
|
||||
def test_1242_scroll_relative_exception_before(self):
|
||||
"1242 - test scrolling relative yields exception (before result set)"
|
||||
cursor = self.connection.cursor(scrollable = True)
|
||||
cursor = self.connection.cursor(scrollable=True)
|
||||
cursor.arraysize = self.cursor.arraysize
|
||||
cursor.execute("""
|
||||
select NumberCol
|
||||
from TestNumbers
|
||||
order by IntCol""")
|
||||
self.assertRaises(cx_Oracle.DatabaseError, cursor.scroll, -5)
|
||||
self.assertRaises(oracledb.DatabaseError, cursor.scroll, -5)
|
||||
|
||||
def test_1243_ScrollRelativeInBuffer(self):
|
||||
def test_1243_scroll_relative_in_buffer(self):
|
||||
"1243 - test scrolling relative (when in buffers)"
|
||||
cursor = self.connection.cursor(scrollable = True)
|
||||
cursor = self.connection.cursor(scrollable=True)
|
||||
cursor.arraysize = self.cursor.arraysize
|
||||
cursor.execute("""
|
||||
select NumberCol
|
||||
from TestNumbers
|
||||
order by IntCol""")
|
||||
cursor.fetchmany()
|
||||
self.assertTrue(cursor.arraysize > 1,
|
||||
"array size must exceed 1 for this test to work correctly")
|
||||
message = "array size must exceed 1 for this test to work correctly"
|
||||
self.assertTrue(cursor.arraysize > 1, message)
|
||||
cursor.scroll(2 - cursor.rowcount)
|
||||
row = cursor.fetchone()
|
||||
self.assertEqual(row[0], 2.5)
|
||||
self.assertEqual(cursor.rowcount, 2)
|
||||
|
||||
def test_1244_ScrollRelativeNotInBuffer(self):
|
||||
def test_1244_scroll_relative_not_in_buffer(self):
|
||||
"1244 - test scrolling relative (when not in buffers)"
|
||||
cursor = self.connection.cursor(scrollable = True)
|
||||
cursor = self.connection.cursor(scrollable=True)
|
||||
cursor.arraysize = self.cursor.arraysize
|
||||
cursor.execute("""
|
||||
select NumberCol
|
||||
|
@ -503,26 +502,26 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
order by IntCol""")
|
||||
cursor.fetchmany()
|
||||
cursor.fetchmany()
|
||||
self.assertTrue(cursor.arraysize > 1,
|
||||
"array size must exceed 2 for this test to work correctly")
|
||||
message = "array size must exceed 1 for this test to work correctly"
|
||||
self.assertTrue(cursor.arraysize > 1, message)
|
||||
cursor.scroll(3 - cursor.rowcount)
|
||||
row = cursor.fetchone()
|
||||
self.assertEqual(row[0], 3.75)
|
||||
self.assertEqual(cursor.rowcount, 3)
|
||||
|
||||
def test_1245_ScrollNoRows(self):
|
||||
def test_1245_scroll_no_rows(self):
|
||||
"1245 - test scrolling when there are no rows"
|
||||
self.cursor.execute("truncate table TestTempTable")
|
||||
cursor = self.connection.cursor(scrollable = True)
|
||||
cursor = self.connection.cursor(scrollable=True)
|
||||
cursor.execute("select * from TestTempTable")
|
||||
cursor.scroll(mode = "last")
|
||||
self.assertEqual(cursor.fetchall(), [])
|
||||
cursor.scroll(mode = "first")
|
||||
self.assertEqual(cursor.fetchall(), [])
|
||||
self.assertRaises(cx_Oracle.DatabaseError, cursor.scroll, 1,
|
||||
mode = "absolute")
|
||||
self.assertRaises(oracledb.DatabaseError, cursor.scroll, 1,
|
||||
mode="absolute")
|
||||
|
||||
def test_1246_ScrollDifferingArrayAndFetchSizes(self):
|
||||
def test_1246_scroll_differing_array_and_fetch_sizes(self):
|
||||
"1246 - test scrolling with differing array and fetch array sizes"
|
||||
self.cursor.execute("truncate table TestTempTable")
|
||||
for i in range(30):
|
||||
|
@ -530,74 +529,75 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
insert into TestTempTable (IntCol, StringCol)
|
||||
values (:1, null)""",
|
||||
(i + 1,))
|
||||
for arraySize in range(1, 6):
|
||||
for arraysize in range(1, 6):
|
||||
cursor = self.connection.cursor(scrollable = True)
|
||||
cursor.arraysize = arraySize
|
||||
cursor.arraysize = arraysize
|
||||
cursor.execute("select IntCol from TestTempTable order by IntCol")
|
||||
for numRows in range(1, arraySize + 1):
|
||||
for num_rows in range(1, arraysize + 1):
|
||||
cursor.scroll(15, "absolute")
|
||||
rows = cursor.fetchmany(numRows)
|
||||
rows = cursor.fetchmany(num_rows)
|
||||
self.assertEqual(rows[0][0], 15)
|
||||
self.assertEqual(cursor.rowcount, 15 + numRows - 1)
|
||||
self.assertEqual(cursor.rowcount, 15 + num_rows - 1)
|
||||
cursor.scroll(9)
|
||||
rows = cursor.fetchmany(numRows)
|
||||
numRowsFetched = len(rows)
|
||||
self.assertEqual(rows[0][0], 15 + numRows + 8)
|
||||
rows = cursor.fetchmany(num_rows)
|
||||
num_rows_fetched = len(rows)
|
||||
self.assertEqual(rows[0][0], 15 + num_rows + 8)
|
||||
self.assertEqual(cursor.rowcount,
|
||||
15 + numRows + numRowsFetched + 7)
|
||||
15 + num_rows + num_rows_fetched + 7)
|
||||
cursor.scroll(-12)
|
||||
rows = cursor.fetchmany(numRows)
|
||||
self.assertEqual(rows[0][0], 15 + numRows + numRowsFetched - 5)
|
||||
self.assertEqual(cursor.rowcount,
|
||||
15 + numRows + numRowsFetched + numRows - 6)
|
||||
rows = cursor.fetchmany(num_rows)
|
||||
count = 15 + num_rows + num_rows_fetched - 5
|
||||
self.assertEqual(rows[0][0], count)
|
||||
count = 15 + num_rows + num_rows_fetched + num_rows - 6
|
||||
self.assertEqual(cursor.rowcount, count)
|
||||
|
||||
def test_1247_SetInputSizesNegative(self):
|
||||
def test_1247_set_input_sizes_negative(self):
|
||||
"1247 - test cursor.setinputsizes() with invalid parameters"
|
||||
val = decimal.Decimal(5)
|
||||
self.assertRaises(cx_Oracle.InterfaceError,
|
||||
self.cursor.setinputsizes, val, x = val)
|
||||
self.assertRaises(oracledb.InterfaceError,
|
||||
self.cursor.setinputsizes, val, x=val)
|
||||
self.assertRaises(TypeError, self.cursor.setinputsizes, val)
|
||||
|
||||
def test_1248_SetInputSizesNoParameters(self):
|
||||
def test_1248_set_input_sizes_no_parameters(self):
|
||||
"1248 - test setting input sizes without any parameters"
|
||||
self.cursor.setinputsizes()
|
||||
self.cursor.execute("select :val from dual", val = "Test Value")
|
||||
self.cursor.execute("select :val from dual", val="Test Value")
|
||||
self.assertEqual(self.cursor.fetchall(), [("Test Value",)])
|
||||
|
||||
def test_1249_SetInputSizesEmptyDict(self):
|
||||
def test_1249_set_input_sizes_empty_dict(self):
|
||||
"1249 - test setting input sizes with an empty dictionary"
|
||||
emptyDict = {}
|
||||
empty_dict = {}
|
||||
self.cursor.prepare("select 236 from dual")
|
||||
self.cursor.setinputsizes(**emptyDict)
|
||||
self.cursor.execute(None, emptyDict)
|
||||
self.cursor.setinputsizes(**empty_dict)
|
||||
self.cursor.execute(None, empty_dict)
|
||||
self.assertEqual(self.cursor.fetchall(), [(236,)])
|
||||
|
||||
def test_1250_SetInputSizesEmptyList(self):
|
||||
def test_1250_set_input_sizes_empty_list(self):
|
||||
"1250 - test setting input sizes with an empty list"
|
||||
emptyList = {}
|
||||
empty_list = {}
|
||||
self.cursor.prepare("select 239 from dual")
|
||||
self.cursor.setinputsizes(*emptyList)
|
||||
self.cursor.execute(None, emptyList)
|
||||
self.cursor.setinputsizes(*empty_list)
|
||||
self.cursor.execute(None, empty_list)
|
||||
self.assertEqual(self.cursor.fetchall(), [(239,)])
|
||||
|
||||
def test_1251_SetInputSizesByPosition(self):
|
||||
def test_1251_set_input_sizes_by_position(self):
|
||||
"1251 - test setting input sizes with positional args"
|
||||
var = self.cursor.var(cx_Oracle.STRING, 100)
|
||||
self.cursor.setinputsizes(None, 5, None, 10, None, cx_Oracle.NUMBER)
|
||||
var = self.cursor.var(oracledb.STRING, 100)
|
||||
self.cursor.setinputsizes(None, 5, None, 10, None, oracledb.NUMBER)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:1 := :2 || to_char(:3) || :4 || to_char(:5) || to_char(:6);
|
||||
end;""", [var, 'test_', 5, '_second_', 3, 7])
|
||||
self.assertEqual(var.getvalue(), "test_5_second_37")
|
||||
|
||||
def test_1252_StringFormat(self):
|
||||
def test_1252_string_format(self):
|
||||
"1252 - test string format of cursor"
|
||||
formatString = "<cx_Oracle.Cursor on <cx_Oracle.Connection to %s@%s>>"
|
||||
expectedValue = formatString % \
|
||||
(TestEnv.GetMainUser(), TestEnv.GetConnectString())
|
||||
self.assertEqual(str(self.cursor), expectedValue)
|
||||
format_string = "<cx_Oracle.Cursor on <cx_Oracle.Connection to %s@%s>>"
|
||||
expected_value = format_string % \
|
||||
(base.get_main_user(), base.get_connect_string())
|
||||
self.assertEqual(str(self.cursor), expected_value)
|
||||
|
||||
def test_1253_CursorFetchRaw(self):
|
||||
def test_1253_cursor_fetch_raw(self):
|
||||
"1253 - test cursor.fetchraw()"
|
||||
cursor = self.connection.cursor()
|
||||
cursor.arraysize = 25
|
||||
|
@ -605,28 +605,28 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
self.assertEqual(cursor.fetchraw(), 10)
|
||||
self.assertEqual(cursor.fetchvars[0].getvalue(), 38)
|
||||
|
||||
def test_1254_Parse(self):
|
||||
def test_1254_parse(self):
|
||||
"1254 - test parsing statements"
|
||||
sql = "select LongIntCol from TestNumbers where IntCol = :val"
|
||||
self.cursor.parse(sql)
|
||||
self.assertEqual(self.cursor.statement, sql)
|
||||
self.assertEqual(self.cursor.description,
|
||||
[ ('LONGINTCOL', cx_Oracle.DB_TYPE_NUMBER, 17, None, 16, 0,
|
||||
0) ])
|
||||
[('LONGINTCOL', oracledb.DB_TYPE_NUMBER, 17, None,
|
||||
16, 0, 0)])
|
||||
|
||||
def test_1255_SetOutputSize(self):
|
||||
def test_1255_set_output_size(self):
|
||||
"1255 - test cursor.setoutputsize() does not fail (but does nothing)"
|
||||
self.cursor.setoutputsize(100, 2)
|
||||
|
||||
def test_1256_VarNegative(self):
|
||||
def test_1256_var_negative(self):
|
||||
"1256 - test cursor.var() with invalid parameters"
|
||||
self.assertRaises(TypeError, self.cursor.var, 5)
|
||||
|
||||
def test_1257_ArrayVarNegative(self):
|
||||
def test_1257_arrayvar_negative(self):
|
||||
"1257 - test cursor.arrayvar() with invalid parameters"
|
||||
self.assertRaises(TypeError, self.cursor.arrayvar, 5, 1)
|
||||
|
||||
def test_1258_BooleanWithoutPlsql(self):
|
||||
def test_1258_boolean_without_plsql(self):
|
||||
"1258 - test binding boolean data without the use of PL/SQL"
|
||||
self.cursor.execute("truncate table TestTempTable")
|
||||
sql = "insert into TestTempTable (IntCol, StringCol) values (:1, :2)"
|
||||
|
@ -637,18 +637,18 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
from TestTempTable
|
||||
order by IntCol""")
|
||||
self.assertEqual(self.cursor.fetchall(),
|
||||
[ (0, "Value should be 0"), (1, "Value should be 1") ])
|
||||
[(0, "Value should be 0"), (1, "Value should be 1")])
|
||||
|
||||
def test_1259_AsContextManager(self):
|
||||
def test_1259_as_context_manager(self):
|
||||
"1259 - test using a cursor as a context manager"
|
||||
with self.cursor as cursor:
|
||||
cursor.execute("truncate table TestTempTable")
|
||||
cursor.execute("select count(*) from TestTempTable")
|
||||
count, = cursor.fetchone()
|
||||
self.assertEqual(count, 0)
|
||||
self.assertRaises(cx_Oracle.InterfaceError, self.cursor.close)
|
||||
self.assertRaises(oracledb.InterfaceError, self.cursor.close)
|
||||
|
||||
def test_1260_QueryRowCount(self):
|
||||
def test_1260_query_row_count(self):
|
||||
"1260 - test that rowcount attribute is reset to zero on query execute"
|
||||
sql = "select * from dual where 1 = :s"
|
||||
self.cursor.execute(sql, [0])
|
||||
|
@ -664,39 +664,39 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
self.cursor.fetchone()
|
||||
self.assertEqual(self.cursor.rowcount, 0)
|
||||
|
||||
def test_1261_VarTypeNameNone(self):
|
||||
def test_1261_var_type_name_none(self):
|
||||
"1261 - test that the typename attribute can be passed a value of None"
|
||||
valueToSet = 5
|
||||
value_to_set = 5
|
||||
var = self.cursor.var(int, typename=None)
|
||||
var.setvalue(0, valueToSet)
|
||||
self.assertEqual(var.getvalue(), valueToSet)
|
||||
var.setvalue(0, value_to_set)
|
||||
self.assertEqual(var.getvalue(), value_to_set)
|
||||
|
||||
def test_1262_VarTypeWithObjectType(self):
|
||||
def test_1262_var_type_with_object_type(self):
|
||||
"1262 - test that an object type can be used as type in cursor.var()"
|
||||
objType = self.connection.gettype("UDT_OBJECT")
|
||||
var = self.cursor.var(objType)
|
||||
obj_type = self.connection.gettype("UDT_OBJECT")
|
||||
var = self.cursor.var(obj_type)
|
||||
self.cursor.callproc("pkg_TestBindObject.BindObjectOut",
|
||||
(28, "Bind obj out", var))
|
||||
(28, "Bind obj out", var))
|
||||
obj = var.getvalue()
|
||||
result = self.cursor.callfunc("pkg_TestBindObject.GetStringRep", str,
|
||||
(obj,))
|
||||
self.assertEqual(result,
|
||||
"udt_Object(28, 'Bind obj out', null, null, null, null, null)")
|
||||
(obj,))
|
||||
exp = "udt_Object(28, 'Bind obj out', null, null, null, null, null)"
|
||||
self.assertEqual(result, exp)
|
||||
|
||||
def test_1263_FetchXMLType(self):
|
||||
def test_1263_fetch_xmltype(self):
|
||||
"1263 - test that fetching an XMLType returns a string"
|
||||
intVal = 5
|
||||
int_val = 5
|
||||
label = "IntCol"
|
||||
expectedResult = "<%s>%s</%s>" % (label, intVal, label)
|
||||
expected_result = "<%s>%s</%s>" % (label, int_val, label)
|
||||
self.cursor.execute("""
|
||||
select XMLElement("%s", IntCol)
|
||||
from TestStrings
|
||||
where IntCol = :intVal""" % label,
|
||||
intVal = intVal)
|
||||
where IntCol = :int_val""" % label,
|
||||
int_val=int_val)
|
||||
result, = self.cursor.fetchone()
|
||||
self.assertEqual(result, expectedResult)
|
||||
self.assertEqual(result, expected_result)
|
||||
|
||||
def test_1264_LastRowid(self):
|
||||
def test_1264_lastrowid(self):
|
||||
"1264 - test last rowid"
|
||||
|
||||
# no statement executed: no rowid
|
||||
|
@ -748,9 +748,9 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
where rowid = :1""", [rowid])
|
||||
self.assertEqual("Row %s" % rows[-3], self.cursor.fetchone()[0])
|
||||
|
||||
def test_1265_PrefetchRows(self):
|
||||
def test_1265_prefetchrows(self):
|
||||
"1265 - test prefetch rows"
|
||||
self.setUpRoundTripChecker()
|
||||
self.setup_round_trip_checker()
|
||||
|
||||
# perform simple query and verify only one round trip is needed
|
||||
with self.connection.cursor() as cursor:
|
||||
|
@ -769,10 +769,10 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
self.assertRoundTrips(1)
|
||||
|
||||
# array execution only requires a single round trip
|
||||
numRows = 590
|
||||
num_rows = 590
|
||||
with self.connection.cursor() as cursor:
|
||||
sql = "insert into TestTempTable (IntCol) values (:1)"
|
||||
data = [(n + 1,) for n in range(numRows)]
|
||||
data = [(n + 1,) for n in range(num_rows)]
|
||||
cursor.executemany(sql, data)
|
||||
self.assertRoundTrips(1)
|
||||
|
||||
|
@ -782,7 +782,7 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
cursor.prefetchrows = 1
|
||||
cursor.arraysize = 1
|
||||
cursor.execute("select IntCol from TestTempTable").fetchall()
|
||||
self.assertRoundTrips(numRows + 1)
|
||||
self.assertRoundTrips(num_rows + 1)
|
||||
|
||||
# setting prefetch and array size to 300 requires 2 round-trips
|
||||
with self.connection.cursor() as cursor:
|
||||
|
@ -792,4 +792,4 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
self.assertRoundTrips(2)
|
||||
|
||||
if __name__ == "__main__":
|
||||
TestEnv.RunTestCases()
|
||||
base.run_test_cases()
|
||||
|
|
|
@ -11,14 +11,14 @@
|
|||
1300 - Module for testing cursor variables
|
||||
"""
|
||||
|
||||
import TestEnv
|
||||
import base
|
||||
|
||||
import cx_Oracle
|
||||
import cx_Oracle as oracledb
|
||||
import sys
|
||||
|
||||
class TestCase(TestEnv.BaseTestCase):
|
||||
class TestCase(base.BaseTestCase):
|
||||
|
||||
def test_1300_BindCursor(self):
|
||||
def test_1300_bind_cursor(self):
|
||||
"1300 - test binding in a cursor"
|
||||
cursor = self.connection.cursor()
|
||||
self.assertEqual(cursor.description, None)
|
||||
|
@ -26,25 +26,28 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
begin
|
||||
open :cursor for select 'X' StringValue from dual;
|
||||
end;""",
|
||||
cursor = cursor)
|
||||
self.assertEqual(cursor.description,
|
||||
[ ('STRINGVALUE', cx_Oracle.DB_TYPE_CHAR, 1,
|
||||
TestEnv.GetCharSetRatio(), None, None, 1) ])
|
||||
cursor=cursor)
|
||||
expected_value = [
|
||||
('STRINGVALUE', oracledb.DB_TYPE_CHAR, 1,
|
||||
base.get_charset_ratio(), None, None, 1)
|
||||
]
|
||||
self.assertEqual(cursor.description, expected_value)
|
||||
self.assertEqual(cursor.fetchall(), [('X',)])
|
||||
|
||||
def test_1301_BindCursorInPackage(self):
|
||||
def test_1301_bind_cursor_in_package(self):
|
||||
"1301 - test binding in a cursor from a package"
|
||||
cursor = self.connection.cursor()
|
||||
self.assertEqual(cursor.description, None)
|
||||
self.cursor.callproc("pkg_TestRefCursors.TestOutCursor", (2, cursor))
|
||||
self.assertEqual(cursor.description,
|
||||
[ ('INTCOL', cx_Oracle.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
|
||||
('STRINGCOL', cx_Oracle.DB_TYPE_VARCHAR, 20, 20 *
|
||||
TestEnv.GetCharSetRatio(), None, None, 0) ])
|
||||
self.assertEqual(cursor.fetchall(),
|
||||
[ (1, 'String 1'), (2, 'String 2') ])
|
||||
expected_value = [
|
||||
('INTCOL', oracledb.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
|
||||
('STRINGCOL', oracledb.DB_TYPE_VARCHAR, 20,
|
||||
20 * base.get_charset_ratio(), None, None, 0)
|
||||
]
|
||||
self.assertEqual(cursor.description, expected_value)
|
||||
self.assertEqual(cursor.fetchall(), [(1, 'String 1'), (2, 'String 2')])
|
||||
|
||||
def test_1302_BindSelf(self):
|
||||
def test_1302_bind_self(self):
|
||||
"1302 - test that binding the cursor itself is not supported"
|
||||
cursor = self.connection.cursor()
|
||||
sql = """
|
||||
|
@ -52,12 +55,12 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
open :pcursor for
|
||||
select 1 from dual;
|
||||
end;"""
|
||||
self.assertRaises(cx_Oracle.DatabaseError, cursor.execute, sql,
|
||||
pcursor = cursor)
|
||||
self.assertRaises(oracledb.DatabaseError, cursor.execute, sql,
|
||||
pcursor=cursor)
|
||||
|
||||
def test_1303_ExecuteAfterClose(self):
|
||||
def test_1303_execute_after_close(self):
|
||||
"1303 - test returning a ref cursor after closing it"
|
||||
outCursor = self.connection.cursor()
|
||||
out_cursor = self.connection.cursor()
|
||||
sql = """
|
||||
begin
|
||||
open :pcursor for
|
||||
|
@ -65,15 +68,15 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
from TestNumbers
|
||||
order by IntCol;
|
||||
end;"""
|
||||
self.cursor.execute(sql, pcursor = outCursor)
|
||||
rows = outCursor.fetchall()
|
||||
outCursor.close()
|
||||
outCursor = self.connection.cursor()
|
||||
self.cursor.execute(sql, pcursor = outCursor)
|
||||
rows2 = outCursor.fetchall()
|
||||
self.cursor.execute(sql, pcursor=out_cursor)
|
||||
rows = out_cursor.fetchall()
|
||||
out_cursor.close()
|
||||
out_cursor = self.connection.cursor()
|
||||
self.cursor.execute(sql, pcursor=out_cursor)
|
||||
rows2 = out_cursor.fetchall()
|
||||
self.assertEqual(rows, rows2)
|
||||
|
||||
def test_1304_FetchCursor(self):
|
||||
def test_1304_fetch_cursor(self):
|
||||
"1304 - test fetching a cursor"
|
||||
self.cursor.execute("""
|
||||
select
|
||||
|
@ -81,14 +84,15 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
cursor(select IntCol + 1 from dual) CursorValue
|
||||
from TestNumbers
|
||||
order by IntCol""")
|
||||
self.assertEqual(self.cursor.description,
|
||||
[ ('INTCOL', cx_Oracle.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
|
||||
('CURSORVALUE', cx_Oracle.DB_TYPE_CURSOR, None, None, None,
|
||||
None, 1) ])
|
||||
expected_value = [
|
||||
('INTCOL', oracledb.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
|
||||
('CURSORVALUE', oracledb.DB_TYPE_CURSOR, None, None, None, None, 1)
|
||||
]
|
||||
self.assertEqual(self.cursor.description, expected_value)
|
||||
for i in range(1, 11):
|
||||
number, cursor = self.cursor.fetchone()
|
||||
self.assertEqual(number, i)
|
||||
self.assertEqual(cursor.fetchall(), [(i + 1,)])
|
||||
|
||||
if __name__ == "__main__":
|
||||
TestEnv.RunTestCases()
|
||||
base.run_test_cases()
|
||||
|
|
|
@ -11,242 +11,239 @@
|
|||
1400 - Module for testing date/time variables
|
||||
"""
|
||||
|
||||
import TestEnv
|
||||
import base
|
||||
|
||||
import cx_Oracle
|
||||
import cx_Oracle as oracledb
|
||||
import datetime
|
||||
import time
|
||||
|
||||
class TestCase(TestEnv.BaseTestCase):
|
||||
class TestCase(base.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
TestEnv.BaseTestCase.setUp(self)
|
||||
self.rawData = []
|
||||
self.dataByKey = {}
|
||||
super().setUp()
|
||||
self.raw_data = []
|
||||
self.data_by_key = {}
|
||||
for i in range(1, 11):
|
||||
timeTuple = (2002, 12, 9, 0, 0, 0, 0, 0, -1)
|
||||
timeInTicks = time.mktime(timeTuple) + i * 86400 + i * 8640
|
||||
dateCol = cx_Oracle.TimestampFromTicks(int(timeInTicks))
|
||||
time_tuple = (2002, 12, 9, 0, 0, 0, 0, 0, -1)
|
||||
time_in_ticks = time.mktime(time_tuple) + i * 86400 + i * 8640
|
||||
date_col = oracledb.TimestampFromTicks(int(time_in_ticks))
|
||||
if i % 2:
|
||||
timeInTicks = time.mktime(timeTuple) + i * 86400 * 2 + \
|
||||
time_in_ticks = time.mktime(time_tuple) + i * 86400 * 2 + \
|
||||
i * 12960
|
||||
nullableCol = cx_Oracle.TimestampFromTicks(int(timeInTicks))
|
||||
nullable_col = oracledb.TimestampFromTicks(int(time_in_ticks))
|
||||
else:
|
||||
nullableCol = None
|
||||
tuple = (i, dateCol, nullableCol)
|
||||
self.rawData.append(tuple)
|
||||
self.dataByKey[i] = tuple
|
||||
nullable_col = None
|
||||
tuple = (i, date_col, nullable_col)
|
||||
self.raw_data.append(tuple)
|
||||
self.data_by_key[i] = tuple
|
||||
|
||||
def test_1400_BindDate(self):
|
||||
def test_1400_bind_date(self):
|
||||
"1400 - test binding in a date"
|
||||
self.cursor.execute("""
|
||||
select * from TestDates
|
||||
where DateCol = :value""",
|
||||
value = cx_Oracle.Timestamp(2002, 12, 13, 9, 36, 0))
|
||||
self.assertEqual(self.cursor.fetchall(), [self.dataByKey[4]])
|
||||
value = oracledb.Timestamp(2002, 12, 13, 9, 36, 0))
|
||||
self.assertEqual(self.cursor.fetchall(), [self.data_by_key[4]])
|
||||
|
||||
def test_1401_BindDateTime(self):
|
||||
def test_1401_bind_datetime(self):
|
||||
"1401 - test binding in a datetime.datetime value"
|
||||
self.cursor.execute("""
|
||||
select * from TestDates
|
||||
where DateCol = :value""",
|
||||
value = datetime.datetime(2002, 12, 13, 9, 36, 0))
|
||||
self.assertEqual(self.cursor.fetchall(), [self.dataByKey[4]])
|
||||
value=datetime.datetime(2002, 12, 13, 9, 36, 0))
|
||||
self.assertEqual(self.cursor.fetchall(), [self.data_by_key[4]])
|
||||
|
||||
def test_1402_BindDateInDateTimeVar(self):
|
||||
def test_1402_bind_date_in_datetime_var(self):
|
||||
"1402 - test binding date in a datetime variable"
|
||||
var = self.cursor.var(cx_Oracle.DATETIME)
|
||||
var = self.cursor.var(oracledb.DATETIME)
|
||||
dateVal = datetime.date.today()
|
||||
var.setvalue(0, dateVal)
|
||||
self.assertEqual(var.getvalue().date(), dateVal)
|
||||
|
||||
def test_1403_BindDateAfterString(self):
|
||||
def test_1403_bind_date_after_string(self):
|
||||
"1403 - test binding in a date after setting input sizes to a string"
|
||||
self.cursor.setinputsizes(value = 15)
|
||||
self.cursor.setinputsizes(value=15)
|
||||
self.cursor.execute("""
|
||||
select * from TestDates
|
||||
where DateCol = :value""",
|
||||
value = cx_Oracle.Timestamp(2002, 12, 14, 12, 0, 0))
|
||||
self.assertEqual(self.cursor.fetchall(), [self.dataByKey[5]])
|
||||
value = oracledb.Timestamp(2002, 12, 14, 12, 0, 0))
|
||||
self.assertEqual(self.cursor.fetchall(), [self.data_by_key[5]])
|
||||
|
||||
def test_1404_BindNull(self):
|
||||
def test_1404_bind_null(self):
|
||||
"1404 - test binding in a null"
|
||||
self.cursor.setinputsizes(value = cx_Oracle.DATETIME)
|
||||
self.cursor.setinputsizes(value=oracledb.DATETIME)
|
||||
self.cursor.execute("""
|
||||
select * from TestDates
|
||||
where DateCol = :value""",
|
||||
value = None)
|
||||
self.assertEqual(self.cursor.fetchall(), [])
|
||||
|
||||
def test_1405_BindDateArrayDirect(self):
|
||||
def test_1405_bind_date_array_direct(self):
|
||||
"1405 - test binding in a date array"
|
||||
returnValue = self.cursor.var(cx_Oracle.NUMBER)
|
||||
array = [r[1] for r in self.rawData]
|
||||
return_value = self.cursor.var(oracledb.NUMBER)
|
||||
array = [r[1] for r in self.raw_data]
|
||||
statement = """
|
||||
begin
|
||||
:returnValue := pkg_TestDateArrays.TestInArrays(
|
||||
:startValue, :baseDate, :array);
|
||||
:return_value := pkg_TestDateArrays.TestInArrays(
|
||||
:start_value, :base_date, :array);
|
||||
end;"""
|
||||
self.cursor.execute(statement,
|
||||
returnValue = returnValue,
|
||||
startValue = 5,
|
||||
baseDate = cx_Oracle.Date(2002, 12, 12),
|
||||
array = array)
|
||||
self.assertEqual(returnValue.getvalue(), 35.5)
|
||||
self.cursor.execute(statement, return_value=return_value,
|
||||
start_value=5,
|
||||
base_date=oracledb.Date(2002, 12, 12), array=array)
|
||||
self.assertEqual(return_value.getvalue(), 35.5)
|
||||
array = array + array[:5]
|
||||
self.cursor.execute(statement,
|
||||
startValue = 7,
|
||||
baseDate = cx_Oracle.Date(2002, 12, 13),
|
||||
array = array)
|
||||
self.assertEqual(returnValue.getvalue(), 24.0)
|
||||
self.cursor.execute(statement, start_value=7,
|
||||
base_date=oracledb.Date(2002, 12, 13), array=array)
|
||||
self.assertEqual(return_value.getvalue(), 24.0)
|
||||
|
||||
def test_1406_BindDateArrayBySizes(self):
|
||||
def test_1406_bind_date_array_by_sizes(self):
|
||||
"1406 - test binding in a date array (with setinputsizes)"
|
||||
returnValue = self.cursor.var(cx_Oracle.NUMBER)
|
||||
self.cursor.setinputsizes(array = [cx_Oracle.DATETIME, 10])
|
||||
array = [r[1] for r in self.rawData]
|
||||
return_value = self.cursor.var(oracledb.NUMBER)
|
||||
self.cursor.setinputsizes(array=[oracledb.DATETIME, 10])
|
||||
array = [r[1] for r in self.raw_data]
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:returnValue := pkg_TestDateArrays.TestInArrays(
|
||||
:startValue, :baseDate, :array);
|
||||
:return_value := pkg_TestDateArrays.TestInArrays(
|
||||
:start_value, :base_date, :array);
|
||||
end;""",
|
||||
returnValue = returnValue,
|
||||
startValue = 6,
|
||||
baseDate = cx_Oracle.Date(2002, 12, 13),
|
||||
array = array)
|
||||
self.assertEqual(returnValue.getvalue(), 26.5)
|
||||
return_value=return_value,
|
||||
start_value=6,
|
||||
base_date=oracledb.Date(2002, 12, 13),
|
||||
array=array)
|
||||
self.assertEqual(return_value.getvalue(), 26.5)
|
||||
|
||||
def test_1407_BindDateArrayByVar(self):
|
||||
def test_1407_bind_date_array_by_var(self):
|
||||
"1407 - test binding in a date array (with arrayvar)"
|
||||
returnValue = self.cursor.var(cx_Oracle.NUMBER)
|
||||
array = self.cursor.arrayvar(cx_Oracle.DATETIME, 10, 20)
|
||||
array.setvalue(0, [r[1] for r in self.rawData])
|
||||
return_value = self.cursor.var(oracledb.NUMBER)
|
||||
array = self.cursor.arrayvar(oracledb.DATETIME, 10, 20)
|
||||
array.setvalue(0, [r[1] for r in self.raw_data])
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:returnValue := pkg_TestDateArrays.TestInArrays(
|
||||
:startValue, :baseDate, :array);
|
||||
:return_value := pkg_TestDateArrays.TestInArrays(
|
||||
:start_value, :base_date, :array);
|
||||
end;""",
|
||||
returnValue = returnValue,
|
||||
startValue = 7,
|
||||
baseDate = cx_Oracle.Date(2002, 12, 14),
|
||||
array = array)
|
||||
self.assertEqual(returnValue.getvalue(), 17.5)
|
||||
return_value=return_value,
|
||||
start_value=7,
|
||||
base_date=oracledb.Date(2002, 12, 14),
|
||||
array=array)
|
||||
self.assertEqual(return_value.getvalue(), 17.5)
|
||||
|
||||
def test_1408_BindInOutDateArrayByVar(self):
|
||||
def test_1408_bind_in_out_date_array_by_var(self):
|
||||
"1408 - test binding in/out a date array (with arrayvar)"
|
||||
array = self.cursor.arrayvar(cx_Oracle.DATETIME, 10, 100)
|
||||
originalData = [r[1] for r in self.rawData]
|
||||
array.setvalue(0, originalData)
|
||||
array = self.cursor.arrayvar(oracledb.DATETIME, 10, 100)
|
||||
original_data = [r[1] for r in self.raw_data]
|
||||
array.setvalue(0, original_data)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
pkg_TestDateArrays.TestInOutArrays(:numElems, :array);
|
||||
pkg_TestDateArrays.TestInOutArrays(:num_elems, :array);
|
||||
end;""",
|
||||
numElems = 5,
|
||||
array = array)
|
||||
num_elems=5,
|
||||
array=array)
|
||||
self.assertEqual(array.getvalue(),
|
||||
[ cx_Oracle.Timestamp(2002, 12, 17, 2, 24, 0),
|
||||
cx_Oracle.Timestamp(2002, 12, 18, 4, 48, 0),
|
||||
cx_Oracle.Timestamp(2002, 12, 19, 7, 12, 0),
|
||||
cx_Oracle.Timestamp(2002, 12, 20, 9, 36, 0),
|
||||
cx_Oracle.Timestamp(2002, 12, 21, 12, 0, 0) ] + \
|
||||
originalData[5:])
|
||||
[ oracledb.Timestamp(2002, 12, 17, 2, 24, 0),
|
||||
oracledb.Timestamp(2002, 12, 18, 4, 48, 0),
|
||||
oracledb.Timestamp(2002, 12, 19, 7, 12, 0),
|
||||
oracledb.Timestamp(2002, 12, 20, 9, 36, 0),
|
||||
oracledb.Timestamp(2002, 12, 21, 12, 0, 0) ] + \
|
||||
original_data[5:])
|
||||
|
||||
def test_1409_BindOutDateArrayByVar(self):
|
||||
def test_1409_bind_out_date_array_by_var(self):
|
||||
"1409 - test binding out a date array (with arrayvar)"
|
||||
array = self.cursor.arrayvar(cx_Oracle.DATETIME, 6, 100)
|
||||
array = self.cursor.arrayvar(oracledb.DATETIME, 6, 100)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
pkg_TestDateArrays.TestOutArrays(:numElems, :array);
|
||||
pkg_TestDateArrays.TestOutArrays(:num_elems, :array);
|
||||
end;""",
|
||||
numElems = 6,
|
||||
array = array)
|
||||
num_elems=6,
|
||||
array=array)
|
||||
self.assertEqual(array.getvalue(),
|
||||
[ cx_Oracle.Timestamp(2002, 12, 13, 4, 48, 0),
|
||||
cx_Oracle.Timestamp(2002, 12, 14, 9, 36, 0),
|
||||
cx_Oracle.Timestamp(2002, 12, 15, 14, 24, 0),
|
||||
cx_Oracle.Timestamp(2002, 12, 16, 19, 12, 0),
|
||||
cx_Oracle.Timestamp(2002, 12, 18, 0, 0, 0),
|
||||
cx_Oracle.Timestamp(2002, 12, 19, 4, 48, 0) ])
|
||||
[ oracledb.Timestamp(2002, 12, 13, 4, 48, 0),
|
||||
oracledb.Timestamp(2002, 12, 14, 9, 36, 0),
|
||||
oracledb.Timestamp(2002, 12, 15, 14, 24, 0),
|
||||
oracledb.Timestamp(2002, 12, 16, 19, 12, 0),
|
||||
oracledb.Timestamp(2002, 12, 18, 0, 0, 0),
|
||||
oracledb.Timestamp(2002, 12, 19, 4, 48, 0) ])
|
||||
|
||||
def test_1410_BindOutSetInputSizes(self):
|
||||
def test_1410_bind_out_set_input_sizes(self):
|
||||
"1410 - test binding out with set input sizes defined"
|
||||
vars = self.cursor.setinputsizes(value = cx_Oracle.DATETIME)
|
||||
bind_vars = self.cursor.setinputsizes(value=oracledb.DATETIME)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:value := to_date(20021209, 'YYYYMMDD');
|
||||
end;""")
|
||||
self.assertEqual(vars["value"].getvalue(),
|
||||
cx_Oracle.Timestamp(2002, 12, 9))
|
||||
self.assertEqual(bind_vars["value"].getvalue(),
|
||||
oracledb.Timestamp(2002, 12, 9))
|
||||
|
||||
def test_1411_BindInOutSetInputSizes(self):
|
||||
def test_1411_bind_in_out_set_input_sizes(self):
|
||||
"1411 - test binding in/out with set input sizes defined"
|
||||
vars = self.cursor.setinputsizes(value = cx_Oracle.DATETIME)
|
||||
bind_vars = self.cursor.setinputsizes(value=oracledb.DATETIME)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:value := :value + 5.25;
|
||||
end;""",
|
||||
value = cx_Oracle.Timestamp(2002, 12, 12, 10, 0, 0))
|
||||
self.assertEqual(vars["value"].getvalue(),
|
||||
cx_Oracle.Timestamp(2002, 12, 17, 16, 0, 0))
|
||||
value=oracledb.Timestamp(2002, 12, 12, 10, 0, 0))
|
||||
self.assertEqual(bind_vars["value"].getvalue(),
|
||||
oracledb.Timestamp(2002, 12, 17, 16, 0, 0))
|
||||
|
||||
def test_1412_BindOutVar(self):
|
||||
def test_1412_bind_out_var(self):
|
||||
"1412 - test binding out with cursor.var() method"
|
||||
var = self.cursor.var(cx_Oracle.DATETIME)
|
||||
var = self.cursor.var(oracledb.DATETIME)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:value := to_date('20021231 12:31:00',
|
||||
'YYYYMMDD HH24:MI:SS');
|
||||
end;""",
|
||||
value = var)
|
||||
value=var)
|
||||
self.assertEqual(var.getvalue(),
|
||||
cx_Oracle.Timestamp(2002, 12, 31, 12, 31, 0))
|
||||
oracledb.Timestamp(2002, 12, 31, 12, 31, 0))
|
||||
|
||||
def test_1413_BindInOutVarDirectSet(self):
|
||||
def test_1413_bind_in_out_var_direct_set(self):
|
||||
"1413 - test binding in/out with cursor.var() method"
|
||||
var = self.cursor.var(cx_Oracle.DATETIME)
|
||||
var.setvalue(0, cx_Oracle.Timestamp(2002, 12, 9, 6, 0, 0))
|
||||
var = self.cursor.var(oracledb.DATETIME)
|
||||
var.setvalue(0, oracledb.Timestamp(2002, 12, 9, 6, 0, 0))
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:value := :value + 5.25;
|
||||
end;""",
|
||||
value = var)
|
||||
value=var)
|
||||
self.assertEqual(var.getvalue(),
|
||||
cx_Oracle.Timestamp(2002, 12, 14, 12, 0, 0))
|
||||
oracledb.Timestamp(2002, 12, 14, 12, 0, 0))
|
||||
|
||||
def test_1414_CursorDescription(self):
|
||||
def test_1414_cursor_description(self):
|
||||
"1414 - test cursor description is accurate"
|
||||
self.cursor.execute("select * from TestDates")
|
||||
self.assertEqual(self.cursor.description,
|
||||
[ ('INTCOL', cx_Oracle.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
|
||||
('DATECOL', cx_Oracle.DB_TYPE_DATE, 23, None, None, None, 0),
|
||||
('NULLABLECOL', cx_Oracle.DB_TYPE_DATE, 23, None, None, None,
|
||||
1) ])
|
||||
expected_value = [
|
||||
('INTCOL', oracledb.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
|
||||
('DATECOL', oracledb.DB_TYPE_DATE, 23, None, None, None, 0),
|
||||
('NULLABLECOL', oracledb.DB_TYPE_DATE, 23, None, None, None, 1)
|
||||
]
|
||||
self.assertEqual(self.cursor.description, expected_value)
|
||||
|
||||
def test_1415_FetchAll(self):
|
||||
def test_1415_fetchall(self):
|
||||
"1415 - test that fetching all of the data returns the correct results"
|
||||
self.cursor.execute("select * From TestDates order by IntCol")
|
||||
self.assertEqual(self.cursor.fetchall(), self.rawData)
|
||||
self.assertEqual(self.cursor.fetchall(), self.raw_data)
|
||||
self.assertEqual(self.cursor.fetchall(), [])
|
||||
|
||||
def test_1416_FetchMany(self):
|
||||
def test_1416_fetchmany(self):
|
||||
"1416 - test that fetching data in chunks returns the correct results"
|
||||
self.cursor.execute("select * From TestDates order by IntCol")
|
||||
self.assertEqual(self.cursor.fetchmany(3), self.rawData[0:3])
|
||||
self.assertEqual(self.cursor.fetchmany(2), self.rawData[3:5])
|
||||
self.assertEqual(self.cursor.fetchmany(4), self.rawData[5:9])
|
||||
self.assertEqual(self.cursor.fetchmany(3), self.rawData[9:])
|
||||
self.assertEqual(self.cursor.fetchmany(3), self.raw_data[0:3])
|
||||
self.assertEqual(self.cursor.fetchmany(2), self.raw_data[3:5])
|
||||
self.assertEqual(self.cursor.fetchmany(4), self.raw_data[5:9])
|
||||
self.assertEqual(self.cursor.fetchmany(3), self.raw_data[9:])
|
||||
self.assertEqual(self.cursor.fetchmany(3), [])
|
||||
|
||||
def test_1417_FetchOne(self):
|
||||
def test_1417_fetchone(self):
|
||||
"1417 - test that fetching a single row returns the correct results"
|
||||
self.cursor.execute("""
|
||||
select *
|
||||
from TestDates
|
||||
where IntCol in (3, 4)
|
||||
order by IntCol""")
|
||||
self.assertEqual(self.cursor.fetchone(), self.dataByKey[3])
|
||||
self.assertEqual(self.cursor.fetchone(), self.dataByKey[4])
|
||||
self.assertEqual(self.cursor.fetchone(), self.data_by_key[3])
|
||||
self.assertEqual(self.cursor.fetchone(), self.data_by_key[4])
|
||||
self.assertEqual(self.cursor.fetchone(), None)
|
||||
|
||||
if __name__ == "__main__":
|
||||
TestEnv.RunTestCases()
|
||||
base.run_test_cases()
|
||||
|
|
|
@ -8,172 +8,173 @@ including the synonyms retained for backwards compatibility. This module also
|
|||
tests for pickling/unpickling of database types and API types.
|
||||
"""
|
||||
|
||||
import TestEnv
|
||||
import base
|
||||
|
||||
import cx_Oracle
|
||||
import cx_Oracle as oracledb
|
||||
import pickle
|
||||
|
||||
class TestCase(TestEnv.BaseTestCase):
|
||||
class TestCase(base.BaseTestCase):
|
||||
requires_connection = False
|
||||
|
||||
def __testCompare(self, dbType, apiType):
|
||||
self.assertEqual(dbType, dbType)
|
||||
self.assertEqual(dbType, apiType)
|
||||
self.assertEqual(apiType, dbType)
|
||||
self.assertNotEqual(dbType, 5)
|
||||
self.assertNotEqual(dbType, cx_Oracle.DB_TYPE_OBJECT)
|
||||
def __test_compare(self, db_type, api_type):
|
||||
self.assertEqual(db_type, db_type)
|
||||
self.assertEqual(db_type, api_type)
|
||||
self.assertEqual(api_type, db_type)
|
||||
self.assertNotEqual(db_type, 5)
|
||||
self.assertNotEqual(db_type, oracledb.DB_TYPE_OBJECT)
|
||||
|
||||
def __testPickle(self, typ):
|
||||
def __test_pickle(self, typ):
|
||||
self.assertIs(typ, pickle.loads(pickle.dumps(typ)))
|
||||
|
||||
def test_1500_DB_TYPE_BFILE(self):
|
||||
"1500 - test cx_Oracle.DB_TYPE_BFILE comparisons and pickling"
|
||||
self.assertEqual(cx_Oracle.DB_TYPE_BFILE, cx_Oracle.BFILE)
|
||||
self.__testPickle(cx_Oracle.DB_TYPE_BFILE)
|
||||
"1500 - test oracledb.DB_TYPE_BFILE comparisons and pickling"
|
||||
self.assertEqual(oracledb.DB_TYPE_BFILE, oracledb.BFILE)
|
||||
self.__test_pickle(oracledb.DB_TYPE_BFILE)
|
||||
|
||||
def test_1501_DB_TYPE_BINARY_DOUBLE(self):
|
||||
"1501 - test cx_Oracle.DB_TYPE_BINARY_DOUBLE comparisons and pickling"
|
||||
self.__testCompare(cx_Oracle.DB_TYPE_BINARY_DOUBLE, cx_Oracle.NUMBER)
|
||||
self.assertEqual(cx_Oracle.DB_TYPE_BINARY_DOUBLE,
|
||||
cx_Oracle.NATIVE_FLOAT)
|
||||
self.__testPickle(cx_Oracle.DB_TYPE_BINARY_DOUBLE)
|
||||
"1501 - test oracledb.DB_TYPE_BINARY_DOUBLE comparisons and pickling"
|
||||
self.__test_compare(oracledb.DB_TYPE_BINARY_DOUBLE, oracledb.NUMBER)
|
||||
self.assertEqual(oracledb.DB_TYPE_BINARY_DOUBLE,
|
||||
oracledb.NATIVE_FLOAT)
|
||||
self.__test_pickle(oracledb.DB_TYPE_BINARY_DOUBLE)
|
||||
|
||||
def test_1502_DB_TYPE_BINARY_FLOAT(self):
|
||||
"1502 - test cx_Oracle.DB_TYPE_BINARY_FLOAT comparisons and pickling"
|
||||
self.__testCompare(cx_Oracle.DB_TYPE_BINARY_FLOAT, cx_Oracle.NUMBER)
|
||||
self.__testPickle(cx_Oracle.DB_TYPE_BINARY_FLOAT)
|
||||
"1502 - test oracledb.DB_TYPE_BINARY_FLOAT comparisons and pickling"
|
||||
self.__test_compare(oracledb.DB_TYPE_BINARY_FLOAT, oracledb.NUMBER)
|
||||
self.__test_pickle(oracledb.DB_TYPE_BINARY_FLOAT)
|
||||
|
||||
def test_1503_DB_TYPE_BINARY_INTEGER(self):
|
||||
"1503 - test cx_Oracle.DB_TYPE_BINARY_INTEGER comparisons and pickling"
|
||||
self.__testCompare(cx_Oracle.DB_TYPE_BINARY_INTEGER, cx_Oracle.NUMBER)
|
||||
self.assertEqual(cx_Oracle.DB_TYPE_BINARY_INTEGER,
|
||||
cx_Oracle.NATIVE_INT)
|
||||
self.__testPickle(cx_Oracle.DB_TYPE_BINARY_INTEGER)
|
||||
"1503 - test oracledb.DB_TYPE_BINARY_INTEGER comparisons and pickling"
|
||||
self.__test_compare(oracledb.DB_TYPE_BINARY_INTEGER, oracledb.NUMBER)
|
||||
self.assertEqual(oracledb.DB_TYPE_BINARY_INTEGER,
|
||||
oracledb.NATIVE_INT)
|
||||
self.__test_pickle(oracledb.DB_TYPE_BINARY_INTEGER)
|
||||
|
||||
def test_1504_DB_TYPE_BLOB(self):
|
||||
"1504 - test cx_Oracle.DB_TYPE_BLOB comparisons and pickling"
|
||||
self.assertEqual(cx_Oracle.DB_TYPE_BLOB, cx_Oracle.BLOB)
|
||||
self.__testPickle(cx_Oracle.DB_TYPE_BLOB)
|
||||
"1504 - test oracledb.DB_TYPE_BLOB comparisons and pickling"
|
||||
self.assertEqual(oracledb.DB_TYPE_BLOB, oracledb.BLOB)
|
||||
self.__test_pickle(oracledb.DB_TYPE_BLOB)
|
||||
|
||||
def test_1505_DB_TYPE_BOOLEAN(self):
|
||||
"1505 - test cx_Oracle.DB_TYPE_BOOLEAN comparisons and pickling"
|
||||
self.assertEqual(cx_Oracle.DB_TYPE_BOOLEAN, cx_Oracle.BOOLEAN)
|
||||
self.__testPickle(cx_Oracle.DB_TYPE_BOOLEAN)
|
||||
"1505 - test oracledb.DB_TYPE_BOOLEAN comparisons and pickling"
|
||||
self.assertEqual(oracledb.DB_TYPE_BOOLEAN, oracledb.BOOLEAN)
|
||||
self.__test_pickle(oracledb.DB_TYPE_BOOLEAN)
|
||||
|
||||
def test_1506_DB_TYPE_CHAR(self):
|
||||
"1506 - test cx_Oracle.DB_TYPE_CHAR comparisons and pickling"
|
||||
self.__testCompare(cx_Oracle.DB_TYPE_CHAR, cx_Oracle.STRING)
|
||||
self.assertEqual(cx_Oracle.DB_TYPE_CHAR, cx_Oracle.FIXED_CHAR)
|
||||
self.__testPickle(cx_Oracle.DB_TYPE_CHAR)
|
||||
"1506 - test oracledb.DB_TYPE_CHAR comparisons and pickling"
|
||||
self.__test_compare(oracledb.DB_TYPE_CHAR, oracledb.STRING)
|
||||
self.assertEqual(oracledb.DB_TYPE_CHAR, oracledb.FIXED_CHAR)
|
||||
self.__test_pickle(oracledb.DB_TYPE_CHAR)
|
||||
|
||||
def test_1507_DB_TYPE_CLOB(self):
|
||||
"1507 - test cx_Oracle.DB_TYPE_CLOB comparisons and pickling"
|
||||
self.assertEqual(cx_Oracle.DB_TYPE_CLOB, cx_Oracle.CLOB)
|
||||
self.__testPickle(cx_Oracle.DB_TYPE_CLOB)
|
||||
"1507 - test oracledb.DB_TYPE_CLOB comparisons and pickling"
|
||||
self.assertEqual(oracledb.DB_TYPE_CLOB, oracledb.CLOB)
|
||||
self.__test_pickle(oracledb.DB_TYPE_CLOB)
|
||||
|
||||
def test_1508_DB_TYPE_CURSOR(self):
|
||||
"1508 - test cx_Oracle.DB_TYPE_CURSOR comparisons and pickling"
|
||||
self.assertEqual(cx_Oracle.DB_TYPE_CURSOR, cx_Oracle.CURSOR)
|
||||
self.__testPickle(cx_Oracle.DB_TYPE_CURSOR)
|
||||
"1508 - test oracledb.DB_TYPE_CURSOR comparisons and pickling"
|
||||
self.assertEqual(oracledb.DB_TYPE_CURSOR, oracledb.CURSOR)
|
||||
self.__test_pickle(oracledb.DB_TYPE_CURSOR)
|
||||
|
||||
def test_1509_DB_TYPE_DATE(self):
|
||||
"1509 - test cx_Oracle.DB_TYPE_DATE comparisons and pickling"
|
||||
self.__testCompare(cx_Oracle.DB_TYPE_DATE, cx_Oracle.DATETIME)
|
||||
self.__testPickle(cx_Oracle.DB_TYPE_DATE)
|
||||
"1509 - test oracledb.DB_TYPE_DATE comparisons and pickling"
|
||||
self.__test_compare(oracledb.DB_TYPE_DATE, oracledb.DATETIME)
|
||||
self.__test_pickle(oracledb.DB_TYPE_DATE)
|
||||
|
||||
def test_1510_DB_TYPE_INTERVAL_DS(self):
|
||||
"1510 - test cx_Oracle.DB_TYPE_INTERVAL_DS comparisons and pickling"
|
||||
self.assertEqual(cx_Oracle.DB_TYPE_INTERVAL_DS, cx_Oracle.INTERVAL)
|
||||
self.__testPickle(cx_Oracle.DB_TYPE_INTERVAL_DS)
|
||||
"1510 - test oracledb.DB_TYPE_INTERVAL_DS comparisons and pickling"
|
||||
self.assertEqual(oracledb.DB_TYPE_INTERVAL_DS, oracledb.INTERVAL)
|
||||
self.__test_pickle(oracledb.DB_TYPE_INTERVAL_DS)
|
||||
|
||||
def test_1511_DB_TYPE_LONG(self):
|
||||
"1511 - test cx_Oracle.DB_TYPE_LONG comparisons and pickling"
|
||||
self.__testCompare(cx_Oracle.DB_TYPE_LONG, cx_Oracle.STRING)
|
||||
self.assertEqual(cx_Oracle.DB_TYPE_LONG, cx_Oracle.LONG_STRING)
|
||||
self.__testPickle(cx_Oracle.DB_TYPE_LONG)
|
||||
"1511 - test oracledb.DB_TYPE_LONG comparisons and pickling"
|
||||
self.__test_compare(oracledb.DB_TYPE_LONG, oracledb.STRING)
|
||||
self.assertEqual(oracledb.DB_TYPE_LONG, oracledb.LONG_STRING)
|
||||
self.__test_pickle(oracledb.DB_TYPE_LONG)
|
||||
|
||||
def test_1512_DB_TYPE_LONG_RAW(self):
|
||||
"1512 - test cx_Oracle.DB_TYPE_LONG_RAW comparisons and pickling"
|
||||
self.__testCompare(cx_Oracle.DB_TYPE_LONG_RAW, cx_Oracle.BINARY)
|
||||
self.assertEqual(cx_Oracle.DB_TYPE_LONG_RAW, cx_Oracle.LONG_BINARY)
|
||||
self.__testPickle(cx_Oracle.DB_TYPE_LONG_RAW)
|
||||
"1512 - test oracledb.DB_TYPE_LONG_RAW comparisons and pickling"
|
||||
self.__test_compare(oracledb.DB_TYPE_LONG_RAW, oracledb.BINARY)
|
||||
self.assertEqual(oracledb.DB_TYPE_LONG_RAW, oracledb.LONG_BINARY)
|
||||
self.__test_pickle(oracledb.DB_TYPE_LONG_RAW)
|
||||
|
||||
def test_1513_DB_TYPE_NCHAR(self):
|
||||
"1513 - test cx_Oracle.DB_TYPE_NCHAR comparisons and pickling"
|
||||
self.__testCompare(cx_Oracle.DB_TYPE_NCHAR, cx_Oracle.STRING)
|
||||
self.assertEqual(cx_Oracle.DB_TYPE_NCHAR, cx_Oracle.FIXED_NCHAR)
|
||||
self.__testPickle(cx_Oracle.DB_TYPE_NCHAR)
|
||||
"1513 - test oracledb.DB_TYPE_NCHAR comparisons and pickling"
|
||||
self.__test_compare(oracledb.DB_TYPE_NCHAR, oracledb.STRING)
|
||||
self.assertEqual(oracledb.DB_TYPE_NCHAR, oracledb.FIXED_NCHAR)
|
||||
self.__test_pickle(oracledb.DB_TYPE_NCHAR)
|
||||
|
||||
def test_1514_DB_TYPE_NCLOB(self):
|
||||
"1514 - test cx_Oracle.DB_TYPE_NCLOB comparisons and pickling"
|
||||
self.assertEqual(cx_Oracle.DB_TYPE_NCLOB, cx_Oracle.NCLOB)
|
||||
self.__testPickle(cx_Oracle.DB_TYPE_NCLOB)
|
||||
"1514 - test oracledb.DB_TYPE_NCLOB comparisons and pickling"
|
||||
self.assertEqual(oracledb.DB_TYPE_NCLOB, oracledb.NCLOB)
|
||||
self.__test_pickle(oracledb.DB_TYPE_NCLOB)
|
||||
|
||||
def test_1515_DB_TYPE_NUMBER(self):
|
||||
"1515 - test cx_Oracle.DB_TYPE_NUMBER comparisons and pickling"
|
||||
self.__testCompare(cx_Oracle.DB_TYPE_NUMBER, cx_Oracle.NUMBER)
|
||||
self.__testPickle(cx_Oracle.DB_TYPE_NUMBER)
|
||||
"1515 - test oracledb.DB_TYPE_NUMBER comparisons and pickling"
|
||||
self.__test_compare(oracledb.DB_TYPE_NUMBER, oracledb.NUMBER)
|
||||
self.__test_pickle(oracledb.DB_TYPE_NUMBER)
|
||||
|
||||
def test_1516_DB_TYPE_NVARCHAR(self):
|
||||
"1516 - test cx_Oracle.DB_TYPE_NVARCHAR comparisons and pickling"
|
||||
self.__testCompare(cx_Oracle.DB_TYPE_NVARCHAR, cx_Oracle.STRING)
|
||||
self.assertEqual(cx_Oracle.DB_TYPE_NVARCHAR, cx_Oracle.NCHAR)
|
||||
self.__testPickle(cx_Oracle.DB_TYPE_NVARCHAR)
|
||||
"1516 - test oracledb.DB_TYPE_NVARCHAR comparisons and pickling"
|
||||
self.__test_compare(oracledb.DB_TYPE_NVARCHAR, oracledb.STRING)
|
||||
self.assertEqual(oracledb.DB_TYPE_NVARCHAR, oracledb.NCHAR)
|
||||
self.__test_pickle(oracledb.DB_TYPE_NVARCHAR)
|
||||
|
||||
def test_1517_DB_TYPE_OBJECT(self):
|
||||
"1517 - test cx_Oracle.DB_TYPE_OBJECT comparisons and pickling"
|
||||
self.assertEqual(cx_Oracle.DB_TYPE_OBJECT, cx_Oracle.OBJECT)
|
||||
self.__testPickle(cx_Oracle.DB_TYPE_OBJECT)
|
||||
"1517 - test oracledb.DB_TYPE_OBJECT comparisons and pickling"
|
||||
self.assertEqual(oracledb.DB_TYPE_OBJECT, oracledb.OBJECT)
|
||||
self.__test_pickle(oracledb.DB_TYPE_OBJECT)
|
||||
|
||||
def test_1518_DB_TYPE_RAW(self):
|
||||
"1518 - test cx_Oracle.DB_TYPE_RAW comparisons and pickling"
|
||||
self.__testCompare(cx_Oracle.DB_TYPE_RAW, cx_Oracle.BINARY)
|
||||
self.__testPickle(cx_Oracle.DB_TYPE_RAW)
|
||||
"1518 - test oracledb.DB_TYPE_RAW comparisons and pickling"
|
||||
self.__test_compare(oracledb.DB_TYPE_RAW, oracledb.BINARY)
|
||||
self.__test_pickle(oracledb.DB_TYPE_RAW)
|
||||
|
||||
def test_1519_DB_TYPE_ROWID(self):
|
||||
"1519 - test cx_Oracle.DB_TYPE_ROWID comparisons and pickling"
|
||||
self.__testCompare(cx_Oracle.DB_TYPE_ROWID, cx_Oracle.ROWID)
|
||||
self.__testPickle(cx_Oracle.DB_TYPE_ROWID)
|
||||
"1519 - test oracledb.DB_TYPE_ROWID comparisons and pickling"
|
||||
self.__test_compare(oracledb.DB_TYPE_ROWID, oracledb.ROWID)
|
||||
self.__test_pickle(oracledb.DB_TYPE_ROWID)
|
||||
|
||||
def test_1520_DB_TYPE_TIMESTAMP(self):
|
||||
"1520 - test cx_Oracle.DB_TYPE_TIMESTAMP comparisons and pickling"
|
||||
self.__testCompare(cx_Oracle.DB_TYPE_TIMESTAMP, cx_Oracle.DATETIME)
|
||||
self.assertEqual(cx_Oracle.DB_TYPE_TIMESTAMP, cx_Oracle.TIMESTAMP)
|
||||
self.__testPickle(cx_Oracle.DB_TYPE_TIMESTAMP)
|
||||
"1520 - test oracledb.DB_TYPE_TIMESTAMP comparisons and pickling"
|
||||
self.__test_compare(oracledb.DB_TYPE_TIMESTAMP, oracledb.DATETIME)
|
||||
self.assertEqual(oracledb.DB_TYPE_TIMESTAMP, oracledb.TIMESTAMP)
|
||||
self.__test_pickle(oracledb.DB_TYPE_TIMESTAMP)
|
||||
|
||||
def test_1521_DB_TYPE_TIMESTAMP_LTZ(self):
|
||||
"1521 - test cx_Oracle.DB_TYPE_TIMESTAMP_LTZ comparisons and pickling"
|
||||
self.__testCompare(cx_Oracle.DB_TYPE_TIMESTAMP_LTZ, cx_Oracle.DATETIME)
|
||||
self.__testPickle(cx_Oracle.DB_TYPE_TIMESTAMP_LTZ)
|
||||
"1521 - test oracledb.DB_TYPE_TIMESTAMP_LTZ comparisons and pickling"
|
||||
self.__test_compare(oracledb.DB_TYPE_TIMESTAMP_LTZ, oracledb.DATETIME)
|
||||
self.__test_pickle(oracledb.DB_TYPE_TIMESTAMP_LTZ)
|
||||
|
||||
def test_1522_DB_TYPE_TIMESTAMP_TZ(self):
|
||||
"1522 - test cx_Oracle.DB_TYPE_TIMESTAMP_TZ comparisons and pickling"
|
||||
self.__testCompare(cx_Oracle.DB_TYPE_TIMESTAMP_TZ, cx_Oracle.DATETIME)
|
||||
self.__testPickle(cx_Oracle.DB_TYPE_TIMESTAMP_TZ)
|
||||
"1522 - test oracledb.DB_TYPE_TIMESTAMP_TZ comparisons and pickling"
|
||||
self.__test_compare(oracledb.DB_TYPE_TIMESTAMP_TZ, oracledb.DATETIME)
|
||||
self.__test_pickle(oracledb.DB_TYPE_TIMESTAMP_TZ)
|
||||
|
||||
def test_1523_DB_TYPE_VARCHAR(self):
|
||||
"1523 - test cx_Oracle.DB_TYPE_VARCHAR comparisons and pickling"
|
||||
self.__testCompare(cx_Oracle.DB_TYPE_VARCHAR, cx_Oracle.STRING)
|
||||
self.__testPickle(cx_Oracle.DB_TYPE_VARCHAR)
|
||||
"1523 - test oracledb.DB_TYPE_VARCHAR comparisons and pickling"
|
||||
self.__test_compare(oracledb.DB_TYPE_VARCHAR, oracledb.STRING)
|
||||
self.__test_pickle(oracledb.DB_TYPE_VARCHAR)
|
||||
|
||||
def test_1524_NUMBER(self):
|
||||
"1524 - test cx_Oracle.NUMBER pickling"
|
||||
self.__testPickle(cx_Oracle.NUMBER)
|
||||
"1524 - test oracledb.NUMBER pickling"
|
||||
self.__test_pickle(oracledb.NUMBER)
|
||||
|
||||
def test_1525_STRING(self):
|
||||
"1525 - test cx_Oracle.STRING pickling"
|
||||
self.__testPickle(cx_Oracle.STRING)
|
||||
"1525 - test oracledb.STRING pickling"
|
||||
self.__test_pickle(oracledb.STRING)
|
||||
|
||||
def test_1526_DATETIME(self):
|
||||
"1526 - test cx_Oracle.DATETIME pickling"
|
||||
self.__testPickle(cx_Oracle.DATETIME)
|
||||
"1526 - test oracledb.DATETIME pickling"
|
||||
self.__test_pickle(oracledb.DATETIME)
|
||||
|
||||
def test_1527_BINARY(self):
|
||||
"1527 - test cx_Oracle.BINARY pickling"
|
||||
self.__testPickle(cx_Oracle.BINARY)
|
||||
"1527 - test oracledb.BINARY pickling"
|
||||
self.__test_pickle(oracledb.BINARY)
|
||||
|
||||
def test_1528_ROWID(self):
|
||||
"1528 - test cx_Oracle.ROWID pickling"
|
||||
self.__testPickle(cx_Oracle.ROWID)
|
||||
"1528 - test oracledb.ROWID pickling"
|
||||
self.__test_pickle(oracledb.ROWID)
|
||||
|
||||
if __name__ == "__main__":
|
||||
TestEnv.RunTestCases()
|
||||
base.run_test_cases()
|
||||
|
|
|
@ -6,110 +6,110 @@
|
|||
1600 - Module for testing DML returning clauses
|
||||
"""
|
||||
|
||||
import TestEnv
|
||||
import base
|
||||
|
||||
import cx_Oracle
|
||||
import cx_Oracle as oracledb
|
||||
|
||||
class TestCase(TestEnv.BaseTestCase):
|
||||
class TestCase(base.BaseTestCase):
|
||||
|
||||
def test_1600_Insert(self):
|
||||
def test_1600_insert(self):
|
||||
"1600 - test insert (single row) with DML returning"
|
||||
self.cursor.execute("truncate table TestTempTable")
|
||||
intVal = 5
|
||||
strVal = "A test string"
|
||||
intVar = self.cursor.var(cx_Oracle.NUMBER)
|
||||
strVar = self.cursor.var(str)
|
||||
int_val = 5
|
||||
str_val = "A test string"
|
||||
int_var = self.cursor.var(oracledb.NUMBER)
|
||||
str_var = self.cursor.var(str)
|
||||
self.cursor.execute("""
|
||||
insert into TestTempTable (IntCol, StringCol)
|
||||
values (:intVal, :strVal)
|
||||
returning IntCol, StringCol into :intVar, :strVar""",
|
||||
intVal = intVal,
|
||||
strVal = strVal,
|
||||
intVar = intVar,
|
||||
strVar = strVar)
|
||||
self.assertEqual(intVar.values, [[intVal]])
|
||||
self.assertEqual(strVar.values, [[strVal]])
|
||||
values (:int_val, :str_val)
|
||||
returning IntCol, StringCol into :int_var, :str_var""",
|
||||
int_val=int_val,
|
||||
str_val=str_val,
|
||||
int_var=int_var,
|
||||
str_var=str_var)
|
||||
self.assertEqual(int_var.values, [[int_val]])
|
||||
self.assertEqual(str_var.values, [[str_val]])
|
||||
|
||||
def test_1601_InsertMany(self):
|
||||
def test_1601_insert_many(self):
|
||||
"1601 - test insert (multiple rows) with DML returning"
|
||||
self.cursor.execute("truncate table TestTempTable")
|
||||
intValues = [5, 8, 17, 24, 6]
|
||||
strValues = ["Test 5", "Test 8", "Test 17", "Test 24", "Test 6"]
|
||||
intVar = self.cursor.var(cx_Oracle.NUMBER, arraysize = len(intValues))
|
||||
strVar = self.cursor.var(str, arraysize = len(intValues))
|
||||
self.cursor.setinputsizes(None, None, intVar, strVar)
|
||||
data = list(zip(intValues, strValues))
|
||||
int_values = [5, 8, 17, 24, 6]
|
||||
str_values = ["Test 5", "Test 8", "Test 17", "Test 24", "Test 6"]
|
||||
int_var = self.cursor.var(oracledb.NUMBER, arraysize=len(int_values))
|
||||
str_var = self.cursor.var(str, arraysize=len(int_values))
|
||||
self.cursor.setinputsizes(None, None, int_var, str_var)
|
||||
data = list(zip(int_values, str_values))
|
||||
self.cursor.executemany("""
|
||||
insert into TestTempTable (IntCol, StringCol)
|
||||
values (:intVal, :strVal)
|
||||
returning IntCol, StringCol into :intVar, :strVar""", data)
|
||||
self.assertEqual(intVar.values, [[v] for v in intValues])
|
||||
self.assertEqual(strVar.values, [[v] for v in strValues])
|
||||
values (:int_val, :str_val)
|
||||
returning IntCol, StringCol into :int_var, :str_var""", data)
|
||||
self.assertEqual(int_var.values, [[v] for v in int_values])
|
||||
self.assertEqual(str_var.values, [[v] for v in str_values])
|
||||
|
||||
def test_1602_InsertWithSmallSize(self):
|
||||
def test_1602_insert_with_small_size(self):
|
||||
"1602 - test insert with DML returning into too small a variable"
|
||||
self.cursor.execute("truncate table TestTempTable")
|
||||
intVal = 6
|
||||
strVal = "A different test string"
|
||||
intVar = self.cursor.var(cx_Oracle.NUMBER)
|
||||
strVar = self.cursor.var(str, 2)
|
||||
parameters = dict(intVal = intVal, strVal = strVal, intVar = intVar,
|
||||
strVar = strVar)
|
||||
self.assertRaises(cx_Oracle.DatabaseError, self.cursor.execute, """
|
||||
int_val = 6
|
||||
str_val = "A different test string"
|
||||
int_var = self.cursor.var(oracledb.NUMBER)
|
||||
str_var = self.cursor.var(str, 2)
|
||||
parameters = dict(int_val=int_val, str_val=str_val, int_var=int_var,
|
||||
str_var=str_var)
|
||||
self.assertRaises(oracledb.DatabaseError, self.cursor.execute, """
|
||||
insert into TestTempTable (IntCol, StringCol)
|
||||
values (:intVal, :strVal)
|
||||
returning IntCol, StringCol into :intVar, :strVar""",
|
||||
values (:int_val, :str_val)
|
||||
returning IntCol, StringCol into :int_var, :str_var""",
|
||||
parameters)
|
||||
|
||||
def test_1603_UpdateSingleRow(self):
|
||||
def test_1603_update_single_row(self):
|
||||
"1603 - test update single row with DML returning"
|
||||
intVal = 7
|
||||
strVal = "The updated value of the string"
|
||||
int_val = 7
|
||||
str_val = "The updated value of the string"
|
||||
self.cursor.execute("truncate table TestTempTable")
|
||||
self.cursor.execute("""
|
||||
insert into TestTempTable (IntCol, StringCol)
|
||||
values (:1, :2)""",
|
||||
(intVal, "The initial value of the string"))
|
||||
intVar = self.cursor.var(cx_Oracle.NUMBER)
|
||||
strVar = self.cursor.var(str)
|
||||
(int_val, "The initial value of the string"))
|
||||
int_var = self.cursor.var(oracledb.NUMBER)
|
||||
str_var = self.cursor.var(str)
|
||||
self.cursor.execute("""
|
||||
update TestTempTable set
|
||||
StringCol = :strVal
|
||||
where IntCol = :intVal
|
||||
returning IntCol, StringCol into :intVar, :strVar""",
|
||||
intVal = intVal,
|
||||
strVal = strVal,
|
||||
intVar = intVar,
|
||||
strVar = strVar)
|
||||
self.assertEqual(intVar.values, [[intVal]])
|
||||
self.assertEqual(strVar.values, [[strVal]])
|
||||
StringCol = :str_val
|
||||
where IntCol = :int_val
|
||||
returning IntCol, StringCol into :int_var, :str_var""",
|
||||
int_val=int_val,
|
||||
str_val=str_val,
|
||||
int_var=int_var,
|
||||
str_var=str_var)
|
||||
self.assertEqual(int_var.values, [[int_val]])
|
||||
self.assertEqual(str_var.values, [[str_val]])
|
||||
|
||||
def test_1604_UpdateNoRows(self):
|
||||
def test_1604_update_no_rows(self):
|
||||
"1604 - test update no rows with DML returning"
|
||||
intVal = 8
|
||||
strVal = "The updated value of the string"
|
||||
int_val = 8
|
||||
str_val = "The updated value of the string"
|
||||
self.cursor.execute("truncate table TestTempTable")
|
||||
self.cursor.execute("""
|
||||
insert into TestTempTable (IntCol, StringCol)
|
||||
values (:1, :2)""",
|
||||
(intVal, "The initial value of the string"))
|
||||
intVar = self.cursor.var(cx_Oracle.NUMBER)
|
||||
strVar = self.cursor.var(str)
|
||||
(int_val, "The initial value of the string"))
|
||||
int_var = self.cursor.var(oracledb.NUMBER)
|
||||
str_var = self.cursor.var(str)
|
||||
self.cursor.execute("""
|
||||
update TestTempTable set
|
||||
StringCol = :strVal
|
||||
where IntCol = :intVal
|
||||
returning IntCol, StringCol into :intVar, :strVar""",
|
||||
intVal = intVal + 1,
|
||||
strVal = strVal,
|
||||
intVar = intVar,
|
||||
strVar = strVar)
|
||||
self.assertEqual(intVar.values, [[]])
|
||||
self.assertEqual(strVar.values, [[]])
|
||||
self.assertEqual(intVar.getvalue(), [])
|
||||
self.assertEqual(strVar.getvalue(), [])
|
||||
StringCol = :str_val
|
||||
where IntCol = :int_val
|
||||
returning IntCol, StringCol into :int_var, :str_var""",
|
||||
int_val=int_val + 1,
|
||||
str_val=str_val,
|
||||
int_var=int_var,
|
||||
str_var=str_var)
|
||||
self.assertEqual(int_var.values, [[]])
|
||||
self.assertEqual(str_var.values, [[]])
|
||||
self.assertEqual(int_var.getvalue(), [])
|
||||
self.assertEqual(str_var.getvalue(), [])
|
||||
|
||||
def test_1605_UpdateMultipleRows(self):
|
||||
def test_1605_update_multiple_rows(self):
|
||||
"1605 - test update multiple rows with DML returning"
|
||||
self.cursor.execute("truncate table TestTempTable")
|
||||
for i in (8, 9, 10):
|
||||
|
@ -117,24 +117,25 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
insert into TestTempTable (IntCol, StringCol)
|
||||
values (:1, :2)""",
|
||||
(i, "The initial value of string %d" % i))
|
||||
intVar = self.cursor.var(cx_Oracle.NUMBER)
|
||||
strVar = self.cursor.var(str)
|
||||
int_var = self.cursor.var(oracledb.NUMBER)
|
||||
str_var = self.cursor.var(str)
|
||||
self.cursor.execute("""
|
||||
update TestTempTable set
|
||||
IntCol = IntCol + 15,
|
||||
StringCol = 'The final value of string ' || to_char(IntCol)
|
||||
returning IntCol, StringCol into :intVar, :strVar""",
|
||||
intVar = intVar,
|
||||
strVar = strVar)
|
||||
returning IntCol, StringCol into :int_var, :str_var""",
|
||||
int_var=int_var,
|
||||
str_var=str_var)
|
||||
self.assertEqual(self.cursor.rowcount, 3)
|
||||
self.assertEqual(intVar.values, [[23, 24, 25]])
|
||||
self.assertEqual(strVar.values, [[
|
||||
"The final value of string 8",
|
||||
"The final value of string 9",
|
||||
"The final value of string 10"
|
||||
]])
|
||||
self.assertEqual(int_var.values, [[23, 24, 25]])
|
||||
expected_values = [[
|
||||
"The final value of string 8",
|
||||
"The final value of string 9",
|
||||
"The final value of string 10"
|
||||
]]
|
||||
self.assertEqual(str_var.values, expected_values)
|
||||
|
||||
def test_1606_UpdateMultipleRowsExecuteMany(self):
|
||||
def test_1606_update_multiple_rows_executemany(self):
|
||||
"1606 - test update multiple rows with DML returning (executeMany)"
|
||||
data = [(i, "The initial value of string %d" % i) \
|
||||
for i in range(1, 11)]
|
||||
|
@ -142,55 +143,63 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
self.cursor.executemany("""
|
||||
insert into TestTempTable (IntCol, StringCol)
|
||||
values (:1, :2)""", data)
|
||||
intVar = self.cursor.var(cx_Oracle.NUMBER, arraysize = 3)
|
||||
strVar = self.cursor.var(str, arraysize = 3)
|
||||
self.cursor.setinputsizes(None, intVar, strVar)
|
||||
int_var = self.cursor.var(oracledb.NUMBER, arraysize=3)
|
||||
str_var = self.cursor.var(str, arraysize=3)
|
||||
self.cursor.setinputsizes(None, int_var, str_var)
|
||||
self.cursor.executemany("""
|
||||
update TestTempTable set
|
||||
IntCol = IntCol + 25,
|
||||
StringCol = 'Updated value of string ' || to_char(IntCol)
|
||||
where IntCol < :inVal
|
||||
returning IntCol, StringCol into :intVar, :strVar""",
|
||||
returning IntCol, StringCol into :int_var, :str_var""",
|
||||
[[3], [8], [11]])
|
||||
self.assertEqual(intVar.values, [
|
||||
expected_values = [
|
||||
[26, 27],
|
||||
[28, 29, 30, 31, 32],
|
||||
[33, 34, 35]
|
||||
])
|
||||
self.assertEqual(strVar.values, [
|
||||
[ "Updated value of string 1",
|
||||
"Updated value of string 2" ],
|
||||
[ "Updated value of string 3",
|
||||
"Updated value of string 4",
|
||||
"Updated value of string 5",
|
||||
"Updated value of string 6",
|
||||
"Updated value of string 7" ],
|
||||
[ "Updated value of string 8",
|
||||
"Updated value of string 9",
|
||||
"Updated value of string 10" ]
|
||||
])
|
||||
]
|
||||
self.assertEqual(int_var.values, expected_values)
|
||||
expected_values = [
|
||||
[
|
||||
"Updated value of string 1",
|
||||
"Updated value of string 2"
|
||||
],
|
||||
[
|
||||
"Updated value of string 3",
|
||||
"Updated value of string 4",
|
||||
"Updated value of string 5",
|
||||
"Updated value of string 6",
|
||||
"Updated value of string 7"
|
||||
],
|
||||
[
|
||||
"Updated value of string 8",
|
||||
"Updated value of string 9",
|
||||
"Updated value of string 10"
|
||||
]
|
||||
]
|
||||
self.assertEqual(str_var.values, expected_values)
|
||||
|
||||
def test_1607_InsertAndReturnObject(self):
|
||||
def test_1607_insert_and_return_object(self):
|
||||
"1607 - test inserting an object with DML returning"
|
||||
typeObj = self.connection.gettype("UDT_OBJECT")
|
||||
stringValue = "The string that will be verified"
|
||||
obj = typeObj.newobject()
|
||||
obj.STRINGVALUE = stringValue
|
||||
outVar = self.cursor.var(cx_Oracle.DB_TYPE_OBJECT,
|
||||
typename = "UDT_OBJECT")
|
||||
type_obj = self.connection.gettype("UDT_OBJECT")
|
||||
string_value = "The string that will be verified"
|
||||
obj = type_obj.newobject()
|
||||
obj.STRINGVALUE = string_value
|
||||
out_var = self.cursor.var(oracledb.DB_TYPE_OBJECT,
|
||||
typename="UDT_OBJECT")
|
||||
self.cursor.execute("""
|
||||
insert into TestObjects (IntCol, ObjectCol)
|
||||
values (4, :obj)
|
||||
returning ObjectCol into :outObj""",
|
||||
obj = obj, outObj = outVar)
|
||||
result, = outVar.getvalue()
|
||||
self.assertEqual(result.STRINGVALUE, stringValue)
|
||||
obj=obj, outObj=out_var)
|
||||
result, = out_var.getvalue()
|
||||
self.assertEqual(result.STRINGVALUE, string_value)
|
||||
self.connection.rollback()
|
||||
|
||||
def test_1608_InsertAndReturnRowid(self):
|
||||
def test_1608_insert_and_return_rowid(self):
|
||||
"1608 - test inserting a row and returning a rowid"
|
||||
self.cursor.execute("truncate table TestTempTable")
|
||||
var = self.cursor.var(cx_Oracle.ROWID)
|
||||
var = self.cursor.var(oracledb.ROWID)
|
||||
self.cursor.execute("""
|
||||
insert into TestTempTable (IntCol, StringCol)
|
||||
values (278, 'String 278')
|
||||
|
@ -203,12 +212,12 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
(rowid,))
|
||||
self.assertEqual(self.cursor.fetchall(), [(278, 'String 278')])
|
||||
|
||||
def test_1609_InsertWithRefCursor(self):
|
||||
def test_1609_insert_with_ref_cursor(self):
|
||||
"1609 - test inserting with a REF cursor and returning a rowid"
|
||||
self.cursor.execute("truncate table TestTempTable")
|
||||
var = self.cursor.var(cx_Oracle.ROWID)
|
||||
inCursor = self.connection.cursor()
|
||||
inCursor.execute("""
|
||||
var = self.cursor.var(oracledb.ROWID)
|
||||
in_cursor = self.connection.cursor()
|
||||
in_cursor.execute("""
|
||||
select StringCol
|
||||
from TestStrings
|
||||
where IntCol >= 5
|
||||
|
@ -216,7 +225,7 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
self.cursor.execute("""
|
||||
insert into TestTempTable (IntCol, StringCol)
|
||||
values (187, pkg_TestRefCursors.TestInCursor(:1))
|
||||
returning rowid into :2""", (inCursor, var))
|
||||
returning rowid into :2""", (in_cursor, var))
|
||||
rowid, = var.getvalue()
|
||||
self.cursor.execute("""
|
||||
select IntCol, StringCol
|
||||
|
@ -226,7 +235,7 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
self.assertEqual(self.cursor.fetchall(),
|
||||
[(187, 'String 7 (Modified)')])
|
||||
|
||||
def test_1610_DeleteReturningDecreasingRowsReturned(self):
|
||||
def test_1610_delete_returning_decreasing_rows_returned(self):
|
||||
"1610 - test delete returning decreasing number of rows"
|
||||
data = [(i, "Test String %d" % i) for i in range(1, 11)]
|
||||
self.cursor.execute("truncate table TestTempTable")
|
||||
|
@ -234,31 +243,31 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
insert into TestTempTable (IntCol, StringCol)
|
||||
values (:1, :2)""", data)
|
||||
results = []
|
||||
intVar = self.cursor.var(int)
|
||||
self.cursor.setinputsizes(None, intVar)
|
||||
for intVal in (5, 8, 10):
|
||||
int_var = self.cursor.var(int)
|
||||
self.cursor.setinputsizes(None, int_var)
|
||||
for int_val in (5, 8, 10):
|
||||
self.cursor.execute("""
|
||||
delete from TestTempTable
|
||||
where IntCol < :1
|
||||
returning IntCol into :2""", [intVal])
|
||||
results.append(intVar.getvalue())
|
||||
self.assertEqual(results, [ [1, 2, 3, 4], [5, 6, 7], [8, 9] ])
|
||||
returning IntCol into :2""", [int_val])
|
||||
results.append(int_var.getvalue())
|
||||
self.assertEqual(results, [[1, 2, 3, 4], [5, 6, 7], [8, 9]])
|
||||
|
||||
def test_1611_DeleteReturningNoRowsAfterManyRows(self):
|
||||
def test_1611_delete_returning_no_rows_after_many_rows(self):
|
||||
"1611 - test delete returning no rows after returning many rows"
|
||||
data = [(i, "Test String %d" % i) for i in range(1, 11)]
|
||||
self.cursor.execute("truncate table TestTempTable")
|
||||
self.cursor.executemany("""
|
||||
insert into TestTempTable (IntCol, StringCol)
|
||||
values (:1, :2)""", data)
|
||||
intVar = self.cursor.var(int)
|
||||
int_var = self.cursor.var(int)
|
||||
self.cursor.execute("""
|
||||
delete from TestTempTable
|
||||
where IntCol < :1
|
||||
returning IntCol into :2""", [5, intVar])
|
||||
self.assertEqual(intVar.getvalue(), [1, 2, 3, 4])
|
||||
self.cursor.execute(None, [4, intVar])
|
||||
self.assertEqual(intVar.getvalue(), [])
|
||||
returning IntCol into :2""", [5, int_var])
|
||||
self.assertEqual(int_var.getvalue(), [1, 2, 3, 4])
|
||||
self.cursor.execute(None, [4, int_var])
|
||||
self.assertEqual(int_var.getvalue(), [])
|
||||
|
||||
if __name__ == "__main__":
|
||||
TestEnv.RunTestCases()
|
||||
base.run_test_cases()
|
||||
|
|
|
@ -11,41 +11,40 @@
|
|||
1700 - Module for testing error objects
|
||||
"""
|
||||
|
||||
import TestEnv
|
||||
import base
|
||||
|
||||
import cx_Oracle
|
||||
import cx_Oracle as oracledb
|
||||
import pickle
|
||||
|
||||
class TestCase(TestEnv.BaseTestCase):
|
||||
class TestCase(base.BaseTestCase):
|
||||
|
||||
def test_1700_ParseError(self):
|
||||
def test_1700_parse_error(self):
|
||||
"1700 - test parse error returns offset correctly"
|
||||
with self.assertRaises(cx_Oracle.Error) as cm:
|
||||
with self.assertRaises(oracledb.Error) as cm:
|
||||
self.cursor.execute("begin t_Missing := 5; end;")
|
||||
errorObj, = cm.exception.args
|
||||
self.assertEqual(errorObj.offset, 6)
|
||||
error_obj, = cm.exception.args
|
||||
self.assertEqual(error_obj.offset, 6)
|
||||
|
||||
def test_1701_PickleError(self):
|
||||
def test_1701_pickle_error(self):
|
||||
"1701 - test picking/unpickling an error object"
|
||||
with self.assertRaises(cx_Oracle.Error) as cm:
|
||||
with self.assertRaises(oracledb.Error) as cm:
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
raise_application_error(-20101, 'Test!');
|
||||
end;""")
|
||||
errorObj, = cm.exception.args
|
||||
self.assertEqual(type(errorObj), cx_Oracle._Error)
|
||||
self.assertTrue("Test!" in errorObj.message)
|
||||
self.assertEqual(errorObj.code, 20101)
|
||||
self.assertEqual(errorObj.offset, 0)
|
||||
self.assertTrue(isinstance(errorObj.isrecoverable, bool))
|
||||
pickledData = pickle.dumps(errorObj)
|
||||
newErrorObj = pickle.loads(pickledData)
|
||||
self.assertEqual(type(newErrorObj), cx_Oracle._Error)
|
||||
self.assertTrue(newErrorObj.message == errorObj.message)
|
||||
self.assertTrue(newErrorObj.code == errorObj.code)
|
||||
self.assertTrue(newErrorObj.offset == errorObj.offset)
|
||||
self.assertTrue(newErrorObj.context == errorObj.context)
|
||||
self.assertTrue(newErrorObj.isrecoverable == errorObj.isrecoverable)
|
||||
error_obj, = cm.exception.args
|
||||
self.assertEqual(type(error_obj), oracledb._Error)
|
||||
self.assertTrue("Test!" in error_obj.message)
|
||||
self.assertEqual(error_obj.code, 20101)
|
||||
self.assertEqual(error_obj.offset, 0)
|
||||
self.assertTrue(isinstance(error_obj.isrecoverable, bool))
|
||||
new_error_obj = pickle.loads(pickle.dumps(error_obj))
|
||||
self.assertEqual(type(new_error_obj), oracledb._Error)
|
||||
self.assertTrue(new_error_obj.message == error_obj.message)
|
||||
self.assertTrue(new_error_obj.code == error_obj.code)
|
||||
self.assertTrue(new_error_obj.offset == error_obj.offset)
|
||||
self.assertTrue(new_error_obj.context == error_obj.context)
|
||||
self.assertTrue(new_error_obj.isrecoverable == error_obj.isrecoverable)
|
||||
|
||||
if __name__ == "__main__":
|
||||
TestEnv.RunTestCases()
|
||||
base.run_test_cases()
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#------------------------------------------------------------------------------
|
||||
# Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
# Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
#
|
||||
# Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved.
|
||||
#
|
||||
|
@ -11,141 +11,145 @@
|
|||
1800 - Module for testing interval variables
|
||||
"""
|
||||
|
||||
import TestEnv
|
||||
import base
|
||||
|
||||
import cx_Oracle
|
||||
import cx_Oracle as oracledb
|
||||
import datetime
|
||||
|
||||
class TestCase(TestEnv.BaseTestCase):
|
||||
class TestCase(base.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
TestEnv.BaseTestCase.setUp(self)
|
||||
self.rawData = []
|
||||
self.dataByKey = {}
|
||||
super().setUp()
|
||||
self.raw_data = []
|
||||
self.data_by_key = {}
|
||||
for i in range(1, 11):
|
||||
delta = datetime.timedelta(days = i, hours = i, minutes = i * 2,
|
||||
seconds = i * 3)
|
||||
delta = datetime.timedelta(days=i, hours=i, minutes=i * 2,
|
||||
seconds=i * 3)
|
||||
if i % 2 == 0:
|
||||
nullableDelta = None
|
||||
nullable_delta = None
|
||||
else:
|
||||
nullableDelta = datetime.timedelta(days = i + 5, hours = i + 2,
|
||||
minutes = i * 2 + 5, seconds = i * 3 + 5)
|
||||
tuple = (i, delta, nullableDelta)
|
||||
self.rawData.append(tuple)
|
||||
self.dataByKey[i] = tuple
|
||||
nullable_delta = datetime.timedelta(days=i + 5, hours=i + 2,
|
||||
minutes=i * 2 + 5,
|
||||
seconds=i * 3 + 5)
|
||||
data_tuple = (i, delta, nullable_delta)
|
||||
self.raw_data.append(data_tuple)
|
||||
self.data_by_key[i] = data_tuple
|
||||
|
||||
def test_1800_BindInterval(self):
|
||||
def test_1800_bind_interval(self):
|
||||
"1800 - test binding in an interval"
|
||||
self.cursor.setinputsizes(value = cx_Oracle.DB_TYPE_INTERVAL_DS)
|
||||
self.cursor.setinputsizes(value=oracledb.DB_TYPE_INTERVAL_DS)
|
||||
value = datetime.timedelta(days=5, hours=5, minutes=10, seconds=15)
|
||||
self.cursor.execute("""
|
||||
select * from TestIntervals
|
||||
where IntervalCol = :value""",
|
||||
value = datetime.timedelta(days = 5, hours = 5, minutes = 10,
|
||||
seconds = 15))
|
||||
self.assertEqual(self.cursor.fetchall(), [self.dataByKey[5]])
|
||||
value=value)
|
||||
self.assertEqual(self.cursor.fetchall(), [self.data_by_key[5]])
|
||||
|
||||
def test_1801_BindNull(self):
|
||||
def test_1801_bind_null(self):
|
||||
"1801 - test binding in a null"
|
||||
self.cursor.setinputsizes(value = cx_Oracle.DB_TYPE_INTERVAL_DS)
|
||||
self.cursor.setinputsizes(value=oracledb.DB_TYPE_INTERVAL_DS)
|
||||
self.cursor.execute("""
|
||||
select * from TestIntervals
|
||||
where IntervalCol = :value""",
|
||||
value = None)
|
||||
value=None)
|
||||
self.assertEqual(self.cursor.fetchall(), [])
|
||||
|
||||
def test_1802_BindOutSetInputSizes(self):
|
||||
def test_1802_bind_out_set_input_sizes(self):
|
||||
"1802 - test binding out with set input sizes defined"
|
||||
vars = self.cursor.setinputsizes(value = cx_Oracle.DB_TYPE_INTERVAL_DS)
|
||||
bind_vars = \
|
||||
self.cursor.setinputsizes(value=oracledb.DB_TYPE_INTERVAL_DS)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:value := to_dsinterval('8 09:24:18.123789');
|
||||
end;""")
|
||||
self.assertEqual(vars["value"].getvalue(),
|
||||
datetime.timedelta(days = 8, hours = 9, minutes = 24,
|
||||
seconds = 18, microseconds = 123789))
|
||||
expected_value = datetime.timedelta(days=8, hours=9, minutes=24,
|
||||
seconds=18, microseconds=123789)
|
||||
self.assertEqual(bind_vars["value"].getvalue(), expected_value)
|
||||
|
||||
def test_1803_BindInOutSetInputSizes(self):
|
||||
def test_1803_bind_in_out_set_input_sizes(self):
|
||||
"1803 - test binding in/out with set input sizes defined"
|
||||
vars = self.cursor.setinputsizes(value = cx_Oracle.DB_TYPE_INTERVAL_DS)
|
||||
bind_vars = \
|
||||
self.cursor.setinputsizes(value=oracledb.DB_TYPE_INTERVAL_DS)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:value := :value + to_dsinterval('5 08:30:00');
|
||||
end;""",
|
||||
value = datetime.timedelta(days = 5, hours = 2, minutes = 15))
|
||||
self.assertEqual(vars["value"].getvalue(),
|
||||
datetime.timedelta(days = 10, hours = 10, minutes = 45))
|
||||
value=datetime.timedelta(days=5, hours=2, minutes=15))
|
||||
expected_value = datetime.timedelta(days=10, hours=10, minutes=45)
|
||||
self.assertEqual(bind_vars["value"].getvalue(), expected_value)
|
||||
|
||||
def test_1804_BindInOutFractionalSecond(self):
|
||||
def test_1804_bind_in_out_fractional_second(self):
|
||||
"1804 - test binding in/out with set input sizes defined"
|
||||
vars = self.cursor.setinputsizes(value = cx_Oracle.DB_TYPE_INTERVAL_DS)
|
||||
bind_vars = \
|
||||
self.cursor.setinputsizes(value=oracledb.DB_TYPE_INTERVAL_DS)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:value := :value + to_dsinterval('5 08:30:00');
|
||||
end;""",
|
||||
value = datetime.timedelta(days = 5, seconds=12.123789))
|
||||
self.assertEqual(vars["value"].getvalue(),
|
||||
datetime.timedelta(days = 10, hours = 8, minutes = 30,
|
||||
seconds=12, microseconds=123789))
|
||||
value=datetime.timedelta(days=5, seconds=12.123789))
|
||||
expected_value = datetime.timedelta(days=10, hours=8, minutes=30,
|
||||
seconds=12, microseconds=123789)
|
||||
self.assertEqual(bind_vars["value"].getvalue(), expected_value)
|
||||
|
||||
def test_1805_BindOutVar(self):
|
||||
def test_1805_bind_out_var(self):
|
||||
"1805 - test binding out with cursor.var() method"
|
||||
var = self.cursor.var(cx_Oracle.DB_TYPE_INTERVAL_DS)
|
||||
var = self.cursor.var(oracledb.DB_TYPE_INTERVAL_DS)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:value := to_dsinterval('15 18:35:45.586');
|
||||
end;""",
|
||||
value = var)
|
||||
self.assertEqual(var.getvalue(),
|
||||
datetime.timedelta(days = 15, hours = 18, minutes = 35,
|
||||
seconds = 45, milliseconds = 586))
|
||||
value=var)
|
||||
expected_value = datetime.timedelta(days=15, hours=18, minutes=35,
|
||||
seconds=45, milliseconds=586)
|
||||
self.assertEqual(var.getvalue(), expected_value)
|
||||
|
||||
def test_1806_BindInOutVarDirectSet(self):
|
||||
def test_1806_bind_in_out_var_direct_set(self):
|
||||
"1806 - test binding in/out with cursor.var() method"
|
||||
var = self.cursor.var(cx_Oracle.DB_TYPE_INTERVAL_DS)
|
||||
var.setvalue(0, datetime.timedelta(days = 1, minutes = 50))
|
||||
var = self.cursor.var(oracledb.DB_TYPE_INTERVAL_DS)
|
||||
var.setvalue(0, datetime.timedelta(days=1, minutes=50))
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:value := :value + to_dsinterval('8 05:15:00');
|
||||
end;""",
|
||||
value = var)
|
||||
self.assertEqual(var.getvalue(),
|
||||
datetime.timedelta(days = 9, hours = 6, minutes = 5))
|
||||
value=var)
|
||||
expected_value = datetime.timedelta(days=9, hours=6, minutes=5)
|
||||
self.assertEqual(var.getvalue(), expected_value)
|
||||
|
||||
def test_1807_CursorDescription(self):
|
||||
def test_1807_cursor_description(self):
|
||||
"1807 - test cursor description is accurate"
|
||||
self.cursor.execute("select * from TestIntervals")
|
||||
self.assertEqual(self.cursor.description,
|
||||
[ ('INTCOL', cx_Oracle.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
|
||||
('INTERVALCOL', cx_Oracle.DB_TYPE_INTERVAL_DS, None, None, 2,
|
||||
6, 0),
|
||||
('NULLABLECOL', cx_Oracle.DB_TYPE_INTERVAL_DS, None, None, 2,
|
||||
6, 1) ])
|
||||
expected_value = [
|
||||
('INTCOL', oracledb.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
|
||||
('INTERVALCOL', oracledb.DB_TYPE_INTERVAL_DS, None, None, 2, 6, 0),
|
||||
('NULLABLECOL', oracledb.DB_TYPE_INTERVAL_DS, None, None, 2, 6, 1)
|
||||
]
|
||||
self.assertEqual(self.cursor.description, expected_value)
|
||||
|
||||
def test_1808_FetchAll(self):
|
||||
def test_1808_fetchall(self):
|
||||
"1808 - test that fetching all of the data returns the correct results"
|
||||
self.cursor.execute("select * From TestIntervals order by IntCol")
|
||||
self.assertEqual(self.cursor.fetchall(), self.rawData)
|
||||
self.assertEqual(self.cursor.fetchall(), self.raw_data)
|
||||
self.assertEqual(self.cursor.fetchall(), [])
|
||||
|
||||
def test_1809_FetchMany(self):
|
||||
def test_1809_fetchmany(self):
|
||||
"1809 - test that fetching data in chunks returns the correct results"
|
||||
self.cursor.execute("select * From TestIntervals order by IntCol")
|
||||
self.assertEqual(self.cursor.fetchmany(3), self.rawData[0:3])
|
||||
self.assertEqual(self.cursor.fetchmany(2), self.rawData[3:5])
|
||||
self.assertEqual(self.cursor.fetchmany(4), self.rawData[5:9])
|
||||
self.assertEqual(self.cursor.fetchmany(3), self.rawData[9:])
|
||||
self.assertEqual(self.cursor.fetchmany(3), self.raw_data[0:3])
|
||||
self.assertEqual(self.cursor.fetchmany(2), self.raw_data[3:5])
|
||||
self.assertEqual(self.cursor.fetchmany(4), self.raw_data[5:9])
|
||||
self.assertEqual(self.cursor.fetchmany(3), self.raw_data[9:])
|
||||
self.assertEqual(self.cursor.fetchmany(3), [])
|
||||
|
||||
def test_1810_FetchOne(self):
|
||||
def test_1810_fetchone(self):
|
||||
"1810 - test that fetching a single row returns the correct results"
|
||||
self.cursor.execute("""
|
||||
select *
|
||||
from TestIntervals
|
||||
where IntCol in (3, 4)
|
||||
order by IntCol""")
|
||||
self.assertEqual(self.cursor.fetchone(), self.dataByKey[3])
|
||||
self.assertEqual(self.cursor.fetchone(), self.dataByKey[4])
|
||||
self.assertEqual(self.cursor.fetchone(), self.data_by_key[3])
|
||||
self.assertEqual(self.cursor.fetchone(), self.data_by_key[4])
|
||||
self.assertEqual(self.cursor.fetchone(), None)
|
||||
|
||||
if __name__ == "__main__":
|
||||
TestEnv.RunTestCases()
|
||||
base.run_test_cases()
|
||||
|
|
|
@ -11,14 +11,13 @@
|
|||
1900 - Module for testing LOB (CLOB and BLOB) variables
|
||||
"""
|
||||
|
||||
import TestEnv
|
||||
import base
|
||||
|
||||
import cx_Oracle
|
||||
import sys
|
||||
import cx_Oracle as oracledb
|
||||
|
||||
class TestCase(TestEnv.BaseTestCase):
|
||||
class TestCase(base.BaseTestCase):
|
||||
|
||||
def __GetTempLobs(self, sid):
|
||||
def __get_temp_lobs(self, sid):
|
||||
cursor = self.connection.cursor()
|
||||
cursor.execute("""
|
||||
select abstract_lobs
|
||||
|
@ -29,60 +28,60 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
return 0
|
||||
return int(row[0])
|
||||
|
||||
def __PerformTest(self, lobType, inputType):
|
||||
longString = ""
|
||||
directType = getattr(cx_Oracle, lobType)
|
||||
self.cursor.execute("truncate table Test%ss" % lobType)
|
||||
def __perform_test(self, lob_type, input_type):
|
||||
long_string = ""
|
||||
db_type = getattr(oracledb, "DB_TYPE_" + lob_type)
|
||||
self.cursor.execute("truncate table Test%ss" % lob_type)
|
||||
for i in range(0, 11):
|
||||
if i > 0:
|
||||
char = chr(ord('A') + i - 1)
|
||||
longString += char * 25000
|
||||
elif inputType != directType:
|
||||
long_string += char * 25000
|
||||
elif input_type is not db_type:
|
||||
continue
|
||||
self.cursor.setinputsizes(longString = inputType)
|
||||
if lobType == "BLOB" and sys.version_info[0] >= 3:
|
||||
bindValue = longString.encode("ascii")
|
||||
self.cursor.setinputsizes(long_string = input_type)
|
||||
if lob_type == "BLOB":
|
||||
bind_value = long_string.encode()
|
||||
else:
|
||||
bindValue = longString
|
||||
bind_value = long_string
|
||||
self.cursor.execute("""
|
||||
insert into Test%ss (
|
||||
IntCol,
|
||||
%sCol
|
||||
) values (
|
||||
:integerValue,
|
||||
:longString
|
||||
)""" % (lobType, lobType),
|
||||
integerValue = i,
|
||||
longString = bindValue)
|
||||
:integer_value,
|
||||
:long_string
|
||||
)""" % (lob_type, lob_type),
|
||||
integer_value=i,
|
||||
long_string=bind_value)
|
||||
self.connection.commit()
|
||||
self.cursor.execute("""
|
||||
select *
|
||||
from Test%ss
|
||||
order by IntCol""" % lobType)
|
||||
self.__ValidateQuery(self.cursor, lobType)
|
||||
order by IntCol""" % lob_type)
|
||||
self.__validate_query(self.cursor, lob_type)
|
||||
|
||||
def __TestLobOperations(self, lobType):
|
||||
self.cursor.execute("truncate table Test%ss" % lobType)
|
||||
self.cursor.setinputsizes(longString = getattr(cx_Oracle, lobType))
|
||||
longString = "X" * 75000
|
||||
writeValue = "TEST"
|
||||
if lobType == "BLOB" and sys.version_info[0] >= 3:
|
||||
longString = longString.encode("ascii")
|
||||
writeValue = writeValue.encode("ascii")
|
||||
def __test_lob_operations(self, lob_type):
|
||||
self.cursor.execute("truncate table Test%ss" % lob_type)
|
||||
self.cursor.setinputsizes(long_string=getattr(oracledb, lob_type))
|
||||
long_string = "X" * 75000
|
||||
write_value = "TEST"
|
||||
if lob_type == "BLOB":
|
||||
long_string = long_string.encode("ascii")
|
||||
write_value = write_value.encode("ascii")
|
||||
self.cursor.execute("""
|
||||
insert into Test%ss (
|
||||
IntCol,
|
||||
%sCol
|
||||
) values (
|
||||
:integerValue,
|
||||
:longString
|
||||
)""" % (lobType, lobType),
|
||||
integerValue = 1,
|
||||
longString = longString)
|
||||
:integer_value,
|
||||
:long_string
|
||||
)""" % (lob_type, lob_type),
|
||||
integer_value=1,
|
||||
long_string=long_string)
|
||||
self.cursor.execute("""
|
||||
select %sCol
|
||||
from Test%ss
|
||||
where IntCol = 1""" % (lobType, lobType))
|
||||
where IntCol = 1""" % (lob_type, lob_type))
|
||||
lob, = self.cursor.fetchone()
|
||||
self.assertEqual(lob.isopen(), False)
|
||||
lob.open()
|
||||
|
@ -90,173 +89,178 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
lob.close()
|
||||
self.assertEqual(lob.isopen(), False)
|
||||
self.assertEqual(lob.size(), 75000)
|
||||
lob.write(writeValue, 75001)
|
||||
self.assertEqual(lob.size(), 75000 + len(writeValue))
|
||||
self.assertEqual(lob.read(), longString + writeValue)
|
||||
lob.write(writeValue, 1)
|
||||
self.assertEqual(lob.read(), writeValue + longString[4:] + writeValue)
|
||||
lob.write(write_value, 75001)
|
||||
self.assertEqual(lob.size(), 75000 + len(write_value))
|
||||
self.assertEqual(lob.read(), long_string + write_value)
|
||||
lob.write(write_value, 1)
|
||||
self.assertEqual(lob.read(),
|
||||
write_value + long_string[4:] + write_value)
|
||||
lob.trim(25000)
|
||||
self.assertEqual(lob.size(), 25000)
|
||||
lob.trim()
|
||||
self.assertEqual(lob.size(), 0)
|
||||
|
||||
def __TestTemporaryLOB(self, lobType):
|
||||
self.cursor.execute("truncate table Test%ss" % lobType)
|
||||
def __test_temporary_lob(self, lob_type):
|
||||
self.cursor.execute("truncate table Test%ss" % lob_type)
|
||||
value = "A test string value"
|
||||
if lobType == "BLOB" and sys.version_info[0] >= 3:
|
||||
if lob_type == "BLOB":
|
||||
value = value.encode("ascii")
|
||||
lobTypeObj = getattr(cx_Oracle, lobType)
|
||||
lob = self.connection.createlob(lobTypeObj)
|
||||
db_type = getattr(oracledb, "DB_TYPE_" + lob_type)
|
||||
lob = self.connection.createlob(db_type)
|
||||
lob.write(value)
|
||||
self.cursor.execute("""
|
||||
insert into Test%ss (IntCol, %sCol)
|
||||
values (:intVal, :lobVal)""" % (lobType, lobType),
|
||||
intVal = 1,
|
||||
lobVal = lob)
|
||||
self.cursor.execute("select %sCol from Test%ss" % (lobType, lobType))
|
||||
values (:int_val, :lob_val)""" % (lob_type, lob_type),
|
||||
int_val=1,
|
||||
lob_val=lob)
|
||||
self.cursor.execute("select %sCol from Test%ss" % (lob_type, lob_type))
|
||||
lob, = self.cursor.fetchone()
|
||||
self.assertEqual(lob.read(), value)
|
||||
|
||||
def __ValidateQuery(self, rows, lobType):
|
||||
longString = ""
|
||||
dbType = getattr(cx_Oracle, "DB_TYPE_" + lobType)
|
||||
def __validate_query(self, rows, lob_type):
|
||||
long_string = ""
|
||||
db_type = getattr(oracledb, "DB_TYPE_" + lob_type)
|
||||
for row in rows:
|
||||
integerValue, lob = row
|
||||
self.assertEqual(lob.type, dbType)
|
||||
if integerValue == 0:
|
||||
integer_value, lob = row
|
||||
self.assertEqual(lob.type, db_type)
|
||||
if integer_value == 0:
|
||||
self.assertEqual(lob.size(), 0)
|
||||
expectedValue = ""
|
||||
if lobType == "BLOB" and sys.version_info[0] >= 3:
|
||||
expectedValue = expectedValue.encode("ascii")
|
||||
self.assertEqual(lob.read(), expectedValue)
|
||||
expected_value = ""
|
||||
if lob_type == "BLOB":
|
||||
expected_value = expected_value.encode()
|
||||
self.assertEqual(lob.read(), expected_value)
|
||||
else:
|
||||
char = chr(ord('A') + integerValue - 1)
|
||||
prevChar = chr(ord('A') + integerValue - 2)
|
||||
longString += char * 25000
|
||||
if lobType == "BLOB" and sys.version_info[0] >= 3:
|
||||
actualValue = longString.encode("ascii")
|
||||
char = chr(ord('A') + integer_value - 1)
|
||||
prev_char = chr(ord('A') + integer_value - 2)
|
||||
long_string += char * 25000
|
||||
if lob_type == "BLOB":
|
||||
actualValue = long_string.encode("ascii")
|
||||
char = char.encode("ascii")
|
||||
prevChar = prevChar.encode("ascii")
|
||||
prev_char = prev_char.encode("ascii")
|
||||
else:
|
||||
actualValue = longString
|
||||
actualValue = long_string
|
||||
self.assertEqual(lob.size(), len(actualValue))
|
||||
self.assertEqual(lob.read(), actualValue)
|
||||
if lobType == "CLOB":
|
||||
if lob_type == "CLOB":
|
||||
self.assertEqual(str(lob), actualValue)
|
||||
self.assertEqual(lob.read(len(actualValue)), char)
|
||||
if integerValue > 1:
|
||||
offset = (integerValue - 1) * 25000 - 4
|
||||
string = prevChar * 5 + char * 5
|
||||
if integer_value > 1:
|
||||
offset = (integer_value - 1) * 25000 - 4
|
||||
string = prev_char * 5 + char * 5
|
||||
self.assertEqual(lob.read(offset, 10), string)
|
||||
|
||||
def test_1900_BindLobValue(self):
|
||||
def test_1900_bind_lob_value(self):
|
||||
"1900 - test binding a LOB value directly"
|
||||
self.cursor.execute("truncate table TestCLOBs")
|
||||
self.cursor.execute("insert into TestCLOBs values (1, 'Short value')")
|
||||
self.cursor.execute("select ClobCol from TestCLOBs")
|
||||
lob, = self.cursor.fetchone()
|
||||
self.cursor.execute("insert into TestCLOBs values (2, :value)",
|
||||
value = lob)
|
||||
value=lob)
|
||||
|
||||
def test_1901_BLOBCursorDescription(self):
|
||||
def test_1901_blob_cursor_description(self):
|
||||
"1901 - test cursor description is accurate for BLOBs"
|
||||
self.cursor.execute("select * from TestBLOBs")
|
||||
self.assertEqual(self.cursor.description,
|
||||
[ ('INTCOL', cx_Oracle.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
|
||||
('BLOBCOL', cx_Oracle.DB_TYPE_BLOB, None, None, None, None,
|
||||
0) ])
|
||||
expected_value = [
|
||||
('INTCOL', oracledb.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
|
||||
('BLOBCOL', oracledb.DB_TYPE_BLOB, None, None, None, None, 0)
|
||||
]
|
||||
self.assertEqual(self.cursor.description, expected_value)
|
||||
|
||||
def test_1902_BLOBsDirect(self):
|
||||
def test_1902_blob_direct(self):
|
||||
"1902 - test binding and fetching BLOB data (directly)"
|
||||
self.__PerformTest("BLOB", cx_Oracle.DB_TYPE_BLOB)
|
||||
self.__perform_test("BLOB", oracledb.DB_TYPE_BLOB)
|
||||
|
||||
def test_1903_BLOBsIndirect(self):
|
||||
def test_1903_blob_indirect(self):
|
||||
"1903 - test binding and fetching BLOB data (indirectly)"
|
||||
self.__PerformTest("BLOB", cx_Oracle.DB_TYPE_LONG_RAW)
|
||||
self.__perform_test("BLOB", oracledb.DB_TYPE_LONG_RAW)
|
||||
|
||||
def test_1904_BLOBOperations(self):
|
||||
def test_1904_blob_operations(self):
|
||||
"1904 - test operations on BLOBs"
|
||||
self.__TestLobOperations("BLOB")
|
||||
self.__test_lob_operations("BLOB")
|
||||
|
||||
def test_1905_CLOBCursorDescription(self):
|
||||
def test_1905_clob_cursor_description(self):
|
||||
"1905 - test cursor description is accurate for CLOBs"
|
||||
self.cursor.execute("select * from TestCLOBs")
|
||||
self.assertEqual(self.cursor.description,
|
||||
[ ('INTCOL', cx_Oracle.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
|
||||
('CLOBCOL', cx_Oracle.DB_TYPE_CLOB, None, None, None, None,
|
||||
0) ])
|
||||
expected_value = [
|
||||
('INTCOL', oracledb.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
|
||||
('CLOBCOL', oracledb.DB_TYPE_CLOB, None, None, None, None, 0)
|
||||
]
|
||||
self.assertEqual(self.cursor.description, expected_value)
|
||||
|
||||
def test_1906_CLOBsDirect(self):
|
||||
def test_1906_clob_direct(self):
|
||||
"1906 - test binding and fetching CLOB data (directly)"
|
||||
self.__PerformTest("CLOB", cx_Oracle.DB_TYPE_CLOB)
|
||||
self.__perform_test("CLOB", oracledb.DB_TYPE_CLOB)
|
||||
|
||||
def test_1907_CLOBsIndirect(self):
|
||||
def test_1907_clob_indirect(self):
|
||||
"1907 - test binding and fetching CLOB data (indirectly)"
|
||||
self.__PerformTest("CLOB", cx_Oracle.DB_TYPE_LONG)
|
||||
self.__perform_test("CLOB", oracledb.DB_TYPE_LONG)
|
||||
|
||||
def test_1908_CLOBOperations(self):
|
||||
def test_1908_clob_operations(self):
|
||||
"1908 - test operations on CLOBs"
|
||||
self.__TestLobOperations("CLOB")
|
||||
self.__test_lob_operations("CLOB")
|
||||
|
||||
def test_1909_CreateBlob(self):
|
||||
def test_1909_create_temp_blob(self):
|
||||
"1909 - test creating a temporary BLOB"
|
||||
self.__TestTemporaryLOB("BLOB")
|
||||
self.__test_temporary_lob("BLOB")
|
||||
|
||||
def test_1910_CreateClob(self):
|
||||
def test_1910_create_temp_clob(self):
|
||||
"1910 - test creating a temporary CLOB"
|
||||
self.__TestTemporaryLOB("CLOB")
|
||||
self.__test_temporary_lob("CLOB")
|
||||
|
||||
def test_1911_CreateNclob(self):
|
||||
def test_1911_create_temp_nclob(self):
|
||||
"1911 - test creating a temporary NCLOB"
|
||||
self.__TestTemporaryLOB("NCLOB")
|
||||
self.__test_temporary_lob("NCLOB")
|
||||
|
||||
def test_1912_MultipleFetch(self):
|
||||
def test_1912_multiple_fetch(self):
|
||||
"1912 - test retrieving data from a CLOB after multiple fetches"
|
||||
self.cursor.arraysize = 1
|
||||
self.cursor.execute("select * from TestCLOBS")
|
||||
rows = self.cursor.fetchall()
|
||||
self.__ValidateQuery(rows, "CLOB")
|
||||
self.__validate_query(rows, "CLOB")
|
||||
|
||||
def test_1913_NCLOBCursorDescription(self):
|
||||
def test_1913_nclob_cursor_description(self):
|
||||
"1913 - test cursor description is accurate for NCLOBs"
|
||||
self.cursor.execute("select * from TestNCLOBs")
|
||||
self.assertEqual(self.cursor.description,
|
||||
[ ('INTCOL', cx_Oracle.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
|
||||
('NCLOBCOL', cx_Oracle.DB_TYPE_NCLOB, None, None, None, None,
|
||||
0) ])
|
||||
expected_value = [
|
||||
('INTCOL', oracledb.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
|
||||
('NCLOBCOL', oracledb.DB_TYPE_NCLOB, None, None, None, None, 0)
|
||||
]
|
||||
self.assertEqual(self.cursor.description, expected_value)
|
||||
|
||||
def test_1914_NCLOBsDirect(self):
|
||||
def test_1914_nclob_direct(self):
|
||||
"1914 - test binding and fetching NCLOB data (directly)"
|
||||
self.__PerformTest("NCLOB", cx_Oracle.DB_TYPE_NCLOB)
|
||||
self.__perform_test("NCLOB", oracledb.DB_TYPE_NCLOB)
|
||||
|
||||
def test_1915_NCLOBDifferentEncodings(self):
|
||||
def test_1915_nclob_different_encodings(self):
|
||||
"1915 - test binding and fetching NCLOB data (different encodings)"
|
||||
connection = cx_Oracle.connect(TestEnv.GetMainUser(),
|
||||
TestEnv.GetMainPassword(), TestEnv.GetConnectString(),
|
||||
encoding = "UTF-8", nencoding = "UTF-16")
|
||||
connection = oracledb.connect(base.get_main_user(),
|
||||
base.get_main_password(),
|
||||
base.get_connect_string(),
|
||||
encoding="UTF-8", nencoding="UTF-16")
|
||||
value = "\u03b4\u4e2a"
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("truncate table TestNCLOBs")
|
||||
cursor.setinputsizes(val = cx_Oracle.DB_TYPE_NVARCHAR)
|
||||
cursor.execute("insert into TestNCLOBs values (1, :val)", val = value)
|
||||
cursor.setinputsizes(val=oracledb.DB_TYPE_NVARCHAR)
|
||||
cursor.execute("insert into TestNCLOBs values (1, :val)", val=value)
|
||||
cursor.execute("select NCLOBCol from TestNCLOBs")
|
||||
nclob, = cursor.fetchone()
|
||||
cursor.setinputsizes(val = cx_Oracle.DB_TYPE_NVARCHAR)
|
||||
cursor.setinputsizes(val=oracledb.DB_TYPE_NVARCHAR)
|
||||
cursor.execute("update TestNCLOBs set NCLOBCol = :val",
|
||||
val = nclob.read() + value)
|
||||
val=nclob.read() + value)
|
||||
cursor.execute("select NCLOBCol from TestNCLOBs")
|
||||
nclob, = cursor.fetchone()
|
||||
self.assertEqual(nclob.read(), value + value)
|
||||
|
||||
def test_1916_NCLOBsIndirect(self):
|
||||
def test_1916_nclob_indirect(self):
|
||||
"1916 - test binding and fetching NCLOB data (indirectly)"
|
||||
self.__PerformTest("NCLOB", cx_Oracle.DB_TYPE_LONG)
|
||||
self.__perform_test("NCLOB", oracledb.DB_TYPE_LONG)
|
||||
|
||||
def test_1917_NCLOBOperations(self):
|
||||
def test_1917_nclob_operations(self):
|
||||
"1917 - test operations on NCLOBs"
|
||||
self.__TestLobOperations("NCLOB")
|
||||
self.__test_lob_operations("NCLOB")
|
||||
|
||||
def test_1918_TemporaryLobs(self):
|
||||
def test_1918_temporary_lobs(self):
|
||||
"1918 - test temporary LOBs"
|
||||
cursor = self.connection.cursor()
|
||||
cursor.arraysize = self.cursor.arraysize
|
||||
|
@ -264,8 +268,8 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
select sys_context('USERENV', 'SID')
|
||||
from dual""")
|
||||
sid, = cursor.fetchone()
|
||||
tempLobs = self.__GetTempLobs(sid)
|
||||
self.assertEqual(tempLobs, 0)
|
||||
temp_lobs = self.__get_temp_lobs(sid)
|
||||
self.assertEqual(temp_lobs, 0)
|
||||
cursor.execute("""
|
||||
select extract(xmlcol, '/').getclobval()
|
||||
from TestXML""")
|
||||
|
@ -273,13 +277,13 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
value = lob.read()
|
||||
del lob
|
||||
cursor.close()
|
||||
tempLobs = self.__GetTempLobs(sid)
|
||||
self.assertEqual(tempLobs, 0)
|
||||
temp_lobs = self.__get_temp_lobs(sid)
|
||||
self.assertEqual(temp_lobs, 0)
|
||||
|
||||
def test_1919_AssignStringBeyondArraySize(self):
|
||||
"1919 - test assign string to NCLOB beyond array size"
|
||||
nclobVar = self.cursor.var(cx_Oracle.DB_TYPE_NCLOB)
|
||||
nclobVar = self.cursor.var(oracledb.DB_TYPE_NCLOB)
|
||||
self.assertRaises(IndexError, nclobVar.setvalue, 1, "test char")
|
||||
|
||||
if __name__ == "__main__":
|
||||
TestEnv.RunTestCases()
|
||||
base.run_test_cases()
|
||||
|
|
|
@ -11,97 +11,95 @@
|
|||
2000 - Module for testing long and long raw variables
|
||||
"""
|
||||
|
||||
import TestEnv
|
||||
import base
|
||||
|
||||
import cx_Oracle
|
||||
import sys
|
||||
import cx_Oracle as oracledb
|
||||
|
||||
class TestCase(TestEnv.BaseTestCase):
|
||||
class TestCase(base.BaseTestCase):
|
||||
|
||||
def __PerformTest(self, a_Type, a_InputType):
|
||||
self.cursor.execute("truncate table Test%ss" % a_Type)
|
||||
longString = ""
|
||||
def __perform_test(self, typ):
|
||||
name_part = "Long" if typ is oracledb.DB_TYPE_LONG else "LongRaw"
|
||||
|
||||
self.cursor.execute("truncate table Test%ss" % name_part)
|
||||
long_string = ""
|
||||
for i in range(1, 11):
|
||||
char = chr(ord('A') + i - 1)
|
||||
longString += char * 25000
|
||||
self.cursor.setinputsizes(longString = a_InputType)
|
||||
if a_Type == "LongRaw" and sys.version_info[0] >= 3:
|
||||
bindValue = longString.encode("ascii")
|
||||
long_string += char * 25000
|
||||
self.cursor.setinputsizes(long_string=typ)
|
||||
if typ is oracledb.DB_TYPE_LONG_RAW:
|
||||
bind_value = long_string.encode()
|
||||
else:
|
||||
bindValue = longString
|
||||
bind_value = long_string
|
||||
self.cursor.execute("""
|
||||
insert into Test%ss (
|
||||
IntCol,
|
||||
%sCol
|
||||
) values (
|
||||
:integerValue,
|
||||
:longString
|
||||
)""" % (a_Type, a_Type),
|
||||
integerValue = i,
|
||||
longString = bindValue)
|
||||
:integer_value,
|
||||
:long_string
|
||||
)""" % (name_part, name_part),
|
||||
integer_value=i,
|
||||
long_string=bind_value)
|
||||
self.connection.commit()
|
||||
self.cursor.execute("""
|
||||
select *
|
||||
from Test%ss
|
||||
order by IntCol""" % a_Type)
|
||||
longString = ""
|
||||
while 1:
|
||||
row = self.cursor.fetchone()
|
||||
if row is None:
|
||||
break
|
||||
integerValue, fetchedValue = row
|
||||
char = chr(ord('A') + integerValue - 1)
|
||||
longString += char * 25000
|
||||
if a_Type == "LongRaw" and sys.version_info[0] >= 3:
|
||||
actualValue = longString.encode("ascii")
|
||||
order by IntCol""" % name_part)
|
||||
long_string = ""
|
||||
for integer_value, fetched_value in self.cursor:
|
||||
char = chr(ord('A') + integer_value - 1)
|
||||
long_string += char * 25000
|
||||
if typ is oracledb.DB_TYPE_LONG_RAW:
|
||||
actual_value = long_string.encode()
|
||||
else:
|
||||
actualValue = longString
|
||||
self.assertEqual(len(fetchedValue), integerValue * 25000)
|
||||
self.assertEqual(fetchedValue, actualValue)
|
||||
actual_value = long_string
|
||||
self.assertEqual(len(fetched_value), integer_value * 25000)
|
||||
self.assertEqual(fetched_value, actual_value)
|
||||
|
||||
def test_2000_Longs(self):
|
||||
def test_2000_longs(self):
|
||||
"2000 - test binding and fetching long data"
|
||||
self.__PerformTest("Long", cx_Oracle.DB_TYPE_LONG)
|
||||
self.__perform_test(oracledb.DB_TYPE_LONG)
|
||||
|
||||
def test_2001_LongWithExecuteMany(self):
|
||||
def test_2001_long_with_execute_many(self):
|
||||
"2001 - test binding long data with executemany()"
|
||||
data = []
|
||||
self.cursor.execute("truncate table TestLongs")
|
||||
for i in range(5):
|
||||
char = chr(ord('A') + i)
|
||||
longStr = char * (32768 * (i + 1))
|
||||
data.append((i + 1, longStr))
|
||||
long_str = char * (32768 * (i + 1))
|
||||
data.append((i + 1, long_str))
|
||||
self.cursor.executemany("insert into TestLongs values (:1, :2)", data)
|
||||
self.connection.commit()
|
||||
self.cursor.execute("select * from TestLongs order by IntCol")
|
||||
fetchedData = self.cursor.fetchall()
|
||||
self.assertEqual(fetchedData, data)
|
||||
fetched_data = self.cursor.fetchall()
|
||||
self.assertEqual(fetched_data, data)
|
||||
|
||||
def test_2002_LongRaws(self):
|
||||
def test_2002_long_raws(self):
|
||||
"2002 - test binding and fetching long raw data"
|
||||
self.__PerformTest("LongRaw", cx_Oracle.DB_TYPE_LONG_RAW)
|
||||
self.__perform_test(oracledb.DB_TYPE_LONG_RAW)
|
||||
|
||||
def test_2003_LongCursorDescription(self):
|
||||
def test_2003_long_cursor_description(self):
|
||||
"2003 - test cursor description is accurate for longs"
|
||||
self.cursor.execute("select * from TestLongs")
|
||||
self.assertEqual(self.cursor.description,
|
||||
[ ('INTCOL', cx_Oracle.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
|
||||
('LONGCOL', cx_Oracle.DB_TYPE_LONG, None, None, None, None,
|
||||
0) ])
|
||||
expected_value = [
|
||||
('INTCOL', oracledb.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
|
||||
('LONGCOL', oracledb.DB_TYPE_LONG, None, None, None, None, 0)
|
||||
]
|
||||
self.assertEqual(self.cursor.description, expected_value)
|
||||
|
||||
def test_2004_LongRawCursorDescription(self):
|
||||
def test_2004_long_raw_cursor_description(self):
|
||||
"2004 - test cursor description is accurate for long raws"
|
||||
self.cursor.execute("select * from TestLongRaws")
|
||||
self.assertEqual(self.cursor.description,
|
||||
[ ('INTCOL', cx_Oracle.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
|
||||
('LONGRAWCOL', cx_Oracle.DB_TYPE_LONG_RAW, None, None, None,
|
||||
[ ('INTCOL', oracledb.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
|
||||
('LONGRAWCOL', oracledb.DB_TYPE_LONG_RAW, None, None, None,
|
||||
None, 0) ])
|
||||
|
||||
def test_2005_ArraySizeTooLarge(self):
|
||||
def test_2005_array_size_too_large(self):
|
||||
"2005 - test array size too large generates an exception"
|
||||
self.cursor.arraysize = 268435456
|
||||
self.assertRaises(cx_Oracle.DatabaseError, self.cursor.execute,
|
||||
"select * from TestLongRaws")
|
||||
self.assertRaises(oracledb.DatabaseError, self.cursor.execute,
|
||||
"select * from TestLongRaws")
|
||||
|
||||
if __name__ == "__main__":
|
||||
TestEnv.RunTestCases()
|
||||
base.run_test_cases()
|
||||
|
|
|
@ -11,151 +11,146 @@
|
|||
2100 - Module for testing NCHAR variables
|
||||
"""
|
||||
|
||||
import TestEnv
|
||||
import base
|
||||
|
||||
import cx_Oracle
|
||||
import cx_Oracle as oracledb
|
||||
|
||||
class TestCase(TestEnv.BaseTestCase):
|
||||
class TestCase(base.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
TestEnv.BaseTestCase.setUp(self)
|
||||
self.rawData = []
|
||||
self.dataByKey = {}
|
||||
super().setUp()
|
||||
self.raw_data = []
|
||||
self.data_by_key = {}
|
||||
for i in range(1, 11):
|
||||
unicodeCol = "Unicode \u3042 %d" % i
|
||||
fixedCharCol = ("Fixed Unicode %d" % i).ljust(40)
|
||||
unicode_col = "Unicode \u3042 %d" % i
|
||||
fixed_char_col = ("Fixed Unicode %d" % i).ljust(40)
|
||||
if i % 2:
|
||||
nullableCol = "Nullable %d" % i
|
||||
nullable_col = "Nullable %d" % i
|
||||
else:
|
||||
nullableCol = None
|
||||
dataTuple = (i, unicodeCol, fixedCharCol, nullableCol)
|
||||
self.rawData.append(dataTuple)
|
||||
self.dataByKey[i] = dataTuple
|
||||
nullable_col = None
|
||||
data_tuple = (i, unicode_col, fixed_char_col, nullable_col)
|
||||
self.raw_data.append(data_tuple)
|
||||
self.data_by_key[i] = data_tuple
|
||||
|
||||
def test_2100_UnicodeLength(self):
|
||||
def test_2100_unicode_length(self):
|
||||
"2100 - test value length"
|
||||
returnValue = self.cursor.var(int)
|
||||
return_value = self.cursor.var(int)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:retval := LENGTH(:value);
|
||||
end;""",
|
||||
value = "InVal \u3042",
|
||||
retval = returnValue)
|
||||
self.assertEqual(returnValue.getvalue(), 7)
|
||||
value="InVal \u3042",
|
||||
retval=return_value)
|
||||
self.assertEqual(return_value.getvalue(), 7)
|
||||
|
||||
def test_2101_BindUnicode(self):
|
||||
def test_2101_bind_unicode(self):
|
||||
"2101 - test binding in a unicode"
|
||||
self.cursor.setinputsizes(value = cx_Oracle.DB_TYPE_NVARCHAR)
|
||||
self.cursor.setinputsizes(value=oracledb.DB_TYPE_NVARCHAR)
|
||||
self.cursor.execute("""
|
||||
select * from TestUnicodes
|
||||
where UnicodeCol = :value""",
|
||||
value = "Unicode \u3042 5")
|
||||
self.assertEqual(self.cursor.fetchall(), [self.dataByKey[5]])
|
||||
value="Unicode \u3042 5")
|
||||
self.assertEqual(self.cursor.fetchall(), [self.data_by_key[5]])
|
||||
|
||||
def test_2102_BindDifferentVar(self):
|
||||
def test_2102_bind_different_var(self):
|
||||
"2102 - test binding a different variable on second execution"
|
||||
retval_1 = self.cursor.var(cx_Oracle.DB_TYPE_NVARCHAR, 30)
|
||||
retval_2 = self.cursor.var(cx_Oracle.DB_TYPE_NVARCHAR, 30)
|
||||
retval_1 = self.cursor.var(oracledb.DB_TYPE_NVARCHAR, 30)
|
||||
retval_2 = self.cursor.var(oracledb.DB_TYPE_NVARCHAR, 30)
|
||||
self.cursor.execute(r"begin :retval := unistr('Called \3042'); end;",
|
||||
retval = retval_1)
|
||||
retval=retval_1)
|
||||
self.assertEqual(retval_1.getvalue(), "Called \u3042")
|
||||
self.cursor.execute("begin :retval := 'Called'; end;",
|
||||
retval = retval_2)
|
||||
self.cursor.execute("begin :retval := 'Called'; end;", retval=retval_2)
|
||||
self.assertEqual(retval_2.getvalue(), "Called")
|
||||
|
||||
def test_2103_BindUnicodeAfterNumber(self):
|
||||
def test_2103_bind_unicode_after_number(self):
|
||||
"2103 - test binding in a string after setting input sizes to a number"
|
||||
unicodeVal = self.cursor.var(cx_Oracle.DB_TYPE_NVARCHAR)
|
||||
unicodeVal.setvalue(0, "Unicode \u3042 6")
|
||||
self.cursor.setinputsizes(value = cx_Oracle.NUMBER)
|
||||
unicode_val = self.cursor.var(oracledb.DB_TYPE_NVARCHAR)
|
||||
unicode_val.setvalue(0, "Unicode \u3042 6")
|
||||
self.cursor.setinputsizes(value=oracledb.NUMBER)
|
||||
self.cursor.execute("""
|
||||
select * from TestUnicodes
|
||||
where UnicodeCol = :value""",
|
||||
value = unicodeVal)
|
||||
self.assertEqual(self.cursor.fetchall(), [self.dataByKey[6]])
|
||||
value=unicode_val)
|
||||
self.assertEqual(self.cursor.fetchall(), [self.data_by_key[6]])
|
||||
|
||||
def test_2104_BindUnicodeArrayDirect(self):
|
||||
def test_2104_bind_unicode_array_direct(self):
|
||||
"2104 - test binding in a unicode array"
|
||||
returnValue = self.cursor.var(cx_Oracle.NUMBER)
|
||||
array = [r[1] for r in self.rawData]
|
||||
arrayVar = self.cursor.arrayvar(cx_Oracle.DB_TYPE_NVARCHAR, array)
|
||||
return_value = self.cursor.var(oracledb.NUMBER)
|
||||
array = [r[1] for r in self.raw_data]
|
||||
array_var = self.cursor.arrayvar(oracledb.DB_TYPE_NVARCHAR, array)
|
||||
statement = """
|
||||
begin
|
||||
:retval := pkg_TestUnicodeArrays.TestInArrays(
|
||||
:integerValue, :array);
|
||||
:integer_value, :array);
|
||||
end;"""
|
||||
self.cursor.execute(statement,
|
||||
retval = returnValue,
|
||||
integerValue = 5,
|
||||
array = arrayVar)
|
||||
self.assertEqual(returnValue.getvalue(), 116)
|
||||
array = [ "Unicode - \u3042 %d" % i for i in range(15) ]
|
||||
arrayVar = self.cursor.arrayvar(cx_Oracle.DB_TYPE_NVARCHAR, array)
|
||||
self.cursor.execute(statement,
|
||||
integerValue = 8,
|
||||
array = arrayVar)
|
||||
self.assertEqual(returnValue.getvalue(), 208)
|
||||
self.cursor.execute(statement, retval=return_value, integer_value=5,
|
||||
array=array_var)
|
||||
self.assertEqual(return_value.getvalue(), 116)
|
||||
array = ["Unicode - \u3042 %d" % i for i in range(15)]
|
||||
array_var = self.cursor.arrayvar(oracledb.DB_TYPE_NVARCHAR, array)
|
||||
self.cursor.execute(statement, integer_value=8, array=array_var)
|
||||
self.assertEqual(return_value.getvalue(), 208)
|
||||
|
||||
def test_2105_BindUnicodeArrayBySizes(self):
|
||||
def test_2105_bind_unicode_array_by_sizes(self):
|
||||
"2105 - test binding in a unicode array (with setinputsizes)"
|
||||
returnValue = self.cursor.var(cx_Oracle.NUMBER)
|
||||
self.cursor.setinputsizes(array = [cx_Oracle.DB_TYPE_NVARCHAR, 10])
|
||||
array = [r[1] for r in self.rawData]
|
||||
return_value = self.cursor.var(oracledb.NUMBER)
|
||||
self.cursor.setinputsizes(array = [oracledb.DB_TYPE_NVARCHAR, 10])
|
||||
array = [r[1] for r in self.raw_data]
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:retval := pkg_TestUnicodeArrays.TestInArrays(:integerValue,
|
||||
:retval := pkg_TestUnicodeArrays.TestInArrays(:integer_value,
|
||||
:array);
|
||||
end;""",
|
||||
retval = returnValue,
|
||||
integerValue = 6,
|
||||
array = array)
|
||||
self.assertEqual(returnValue.getvalue(), 117)
|
||||
retval=return_value,
|
||||
integer_value=6,
|
||||
array=array)
|
||||
self.assertEqual(return_value.getvalue(), 117)
|
||||
|
||||
def test_2106_BindUnicodeArrayByVar(self):
|
||||
def test_2106_bind_unicode_array_by_var(self):
|
||||
"2106 - test binding in a unicode array (with arrayvar)"
|
||||
returnValue = self.cursor.var(cx_Oracle.NUMBER)
|
||||
array = self.cursor.arrayvar(cx_Oracle.DB_TYPE_NVARCHAR, 10, 20)
|
||||
array.setvalue(0, [r[1] for r in self.rawData])
|
||||
return_value = self.cursor.var(oracledb.NUMBER)
|
||||
array = self.cursor.arrayvar(oracledb.DB_TYPE_NVARCHAR, 10, 20)
|
||||
array.setvalue(0, [r[1] for r in self.raw_data])
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:retval := pkg_TestUnicodeArrays.TestInArrays(:integerValue,
|
||||
:retval := pkg_TestUnicodeArrays.TestInArrays(:integer_value,
|
||||
:array);
|
||||
end;""",
|
||||
retval = returnValue,
|
||||
integerValue = 7,
|
||||
array = array)
|
||||
self.assertEqual(returnValue.getvalue(), 118)
|
||||
retval=return_value,
|
||||
integer_value=7,
|
||||
array=array)
|
||||
self.assertEqual(return_value.getvalue(), 118)
|
||||
|
||||
def test_2107_BindInOutUnicodeArrayByVar(self):
|
||||
def test_2107_bind_in_out_unicode_array_by_var(self):
|
||||
"2107 - test binding in/out a unicode array (with arrayvar)"
|
||||
array = self.cursor.arrayvar(cx_Oracle.DB_TYPE_NVARCHAR, 10, 100)
|
||||
originalData = [r[1] for r in self.rawData]
|
||||
format = "Converted element \u3042 # %d originally had length %d"
|
||||
expectedData = [format % (i, len(originalData[i - 1])) \
|
||||
for i in range(1, 6)] + originalData[5:]
|
||||
array.setvalue(0, originalData)
|
||||
array = self.cursor.arrayvar(oracledb.DB_TYPE_NVARCHAR, 10, 100)
|
||||
original_data = [r[1] for r in self.raw_data]
|
||||
fmt = "Converted element \u3042 # %d originally had length %d"
|
||||
expected_data = [fmt % (i, len(original_data[i - 1])) \
|
||||
for i in range(1, 6)] + original_data[5:]
|
||||
array.setvalue(0, original_data)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
pkg_TestUnicodeArrays.TestInOutArrays(:numElems, :array);
|
||||
end;""",
|
||||
numElems = 5,
|
||||
array = array)
|
||||
self.assertEqual(array.getvalue(), expectedData)
|
||||
self.assertEqual(array.getvalue(), expected_data)
|
||||
|
||||
def test_2108_BindOutUnicodeArrayByVar(self):
|
||||
def test_2108_bind_out_unicode_array_by_var(self):
|
||||
"2108 - test binding out a unicode array (with arrayvar)"
|
||||
array = self.cursor.arrayvar(cx_Oracle.DB_TYPE_NVARCHAR, 6, 100)
|
||||
format = "Test out element \u3042 # %d"
|
||||
expectedData = [format % i for i in range(1, 7)]
|
||||
array = self.cursor.arrayvar(oracledb.DB_TYPE_NVARCHAR, 6, 100)
|
||||
fmt = "Test out element \u3042 # %d"
|
||||
expected_data = [fmt % i for i in range(1, 7)]
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
pkg_TestUnicodeArrays.TestOutArrays(:numElems, :array);
|
||||
end;""",
|
||||
numElems = 6,
|
||||
array = array)
|
||||
self.assertEqual(array.getvalue(), expectedData)
|
||||
self.assertEqual(array.getvalue(), expected_data)
|
||||
|
||||
def test_2109_BindNull(self):
|
||||
def test_2109_bind_null(self):
|
||||
"2109 - test binding in a null"
|
||||
self.cursor.execute("""
|
||||
select * from TestUnicodes
|
||||
|
@ -163,39 +158,39 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
value = None)
|
||||
self.assertEqual(self.cursor.fetchall(), [])
|
||||
|
||||
def test_2110_BindOutSetInputSizesByType(self):
|
||||
def test_2110_bind_out_set_input_sizes_by_type(self):
|
||||
"2110 - test binding out with set input sizes defined (by type)"
|
||||
vars = self.cursor.setinputsizes(value = cx_Oracle.DB_TYPE_NVARCHAR)
|
||||
bind_vars = self.cursor.setinputsizes(value=oracledb.DB_TYPE_NVARCHAR)
|
||||
self.cursor.execute(r"""
|
||||
begin
|
||||
:value := unistr('TSI \3042');
|
||||
end;""")
|
||||
self.assertEqual(vars["value"].getvalue(), "TSI \u3042")
|
||||
self.assertEqual(bind_vars["value"].getvalue(), "TSI \u3042")
|
||||
|
||||
def test_2111_BindInOutSetInputSizesByType(self):
|
||||
def test_2111_bind_in_out_set_input_sizes_by_type(self):
|
||||
"2111 - test binding in/out with set input sizes defined (by type)"
|
||||
vars = self.cursor.setinputsizes(value = cx_Oracle.DB_TYPE_NVARCHAR)
|
||||
bind_vars = self.cursor.setinputsizes(value=oracledb.DB_TYPE_NVARCHAR)
|
||||
self.cursor.execute(r"""
|
||||
begin
|
||||
:value := :value || unistr(' TSI \3042');
|
||||
end;""",
|
||||
value = "InVal \u3041")
|
||||
self.assertEqual(vars["value"].getvalue(),
|
||||
self.assertEqual(bind_vars["value"].getvalue(),
|
||||
"InVal \u3041 TSI \u3042")
|
||||
|
||||
def test_2112_BindOutVar(self):
|
||||
def test_2112_bind_out_var(self):
|
||||
"2112 - test binding out with cursor.var() method"
|
||||
var = self.cursor.var(cx_Oracle.DB_TYPE_NVARCHAR)
|
||||
var = self.cursor.var(oracledb.DB_TYPE_NVARCHAR)
|
||||
self.cursor.execute(r"""
|
||||
begin
|
||||
:value := unistr('TSI (VAR) \3042');
|
||||
end;""",
|
||||
value = var)
|
||||
value=var)
|
||||
self.assertEqual(var.getvalue(), "TSI (VAR) \u3042")
|
||||
|
||||
def test_2113_BindInOutVarDirectSet(self):
|
||||
def test_2113_bind_in_out_var_direct_set(self):
|
||||
"2113 - test binding in/out with cursor.var() method"
|
||||
var = self.cursor.var(cx_Oracle.DB_TYPE_NVARCHAR)
|
||||
var = self.cursor.var(oracledb.DB_TYPE_NVARCHAR)
|
||||
var.setvalue(0, "InVal \u3041")
|
||||
self.cursor.execute(r"""
|
||||
begin
|
||||
|
@ -204,43 +199,42 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
value = var)
|
||||
self.assertEqual(var.getvalue(), "InVal \u3041 TSI (VAR) \u3042")
|
||||
|
||||
def test_2114_CursorDescription(self):
|
||||
def test_2114_cursor_description(self):
|
||||
"2114 - test cursor description is accurate"
|
||||
self.cursor.execute("select * from TestUnicodes")
|
||||
self.assertEqual(self.cursor.description,
|
||||
[ ('INTCOL', cx_Oracle.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
|
||||
('UNICODECOL', cx_Oracle.DB_TYPE_NVARCHAR, 20, 80, None,
|
||||
None, 0),
|
||||
('FIXEDUNICODECOL', cx_Oracle.DB_TYPE_NCHAR, 40, 160, None,
|
||||
None, 0),
|
||||
('NULLABLECOL', cx_Oracle.DB_TYPE_NVARCHAR, 50, 200, None,
|
||||
None, 1) ])
|
||||
expected_value = [
|
||||
('INTCOL', oracledb.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
|
||||
('UNICODECOL', oracledb.DB_TYPE_NVARCHAR, 20, 80, None, None, 0),
|
||||
('FIXEDUNICODECOL', oracledb.DB_TYPE_NCHAR, 40, 160, None, None, 0),
|
||||
('NULLABLECOL', oracledb.DB_TYPE_NVARCHAR, 50, 200, None, None, 1)
|
||||
]
|
||||
self.assertEqual(self.cursor.description, expected_value)
|
||||
|
||||
def test_2115_FetchAll(self):
|
||||
def test_2115_fetchall(self):
|
||||
"2115 - test that fetching all of the data returns the correct results"
|
||||
self.cursor.execute("select * From TestUnicodes order by IntCol")
|
||||
self.assertEqual(self.cursor.fetchall(), self.rawData)
|
||||
self.assertEqual(self.cursor.fetchall(), self.raw_data)
|
||||
self.assertEqual(self.cursor.fetchall(), [])
|
||||
|
||||
def test_2116_FetchMany(self):
|
||||
def test_2116_fetchmany(self):
|
||||
"2116 - test that fetching data in chunks returns the correct results"
|
||||
self.cursor.execute("select * From TestUnicodes order by IntCol")
|
||||
self.assertEqual(self.cursor.fetchmany(3), self.rawData[0:3])
|
||||
self.assertEqual(self.cursor.fetchmany(2), self.rawData[3:5])
|
||||
self.assertEqual(self.cursor.fetchmany(4), self.rawData[5:9])
|
||||
self.assertEqual(self.cursor.fetchmany(3), self.rawData[9:])
|
||||
self.assertEqual(self.cursor.fetchmany(3), self.raw_data[0:3])
|
||||
self.assertEqual(self.cursor.fetchmany(2), self.raw_data[3:5])
|
||||
self.assertEqual(self.cursor.fetchmany(4), self.raw_data[5:9])
|
||||
self.assertEqual(self.cursor.fetchmany(3), self.raw_data[9:])
|
||||
self.assertEqual(self.cursor.fetchmany(3), [])
|
||||
|
||||
def test_2117_FetchOne(self):
|
||||
def test_2117_fetchone(self):
|
||||
"2117 - test that fetching a single row returns the correct results"
|
||||
self.cursor.execute("""
|
||||
select *
|
||||
from TestUnicodes
|
||||
where IntCol in (3, 4)
|
||||
order by IntCol""")
|
||||
self.assertEqual(self.cursor.fetchone(), self.dataByKey[3])
|
||||
self.assertEqual(self.cursor.fetchone(), self.dataByKey[4])
|
||||
self.assertEqual(self.cursor.fetchone(), self.data_by_key[3])
|
||||
self.assertEqual(self.cursor.fetchone(), self.data_by_key[4])
|
||||
self.assertEqual(self.cursor.fetchone(), None)
|
||||
|
||||
if __name__ == "__main__":
|
||||
TestEnv.RunTestCases()
|
||||
base.run_test_cases()
|
||||
|
|
|
@ -11,51 +11,51 @@
|
|||
2200 - Module for testing number variables
|
||||
"""
|
||||
|
||||
import TestEnv
|
||||
import base
|
||||
|
||||
import cx_Oracle
|
||||
import cx_Oracle as oracledb
|
||||
import decimal
|
||||
import sys
|
||||
|
||||
class TestCase(TestEnv.BaseTestCase):
|
||||
class TestCase(base.BaseTestCase):
|
||||
|
||||
def outputTypeHandlerNativeInt(self, cursor, name, defaultType, size,
|
||||
precision, scale):
|
||||
return cursor.var(cx_Oracle.DB_TYPE_BINARY_INTEGER,
|
||||
arraysize=cursor.arraysize)
|
||||
def output_type_handler_binary_int(self, cursor, name, default_type, size,
|
||||
precision, scale):
|
||||
return cursor.var(oracledb.DB_TYPE_BINARY_INTEGER,
|
||||
arraysize=cursor.arraysize)
|
||||
|
||||
def outputTypeHandlerDecimal(self, cursor, name, defaultType, size,
|
||||
precision, scale):
|
||||
if defaultType == cx_Oracle.NUMBER:
|
||||
return cursor.var(str, 255, outconverter = decimal.Decimal,
|
||||
arraysize = cursor.arraysize)
|
||||
def output_type_handler_decimal(self, cursor, name, default_type, size,
|
||||
precision, scale):
|
||||
if default_type == oracledb.NUMBER:
|
||||
return cursor.var(str, 255, outconverter=decimal.Decimal,
|
||||
arraysize=cursor.arraysize)
|
||||
|
||||
def setUp(self):
|
||||
TestEnv.BaseTestCase.setUp(self)
|
||||
self.rawData = []
|
||||
self.dataByKey = {}
|
||||
super().setUp()
|
||||
self.raw_data = []
|
||||
self.data_by_key = {}
|
||||
for i in range(1, 11):
|
||||
numberCol = i + i * 0.25
|
||||
floatCol = i + i * 0.75
|
||||
unconstrainedCol = i ** 3 + i * 0.5
|
||||
number_col = i + i * 0.25
|
||||
float_col = i + i * 0.75
|
||||
unconstrained_col = i ** 3 + i * 0.5
|
||||
if i % 2:
|
||||
nullableCol = 143 ** i
|
||||
nullable_col = 143 ** i
|
||||
else:
|
||||
nullableCol = None
|
||||
dataTuple = (i, 38 ** i, numberCol, floatCol,
|
||||
unconstrainedCol, nullableCol)
|
||||
self.rawData.append(dataTuple)
|
||||
self.dataByKey[i] = dataTuple
|
||||
nullable_col = None
|
||||
data_tuple = (i, 38 ** i, number_col, float_col,
|
||||
unconstrained_col, nullable_col)
|
||||
self.raw_data.append(data_tuple)
|
||||
self.data_by_key[i] = data_tuple
|
||||
|
||||
def test_2200_BindBoolean(self):
|
||||
def test_2200_bind_boolean(self):
|
||||
"2200 - test binding in a boolean"
|
||||
result = self.cursor.callfunc("pkg_TestBooleans.GetStringRep", str,
|
||||
(True,))
|
||||
self.assertEqual(result, "TRUE")
|
||||
|
||||
def test_2201_BindBooleanAsNumber(self):
|
||||
def test_2201_bind_boolean_as_number(self):
|
||||
"2201 - test binding in a boolean as a number"
|
||||
var = self.cursor.var(cx_Oracle.NUMBER)
|
||||
var = self.cursor.var(oracledb.NUMBER)
|
||||
var.setvalue(0, True)
|
||||
self.cursor.execute("select :1 from dual", [var])
|
||||
result, = self.cursor.fetchone()
|
||||
|
@ -65,194 +65,192 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
result, = self.cursor.fetchone()
|
||||
self.assertEqual(result, 0)
|
||||
|
||||
def test_2202_BindDecimal(self):
|
||||
def test_2202_bind_decimal(self):
|
||||
"2202 - test binding in a decimal.Decimal"
|
||||
self.cursor.execute("""
|
||||
select * from TestNumbers
|
||||
where NumberCol - :value1 - :value2 = trunc(NumberCol)""",
|
||||
value1 = decimal.Decimal("0.20"),
|
||||
value2 = decimal.Decimal("0.05"))
|
||||
self.assertEqual(self.cursor.fetchall(),
|
||||
[self.dataByKey[1], self.dataByKey[5], self.dataByKey[9]])
|
||||
value1=decimal.Decimal("0.20"),
|
||||
value2=decimal.Decimal("0.05"))
|
||||
expected_data = [self.data_by_key[1], self.data_by_key[5],
|
||||
self.data_by_key[9]]
|
||||
self.assertEqual(self.cursor.fetchall(), expected_data)
|
||||
|
||||
def test_2203_BindFloat(self):
|
||||
def test_2203_bind_float(self):
|
||||
"2203 - test binding in a float"
|
||||
self.cursor.execute("""
|
||||
select * from TestNumbers
|
||||
where NumberCol - :value = trunc(NumberCol)""",
|
||||
value = 0.25)
|
||||
self.assertEqual(self.cursor.fetchall(),
|
||||
[self.dataByKey[1], self.dataByKey[5], self.dataByKey[9]])
|
||||
value=0.25)
|
||||
expected_data = [self.data_by_key[1], self.data_by_key[5],
|
||||
self.data_by_key[9]]
|
||||
self.assertEqual(self.cursor.fetchall(), expected_data)
|
||||
|
||||
def test_2204_BindInteger(self):
|
||||
def test_2204_bind_integer(self):
|
||||
"2204 - test binding in an integer"
|
||||
self.cursor.execute("""
|
||||
select * from TestNumbers
|
||||
where IntCol = :value""",
|
||||
value = 2)
|
||||
self.assertEqual(self.cursor.fetchall(), [self.dataByKey[2]])
|
||||
self.assertEqual(self.cursor.fetchall(), [self.data_by_key[2]])
|
||||
|
||||
def test_2205_BindLargeLongAsOracleNumber(self):
|
||||
def test_2205_bind_large_long_as_oracle_number(self):
|
||||
"2205 - test binding in a large long integer as Oracle number"
|
||||
valueVar = self.cursor.var(cx_Oracle.NUMBER)
|
||||
valueVar.setvalue(0, 6088343244)
|
||||
in_val = 6088343244
|
||||
value_var = self.cursor.var(oracledb.NUMBER)
|
||||
value_var.setvalue(0, in_val)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:value := :value + 5;
|
||||
end;""",
|
||||
value = valueVar)
|
||||
value = valueVar.getvalue()
|
||||
self.assertEqual(value, 6088343249)
|
||||
value=value_var)
|
||||
value = value_var.getvalue()
|
||||
self.assertEqual(value, in_val + 5)
|
||||
|
||||
def test_2206_BindLargeLongAsInteger(self):
|
||||
def test_2206_bind_large_long_as_integer(self):
|
||||
"2206 - test binding in a large long integer as Python integer"
|
||||
longValue = -9999999999999999999
|
||||
self.cursor.execute("select :value from dual", value = longValue)
|
||||
long_value = -9999999999999999999
|
||||
self.cursor.execute("select :value from dual", value=long_value)
|
||||
result, = self.cursor.fetchone()
|
||||
self.assertEqual(result, longValue)
|
||||
self.assertEqual(result, long_value)
|
||||
|
||||
def test_2207_BindIntegerAfterString(self):
|
||||
def test_2207_bind_integer_after_string(self):
|
||||
"2207 - test binding in an integer after setting input sizes to string"
|
||||
self.cursor.setinputsizes(value = 15)
|
||||
self.cursor.setinputsizes(value=15)
|
||||
self.cursor.execute("""
|
||||
select * from TestNumbers
|
||||
where IntCol = :value""",
|
||||
value = 3)
|
||||
self.assertEqual(self.cursor.fetchall(), [self.dataByKey[3]])
|
||||
value=3)
|
||||
self.assertEqual(self.cursor.fetchall(), [self.data_by_key[3]])
|
||||
|
||||
def test_2208_BindDecimalAfterNumber(self):
|
||||
def test_2208_bind_decimal_after_number(self):
|
||||
"2208 - test binding in a decimal after setting input sizes to number"
|
||||
cursor = self.connection.cursor()
|
||||
value = decimal.Decimal("319438950232418390.273596")
|
||||
cursor.setinputsizes(value = cx_Oracle.NUMBER)
|
||||
cursor.outputtypehandler = self.outputTypeHandlerDecimal
|
||||
cursor.execute("select :value from dual",
|
||||
value = value)
|
||||
outValue, = cursor.fetchone()
|
||||
self.assertEqual(outValue, value)
|
||||
cursor.setinputsizes(value=oracledb.NUMBER)
|
||||
cursor.outputtypehandler = self.output_type_handler_decimal
|
||||
cursor.execute("select :value from dual", value=value)
|
||||
out_value, = cursor.fetchone()
|
||||
self.assertEqual(out_value, value)
|
||||
|
||||
def test_2209_BindNull(self):
|
||||
def test_2209_bind_null(self):
|
||||
"2209 - test binding in a null"
|
||||
self.cursor.execute("""
|
||||
select * from TestNumbers
|
||||
where IntCol = :value""",
|
||||
value = None)
|
||||
value=None)
|
||||
self.assertEqual(self.cursor.fetchall(), [])
|
||||
|
||||
def test_2210_BindNumberArrayDirect(self):
|
||||
def test_2210_bind_number_array_direct(self):
|
||||
"2210 - test binding in a number array"
|
||||
returnValue = self.cursor.var(cx_Oracle.NUMBER)
|
||||
array = [r[2] for r in self.rawData]
|
||||
return_value = self.cursor.var(oracledb.NUMBER)
|
||||
array = [r[2] for r in self.raw_data]
|
||||
statement = """
|
||||
begin
|
||||
:returnValue := pkg_TestNumberArrays.TestInArrays(
|
||||
:startValue, :array);
|
||||
:return_value := pkg_TestNumberArrays.TestInArrays(
|
||||
:start_value, :array);
|
||||
end;"""
|
||||
self.cursor.execute(statement,
|
||||
returnValue = returnValue,
|
||||
startValue = 5,
|
||||
array = array)
|
||||
self.assertEqual(returnValue.getvalue(), 73.75)
|
||||
self.cursor.execute(statement, return_value=return_value,
|
||||
start_value=5, array=array)
|
||||
self.assertEqual(return_value.getvalue(), 73.75)
|
||||
array = list(range(15))
|
||||
self.cursor.execute(statement,
|
||||
startValue = 10,
|
||||
array = array)
|
||||
self.assertEqual(returnValue.getvalue(), 115.0)
|
||||
self.cursor.execute(statement, start_value=10, array=array)
|
||||
self.assertEqual(return_value.getvalue(), 115.0)
|
||||
|
||||
def test_2211_BindNumberArrayBySizes(self):
|
||||
def test_2211_bind_number_array_by_sizes(self):
|
||||
"2211 - test binding in a number array (with setinputsizes)"
|
||||
returnValue = self.cursor.var(cx_Oracle.NUMBER)
|
||||
self.cursor.setinputsizes(array = [cx_Oracle.NUMBER, 10])
|
||||
array = [r[2] for r in self.rawData]
|
||||
return_value = self.cursor.var(oracledb.NUMBER)
|
||||
self.cursor.setinputsizes(array = [oracledb.NUMBER, 10])
|
||||
array = [r[2] for r in self.raw_data]
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:returnValue := pkg_TestNumberArrays.TestInArrays(
|
||||
:startValue, :array);
|
||||
:return_value := pkg_TestNumberArrays.TestInArrays(
|
||||
:start_value, :array);
|
||||
end;""",
|
||||
returnValue = returnValue,
|
||||
startValue = 6,
|
||||
array = array)
|
||||
self.assertEqual(returnValue.getvalue(), 74.75)
|
||||
return_value=return_value,
|
||||
start_value=6,
|
||||
array=array)
|
||||
self.assertEqual(return_value.getvalue(), 74.75)
|
||||
|
||||
def test_2212_BindNumberArrayByVar(self):
|
||||
def test_2212_bind_number_array_by_var(self):
|
||||
"2212 - test binding in a number array (with arrayvar)"
|
||||
returnValue = self.cursor.var(cx_Oracle.NUMBER)
|
||||
array = self.cursor.arrayvar(cx_Oracle.NUMBER,
|
||||
[r[2] for r in self.rawData])
|
||||
return_value = self.cursor.var(oracledb.NUMBER)
|
||||
array = self.cursor.arrayvar(oracledb.NUMBER,
|
||||
[r[2] for r in self.raw_data])
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:returnValue := pkg_TestNumberArrays.TestInArrays(
|
||||
:integerValue, :array);
|
||||
:return_value := pkg_TestNumberArrays.TestInArrays(
|
||||
:integer_value, :array);
|
||||
end;""",
|
||||
returnValue = returnValue,
|
||||
integerValue = 7,
|
||||
return_value = return_value,
|
||||
integer_value = 7,
|
||||
array = array)
|
||||
self.assertEqual(returnValue.getvalue(), 75.75)
|
||||
self.assertEqual(return_value.getvalue(), 75.75)
|
||||
|
||||
def test_2213_BindZeroLengthNumberArrayByVar(self):
|
||||
def test_2213_bind_zero_length_number_array_by_var(self):
|
||||
"2213 - test binding in a zero length number array (with arrayvar)"
|
||||
returnValue = self.cursor.var(cx_Oracle.NUMBER)
|
||||
array = self.cursor.arrayvar(cx_Oracle.NUMBER, 0)
|
||||
return_value = self.cursor.var(oracledb.NUMBER)
|
||||
array = self.cursor.arrayvar(oracledb.NUMBER, 0)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:returnValue := pkg_TestNumberArrays.TestInArrays(
|
||||
:integerValue, :array);
|
||||
:return_value := pkg_TestNumberArrays.TestInArrays(
|
||||
:integer_value, :array);
|
||||
end;""",
|
||||
returnValue = returnValue,
|
||||
integerValue = 8,
|
||||
array = array)
|
||||
self.assertEqual(returnValue.getvalue(), 8.0)
|
||||
return_value=return_value,
|
||||
integer_value=8,
|
||||
array=array)
|
||||
self.assertEqual(return_value.getvalue(), 8.0)
|
||||
self.assertEqual(array.getvalue(), [])
|
||||
|
||||
def test_2214_BindInOutNumberArrayByVar(self):
|
||||
def test_2214_bind_in_out_number_array_by_var(self):
|
||||
"2214 - test binding in/out a number array (with arrayvar)"
|
||||
array = self.cursor.arrayvar(cx_Oracle.NUMBER, 10)
|
||||
originalData = [r[2] for r in self.rawData]
|
||||
expectedData = [originalData[i - 1] * 10 for i in range(1, 6)] + \
|
||||
originalData[5:]
|
||||
array.setvalue(0, originalData)
|
||||
array = self.cursor.arrayvar(oracledb.NUMBER, 10)
|
||||
original_data = [r[2] for r in self.raw_data]
|
||||
expected_data = [original_data[i - 1] * 10 for i in range(1, 6)] + \
|
||||
original_data[5:]
|
||||
array.setvalue(0, original_data)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
pkg_TestNumberArrays.TestInOutArrays(:numElems, :array);
|
||||
pkg_TestNumberArrays.TestInOutArrays(:num_elems, :array);
|
||||
end;""",
|
||||
numElems = 5,
|
||||
array = array)
|
||||
self.assertEqual(array.getvalue(), expectedData)
|
||||
num_elems=5,
|
||||
array=array)
|
||||
self.assertEqual(array.getvalue(), expected_data)
|
||||
|
||||
def test_2215_BindOutNumberArrayByVar(self):
|
||||
def test_2215_bind_out_number_array_by_var(self):
|
||||
"2215 - test binding out a Number array (with arrayvar)"
|
||||
array = self.cursor.arrayvar(cx_Oracle.NUMBER, 6)
|
||||
expectedData = [i * 100 for i in range(1, 7)]
|
||||
array = self.cursor.arrayvar(oracledb.NUMBER, 6)
|
||||
expected_data = [i * 100 for i in range(1, 7)]
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
pkg_TestNumberArrays.TestOutArrays(:numElems, :array);
|
||||
pkg_TestNumberArrays.TestOutArrays(:num_elems, :array);
|
||||
end;""",
|
||||
numElems = 6,
|
||||
array = array)
|
||||
self.assertEqual(array.getvalue(), expectedData)
|
||||
num_elems=6,
|
||||
array=array)
|
||||
self.assertEqual(array.getvalue(), expected_data)
|
||||
|
||||
def test_2216_BindOutSetInputSizes(self):
|
||||
def test_2216_bind_out_set_input_sizes(self):
|
||||
"2216 - test binding out with set input sizes defined"
|
||||
vars = self.cursor.setinputsizes(value = cx_Oracle.NUMBER)
|
||||
bind_vars = self.cursor.setinputsizes(value = oracledb.NUMBER)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:value := 5;
|
||||
end;""")
|
||||
self.assertEqual(vars["value"].getvalue(), 5)
|
||||
self.assertEqual(bind_vars["value"].getvalue(), 5)
|
||||
|
||||
def test_2217_BindInOutSetInputSizes(self):
|
||||
def test_2217_bind_in_out_set_input_sizes(self):
|
||||
"2217 - test binding in/out with set input sizes defined"
|
||||
vars = self.cursor.setinputsizes(value = cx_Oracle.NUMBER)
|
||||
bind_vars = self.cursor.setinputsizes(value = oracledb.NUMBER)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:value := :value + 5;
|
||||
end;""",
|
||||
value = 1.25)
|
||||
self.assertEqual(vars["value"].getvalue(), 6.25)
|
||||
self.assertEqual(bind_vars["value"].getvalue(), 6.25)
|
||||
|
||||
def test_2218_BindOutVar(self):
|
||||
def test_2218_bind_out_var(self):
|
||||
"2218 - test binding out with cursor.var() method"
|
||||
var = self.cursor.var(cx_Oracle.NUMBER)
|
||||
var = self.cursor.var(oracledb.NUMBER)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:value := 5;
|
||||
|
@ -260,9 +258,9 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
value = var)
|
||||
self.assertEqual(var.getvalue(), 5)
|
||||
|
||||
def test_2219_BindInOutVarDirectSet(self):
|
||||
def test_2219_bind_in_out_var_direct_set(self):
|
||||
"2219 - test binding in/out with cursor.var() method"
|
||||
var = self.cursor.var(cx_Oracle.NUMBER)
|
||||
var = self.cursor.var(oracledb.NUMBER)
|
||||
var.setvalue(0, 2.25)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
|
@ -271,47 +269,47 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
value = var)
|
||||
self.assertEqual(var.getvalue(), 7.25)
|
||||
|
||||
def test_2220_CursorDescription(self):
|
||||
def test_2220_cursor_description(self):
|
||||
"2220 - test cursor description is accurate"
|
||||
self.cursor.execute("select * from TestNumbers")
|
||||
self.assertEqual(self.cursor.description,
|
||||
[ ('INTCOL', cx_Oracle.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
|
||||
('LONGINTCOL', cx_Oracle.DB_TYPE_NUMBER, 17, None, 16, 0, 0),
|
||||
('NUMBERCOL', cx_Oracle.DB_TYPE_NUMBER, 13, None, 9, 2, 0),
|
||||
('FLOATCOL', cx_Oracle.DB_TYPE_NUMBER, 127, None, 126, -127,
|
||||
0),
|
||||
('UNCONSTRAINEDCOL', cx_Oracle.DB_TYPE_NUMBER, 127, None, 0,
|
||||
-127, 0),
|
||||
('NULLABLECOL', cx_Oracle.DB_TYPE_NUMBER, 39, None, 38, 0,
|
||||
1) ])
|
||||
expected_value = [
|
||||
('INTCOL', oracledb.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
|
||||
('LONGINTCOL', oracledb.DB_TYPE_NUMBER, 17, None, 16, 0, 0),
|
||||
('NUMBERCOL', oracledb.DB_TYPE_NUMBER, 13, None, 9, 2, 0),
|
||||
('FLOATCOL', oracledb.DB_TYPE_NUMBER, 127, None, 126, -127, 0),
|
||||
('UNCONSTRAINEDCOL', oracledb.DB_TYPE_NUMBER, 127, None, 0, -127,
|
||||
0),
|
||||
('NULLABLECOL', oracledb.DB_TYPE_NUMBER, 39, None, 38, 0, 1)
|
||||
]
|
||||
self.assertEqual(self.cursor.description, expected_value)
|
||||
|
||||
def test_2221_FetchAll(self):
|
||||
def test_2221_fetchall(self):
|
||||
"2221 - test that fetching all of the data returns the correct results"
|
||||
self.cursor.execute("select * From TestNumbers order by IntCol")
|
||||
self.assertEqual(self.cursor.fetchall(), self.rawData)
|
||||
self.assertEqual(self.cursor.fetchall(), self.raw_data)
|
||||
self.assertEqual(self.cursor.fetchall(), [])
|
||||
|
||||
def test_2222_FetchMany(self):
|
||||
def test_2222_fetchmany(self):
|
||||
"2222 - test that fetching data in chunks returns the correct results"
|
||||
self.cursor.execute("select * From TestNumbers order by IntCol")
|
||||
self.assertEqual(self.cursor.fetchmany(3), self.rawData[0:3])
|
||||
self.assertEqual(self.cursor.fetchmany(2), self.rawData[3:5])
|
||||
self.assertEqual(self.cursor.fetchmany(4), self.rawData[5:9])
|
||||
self.assertEqual(self.cursor.fetchmany(3), self.rawData[9:])
|
||||
self.assertEqual(self.cursor.fetchmany(3), self.raw_data[0:3])
|
||||
self.assertEqual(self.cursor.fetchmany(2), self.raw_data[3:5])
|
||||
self.assertEqual(self.cursor.fetchmany(4), self.raw_data[5:9])
|
||||
self.assertEqual(self.cursor.fetchmany(3), self.raw_data[9:])
|
||||
self.assertEqual(self.cursor.fetchmany(3), [])
|
||||
|
||||
def test_2223_FetchOne(self):
|
||||
def test_2223_fetchone(self):
|
||||
"2223 - test that fetching a single row returns the correct results"
|
||||
self.cursor.execute("""
|
||||
select *
|
||||
from TestNumbers
|
||||
where IntCol in (3, 4)
|
||||
order by IntCol""")
|
||||
self.assertEqual(self.cursor.fetchone(), self.dataByKey[3])
|
||||
self.assertEqual(self.cursor.fetchone(), self.dataByKey[4])
|
||||
self.assertEqual(self.cursor.fetchone(), self.data_by_key[3])
|
||||
self.assertEqual(self.cursor.fetchone(), self.data_by_key[4])
|
||||
self.assertEqual(self.cursor.fetchone(), None)
|
||||
|
||||
def test_2224_ReturnAsLong(self):
|
||||
def test_2224_return_as_long(self):
|
||||
"2224 - test that fetching a long integer returns such in Python"
|
||||
self.cursor.execute("""
|
||||
select NullableCol
|
||||
|
@ -320,49 +318,48 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
col, = self.cursor.fetchone()
|
||||
self.assertEqual(col, 25004854810776297743)
|
||||
|
||||
def test_2225_ReturnConstantFloat(self):
|
||||
def test_2225_return_constant_float(self):
|
||||
"2225 - test fetching a floating point number returns such in Python"
|
||||
self.cursor.execute("select 1.25 from dual")
|
||||
result, = self.cursor.fetchone()
|
||||
self.assertEqual(result, 1.25)
|
||||
|
||||
def test_2226_ReturnConstantInteger(self):
|
||||
def test_2226_return_constant_integer(self):
|
||||
"2226 - test that fetching an integer returns such in Python"
|
||||
self.cursor.execute("select 148 from dual")
|
||||
result, = self.cursor.fetchone()
|
||||
self.assertEqual(result, 148)
|
||||
self.assertTrue(isinstance(result, int), "integer not returned")
|
||||
|
||||
def test_2227_AcceptableBoundaryNumbers(self):
|
||||
def test_2227_acceptable_boundary_numbers(self):
|
||||
"2227 - test that acceptable boundary numbers are handled properly"
|
||||
inValues = [decimal.Decimal("9.99999999999999e+125"),
|
||||
decimal.Decimal("-9.99999999999999e+125"), 0.0, 1e-130,
|
||||
-1e-130]
|
||||
outValues = [int("9" * 15 + "0" * 111), -int("9" * 15 + "0" * 111),
|
||||
0, 1e-130, -1e-130]
|
||||
for inValue, outValue in zip(inValues, outValues):
|
||||
self.cursor.execute("select :1 from dual", (inValue,))
|
||||
in_values = [decimal.Decimal("9.99999999999999e+125"),
|
||||
decimal.Decimal("-9.99999999999999e+125"), 0.0, 1e-130,
|
||||
-1e-130]
|
||||
out_values = [int("9" * 15 + "0" * 111), -int("9" * 15 + "0" * 111),
|
||||
0, 1e-130, -1e-130]
|
||||
for in_value, out_value in zip(in_values, out_values):
|
||||
self.cursor.execute("select :1 from dual", (in_value,))
|
||||
result, = self.cursor.fetchone()
|
||||
self.assertEqual(result, outValue)
|
||||
self.assertEqual(result, out_value)
|
||||
|
||||
def test_2228_UnacceptableBoundaryNumbers(self):
|
||||
def test_2228_unacceptable_boundary_numbers(self):
|
||||
"2228 - test that unacceptable boundary numbers are rejected"
|
||||
inValues = [1e126, -1e126, float("inf"), float("-inf"),
|
||||
float("NaN"), decimal.Decimal("1e126"),
|
||||
decimal.Decimal("-1e126"), decimal.Decimal("inf"),
|
||||
decimal.Decimal("-inf"), decimal.Decimal("NaN")]
|
||||
noRepErr = "DPI-1044: value cannot be represented as an Oracle number"
|
||||
invalidErr = ""
|
||||
expectedErrors = [noRepErr, noRepErr, invalidErr, invalidErr,
|
||||
invalidErr, noRepErr, noRepErr, invalidErr, invalidErr,
|
||||
invalidErr]
|
||||
for inValue, error in zip(inValues, expectedErrors):
|
||||
method = self.assertRaisesRegex if sys.version_info[0] == 3 \
|
||||
else self.assertRaisesRegexp
|
||||
method(cx_Oracle.DatabaseError, error, self.cursor.execute,
|
||||
"select :1 from dual", (inValue,))
|
||||
in_values = [1e126, -1e126, float("inf"), float("-inf"),
|
||||
float("NaN"), decimal.Decimal("1e126"),
|
||||
decimal.Decimal("-1e126"), decimal.Decimal("inf"),
|
||||
decimal.Decimal("-inf"), decimal.Decimal("NaN")]
|
||||
no_rep_err = "value cannot be represented as an Oracle number"
|
||||
invalid_err = "invalid number"
|
||||
expected_errors = [no_rep_err, no_rep_err, invalid_err, invalid_err,
|
||||
invalid_err, no_rep_err, no_rep_err, invalid_err,
|
||||
invalid_err, invalid_err]
|
||||
for in_value, error in zip(in_values, expected_errors):
|
||||
self.assertRaisesRegex(oracledb.DatabaseError, error,
|
||||
self.cursor.execute, "select :1 from dual",
|
||||
(in_value,))
|
||||
|
||||
def test_2229_ReturnFloatFromDivision(self):
|
||||
def test_2229_return_float_from_division(self):
|
||||
"2229 - test that fetching the result of division returns a float"
|
||||
self.cursor.execute("""
|
||||
select IntCol / 7
|
||||
|
@ -372,41 +369,42 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
self.assertEqual(result, 1.0 / 7.0)
|
||||
self.assertTrue(isinstance(result, float), "float not returned")
|
||||
|
||||
def test_2230_StringFormat(self):
|
||||
def test_2230_string_format(self):
|
||||
"2230 - test that string format is returned properly"
|
||||
var = self.cursor.var(cx_Oracle.NUMBER)
|
||||
var = self.cursor.var(oracledb.NUMBER)
|
||||
self.assertEqual(str(var),
|
||||
"<cx_Oracle.Var of type DB_TYPE_NUMBER with value None>")
|
||||
var.setvalue(0, 4)
|
||||
self.assertEqual(str(var),
|
||||
"<cx_Oracle.Var of type DB_TYPE_NUMBER with value 4.0>")
|
||||
|
||||
def test_2231_BindNativeFloat(self):
|
||||
"2231 - test that binding native float is possible"
|
||||
self.cursor.setinputsizes(cx_Oracle.DB_TYPE_BINARY_DOUBLE)
|
||||
self.cursor.execute("select :1 from dual", (5,))
|
||||
def test_2231_bind_binary_double(self):
|
||||
"2231 - test that binding binary double is possible"
|
||||
statement = "select :1 from dual"
|
||||
self.cursor.setinputsizes(oracledb.DB_TYPE_BINARY_DOUBLE)
|
||||
self.cursor.execute(statement, (5,))
|
||||
self.assertEqual(self.cursor.bindvars[0].type,
|
||||
cx_Oracle.DB_TYPE_BINARY_DOUBLE)
|
||||
oracledb.DB_TYPE_BINARY_DOUBLE)
|
||||
value, = self.cursor.fetchone()
|
||||
self.assertEqual(value, 5)
|
||||
self.cursor.execute("select :1 from dual", (1.5,))
|
||||
self.cursor.execute(statement, (1.5,))
|
||||
self.assertEqual(self.cursor.bindvars[0].type,
|
||||
cx_Oracle.DB_TYPE_BINARY_DOUBLE)
|
||||
oracledb.DB_TYPE_BINARY_DOUBLE)
|
||||
value, = self.cursor.fetchone()
|
||||
self.assertEqual(value, 1.5)
|
||||
self.cursor.execute("select :1 from dual", (decimal.Decimal("NaN"),))
|
||||
self.cursor.execute(statement, (decimal.Decimal("NaN"),))
|
||||
self.assertEqual(self.cursor.bindvars[0].type,
|
||||
cx_Oracle.DB_TYPE_BINARY_DOUBLE)
|
||||
oracledb.DB_TYPE_BINARY_DOUBLE)
|
||||
value, = self.cursor.fetchone()
|
||||
self.assertEqual(str(value), str(float("NaN")))
|
||||
|
||||
def test_2232_FetchNativeInt(self):
|
||||
"2232 - test fetching numbers as native integers"
|
||||
self.cursor.outputtypehandler = self.outputTypeHandlerNativeInt
|
||||
def test_2232_fetch_binary_int(self):
|
||||
"2232 - test fetching numbers as binary integers"
|
||||
self.cursor.outputtypehandler = self.output_type_handler_binary_int
|
||||
for value in (1, 2 ** 31, 2 ** 63 - 1, -1, -2 ** 31, -2 ** 63 + 1):
|
||||
self.cursor.execute("select :1 from dual", [str(value)])
|
||||
fetchedValue, = self.cursor.fetchone()
|
||||
self.assertEqual(value, fetchedValue)
|
||||
fetched_value, = self.cursor.fetchone()
|
||||
self.assertEqual(value, fetched_value)
|
||||
|
||||
if __name__ == "__main__":
|
||||
TestEnv.RunTestCases()
|
||||
base.run_test_cases()
|
||||
|
|
|
@ -11,110 +11,108 @@
|
|||
2300 - Module for testing object variables
|
||||
"""
|
||||
|
||||
import TestEnv
|
||||
import base
|
||||
|
||||
import cx_Oracle
|
||||
import cx_Oracle as oracledb
|
||||
import datetime
|
||||
import decimal
|
||||
|
||||
class TestCase(TestEnv.BaseTestCase):
|
||||
class TestCase(base.BaseTestCase):
|
||||
|
||||
def __GetObjectAsTuple(self, obj):
|
||||
def __get_object_as_tuple(self, obj):
|
||||
if obj.type.iscollection:
|
||||
value = []
|
||||
for v in obj.aslist():
|
||||
if isinstance(v, cx_Oracle.Object):
|
||||
v = self.__GetObjectAsTuple(v)
|
||||
elif isinstance(value, cx_Oracle.LOB):
|
||||
if isinstance(v, oracledb.Object):
|
||||
v = self.__get_object_as_tuple(v)
|
||||
elif isinstance(value, oracledb.LOB):
|
||||
v = v.read()
|
||||
value.append(v)
|
||||
return value
|
||||
attributeValues = []
|
||||
attribute_values = []
|
||||
for attribute in obj.type.attributes:
|
||||
value = getattr(obj, attribute.name)
|
||||
if isinstance(value, cx_Oracle.Object):
|
||||
value = self.__GetObjectAsTuple(value)
|
||||
elif isinstance(value, cx_Oracle.LOB):
|
||||
if isinstance(value, oracledb.Object):
|
||||
value = self.__get_object_as_tuple(value)
|
||||
elif isinstance(value, oracledb.LOB):
|
||||
value = value.read()
|
||||
attributeValues.append(value)
|
||||
return tuple(attributeValues)
|
||||
attribute_values.append(value)
|
||||
return tuple(attribute_values)
|
||||
|
||||
def __TestData(self, expectedIntValue, expectedObjectValue,
|
||||
expectedArrayValue):
|
||||
intValue, objectValue, arrayValue = self.cursor.fetchone()
|
||||
if objectValue is not None:
|
||||
objectValue = self.__GetObjectAsTuple(objectValue)
|
||||
if arrayValue is not None:
|
||||
arrayValue = arrayValue.aslist()
|
||||
self.assertEqual(intValue, expectedIntValue)
|
||||
self.assertEqual(objectValue, expectedObjectValue)
|
||||
self.assertEqual(arrayValue, expectedArrayValue)
|
||||
def __test_data(self, expected_int_value, expected_obj_value,
|
||||
expected_array_value):
|
||||
int_value, object_value, array_value = self.cursor.fetchone()
|
||||
if object_value is not None:
|
||||
object_value = self.__get_object_as_tuple(object_value)
|
||||
if array_value is not None:
|
||||
array_value = array_value.aslist()
|
||||
self.assertEqual(int_value, expected_int_value)
|
||||
self.assertEqual(object_value, expected_obj_value)
|
||||
self.assertEqual(array_value, expected_array_value)
|
||||
|
||||
def test_2300_BindNullIn(self):
|
||||
def test_2300_bind_null_in(self):
|
||||
"2300 - test binding a null value (IN)"
|
||||
var = self.cursor.var(cx_Oracle.DB_TYPE_OBJECT,
|
||||
typename = "UDT_OBJECT")
|
||||
var = self.cursor.var(oracledb.DB_TYPE_OBJECT, typename="UDT_OBJECT")
|
||||
result = self.cursor.callfunc("pkg_TestBindObject.GetStringRep", str,
|
||||
(var,))
|
||||
(var,))
|
||||
self.assertEqual(result, "null")
|
||||
|
||||
def test_2301_BindObjectIn(self):
|
||||
def test_2301_bind_object_in(self):
|
||||
"2301 - test binding an object (IN)"
|
||||
typeObj = self.connection.gettype("UDT_OBJECT")
|
||||
obj = typeObj.newobject()
|
||||
type_obj = self.connection.gettype("UDT_OBJECT")
|
||||
obj = type_obj.newobject()
|
||||
obj.NUMBERVALUE = 13
|
||||
obj.STRINGVALUE = "Test String"
|
||||
result = self.cursor.callfunc("pkg_TestBindObject.GetStringRep", str,
|
||||
(obj,))
|
||||
self.assertEqual(result,
|
||||
"udt_Object(13, 'Test String', null, null, null, null, null)")
|
||||
(obj,))
|
||||
exp = "udt_Object(13, 'Test String', null, null, null, null, null)"
|
||||
self.assertEqual(result, exp)
|
||||
obj.NUMBERVALUE = None
|
||||
obj.STRINGVALUE = "Test With Dates"
|
||||
obj.DATEVALUE = datetime.datetime(2016, 2, 10)
|
||||
obj.TIMESTAMPVALUE = datetime.datetime(2016, 2, 10, 14, 13, 50)
|
||||
result = self.cursor.callfunc("pkg_TestBindObject.GetStringRep", str,
|
||||
(obj,))
|
||||
(obj,))
|
||||
self.assertEqual(result,
|
||||
"udt_Object(null, 'Test With Dates', null, " \
|
||||
"to_date('2016-02-10', 'YYYY-MM-DD'), " \
|
||||
"to_timestamp('2016-02-10 14:13:50', " \
|
||||
"'YYYY-MM-DD HH24:MI:SS'), " \
|
||||
"null, null)")
|
||||
"udt_Object(null, 'Test With Dates', null, " \
|
||||
"to_date('2016-02-10', 'YYYY-MM-DD'), " \
|
||||
"to_timestamp('2016-02-10 14:13:50', " \
|
||||
"'YYYY-MM-DD HH24:MI:SS'), " \
|
||||
"null, null)")
|
||||
obj.DATEVALUE = None
|
||||
obj.TIMESTAMPVALUE = None
|
||||
subTypeObj = self.connection.gettype("UDT_SUBOBJECT")
|
||||
subObj = subTypeObj.newobject()
|
||||
subObj.SUBNUMBERVALUE = decimal.Decimal("18.25")
|
||||
subObj.SUBSTRINGVALUE = "Sub String"
|
||||
obj.SUBOBJECTVALUE = subObj
|
||||
sub_type_obj = self.connection.gettype("UDT_SUBOBJECT")
|
||||
sub_obj = sub_type_obj.newobject()
|
||||
sub_obj.SUBNUMBERVALUE = decimal.Decimal("18.25")
|
||||
sub_obj.SUBSTRINGVALUE = "Sub String"
|
||||
obj.SUBOBJECTVALUE = sub_obj
|
||||
result = self.cursor.callfunc("pkg_TestBindObject.GetStringRep", str,
|
||||
(obj,))
|
||||
(obj,))
|
||||
self.assertEqual(result,
|
||||
"udt_Object(null, 'Test With Dates', null, null, null, " \
|
||||
"udt_SubObject(18.25, 'Sub String'), null)")
|
||||
"udt_Object(null, 'Test With Dates', null, null, " \
|
||||
"null, udt_SubObject(18.25, 'Sub String'), null)")
|
||||
|
||||
def test_2302_CopyObject(self):
|
||||
def test_2302_copy_object(self):
|
||||
"2302 - test copying an object"
|
||||
typeObj = self.connection.gettype("UDT_OBJECT")
|
||||
obj = typeObj()
|
||||
type_obj = self.connection.gettype("UDT_OBJECT")
|
||||
obj = type_obj()
|
||||
obj.NUMBERVALUE = 5124
|
||||
obj.STRINGVALUE = "A test string"
|
||||
obj.DATEVALUE = datetime.datetime(2016, 2, 24)
|
||||
obj.TIMESTAMPVALUE = datetime.datetime(2016, 2, 24, 13, 39, 10)
|
||||
copiedObj = obj.copy()
|
||||
self.assertEqual(obj.NUMBERVALUE, copiedObj.NUMBERVALUE)
|
||||
self.assertEqual(obj.STRINGVALUE, copiedObj.STRINGVALUE)
|
||||
self.assertEqual(obj.DATEVALUE, copiedObj.DATEVALUE)
|
||||
self.assertEqual(obj.TIMESTAMPVALUE, copiedObj.TIMESTAMPVALUE)
|
||||
copied_obj = obj.copy()
|
||||
self.assertEqual(obj.NUMBERVALUE, copied_obj.NUMBERVALUE)
|
||||
self.assertEqual(obj.STRINGVALUE, copied_obj.STRINGVALUE)
|
||||
self.assertEqual(obj.DATEVALUE, copied_obj.DATEVALUE)
|
||||
self.assertEqual(obj.TIMESTAMPVALUE, copied_obj.TIMESTAMPVALUE)
|
||||
|
||||
def test_2303_EmptyCollectionAsList(self):
|
||||
def test_2303_empty_collection_as_list(self):
|
||||
"2303 - test getting an empty collection as a list"
|
||||
typeName = "UDT_ARRAY"
|
||||
typeObj = self.connection.gettype(typeName)
|
||||
obj = typeObj.newobject()
|
||||
type_obj = self.connection.gettype("UDT_ARRAY")
|
||||
obj = type_obj.newobject()
|
||||
self.assertEqual(obj.aslist(), [])
|
||||
|
||||
def test_2304_FetchData(self):
|
||||
def test_2304_fetch_data(self):
|
||||
"2304 - test fetching objects"
|
||||
self.cursor.execute("alter session set time_zone = 'UTC'")
|
||||
self.cursor.execute("""
|
||||
|
@ -124,95 +122,156 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
ArrayCol
|
||||
from TestObjects
|
||||
order by IntCol""")
|
||||
self.assertEqual(self.cursor.description,
|
||||
[ ('INTCOL', cx_Oracle.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
|
||||
('OBJECTCOL', cx_Oracle.DB_TYPE_OBJECT, None, None, None,
|
||||
None, 1),
|
||||
('ARRAYCOL', cx_Oracle.DB_TYPE_OBJECT, None, None, None,
|
||||
None, 1) ])
|
||||
self.__TestData(1, (1, 'First row', 'First ', 'N First Row',
|
||||
'N First ', b'Raw Data 1', 2, 5, 12.125, 0.5, 12.5, 25.25,
|
||||
50.125, cx_Oracle.Timestamp(2007, 3, 6, 0, 0, 0),
|
||||
cx_Oracle.Timestamp(2008, 9, 12, 16, 40),
|
||||
cx_Oracle.Timestamp(2009, 10, 13, 17, 50),
|
||||
cx_Oracle.Timestamp(2010, 11, 14, 18, 55),
|
||||
'Short CLOB value', 'Short NCLOB Value', b'Short BLOB value',
|
||||
(11, 'Sub object 1'),
|
||||
[(5, 'first element'), (6, 'second element')]),
|
||||
[5, 10, None, 20])
|
||||
self.__TestData(2, None, [3, None, 9, 12, 15])
|
||||
self.__TestData(3, (3, 'Third row', 'Third ', 'N Third Row',
|
||||
'N Third ', b'Raw Data 3', 4, 10, 6.5, 0.75, 43.25, 86.5,
|
||||
192.125, cx_Oracle.Timestamp(2007, 6, 21, 0, 0, 0),
|
||||
cx_Oracle.Timestamp(2007, 12, 13, 7, 30, 45),
|
||||
cx_Oracle.Timestamp(2017, 6, 21, 23, 18, 45),
|
||||
cx_Oracle.Timestamp(2017, 7, 21, 8, 27, 13),
|
||||
'Another short CLOB value', 'Another short NCLOB Value',
|
||||
b'Yet another short BLOB value',
|
||||
(13, 'Sub object 3'),
|
||||
[(10, 'element #1'), (20, 'element #2'),
|
||||
(30, 'element #3'), (40, 'element #4')]), None)
|
||||
expected_value = [
|
||||
('INTCOL', oracledb.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
|
||||
('OBJECTCOL', oracledb.DB_TYPE_OBJECT, None, None, None, None, 1),
|
||||
('ARRAYCOL', oracledb.DB_TYPE_OBJECT, None, None, None, None, 1)
|
||||
]
|
||||
self.assertEqual(self.cursor.description, expected_value)
|
||||
expected_value = (
|
||||
1,
|
||||
'First row',
|
||||
'First ',
|
||||
'N First Row',
|
||||
'N First ',
|
||||
b'Raw Data 1',
|
||||
2,
|
||||
5,
|
||||
12.125,
|
||||
0.5,
|
||||
12.5,
|
||||
25.25,
|
||||
50.125,
|
||||
oracledb.Timestamp(2007, 3, 6, 0, 0, 0),
|
||||
oracledb.Timestamp(2008, 9, 12, 16, 40),
|
||||
oracledb.Timestamp(2009, 10, 13, 17, 50),
|
||||
oracledb.Timestamp(2010, 11, 14, 18, 55),
|
||||
'Short CLOB value',
|
||||
'Short NCLOB Value',
|
||||
b'Short BLOB value',
|
||||
(11, 'Sub object 1'),
|
||||
[(5, 'first element'), (6, 'second element')]
|
||||
)
|
||||
self.__test_data(1, expected_value, [5, 10, None, 20])
|
||||
self.__test_data(2, None, [3, None, 9, 12, 15])
|
||||
expected_value = (
|
||||
3,
|
||||
'Third row',
|
||||
'Third ',
|
||||
'N Third Row',
|
||||
'N Third ',
|
||||
b'Raw Data 3',
|
||||
4,
|
||||
10,
|
||||
6.5,
|
||||
0.75,
|
||||
43.25,
|
||||
86.5,
|
||||
192.125,
|
||||
oracledb.Timestamp(2007, 6, 21, 0, 0, 0),
|
||||
oracledb.Timestamp(2007, 12, 13, 7, 30, 45),
|
||||
oracledb.Timestamp(2017, 6, 21, 23, 18, 45),
|
||||
oracledb.Timestamp(2017, 7, 21, 8, 27, 13),
|
||||
'Another short CLOB value',
|
||||
'Another short NCLOB Value',
|
||||
b'Yet another short BLOB value',
|
||||
(13, 'Sub object 3'),
|
||||
[
|
||||
(10, 'element #1'),
|
||||
(20, 'element #2'),
|
||||
(30, 'element #3'),
|
||||
(40, 'element #4')
|
||||
]
|
||||
)
|
||||
self.__test_data(3, expected_value, None)
|
||||
|
||||
def test_2305_GetObjectType(self):
|
||||
def test_2305_get_object_type(self):
|
||||
"2305 - test getting object type"
|
||||
typeObj = self.connection.gettype("UDT_OBJECT")
|
||||
self.assertEqual(typeObj.iscollection, False)
|
||||
self.assertEqual(typeObj.schema, self.connection.username.upper())
|
||||
self.assertEqual(typeObj.name, "UDT_OBJECT")
|
||||
subObjectValueType = self.connection.gettype("UDT_SUBOBJECT")
|
||||
subObjectArrayType = self.connection.gettype("UDT_OBJECTARRAY")
|
||||
expectedAttributeNames = ["NUMBERVALUE", "STRINGVALUE",
|
||||
"FIXEDCHARVALUE", "NSTRINGVALUE", "NFIXEDCHARVALUE",
|
||||
"RAWVALUE", "INTVALUE", "SMALLINTVALUE", "REALVALUE",
|
||||
"DOUBLEPRECISIONVALUE", "FLOATVALUE", "BINARYFLOATVALUE",
|
||||
"BINARYDOUBLEVALUE", "DATEVALUE", "TIMESTAMPVALUE",
|
||||
"TIMESTAMPTZVALUE", "TIMESTAMPLTZVALUE", "CLOBVALUE",
|
||||
"NCLOBVALUE", "BLOBVALUE", "SUBOBJECTVALUE", "SUBOBJECTARRAY"]
|
||||
actualAttributeNames = [a.name for a in typeObj.attributes]
|
||||
self.assertEqual(actualAttributeNames, expectedAttributeNames)
|
||||
expectedAttributeTypes = [cx_Oracle.DB_TYPE_NUMBER,
|
||||
cx_Oracle.DB_TYPE_VARCHAR, cx_Oracle.DB_TYPE_CHAR,
|
||||
cx_Oracle.DB_TYPE_NVARCHAR, cx_Oracle.DB_TYPE_NCHAR,
|
||||
cx_Oracle.DB_TYPE_RAW, cx_Oracle.DB_TYPE_NUMBER,
|
||||
cx_Oracle.DB_TYPE_NUMBER, cx_Oracle.DB_TYPE_NUMBER,
|
||||
cx_Oracle.DB_TYPE_NUMBER, cx_Oracle.DB_TYPE_NUMBER,
|
||||
cx_Oracle.DB_TYPE_BINARY_FLOAT,
|
||||
cx_Oracle.DB_TYPE_BINARY_DOUBLE,
|
||||
cx_Oracle.DB_TYPE_DATE, cx_Oracle.DB_TYPE_TIMESTAMP,
|
||||
cx_Oracle.DB_TYPE_TIMESTAMP_TZ,
|
||||
cx_Oracle.DB_TYPE_TIMESTAMP_LTZ, cx_Oracle.DB_TYPE_CLOB,
|
||||
cx_Oracle.DB_TYPE_NCLOB, cx_Oracle.DB_TYPE_BLOB,
|
||||
subObjectValueType, subObjectArrayType]
|
||||
actualAttributeTypes = [a.type for a in typeObj.attributes]
|
||||
self.assertEqual(actualAttributeTypes, expectedAttributeTypes)
|
||||
self.assertEqual(subObjectArrayType.iscollection, True)
|
||||
self.assertEqual(subObjectArrayType.attributes, [])
|
||||
type_obj = self.connection.gettype("UDT_OBJECT")
|
||||
self.assertEqual(type_obj.iscollection, False)
|
||||
self.assertEqual(type_obj.schema, self.connection.username.upper())
|
||||
self.assertEqual(type_obj.name, "UDT_OBJECT")
|
||||
sub_object_value_type = self.connection.gettype("UDT_SUBOBJECT")
|
||||
sub_object_array_type = self.connection.gettype("UDT_OBJECTARRAY")
|
||||
expected_attr_names = [
|
||||
"NUMBERVALUE",
|
||||
"STRINGVALUE",
|
||||
"FIXEDCHARVALUE",
|
||||
"NSTRINGVALUE",
|
||||
"NFIXEDCHARVALUE",
|
||||
"RAWVALUE",
|
||||
"INTVALUE",
|
||||
"SMALLINTVALUE",
|
||||
"REALVALUE",
|
||||
"DOUBLEPRECISIONVALUE",
|
||||
"FLOATVALUE",
|
||||
"BINARYFLOATVALUE",
|
||||
"BINARYDOUBLEVALUE",
|
||||
"DATEVALUE",
|
||||
"TIMESTAMPVALUE",
|
||||
"TIMESTAMPTZVALUE",
|
||||
"TIMESTAMPLTZVALUE",
|
||||
"CLOBVALUE",
|
||||
"NCLOBVALUE",
|
||||
"BLOBVALUE",
|
||||
"SUBOBJECTVALUE",
|
||||
"SUBOBJECTARRAY"
|
||||
]
|
||||
actual_attr_names = [a.name for a in type_obj.attributes]
|
||||
self.assertEqual(actual_attr_names, expected_attr_names)
|
||||
expected_attr_types = [
|
||||
oracledb.DB_TYPE_NUMBER,
|
||||
oracledb.DB_TYPE_VARCHAR,
|
||||
oracledb.DB_TYPE_CHAR,
|
||||
oracledb.DB_TYPE_NVARCHAR,
|
||||
oracledb.DB_TYPE_NCHAR,
|
||||
oracledb.DB_TYPE_RAW,
|
||||
oracledb.DB_TYPE_NUMBER,
|
||||
oracledb.DB_TYPE_NUMBER,
|
||||
oracledb.DB_TYPE_NUMBER,
|
||||
oracledb.DB_TYPE_NUMBER,
|
||||
oracledb.DB_TYPE_NUMBER,
|
||||
oracledb.DB_TYPE_BINARY_FLOAT,
|
||||
oracledb.DB_TYPE_BINARY_DOUBLE,
|
||||
oracledb.DB_TYPE_DATE,
|
||||
oracledb.DB_TYPE_TIMESTAMP,
|
||||
oracledb.DB_TYPE_TIMESTAMP_TZ,
|
||||
oracledb.DB_TYPE_TIMESTAMP_LTZ,
|
||||
oracledb.DB_TYPE_CLOB,
|
||||
oracledb.DB_TYPE_NCLOB,
|
||||
oracledb.DB_TYPE_BLOB,
|
||||
sub_object_value_type,
|
||||
sub_object_array_type
|
||||
]
|
||||
actual_attr_types = [a.type for a in type_obj.attributes]
|
||||
self.assertEqual(actual_attr_types, expected_attr_types)
|
||||
self.assertEqual(sub_object_array_type.iscollection, True)
|
||||
self.assertEqual(sub_object_array_type.attributes, [])
|
||||
|
||||
def test_2306_ObjectType(self):
|
||||
def test_2306_object_type(self):
|
||||
"2306 - test object type data"
|
||||
self.cursor.execute("""
|
||||
select ObjectCol
|
||||
from TestObjects
|
||||
where ObjectCol is not null
|
||||
and rownum <= 1""")
|
||||
objValue, = self.cursor.fetchone()
|
||||
self.assertEqual(objValue.type.schema,
|
||||
self.connection.username.upper())
|
||||
self.assertEqual(objValue.type.name, "UDT_OBJECT")
|
||||
self.assertEqual(objValue.type.attributes[0].name, "NUMBERVALUE")
|
||||
obj, = self.cursor.fetchone()
|
||||
self.assertEqual(obj.type.schema, self.connection.username.upper())
|
||||
self.assertEqual(obj.type.name, "UDT_OBJECT")
|
||||
self.assertEqual(obj.type.attributes[0].name, "NUMBERVALUE")
|
||||
|
||||
def test_2307_RoundTripObject(self):
|
||||
def test_2307_round_trip_object(self):
|
||||
"2307 - test inserting and then querying object with all data types"
|
||||
self.cursor.execute("alter session set time_zone = 'UTC'")
|
||||
self.cursor.execute("truncate table TestClobs")
|
||||
self.cursor.execute("truncate table TestNClobs")
|
||||
self.cursor.execute("truncate table TestBlobs")
|
||||
self.cursor.execute("insert into TestClobs values " \
|
||||
"(1, 'A short CLOB')")
|
||||
"(1, 'A short CLOB')")
|
||||
self.cursor.execute("insert into TestNClobs values " \
|
||||
"(1, 'A short NCLOB')")
|
||||
"(1, 'A short NCLOB')")
|
||||
self.cursor.execute("insert into TestBlobs values " \
|
||||
"(1, utl_raw.cast_to_raw('A short BLOB'))")
|
||||
"(1, utl_raw.cast_to_raw('A short BLOB'))")
|
||||
self.connection.commit()
|
||||
self.cursor.execute("select CLOBCol from TestClobs")
|
||||
clob, = self.cursor.fetchone()
|
||||
|
@ -220,8 +279,8 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
nclob, = self.cursor.fetchone()
|
||||
self.cursor.execute("select BLOBCol from TestBlobs")
|
||||
blob, = self.cursor.fetchone()
|
||||
typeObj = self.connection.gettype("UDT_OBJECT")
|
||||
obj = typeObj.newobject()
|
||||
type_obj = self.connection.gettype("UDT_OBJECT")
|
||||
obj = type_obj.newobject()
|
||||
obj.NUMBERVALUE = 5
|
||||
obj.STRINGVALUE = "A string"
|
||||
obj.FIXEDCHARVALUE = "Fixed str"
|
||||
|
@ -242,25 +301,42 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
obj.CLOBVALUE = clob
|
||||
obj.NCLOBVALUE = nclob
|
||||
obj.BLOBVALUE = blob
|
||||
subTypeObj = self.connection.gettype("UDT_SUBOBJECT")
|
||||
subObj = subTypeObj.newobject()
|
||||
subObj.SUBNUMBERVALUE = 23
|
||||
subObj.SUBSTRINGVALUE = "Substring value"
|
||||
obj.SUBOBJECTVALUE = subObj
|
||||
sub_type_obj = self.connection.gettype("UDT_SUBOBJECT")
|
||||
sub_obj = sub_type_obj.newobject()
|
||||
sub_obj.SUBNUMBERVALUE = 23
|
||||
sub_obj.SUBSTRINGVALUE = "Substring value"
|
||||
obj.SUBOBJECTVALUE = sub_obj
|
||||
self.cursor.execute("insert into TestObjects (IntCol, ObjectCol) " \
|
||||
"values (4, :obj)", obj = obj)
|
||||
self.cursor.execute("""
|
||||
select IntCol, ObjectCol, ArrayCol
|
||||
from TestObjects
|
||||
where IntCol = 4""")
|
||||
self.__TestData(4, (5, 'A string', 'Fixed str ', 'A NCHAR string',
|
||||
'Fixed N ', b'Raw Value', 27, 13, 184.875, 1.375, 23.75,
|
||||
14.25, 29.1625, cx_Oracle.Timestamp(2017, 5, 9, 0, 0, 0),
|
||||
cx_Oracle.Timestamp(2017, 5, 9, 9, 41, 13),
|
||||
cx_Oracle.Timestamp(1986, 8, 2, 15, 27, 38),
|
||||
cx_Oracle.Timestamp(1999, 11, 12, 23, 5, 2),
|
||||
'A short CLOB', 'A short NCLOB', b'A short BLOB',
|
||||
(23, 'Substring value'), None), None)
|
||||
expected_value = (
|
||||
5,
|
||||
'A string',
|
||||
'Fixed str ',
|
||||
'A NCHAR string',
|
||||
'Fixed N ',
|
||||
b'Raw Value',
|
||||
27,
|
||||
13,
|
||||
184.875,
|
||||
1.375,
|
||||
23.75,
|
||||
14.25,
|
||||
29.1625,
|
||||
oracledb.Timestamp(2017, 5, 9, 0, 0, 0),
|
||||
oracledb.Timestamp(2017, 5, 9, 9, 41, 13),
|
||||
oracledb.Timestamp(1986, 8, 2, 15, 27, 38),
|
||||
oracledb.Timestamp(1999, 11, 12, 23, 5, 2),
|
||||
'A short CLOB',
|
||||
'A short NCLOB',
|
||||
b'A short BLOB',
|
||||
(23, 'Substring value'),
|
||||
None
|
||||
)
|
||||
self.__test_data(4, expected_value, None)
|
||||
obj.CLOBVALUE = "A short CLOB (modified)"
|
||||
obj.NCLOBVALUE = "A short NCLOB (modified)"
|
||||
obj.BLOBVALUE = "A short BLOB (modified)"
|
||||
|
@ -270,106 +346,121 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
select IntCol, ObjectCol, ArrayCol
|
||||
from TestObjects
|
||||
where IntCol = 5""")
|
||||
self.__TestData(5, (5, 'A string', 'Fixed str ', 'A NCHAR string',
|
||||
'Fixed N ', b'Raw Value', 27, 13, 184.875, 1.375, 23.75,
|
||||
14.25, 29.1625, cx_Oracle.Timestamp(2017, 5, 9, 0, 0, 0),
|
||||
cx_Oracle.Timestamp(2017, 5, 9, 9, 41, 13),
|
||||
cx_Oracle.Timestamp(1986, 8, 2, 15, 27, 38),
|
||||
cx_Oracle.Timestamp(1999, 11, 12, 23, 5, 2),
|
||||
'A short CLOB (modified)', 'A short NCLOB (modified)',
|
||||
b'A short BLOB (modified)',
|
||||
(23, 'Substring value'), None), None)
|
||||
expected_value = (
|
||||
5,
|
||||
'A string',
|
||||
'Fixed str ',
|
||||
'A NCHAR string',
|
||||
'Fixed N ',
|
||||
b'Raw Value',
|
||||
27,
|
||||
13,
|
||||
184.875,
|
||||
1.375,
|
||||
23.75,
|
||||
14.25,
|
||||
29.1625,
|
||||
oracledb.Timestamp(2017, 5, 9, 0, 0, 0),
|
||||
oracledb.Timestamp(2017, 5, 9, 9, 41, 13),
|
||||
oracledb.Timestamp(1986, 8, 2, 15, 27, 38),
|
||||
oracledb.Timestamp(1999, 11, 12, 23, 5, 2),
|
||||
'A short CLOB (modified)',
|
||||
'A short NCLOB (modified)',
|
||||
b'A short BLOB (modified)',
|
||||
(23, 'Substring value'),
|
||||
None
|
||||
)
|
||||
self.__test_data(5, expected_value, None)
|
||||
self.connection.rollback()
|
||||
|
||||
def test_2308_InvalidTypeObject(self):
|
||||
def test_2308_invalid_type_object(self):
|
||||
"2308 - test trying to find an object type that does not exist"
|
||||
self.assertRaises(cx_Oracle.DatabaseError, self.connection.gettype,
|
||||
"A TYPE THAT DOES NOT EXIST")
|
||||
self.assertRaises(oracledb.DatabaseError, self.connection.gettype,
|
||||
"A TYPE THAT DOES NOT EXIST")
|
||||
|
||||
def test_2309_AppendingWrongObjectType(self):
|
||||
def test_2309_appending_wrong_object_type(self):
|
||||
"2309 - test appending an object of the wrong type to a collection"
|
||||
collectionObjType = self.connection.gettype("UDT_OBJECTARRAY")
|
||||
collectionObj = collectionObjType.newobject()
|
||||
arrayObjType = self.connection.gettype("UDT_ARRAY")
|
||||
arrayObj = arrayObjType.newobject()
|
||||
self.assertRaises(cx_Oracle.DatabaseError, collectionObj.append,
|
||||
arrayObj)
|
||||
collection_obj_type = self.connection.gettype("UDT_OBJECTARRAY")
|
||||
collection_obj = collection_obj_type.newobject()
|
||||
array_obj_type = self.connection.gettype("UDT_ARRAY")
|
||||
array_obj = array_obj_type.newobject()
|
||||
self.assertRaises(oracledb.DatabaseError, collection_obj.append,
|
||||
array_obj)
|
||||
|
||||
def test_2310_ReferencingSubObj(self):
|
||||
def test_2310_referencing_sub_obj(self):
|
||||
"2310 - test that referencing a sub object affects the parent object"
|
||||
objType = self.connection.gettype("UDT_OBJECT")
|
||||
subObjType = self.connection.gettype("UDT_SUBOBJECT")
|
||||
obj = objType.newobject()
|
||||
obj.SUBOBJECTVALUE = subObjType.newobject()
|
||||
obj_type = self.connection.gettype("UDT_OBJECT")
|
||||
sub_obj_type = self.connection.gettype("UDT_SUBOBJECT")
|
||||
obj = obj_type.newobject()
|
||||
obj.SUBOBJECTVALUE = sub_obj_type.newobject()
|
||||
obj.SUBOBJECTVALUE.SUBNUMBERVALUE = 5
|
||||
obj.SUBOBJECTVALUE.SUBSTRINGVALUE = "Substring"
|
||||
self.assertEqual(obj.SUBOBJECTVALUE.SUBNUMBERVALUE, 5)
|
||||
self.assertEqual(obj.SUBOBJECTVALUE.SUBSTRINGVALUE, "Substring")
|
||||
|
||||
def test_2311_AccessSubObjectParentObjectDestroyed(self):
|
||||
def test_2311_access_sub_object_parent_object_destroyed(self):
|
||||
"2311 - test accessing sub object after parent object destroyed"
|
||||
objType = self.connection.gettype("UDT_OBJECT")
|
||||
subObjType = self.connection.gettype("UDT_SUBOBJECT")
|
||||
arrayType = self.connection.gettype("UDT_OBJECTARRAY")
|
||||
subObj1 = subObjType.newobject()
|
||||
subObj1.SUBNUMBERVALUE = 2
|
||||
subObj1.SUBSTRINGVALUE = "AB"
|
||||
subObj2 = subObjType.newobject()
|
||||
subObj2.SUBNUMBERVALUE = 3
|
||||
subObj2.SUBSTRINGVALUE = "CDE"
|
||||
obj = objType.newobject()
|
||||
obj.SUBOBJECTARRAY = arrayType.newobject([subObj1, subObj2])
|
||||
subObjArray = obj.SUBOBJECTARRAY
|
||||
obj_type = self.connection.gettype("UDT_OBJECT")
|
||||
sub_obj_type = self.connection.gettype("UDT_SUBOBJECT")
|
||||
array_type = self.connection.gettype("UDT_OBJECTARRAY")
|
||||
sub_obj1 = sub_obj_type.newobject()
|
||||
sub_obj1.SUBNUMBERVALUE = 2
|
||||
sub_obj1.SUBSTRINGVALUE = "AB"
|
||||
sub_obj2 = sub_obj_type.newobject()
|
||||
sub_obj2.SUBNUMBERVALUE = 3
|
||||
sub_obj2.SUBSTRINGVALUE = "CDE"
|
||||
obj = obj_type.newobject()
|
||||
obj.SUBOBJECTARRAY = array_type.newobject([sub_obj1, sub_obj2])
|
||||
sub_obj_array = obj.SUBOBJECTARRAY
|
||||
del obj
|
||||
self.assertEqual(self.__GetObjectAsTuple(subObjArray),
|
||||
[(2, "AB"), (3, "CDE")])
|
||||
self.assertEqual(self.__get_object_as_tuple(sub_obj_array),
|
||||
[(2, "AB"), (3, "CDE")])
|
||||
|
||||
def test_2312_SettingAttrWrongObjectType(self):
|
||||
def test_2312_setting_attr_wrong_object_type(self):
|
||||
"2312 - test assigning an object of wrong type to an object attribute"
|
||||
objType = self.connection.gettype("UDT_OBJECT")
|
||||
obj = objType.newobject()
|
||||
wrongObjType = self.connection.gettype("UDT_OBJECTARRAY")
|
||||
wrongObj = wrongObjType.newobject()
|
||||
self.assertRaises(cx_Oracle.DatabaseError, setattr, obj,
|
||||
"SUBOBJECTVALUE", wrongObj)
|
||||
obj_type = self.connection.gettype("UDT_OBJECT")
|
||||
obj = obj_type.newobject()
|
||||
wrong_obj_type = self.connection.gettype("UDT_OBJECTARRAY")
|
||||
wrong_obj = wrong_obj_type.newobject()
|
||||
self.assertRaises(oracledb.DatabaseError, setattr, obj,
|
||||
"SUBOBJECTVALUE", wrong_obj)
|
||||
|
||||
def test_2313_SettingVarWrongObjectType(self):
|
||||
def test_2313_setting_var_wrong_object_type(self):
|
||||
"2313 - test setting value of object variable to wrong object type"
|
||||
wrongObjType = self.connection.gettype("UDT_OBJECTARRAY")
|
||||
wrongObj = wrongObjType.newobject()
|
||||
var = self.cursor.var(cx_Oracle.DB_TYPE_OBJECT,
|
||||
typename = "UDT_OBJECT")
|
||||
self.assertRaises(cx_Oracle.DatabaseError, var.setvalue, 0, wrongObj)
|
||||
wrong_obj_type = self.connection.gettype("UDT_OBJECTARRAY")
|
||||
wrong_obj = wrong_obj_type.newobject()
|
||||
var = self.cursor.var(oracledb.DB_TYPE_OBJECT, typename="UDT_OBJECT")
|
||||
self.assertRaises(oracledb.DatabaseError, var.setvalue, 0, wrong_obj)
|
||||
|
||||
def test_2314_StringFormat(self):
|
||||
def test_2314_string_format(self):
|
||||
"2314 - test object string format"
|
||||
objType = self.connection.gettype("UDT_OBJECT")
|
||||
user = TestEnv.GetMainUser()
|
||||
self.assertEqual(str(objType),
|
||||
"<cx_Oracle.ObjectType %s.UDT_OBJECT>" % user.upper())
|
||||
self.assertEqual(str(objType.attributes[0]),
|
||||
"<cx_Oracle.ObjectAttribute NUMBERVALUE>")
|
||||
obj_type = self.connection.gettype("UDT_OBJECT")
|
||||
user = base.get_main_user()
|
||||
self.assertEqual(str(obj_type),
|
||||
"<cx_Oracle.ObjectType %s.UDT_OBJECT>" % user.upper())
|
||||
self.assertEqual(str(obj_type.attributes[0]),
|
||||
"<cx_Oracle.ObjectAttribute NUMBERVALUE>")
|
||||
|
||||
def test_2315_TrimCollectionList(self):
|
||||
def test_2315_trim_collection_list(self):
|
||||
"2315 - test Trim number of elements from collection"
|
||||
subObjType = self.connection.gettype("UDT_SUBOBJECT")
|
||||
arrayType = self.connection.gettype("UDT_OBJECTARRAY")
|
||||
sub_obj_type = self.connection.gettype("UDT_SUBOBJECT")
|
||||
array_type = self.connection.gettype("UDT_OBJECTARRAY")
|
||||
data = [(1, "AB"), (2, "CDE"), (3, "FGH"), (4, "IJK")]
|
||||
arrayObj = arrayType()
|
||||
for numVal, strVal in data:
|
||||
subObj = subObjType()
|
||||
subObj.SUBNUMBERVALUE = numVal
|
||||
subObj.SUBSTRINGVALUE = strVal
|
||||
arrayObj.append(subObj)
|
||||
self.assertEqual(self.__GetObjectAsTuple(arrayObj), data)
|
||||
arrayObj.trim(2)
|
||||
self.assertEqual(self.__GetObjectAsTuple(arrayObj), data[:2])
|
||||
arrayObj.trim(1)
|
||||
self.assertEqual(self.__GetObjectAsTuple(arrayObj), data[:1])
|
||||
arrayObj.trim(0)
|
||||
self.assertEqual(self.__GetObjectAsTuple(arrayObj), data[:1])
|
||||
arrayObj.trim(1)
|
||||
self.assertEqual(self.__GetObjectAsTuple(arrayObj), [])
|
||||
array_obj = array_type()
|
||||
for num_val, str_val in data:
|
||||
subObj = sub_obj_type()
|
||||
subObj.SUBNUMBERVALUE = num_val
|
||||
subObj.SUBSTRINGVALUE = str_val
|
||||
array_obj.append(subObj)
|
||||
self.assertEqual(self.__get_object_as_tuple(array_obj), data)
|
||||
array_obj.trim(2)
|
||||
self.assertEqual(self.__get_object_as_tuple(array_obj), data[:2])
|
||||
array_obj.trim(1)
|
||||
self.assertEqual(self.__get_object_as_tuple(array_obj), data[:1])
|
||||
array_obj.trim(0)
|
||||
self.assertEqual(self.__get_object_as_tuple(array_obj), data[:1])
|
||||
array_obj.trim(1)
|
||||
self.assertEqual(self.__get_object_as_tuple(array_obj), [])
|
||||
|
||||
if __name__ == "__main__":
|
||||
TestEnv.RunTestCases()
|
||||
base.run_test_cases()
|
||||
|
|
|
@ -11,56 +11,49 @@
|
|||
2400 - Module for testing session pools
|
||||
"""
|
||||
|
||||
import TestEnv
|
||||
import base
|
||||
|
||||
import cx_Oracle
|
||||
import cx_Oracle as oracledb
|
||||
import threading
|
||||
|
||||
class TestCase(TestEnv.BaseTestCase):
|
||||
class TestCase(base.BaseTestCase):
|
||||
require_connection = False
|
||||
|
||||
def __ConnectAndDrop(self):
|
||||
"""Connect to the database, perform a query and drop the connection."""
|
||||
def __connect_and_drop(self):
|
||||
connection = self.pool.acquire()
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("select count(*) from TestNumbers")
|
||||
count, = cursor.fetchone()
|
||||
self.assertEqual(count, 10)
|
||||
|
||||
def __ConnectAndGenerateError(self):
|
||||
"""Connect to the database, perform a query which raises an error"""
|
||||
def __connect_and_generate_error(self):
|
||||
connection = self.pool.acquire()
|
||||
cursor = connection.cursor()
|
||||
self.assertRaises(cx_Oracle.DatabaseError, cursor.execute,
|
||||
"select 1 / 0 from dual")
|
||||
self.assertRaises(oracledb.DatabaseError, cursor.execute,
|
||||
"select 1 / 0 from dual")
|
||||
|
||||
def __VerifyConnection(self, connection, expectedUser,
|
||||
expectedProxyUser = None):
|
||||
def __verify_connection(self, connection, expected_user,
|
||||
expected_proxy_user=None):
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("""
|
||||
select
|
||||
sys_context('userenv', 'session_user'),
|
||||
sys_context('userenv', 'proxy_user')
|
||||
from dual""")
|
||||
actualUser, actualProxyUser = cursor.fetchone()
|
||||
self.assertEqual(actualUser, expectedUser.upper())
|
||||
self.assertEqual(actualProxyUser,
|
||||
expectedProxyUser and expectedProxyUser.upper())
|
||||
actual_user, actual_proxy_user = cursor.fetchone()
|
||||
self.assertEqual(actual_user, expected_user.upper())
|
||||
self.assertEqual(actual_proxy_user,
|
||||
expected_proxy_user and expected_proxy_user.upper())
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def test_2400_Pool(self):
|
||||
def test_2400_pool(self):
|
||||
"2400 - test that the pool is created and has the right attributes"
|
||||
pool = TestEnv.GetPool(min=2, max=8, increment=3,
|
||||
getmode=cx_Oracle.SPOOL_ATTRVAL_WAIT)
|
||||
self.assertEqual(pool.username, TestEnv.GetMainUser(),
|
||||
"user name differs")
|
||||
self.assertEqual(pool.tnsentry, TestEnv.GetConnectString(),
|
||||
"tnsentry differs")
|
||||
self.assertEqual(pool.dsn, TestEnv.GetConnectString(), "dsn differs")
|
||||
pool = base.get_pool(min=2, max=8, increment=3,
|
||||
getmode=oracledb.SPOOL_ATTRVAL_WAIT)
|
||||
self.assertEqual(pool.username, base.get_main_user(),
|
||||
"user name differs")
|
||||
self.assertEqual(pool.tnsentry, base.get_connect_string(),
|
||||
"tnsentry differs")
|
||||
self.assertEqual(pool.dsn, base.get_connect_string(), "dsn differs")
|
||||
self.assertEqual(pool.max, 8, "max differs")
|
||||
self.assertEqual(pool.min, 2, "min differs")
|
||||
self.assertEqual(pool.increment, 3, "increment differs")
|
||||
|
@ -79,98 +72,99 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
self.assertEqual(pool.busy, 2, "busy not 2 after release")
|
||||
del connection_2
|
||||
self.assertEqual(pool.busy, 1, "busy not 1 after del")
|
||||
pool.getmode = cx_Oracle.SPOOL_ATTRVAL_NOWAIT
|
||||
self.assertEqual(pool.getmode, cx_Oracle.SPOOL_ATTRVAL_NOWAIT)
|
||||
if TestEnv.GetClientVersion() >= (12, 2):
|
||||
pool.getmode = cx_Oracle.SPOOL_ATTRVAL_TIMEDWAIT
|
||||
self.assertEqual(pool.getmode, cx_Oracle.SPOOL_ATTRVAL_TIMEDWAIT)
|
||||
pool.getmode = oracledb.SPOOL_ATTRVAL_NOWAIT
|
||||
self.assertEqual(pool.getmode, oracledb.SPOOL_ATTRVAL_NOWAIT)
|
||||
if base.get_client_version() >= (12, 2):
|
||||
pool.getmode = oracledb.SPOOL_ATTRVAL_TIMEDWAIT
|
||||
self.assertEqual(pool.getmode, oracledb.SPOOL_ATTRVAL_TIMEDWAIT)
|
||||
pool.stmtcachesize = 50
|
||||
self.assertEqual(pool.stmtcachesize, 50)
|
||||
pool.timeout = 10
|
||||
self.assertEqual(pool.timeout, 10)
|
||||
if TestEnv.GetClientVersion() >= (12, 1):
|
||||
if base.get_client_version() >= (12, 1):
|
||||
pool.max_lifetime_session = 10
|
||||
self.assertEqual(pool.max_lifetime_session, 10)
|
||||
|
||||
def test_2401_ProxyAuth(self):
|
||||
def test_2401_proxy_auth(self):
|
||||
"2401 - test that proxy authentication is possible"
|
||||
pool = TestEnv.GetPool(min=2, max=8, increment=3,
|
||||
getmode=cx_Oracle.SPOOL_ATTRVAL_WAIT)
|
||||
self.assertEqual(pool.homogeneous, 1,
|
||||
"homogeneous should be 1 by default")
|
||||
self.assertRaises(cx_Oracle.DatabaseError, pool.acquire,
|
||||
user = "missing_proxyuser")
|
||||
pool = TestEnv.GetPool(min=2, max=8, increment=3,
|
||||
getmode=cx_Oracle.SPOOL_ATTRVAL_WAIT, homogeneous=False)
|
||||
self.assertEqual(pool.homogeneous, 0,
|
||||
"homogeneous should be 0 after setting it in the constructor")
|
||||
connection = pool.acquire(user = TestEnv.GetProxyUser())
|
||||
pool = base.get_pool(min=2, max=8, increment=3,
|
||||
getmode=oracledb.SPOOL_ATTRVAL_WAIT)
|
||||
self.assertEqual(pool.homogeneous, True,
|
||||
"homogeneous should be True by default")
|
||||
self.assertRaises(oracledb.DatabaseError, pool.acquire,
|
||||
user="missing_proxyuser")
|
||||
pool = base.get_pool(min=2, max=8, increment=3,
|
||||
getmode=oracledb.SPOOL_ATTRVAL_WAIT,
|
||||
homogeneous=False)
|
||||
msg = "homogeneous should be False after setting it in the constructor"
|
||||
self.assertEqual(pool.homogeneous, False, msg)
|
||||
connection = pool.acquire(user=base.get_proxy_user())
|
||||
cursor = connection.cursor()
|
||||
cursor.execute('select user from dual')
|
||||
result, = cursor.fetchone()
|
||||
self.assertEqual(result, TestEnv.GetProxyUser().upper())
|
||||
self.assertEqual(result, base.get_proxy_user().upper())
|
||||
|
||||
def test_2402_RollbackOnDel(self):
|
||||
def test_2402_rollback_on_del(self):
|
||||
"2402 - connection rolls back before being destroyed"
|
||||
pool = TestEnv.GetPool()
|
||||
pool = base.get_pool()
|
||||
connection = pool.acquire()
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("truncate table TestTempTable")
|
||||
cursor.execute("insert into TestTempTable (IntCol) values (1)")
|
||||
pool = TestEnv.GetPool()
|
||||
pool = base.get_pool()
|
||||
connection = pool.acquire()
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("select count(*) from TestTempTable")
|
||||
count, = cursor.fetchone()
|
||||
self.assertEqual(count, 0)
|
||||
|
||||
def test_2403_RollbackOnRelease(self):
|
||||
def test_2403_rollback_on_release(self):
|
||||
"2403 - connection rolls back before released back to the pool"
|
||||
pool = TestEnv.GetPool()
|
||||
pool = base.get_pool()
|
||||
connection = pool.acquire()
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("truncate table TestTempTable")
|
||||
cursor.execute("insert into TestTempTable (IntCol) values (1)")
|
||||
cursor.close()
|
||||
pool.release(connection)
|
||||
pool = TestEnv.GetPool()
|
||||
pool = base.get_pool()
|
||||
connection = pool.acquire()
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("select count(*) from TestTempTable")
|
||||
count, = cursor.fetchone()
|
||||
self.assertEqual(count, 0)
|
||||
|
||||
def test_2404_Threading(self):
|
||||
def test_2404_threading(self):
|
||||
"2404 - test session pool with multiple threads"
|
||||
self.pool = TestEnv.GetPool(min=5, max=20, increment=2, threaded=True,
|
||||
getmode=cx_Oracle.SPOOL_ATTRVAL_WAIT)
|
||||
self.pool = base.get_pool(min=5, max=20, increment=2, threaded=True,
|
||||
getmode=oracledb.SPOOL_ATTRVAL_WAIT)
|
||||
threads = []
|
||||
for i in range(20):
|
||||
thread = threading.Thread(None, self.__ConnectAndDrop)
|
||||
thread = threading.Thread(None, self.__connect_and_drop)
|
||||
threads.append(thread)
|
||||
thread.start()
|
||||
for thread in threads:
|
||||
thread.join()
|
||||
|
||||
def test_2405_ThreadingWithErrors(self):
|
||||
def test_2405_threading_with_errors(self):
|
||||
"2405 - test session pool with multiple threads (with errors)"
|
||||
self.pool = TestEnv.GetPool(min=5, max=20, increment=2, threaded=True,
|
||||
getmode=cx_Oracle.SPOOL_ATTRVAL_WAIT)
|
||||
self.pool = base.get_pool(min=5, max=20, increment=2, threaded=True,
|
||||
getmode=oracledb.SPOOL_ATTRVAL_WAIT)
|
||||
threads = []
|
||||
for i in range(20):
|
||||
thread = threading.Thread(None, self.__ConnectAndGenerateError)
|
||||
thread = threading.Thread(None, self.__connect_and_generate_error)
|
||||
threads.append(thread)
|
||||
thread.start()
|
||||
for thread in threads:
|
||||
thread.join()
|
||||
|
||||
def test_2406_Purity(self):
|
||||
def test_2406_purity(self):
|
||||
"2406 - test session pool with various types of purity"
|
||||
action = "TEST_ACTION"
|
||||
pool = TestEnv.GetPool(min=1, max=8, increment=1,
|
||||
getmode=cx_Oracle.SPOOL_ATTRVAL_WAIT)
|
||||
pool = base.get_pool(min=1, max=8, increment=1,
|
||||
getmode=oracledb.SPOOL_ATTRVAL_WAIT)
|
||||
|
||||
# get connection and set the action
|
||||
action = "TEST_ACTION"
|
||||
connection = pool.acquire()
|
||||
connection.action = action
|
||||
cursor = connection.cursor()
|
||||
|
@ -190,7 +184,7 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
self.assertEqual(pool.opened, 1, "opened (2)")
|
||||
|
||||
# get a new connection with new purity (should not have state)
|
||||
connection = pool.acquire(purity = cx_Oracle.ATTR_PURITY_NEW)
|
||||
connection = pool.acquire(purity=oracledb.ATTR_PURITY_NEW)
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("select sys_context('userenv', 'action') from dual")
|
||||
result, = cursor.fetchone()
|
||||
|
@ -200,77 +194,85 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
pool.drop(connection)
|
||||
self.assertEqual(pool.opened, 1, "opened (4)")
|
||||
|
||||
def test_2407_Heterogeneous(self):
|
||||
def test_2407_heterogeneous(self):
|
||||
"2407 - test heterogeneous pool with user and password specified"
|
||||
pool = TestEnv.GetPool(min=2, max=8, increment=3, homogeneous=False,
|
||||
getmode=cx_Oracle.SPOOL_ATTRVAL_WAIT)
|
||||
pool = base.get_pool(min=2, max=8, increment=3, homogeneous=False,
|
||||
getmode=oracledb.SPOOL_ATTRVAL_WAIT)
|
||||
self.assertEqual(pool.homogeneous, 0)
|
||||
self.__VerifyConnection(pool.acquire(), TestEnv.GetMainUser())
|
||||
self.__VerifyConnection(pool.acquire(TestEnv.GetMainUser(),
|
||||
TestEnv.GetMainPassword()), TestEnv.GetMainUser())
|
||||
self.__VerifyConnection(pool.acquire(TestEnv.GetProxyUser(),
|
||||
TestEnv.GetProxyPassword()), TestEnv.GetProxyUser())
|
||||
userStr = "%s[%s]" % (TestEnv.GetMainUser(), TestEnv.GetProxyUser())
|
||||
self.__VerifyConnection(pool.acquire(userStr,
|
||||
TestEnv.GetMainPassword()), TestEnv.GetProxyUser(),
|
||||
TestEnv.GetMainUser())
|
||||
self.__verify_connection(pool.acquire(), base.get_main_user())
|
||||
self.__verify_connection(pool.acquire(base.get_main_user(),
|
||||
base.get_main_password()),
|
||||
base.get_main_user())
|
||||
self.__verify_connection(pool.acquire(base.get_proxy_user(),
|
||||
base.get_proxy_password()),
|
||||
base.get_proxy_user())
|
||||
user_str = "%s[%s]" % (base.get_main_user(), base.get_proxy_user())
|
||||
self.__verify_connection(pool.acquire(user_str,
|
||||
base.get_main_password()),
|
||||
base.get_proxy_user(), base.get_main_user())
|
||||
|
||||
def test_2408_HeterogenousWithoutUser(self):
|
||||
def test_2408_heterogenous_without_user(self):
|
||||
"2408 - test heterogeneous pool without user and password specified"
|
||||
pool = TestEnv.GetPool(user="", password="", min=2, max=8, increment=3,
|
||||
getmode=cx_Oracle.SPOOL_ATTRVAL_WAIT, homogeneous=False)
|
||||
self.__VerifyConnection(pool.acquire(TestEnv.GetMainUser(),
|
||||
TestEnv.GetMainPassword()), TestEnv.GetMainUser())
|
||||
self.__VerifyConnection(pool.acquire(TestEnv.GetProxyUser(),
|
||||
TestEnv.GetProxyPassword()), TestEnv.GetProxyUser())
|
||||
userStr = "%s[%s]" % (TestEnv.GetMainUser(), TestEnv.GetProxyUser())
|
||||
self.__VerifyConnection(pool.acquire(userStr,
|
||||
TestEnv.GetMainPassword()), TestEnv.GetProxyUser(),
|
||||
TestEnv.GetMainUser())
|
||||
pool = base.get_pool(user="", password="", min=2, max=8, increment=3,
|
||||
getmode=oracledb.SPOOL_ATTRVAL_WAIT,
|
||||
homogeneous=False)
|
||||
self.__verify_connection(pool.acquire(base.get_main_user(),
|
||||
base.get_main_password()),
|
||||
base.get_main_user())
|
||||
self.__verify_connection(pool.acquire(base.get_proxy_user(),
|
||||
base.get_proxy_password()),
|
||||
base.get_proxy_user())
|
||||
user_str = "%s[%s]" % (base.get_main_user(), base.get_proxy_user())
|
||||
self.__verify_connection(pool.acquire(user_str,
|
||||
base.get_main_password()),
|
||||
base.get_proxy_user(), base.get_main_user())
|
||||
|
||||
def test_2409_HeterogeneousWrongPassword(self):
|
||||
def test_2409_heterogeneous_wrong_password(self):
|
||||
"2409 - test heterogeneous pool with wrong password specified"
|
||||
pool = TestEnv.GetPool(min=2, max=8, increment=3,
|
||||
getmode=cx_Oracle.SPOOL_ATTRVAL_WAIT, homogeneous=False)
|
||||
self.assertRaises(cx_Oracle.DatabaseError, pool.acquire,
|
||||
TestEnv.GetProxyUser(), "this is the wrong password")
|
||||
pool = base.get_pool(min=2, max=8, increment=3,
|
||||
getmode=oracledb.SPOOL_ATTRVAL_WAIT,
|
||||
homogeneous=False)
|
||||
self.assertRaises(oracledb.DatabaseError, pool.acquire,
|
||||
base.get_proxy_user(), "this is the wrong password")
|
||||
|
||||
def test_2410_TaggingSession(self):
|
||||
def test_2410_tagging_session(self):
|
||||
"2410 - test tagging a session"
|
||||
pool = TestEnv.GetPool(min=2, max=8, increment=3,
|
||||
getmode=cx_Oracle.SPOOL_ATTRVAL_NOWAIT)
|
||||
pool = base.get_pool(min=2, max=8, increment=3,
|
||||
getmode=oracledb.SPOOL_ATTRVAL_NOWAIT)
|
||||
|
||||
tagMST = "TIME_ZONE=MST"
|
||||
tagUTC = "TIME_ZONE=UTC"
|
||||
tag_mst = "TIME_ZONE=MST"
|
||||
tag_utc = "TIME_ZONE=UTC"
|
||||
|
||||
conn = pool.acquire()
|
||||
self.assertEqual(conn.tag, None)
|
||||
pool.release(conn, tag=tagMST)
|
||||
pool.release(conn, tag=tag_mst)
|
||||
|
||||
conn = pool.acquire()
|
||||
self.assertEqual(conn.tag, None)
|
||||
conn.tag = tagUTC
|
||||
conn.tag = tag_utc
|
||||
conn.close()
|
||||
|
||||
conn = pool.acquire(tag=tagMST)
|
||||
self.assertEqual(conn.tag, tagMST)
|
||||
conn = pool.acquire(tag=tag_mst)
|
||||
self.assertEqual(conn.tag, tag_mst)
|
||||
conn.close()
|
||||
|
||||
conn = pool.acquire(tag=tagUTC)
|
||||
self.assertEqual(conn.tag, tagUTC)
|
||||
conn = pool.acquire(tag=tag_utc)
|
||||
self.assertEqual(conn.tag, tag_utc)
|
||||
conn.close()
|
||||
|
||||
def test_2411_PLSQLSessionCallbacks(self):
|
||||
def test_2411_plsql_session_callbacks(self):
|
||||
"2411 - test PL/SQL session callbacks"
|
||||
clientVersion = cx_Oracle.clientversion()
|
||||
if clientVersion < (12, 2):
|
||||
if base.get_client_version() < (12, 2):
|
||||
self.skipTest("PL/SQL session callbacks not supported before 12.2")
|
||||
pool = TestEnv.GetPool(min=2, max=8, increment=3,
|
||||
getmode=cx_Oracle.SPOOL_ATTRVAL_NOWAIT,
|
||||
sessionCallback="pkg_SessionCallback.TheCallback")
|
||||
tags = ["NLS_DATE_FORMAT=SIMPLE", "NLS_DATE_FORMAT=FULL;TIME_ZONE=UTC",
|
||||
"NLS_DATE_FORMAT=FULL;TIME_ZONE=MST"]
|
||||
actualTags = [None, None, "NLS_DATE_FORMAT=FULL;TIME_ZONE=UTC"]
|
||||
pool = base.get_pool(min=2, max=8, increment=3,
|
||||
getmode=oracledb.SPOOL_ATTRVAL_NOWAIT,
|
||||
sessionCallback="pkg_SessionCallback.TheCallback")
|
||||
tags = [
|
||||
"NLS_DATE_FORMAT=SIMPLE",
|
||||
"NLS_DATE_FORMAT=FULL;TIME_ZONE=UTC",
|
||||
"NLS_DATE_FORMAT=FULL;TIME_ZONE=MST"
|
||||
]
|
||||
actual_tags = [None, None, "NLS_DATE_FORMAT=FULL;TIME_ZONE=UTC"]
|
||||
|
||||
# truncate PL/SQL session callback log
|
||||
conn = pool.acquire()
|
||||
|
@ -295,18 +297,17 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
from PLSQLSessionCallbacks
|
||||
order by FixupTimestamp""")
|
||||
results = cursor.fetchall()
|
||||
expectedResults = list(zip(tags, actualTags))
|
||||
self.assertEqual(results, expectedResults)
|
||||
expected_results = list(zip(tags, actual_tags))
|
||||
self.assertEqual(results, expected_results)
|
||||
|
||||
def test_2412_TaggingInvalidKey(self):
|
||||
def test_2412_tagging_invalid_key(self):
|
||||
"2412 - testTagging with Invalid key"
|
||||
pool = TestEnv.GetPool(getmode=cx_Oracle.SPOOL_ATTRVAL_NOWAIT)
|
||||
pool = base.get_pool(getmode=oracledb.SPOOL_ATTRVAL_NOWAIT)
|
||||
conn = pool.acquire()
|
||||
self.assertRaises(TypeError, pool.release, conn, tag=12345)
|
||||
clientVersion = cx_Oracle.clientversion()
|
||||
if clientVersion >= (12, 2):
|
||||
self.assertRaises(cx_Oracle.DatabaseError, pool.release, conn,
|
||||
tag="INVALID_TAG")
|
||||
if base.get_client_version() >= (12, 2):
|
||||
self.assertRaises(oracledb.DatabaseError, pool.release, conn,
|
||||
tag="INVALID_TAG")
|
||||
|
||||
if __name__ == "__main__":
|
||||
TestEnv.RunTestCases()
|
||||
base.run_test_cases()
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#------------------------------------------------------------------------------
|
||||
# Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
#
|
||||
|
@ -12,159 +11,155 @@
|
|||
2500 - Module for testing string variables
|
||||
"""
|
||||
|
||||
import TestEnv
|
||||
import base
|
||||
|
||||
import cx_Oracle
|
||||
import cx_Oracle as oracledb
|
||||
import datetime
|
||||
import string
|
||||
import random
|
||||
|
||||
class TestCase(TestEnv.BaseTestCase):
|
||||
class TestCase(base.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
TestEnv.BaseTestCase.setUp(self)
|
||||
self.rawData = []
|
||||
self.dataByKey = {}
|
||||
super().setUp()
|
||||
self.raw_data = []
|
||||
self.data_by_key = {}
|
||||
for i in range(1, 11):
|
||||
stringCol = "String %d" % i
|
||||
fixedCharCol = ("Fixed Char %d" % i).ljust(40)
|
||||
rawCol = ("Raw %d" % i).encode("ascii")
|
||||
string_col = "String %d" % i
|
||||
fixed_char_col = ("Fixed Char %d" % i).ljust(40)
|
||||
raw_col = ("Raw %d" % i).encode("ascii")
|
||||
if i % 2:
|
||||
nullableCol = "Nullable %d" % i
|
||||
nullable_col = "Nullable %d" % i
|
||||
else:
|
||||
nullableCol = None
|
||||
dataTuple = (i, stringCol, rawCol, fixedCharCol, nullableCol)
|
||||
self.rawData.append(dataTuple)
|
||||
self.dataByKey[i] = dataTuple
|
||||
nullable_col = None
|
||||
data_tuple = (i, string_col, raw_col, fixed_char_col, nullable_col)
|
||||
self.raw_data.append(data_tuple)
|
||||
self.data_by_key[i] = data_tuple
|
||||
|
||||
def test_2500_ArrayWithIncreasedSize(self):
|
||||
def test_2500_array_with_increased_size(self):
|
||||
"2500 - test creating array var and then increasing the internal size"
|
||||
val = ["12345678901234567890"] * 3
|
||||
arrayVar = self.cursor.arrayvar(str, len(val), 4)
|
||||
arrayVar.setvalue(0, val)
|
||||
self.assertEqual(arrayVar.getvalue(), val)
|
||||
var = self.cursor.arrayvar(str, len(val), 4)
|
||||
var.setvalue(0, val)
|
||||
self.assertEqual(var.getvalue(), val)
|
||||
|
||||
def test_2501_BindString(self):
|
||||
def test_2501_bind_string(self):
|
||||
"2501 - test binding in a string"
|
||||
self.cursor.execute("""
|
||||
select * from TestStrings
|
||||
where StringCol = :value""",
|
||||
value = "String 5")
|
||||
self.assertEqual(self.cursor.fetchall(), [self.dataByKey[5]])
|
||||
value="String 5")
|
||||
self.assertEqual(self.cursor.fetchall(), [self.data_by_key[5]])
|
||||
|
||||
def test_2502_BindDifferentVar(self):
|
||||
def test_2502_bind_different_var(self):
|
||||
"2502 - test binding a different variable on second execution"
|
||||
retval_1 = self.cursor.var(cx_Oracle.STRING, 30)
|
||||
retval_2 = self.cursor.var(cx_Oracle.STRING, 30)
|
||||
retval_1 = self.cursor.var(oracledb.STRING, 30)
|
||||
retval_2 = self.cursor.var(oracledb.STRING, 30)
|
||||
self.cursor.execute("begin :retval := 'Called'; end;",
|
||||
retval = retval_1)
|
||||
retval=retval_1)
|
||||
self.assertEqual(retval_1.getvalue(), "Called")
|
||||
self.cursor.execute("begin :retval := 'Called'; end;",
|
||||
retval = retval_2)
|
||||
retval=retval_2)
|
||||
self.assertEqual(retval_2.getvalue(), "Called")
|
||||
|
||||
def test_2503_ExceedsNumElements(self):
|
||||
def test_2503_exceeds_num_elements(self):
|
||||
"2503 - test exceeding the number of elements returns IndexError"
|
||||
var = self.cursor.var(str)
|
||||
self.assertRaises(IndexError, var.getvalue, 1)
|
||||
|
||||
def test_2504_BindStringAfterNumber(self):
|
||||
def test_2504_bind_string_after_number(self):
|
||||
"2504 - test binding in a string after setting input sizes to a number"
|
||||
self.cursor.setinputsizes(value = cx_Oracle.NUMBER)
|
||||
self.cursor.setinputsizes(value = oracledb.NUMBER)
|
||||
self.cursor.execute("""
|
||||
select * from TestStrings
|
||||
where StringCol = :value""",
|
||||
value = "String 6")
|
||||
self.assertEqual(self.cursor.fetchall(), [self.dataByKey[6]])
|
||||
value="String 6")
|
||||
self.assertEqual(self.cursor.fetchall(), [self.data_by_key[6]])
|
||||
|
||||
def test_2505_BindStringArrayDirect(self):
|
||||
def test_2505_bind_string_array_direct(self):
|
||||
"2505 - test binding in a string array"
|
||||
returnValue = self.cursor.var(cx_Oracle.NUMBER)
|
||||
array = [r[1] for r in self.rawData]
|
||||
return_value = self.cursor.var(oracledb.NUMBER)
|
||||
array = [r[1] for r in self.raw_data]
|
||||
statement = """
|
||||
begin
|
||||
:returnValue := pkg_TestStringArrays.TestInArrays(
|
||||
:integerValue, :array);
|
||||
:return_value := pkg_TestStringArrays.TestInArrays(
|
||||
:integer_value, :array);
|
||||
end;"""
|
||||
self.cursor.execute(statement,
|
||||
returnValue = returnValue,
|
||||
integerValue = 5,
|
||||
array = array)
|
||||
self.assertEqual(returnValue.getvalue(), 86)
|
||||
self.cursor.execute(statement, return_value=return_value,
|
||||
integer_value=5, array=array)
|
||||
self.assertEqual(return_value.getvalue(), 86)
|
||||
array = [ "String - %d" % i for i in range(15) ]
|
||||
self.cursor.execute(statement,
|
||||
integerValue = 8,
|
||||
array = array)
|
||||
self.assertEqual(returnValue.getvalue(), 163)
|
||||
self.cursor.execute(statement, integer_value=8, array=array)
|
||||
self.assertEqual(return_value.getvalue(), 163)
|
||||
|
||||
def test_2506_BindStringArrayBySizes(self):
|
||||
def test_2506_bind_string_array_by_sizes(self):
|
||||
"2506 - test binding in a string array (with setinputsizes)"
|
||||
returnValue = self.cursor.var(cx_Oracle.NUMBER)
|
||||
self.cursor.setinputsizes(array = [cx_Oracle.STRING, 10])
|
||||
array = [r[1] for r in self.rawData]
|
||||
return_value = self.cursor.var(oracledb.NUMBER)
|
||||
self.cursor.setinputsizes(array=[oracledb.STRING, 10])
|
||||
array = [r[1] for r in self.raw_data]
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:returnValue := pkg_TestStringArrays.TestInArrays(
|
||||
:integerValue, :array);
|
||||
:return_value := pkg_TestStringArrays.TestInArrays(
|
||||
:integer_value, :array);
|
||||
end;""",
|
||||
returnValue = returnValue,
|
||||
integerValue = 6,
|
||||
array = array)
|
||||
self.assertEqual(returnValue.getvalue(), 87)
|
||||
return_value=return_value,
|
||||
integer_value=6,
|
||||
array=array)
|
||||
self.assertEqual(return_value.getvalue(), 87)
|
||||
|
||||
def test_2507_BindStringArrayByVar(self):
|
||||
def test_2507_bind_string_array_by_var(self):
|
||||
"2507 - test binding in a string array (with arrayvar)"
|
||||
returnValue = self.cursor.var(cx_Oracle.NUMBER)
|
||||
array = self.cursor.arrayvar(cx_Oracle.STRING, 10, 20)
|
||||
array.setvalue(0, [r[1] for r in self.rawData])
|
||||
return_value = self.cursor.var(oracledb.NUMBER)
|
||||
array = self.cursor.arrayvar(oracledb.STRING, 10, 20)
|
||||
array.setvalue(0, [r[1] for r in self.raw_data])
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:returnValue := pkg_TestStringArrays.TestInArrays(
|
||||
:integerValue, :array);
|
||||
:return_value := pkg_TestStringArrays.TestInArrays(
|
||||
:integer_value, :array);
|
||||
end;""",
|
||||
returnValue = returnValue,
|
||||
integerValue = 7,
|
||||
array = array)
|
||||
self.assertEqual(returnValue.getvalue(), 88)
|
||||
return_value=return_value,
|
||||
integer_value=7,
|
||||
array=array)
|
||||
self.assertEqual(return_value.getvalue(), 88)
|
||||
|
||||
def test_2508_BindInOutStringArrayByVar(self):
|
||||
def test_2508_bind_in_out_string_array_by_var(self):
|
||||
"2508 - test binding in/out a string array (with arrayvar)"
|
||||
array = self.cursor.arrayvar(cx_Oracle.STRING, 10, 100)
|
||||
originalData = [r[1] for r in self.rawData]
|
||||
expectedData = ["Converted element # %d originally had length %d" % \
|
||||
(i, len(originalData[i - 1])) for i in range(1, 6)] + \
|
||||
originalData[5:]
|
||||
array.setvalue(0, originalData)
|
||||
array = self.cursor.arrayvar(oracledb.STRING, 10, 100)
|
||||
original_data = [r[1] for r in self.raw_data]
|
||||
expected_data = ["Converted element # %d originally had length %d" % \
|
||||
(i, len(original_data[i - 1])) \
|
||||
for i in range(1, 6)] + original_data[5:]
|
||||
array.setvalue(0, original_data)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
pkg_TestStringArrays.TestInOutArrays(:numElems, :array);
|
||||
pkg_TestStringArrays.TestInOutArrays(:num_elems, :array);
|
||||
end;""",
|
||||
numElems = 5,
|
||||
array = array)
|
||||
self.assertEqual(array.getvalue(), expectedData)
|
||||
num_elems=5,
|
||||
array=array)
|
||||
self.assertEqual(array.getvalue(), expected_data)
|
||||
|
||||
def test_2509_BindOutStringArrayByVar(self):
|
||||
def test_2509_bind_out_string_array_by_var(self):
|
||||
"2509 - test binding out a string array (with arrayvar)"
|
||||
array = self.cursor.arrayvar(cx_Oracle.STRING, 6, 100)
|
||||
expectedData = ["Test out element # %d" % i for i in range(1, 7)]
|
||||
array = self.cursor.arrayvar(oracledb.STRING, 6, 100)
|
||||
expected_data = ["Test out element # %d" % i for i in range(1, 7)]
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
pkg_TestStringArrays.TestOutArrays(:numElems, :array);
|
||||
pkg_TestStringArrays.TestOutArrays(:num_elems, :array);
|
||||
end;""",
|
||||
numElems = 6,
|
||||
array = array)
|
||||
self.assertEqual(array.getvalue(), expectedData)
|
||||
num_elems=6,
|
||||
array=array)
|
||||
self.assertEqual(array.getvalue(), expected_data)
|
||||
|
||||
def test_2510_BindRaw(self):
|
||||
def test_2510_bind_raw(self):
|
||||
"2510 - test binding in a raw"
|
||||
self.cursor.setinputsizes(value = cx_Oracle.BINARY)
|
||||
self.cursor.setinputsizes(value = oracledb.BINARY)
|
||||
self.cursor.execute("""
|
||||
select * from TestStrings
|
||||
where RawCol = :value""",
|
||||
value = "Raw 4".encode("ascii"))
|
||||
self.assertEqual(self.cursor.fetchall(), [self.dataByKey[4]])
|
||||
value="Raw 4".encode())
|
||||
self.assertEqual(self.cursor.fetchall(), [self.data_by_key[4]])
|
||||
|
||||
def test_2511_BindAndFetchRowid(self):
|
||||
def test_2511_bind_and_fetch_rowid(self):
|
||||
"2511 - test binding (and fetching) a rowid"
|
||||
self.cursor.execute("""
|
||||
select rowid
|
||||
|
@ -175,10 +170,10 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
select *
|
||||
from TestStrings
|
||||
where rowid = :value""",
|
||||
value = rowid)
|
||||
self.assertEqual(self.cursor.fetchall(), [self.dataByKey[3]])
|
||||
value=rowid)
|
||||
self.assertEqual(self.cursor.fetchall(), [self.data_by_key[3]])
|
||||
|
||||
def test_2512_BindAndFetchUniversalRowids(self):
|
||||
def test_2512_bind_and_fetch_universal_rowids(self):
|
||||
"2512 - test binding (and fetching) universal rowids"
|
||||
self.cursor.execute("truncate table TestUniversalRowids")
|
||||
data = [
|
||||
|
@ -195,147 +190,146 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
from TestUniversalRowIds
|
||||
order by IntCol""")
|
||||
rowids = [r for r, in self.cursor]
|
||||
fetchedData = []
|
||||
fetched_data = []
|
||||
for rowid in rowids:
|
||||
self.cursor.execute("""
|
||||
select *
|
||||
from TestUniversalRowids
|
||||
where rowid = :rid""",
|
||||
rid = rowid)
|
||||
fetchedData.extend(self.cursor.fetchall())
|
||||
self.assertEqual(fetchedData, data)
|
||||
rid=rowid)
|
||||
fetched_data.extend(self.cursor.fetchall())
|
||||
self.assertEqual(fetched_data, data)
|
||||
|
||||
def test_2513_BindNull(self):
|
||||
def test_2513_bind_null(self):
|
||||
"2513 - test binding in a null"
|
||||
self.cursor.execute("""
|
||||
select * from TestStrings
|
||||
where StringCol = :value""",
|
||||
value = None)
|
||||
value=None)
|
||||
self.assertEqual(self.cursor.fetchall(), [])
|
||||
|
||||
def test_2514_BindOutSetInputSizesByType(self):
|
||||
def test_2514_bind_out_set_input_sizes_by_type(self):
|
||||
"2514 - test binding out with set input sizes defined (by type)"
|
||||
vars = self.cursor.setinputsizes(value = cx_Oracle.STRING)
|
||||
bind_vars = self.cursor.setinputsizes(value=oracledb.STRING)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:value := 'TSI';
|
||||
end;""")
|
||||
self.assertEqual(vars["value"].getvalue(), "TSI")
|
||||
self.assertEqual(bind_vars["value"].getvalue(), "TSI")
|
||||
|
||||
def test_2515_BindOutSetInputSizesByInteger(self):
|
||||
def test_2515_bind_out_set_input_sizes_by_integer(self):
|
||||
"2515 - test binding out with set input sizes defined (by integer)"
|
||||
vars = self.cursor.setinputsizes(value = 30)
|
||||
bind_vars = self.cursor.setinputsizes(value=30)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:value := 'TSI (I)';
|
||||
end;""")
|
||||
self.assertEqual(vars["value"].getvalue(), "TSI (I)")
|
||||
self.assertEqual(bind_vars["value"].getvalue(), "TSI (I)")
|
||||
|
||||
def test_2516_BindInOutSetInputSizesByType(self):
|
||||
def test_2516_bind_in_out_set_input_sizes_by_type(self):
|
||||
"2516 - test binding in/out with set input sizes defined (by type)"
|
||||
vars = self.cursor.setinputsizes(value = cx_Oracle.STRING)
|
||||
bind_vars = self.cursor.setinputsizes(value=oracledb.STRING)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:value := :value || ' TSI';
|
||||
end;""",
|
||||
value = "InVal")
|
||||
self.assertEqual(vars["value"].getvalue(), "InVal TSI")
|
||||
value="InVal")
|
||||
self.assertEqual(bind_vars["value"].getvalue(), "InVal TSI")
|
||||
|
||||
def test_2517_BindInOutSetInputSizesByInteger(self):
|
||||
def test_2517_bind_in_out_set_input_sizes_by_integer(self):
|
||||
"2517 - test binding in/out with set input sizes defined (by integer)"
|
||||
vars = self.cursor.setinputsizes(value = 30)
|
||||
bind_vars = self.cursor.setinputsizes(value=30)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:value := :value || ' TSI (I)';
|
||||
end;""",
|
||||
value = "InVal")
|
||||
self.assertEqual(vars["value"].getvalue(), "InVal TSI (I)")
|
||||
value="InVal")
|
||||
self.assertEqual(bind_vars["value"].getvalue(), "InVal TSI (I)")
|
||||
|
||||
def test_2518_BindOutVar(self):
|
||||
def test_2518_bind_out_var(self):
|
||||
"2518 - test binding out with cursor.var() method"
|
||||
var = self.cursor.var(cx_Oracle.STRING)
|
||||
var = self.cursor.var(oracledb.STRING)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:value := 'TSI (VAR)';
|
||||
end;""",
|
||||
value = var)
|
||||
value=var)
|
||||
self.assertEqual(var.getvalue(), "TSI (VAR)")
|
||||
|
||||
def test_2519_BindInOutVarDirectSet(self):
|
||||
def test_2519_bind_in_out_var_direct_set(self):
|
||||
"2519 - test binding in/out with cursor.var() method"
|
||||
var = self.cursor.var(cx_Oracle.STRING)
|
||||
var = self.cursor.var(oracledb.STRING)
|
||||
var.setvalue(0, "InVal")
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:value := :value || ' TSI (VAR)';
|
||||
end;""",
|
||||
value = var)
|
||||
value=var)
|
||||
self.assertEqual(var.getvalue(), "InVal TSI (VAR)")
|
||||
|
||||
def test_2520_BindLongString(self):
|
||||
def test_2520_bind_long_string(self):
|
||||
"2520 - test that binding a long string succeeds"
|
||||
self.cursor.setinputsizes(bigString = cx_Oracle.DB_TYPE_LONG)
|
||||
self.cursor.setinputsizes(big_string=oracledb.DB_TYPE_LONG)
|
||||
self.cursor.execute("""
|
||||
declare
|
||||
t_Temp varchar2(20000);
|
||||
begin
|
||||
t_Temp := :bigString;
|
||||
t_Temp := :big_string;
|
||||
end;""",
|
||||
bigString = "X" * 10000)
|
||||
big_string="X" * 10000)
|
||||
|
||||
def test_2521_BindLongStringAfterSettingSize(self):
|
||||
def test_2521_bind_long_string_after_setting_size(self):
|
||||
"2521 - test that setinputsizes() returns a long variable"
|
||||
var = self.cursor.setinputsizes(test = 90000)["test"]
|
||||
inString = "1234567890" * 9000
|
||||
var.setvalue(0, inString)
|
||||
outString = var.getvalue()
|
||||
self.assertEqual(inString, outString,
|
||||
"output does not match: in was %d, out was %d" % \
|
||||
(len(inString), len(outString)))
|
||||
var = self.cursor.setinputsizes(test=90000)["test"]
|
||||
in_string = "1234567890" * 9000
|
||||
var.setvalue(0, in_string)
|
||||
out_string = var.getvalue()
|
||||
msg = f"output does not match: in was {len(in_string)}, " \
|
||||
f"out was {len(out_string)}"
|
||||
self.assertEqual(in_string, out_string, msg)
|
||||
|
||||
def test_2522_CursorDescription(self):
|
||||
def test_2522_cursor_description(self):
|
||||
"2522 - test cursor description is accurate"
|
||||
self.cursor.execute("select * from TestStrings")
|
||||
self.assertEqual(self.cursor.description,
|
||||
[ ('INTCOL', cx_Oracle.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
|
||||
('STRINGCOL', cx_Oracle.DB_TYPE_VARCHAR, 20,
|
||||
20 * TestEnv.GetCharSetRatio(), None,
|
||||
None, 0),
|
||||
('RAWCOL', cx_Oracle.DB_TYPE_RAW, 30, 30, None, None, 0),
|
||||
('FIXEDCHARCOL', cx_Oracle.DB_TYPE_CHAR, 40,
|
||||
40 * TestEnv.GetCharSetRatio(),
|
||||
None, None, 0),
|
||||
('NULLABLECOL', cx_Oracle.DB_TYPE_VARCHAR, 50,
|
||||
50 * TestEnv.GetCharSetRatio(), None,
|
||||
None, 1) ])
|
||||
expected_value = [
|
||||
('INTCOL', oracledb.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
|
||||
('STRINGCOL', oracledb.DB_TYPE_VARCHAR, 20,
|
||||
20 * base.get_charset_ratio(), None, None, 0),
|
||||
('RAWCOL', oracledb.DB_TYPE_RAW, 30, 30, None, None, 0),
|
||||
('FIXEDCHARCOL', oracledb.DB_TYPE_CHAR, 40,
|
||||
40 * base.get_charset_ratio(), None, None, 0),
|
||||
('NULLABLECOL', oracledb.DB_TYPE_VARCHAR, 50,
|
||||
50 * base.get_charset_ratio(), None, None, 1)
|
||||
]
|
||||
self.assertEqual(self.cursor.description, expected_value)
|
||||
|
||||
def test_2523_FetchAll(self):
|
||||
def test_2523_fetchall(self):
|
||||
"2523 - test that fetching all of the data returns the correct results"
|
||||
self.cursor.execute("select * From TestStrings order by IntCol")
|
||||
self.assertEqual(self.cursor.fetchall(), self.rawData)
|
||||
self.assertEqual(self.cursor.fetchall(), self.raw_data)
|
||||
self.assertEqual(self.cursor.fetchall(), [])
|
||||
|
||||
def test_2524_FetchMany(self):
|
||||
def test_2524_fetchmany(self):
|
||||
"2524 - test that fetching data in chunks returns the correct results"
|
||||
self.cursor.execute("select * From TestStrings order by IntCol")
|
||||
self.assertEqual(self.cursor.fetchmany(3), self.rawData[0:3])
|
||||
self.assertEqual(self.cursor.fetchmany(2), self.rawData[3:5])
|
||||
self.assertEqual(self.cursor.fetchmany(4), self.rawData[5:9])
|
||||
self.assertEqual(self.cursor.fetchmany(3), self.rawData[9:])
|
||||
self.assertEqual(self.cursor.fetchmany(3), self.raw_data[0:3])
|
||||
self.assertEqual(self.cursor.fetchmany(2), self.raw_data[3:5])
|
||||
self.assertEqual(self.cursor.fetchmany(4), self.raw_data[5:9])
|
||||
self.assertEqual(self.cursor.fetchmany(3), self.raw_data[9:])
|
||||
self.assertEqual(self.cursor.fetchmany(3), [])
|
||||
|
||||
def test_2525_FetchOne(self):
|
||||
def test_2525_fetchone(self):
|
||||
"2525 - test that fetching a single row returns the correct results"
|
||||
self.cursor.execute("""
|
||||
select *
|
||||
from TestStrings
|
||||
where IntCol in (3, 4)
|
||||
order by IntCol""")
|
||||
self.assertEqual(self.cursor.fetchone(), self.dataByKey[3])
|
||||
self.assertEqual(self.cursor.fetchone(), self.dataByKey[4])
|
||||
self.assertEqual(self.cursor.fetchone(), self.data_by_key[3])
|
||||
self.assertEqual(self.cursor.fetchone(), self.data_by_key[4])
|
||||
self.assertEqual(self.cursor.fetchone(), None)
|
||||
|
||||
def test_2526_SupplementalCharacters(self):
|
||||
def test_2526_supplemental_characters(self):
|
||||
"2526 - test binding and fetching supplemental charcters"
|
||||
self.cursor.execute("""
|
||||
select value
|
||||
|
@ -344,7 +338,7 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
charset, = self.cursor.fetchone()
|
||||
if charset != "AL32UTF8":
|
||||
self.skipTest("Database character set must be AL32UTF8")
|
||||
supplementalChars = "𠜎 𠜱 𠝹 𠱓 𠱸 𠲖 𠳏 𠳕 𠴕 𠵼 𠵿 𠸎 𠸏 𠹷 𠺝 " \
|
||||
supplemental_chars = "𠜎 𠜱 𠝹 𠱓 𠱸 𠲖 𠳏 𠳕 𠴕 𠵼 𠵿 𠸎 𠸏 𠹷 𠺝 " \
|
||||
"𠺢 𠻗 𠻹 𠻺 𠼭 𠼮 𠽌 𠾴 𠾼 𠿪 𡁜 𡁯 𡁵 𡁶 𡁻 𡃁 𡃉 𡇙 𢃇 " \
|
||||
"𢞵 𢫕 𢭃 𢯊 𢱑 𢱕 𢳂 𢴈 𢵌 𢵧 𢺳 𣲷 𤓓 𤶸 𤷪 𥄫 𦉘 𦟌 𦧲 " \
|
||||
"𦧺 𧨾 𨅝 𨈇 𨋢 𨳊 𨳍 𨳒 𩶘"
|
||||
|
@ -352,34 +346,34 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
self.cursor.execute("""
|
||||
insert into TestTempTable (IntCol, StringCol)
|
||||
values (:1, :2)""",
|
||||
(1, supplementalChars))
|
||||
(1, supplemental_chars))
|
||||
self.connection.commit()
|
||||
self.cursor.execute("select StringCol from TestTempTable")
|
||||
value, = self.cursor.fetchone()
|
||||
self.assertEqual(value, supplementalChars)
|
||||
self.assertEqual(value, supplemental_chars)
|
||||
|
||||
def test_2527_BindTwiceWithLargeStringSecond(self):
|
||||
def test_2527_bind_twice_with_large_string_second(self):
|
||||
"2527 - test binding twice with a larger string the second time"
|
||||
self.cursor.execute("truncate table TestTempTable")
|
||||
sql = "insert into TestTempTable (IntCol, StringCol) values (:1, :2)"
|
||||
shortString = "short string"
|
||||
longString = "long string " * 30
|
||||
self.cursor.execute(sql, (1, shortString))
|
||||
self.cursor.execute(sql, (2, longString))
|
||||
short_string = "short string"
|
||||
long_string = "long string " * 30
|
||||
self.cursor.execute(sql, (1, short_string))
|
||||
self.cursor.execute(sql, (2, long_string))
|
||||
self.connection.commit()
|
||||
self.cursor.execute("""
|
||||
select IntCol, StringCol
|
||||
from TestTempTable
|
||||
order by IntCol""")
|
||||
self.assertEqual(self.cursor.fetchall(),
|
||||
[(1, shortString), (2, longString)])
|
||||
[(1, short_string), (2, long_string)])
|
||||
|
||||
def test_2528_Issue50(self):
|
||||
def test_2528_issue_50(self):
|
||||
"2528 - test issue 50 - avoid error ORA-24816"
|
||||
cursor = self.connection.cursor()
|
||||
try:
|
||||
cursor.execute("drop table issue_50 purge")
|
||||
except cx_Oracle.DatabaseError:
|
||||
except oracledb.DatabaseError:
|
||||
pass
|
||||
cursor.execute("""
|
||||
create table issue_50 (
|
||||
|
@ -390,49 +384,49 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
NClob1 nclob,
|
||||
NClob2 nclob
|
||||
)""")
|
||||
idVar = cursor.var(cx_Oracle.NUMBER)
|
||||
id_var = cursor.var(oracledb.NUMBER)
|
||||
cursor.execute("""
|
||||
insert into issue_50 (Id, Str2, Str3, NClob1, NClob2, Str1)
|
||||
values (:arg0, :arg1, :arg2, :arg3, :arg4, :arg5)
|
||||
returning id into :arg6""",
|
||||
[1, '555a4c78', 'f319ef0e', '23009914', '', '', idVar])
|
||||
[1, '555a4c78', 'f319ef0e', '23009914', '', '', id_var])
|
||||
cursor = self.connection.cursor()
|
||||
cursor.execute("""
|
||||
insert into issue_50 (Id, Str2, Str3, NClob1, NClob2, Str1)
|
||||
values (:arg0, :arg1, :arg2, :arg3, :arg4, :arg5)
|
||||
returning id into :arg6""",
|
||||
[2, u'd5ff845a', u'94275767', u'bf161ff6', u'', u'', idVar])
|
||||
[2, u'd5ff845a', u'94275767', u'bf161ff6', u'', u'', id_var])
|
||||
cursor.execute("drop table issue_50 purge")
|
||||
|
||||
def test_2529_SetRowidToString(self):
|
||||
def test_2529_set_rowid_to_string(self):
|
||||
"2529 - test assigning a string to rowid"
|
||||
var = self.cursor.var(cx_Oracle.ROWID)
|
||||
self.assertRaises(cx_Oracle.NotSupportedError, var.setvalue, 0,
|
||||
var = self.cursor.var(oracledb.ROWID)
|
||||
self.assertRaises(oracledb.NotSupportedError, var.setvalue, 0,
|
||||
"ABDHRYTHFJGKDKKDH")
|
||||
|
||||
def test_2530_ShortXMLAsString(self):
|
||||
def test_2530_short_xml_as_string(self):
|
||||
"2530 - test fetching XMLType object as a string"
|
||||
self.cursor.execute("""
|
||||
select XMLElement("string", stringCol)
|
||||
from TestStrings
|
||||
where intCol = 1""")
|
||||
actualValue, = self.cursor.fetchone()
|
||||
expectedValue = "<string>String 1</string>"
|
||||
self.assertEqual(actualValue, expectedValue)
|
||||
actual_value, = self.cursor.fetchone()
|
||||
expected_value = "<string>String 1</string>"
|
||||
self.assertEqual(actual_value, expected_value)
|
||||
|
||||
def test_2531_LongXMLAsString(self):
|
||||
def test_2531_long_xml_as_string(self):
|
||||
"2531 - test inserting and fetching an XMLType object (1K) as a string"
|
||||
chars = string.ascii_uppercase + string.ascii_lowercase
|
||||
randomString = ''.join(random.choice(chars) for _ in range(1024))
|
||||
intVal = 200
|
||||
xmlString = '<data>' + randomString + '</data>'
|
||||
random_string = ''.join(random.choice(chars) for _ in range(1024))
|
||||
int_val = 200
|
||||
xml_string = '<data>' + random_string + '</data>'
|
||||
self.cursor.execute("""
|
||||
insert into TestXML (IntCol, XMLCol)
|
||||
values (:1, :2)""", (intVal, xmlString))
|
||||
values (:1, :2)""", (int_val, xml_string))
|
||||
self.cursor.execute("select XMLCol from TestXML where intCol = :1",
|
||||
(intVal,))
|
||||
actualValue, = self.cursor.fetchone()
|
||||
self.assertEqual(actualValue.strip(), xmlString)
|
||||
(int_val,))
|
||||
actual_value, = self.cursor.fetchone()
|
||||
self.assertEqual(actual_value.strip(), xml_string)
|
||||
|
||||
if __name__ == "__main__":
|
||||
TestEnv.RunTestCases()
|
||||
base.run_test_cases()
|
||||
|
|
|
@ -11,138 +11,141 @@
|
|||
2600 - Module for testing timestamp variables
|
||||
"""
|
||||
|
||||
import TestEnv
|
||||
import base
|
||||
|
||||
import cx_Oracle
|
||||
import cx_Oracle as oracledb
|
||||
import time
|
||||
|
||||
class TestCase(TestEnv.BaseTestCase):
|
||||
class TestCase(base.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
TestEnv.BaseTestCase.setUp(self)
|
||||
self.rawData = []
|
||||
self.dataByKey = {}
|
||||
super().setUp()
|
||||
self.raw_data = []
|
||||
self.data_by_key = {}
|
||||
for i in range(1, 11):
|
||||
timeTuple = (2002, 12, 9, 0, 0, 0, 0, 0, -1)
|
||||
timeInTicks = time.mktime(timeTuple) + i * 86400
|
||||
dateValue = cx_Oracle.TimestampFromTicks(int(timeInTicks))
|
||||
strValue = str(i * 50)
|
||||
fsecond = int(strValue + "0" * (6 - len(strValue)))
|
||||
dateCol = cx_Oracle.Timestamp(dateValue.year, dateValue.month,
|
||||
dateValue.day, dateValue.hour, dateValue.minute,
|
||||
i * 2, fsecond)
|
||||
time_tuple = (2002, 12, 9, 0, 0, 0, 0, 0, -1)
|
||||
time_in_ticks = time.mktime(time_tuple) + i * 86400
|
||||
date_value = oracledb.TimestampFromTicks(int(time_in_ticks))
|
||||
str_value = str(i * 50)
|
||||
fsecond = int(str_value + "0" * (6 - len(str_value)))
|
||||
date_col = oracledb.Timestamp(date_value.year, date_value.month,
|
||||
date_value.day, date_value.hour,
|
||||
date_value.minute, i * 2, fsecond)
|
||||
if i % 2:
|
||||
timeInTicks = time.mktime(timeTuple) + i * 86400 + 86400
|
||||
dateValue = cx_Oracle.TimestampFromTicks(int(timeInTicks))
|
||||
strValue = str(i * 125)
|
||||
fsecond = int(strValue + "0" * (6 - len(strValue)))
|
||||
nullableCol = cx_Oracle.Timestamp(dateValue.year,
|
||||
dateValue.month, dateValue.day, dateValue.hour,
|
||||
dateValue.minute, i * 3, fsecond)
|
||||
time_in_ticks = time.mktime(time_tuple) + i * 86400 + 86400
|
||||
date_value = oracledb.TimestampFromTicks(int(time_in_ticks))
|
||||
str_value = str(i * 125)
|
||||
fsecond = int(str_value + "0" * (6 - len(str_value)))
|
||||
nullable_col = oracledb.Timestamp(date_value.year,
|
||||
date_value.month,
|
||||
date_value.day,
|
||||
date_value.hour,
|
||||
date_value.minute, i * 3,
|
||||
fsecond)
|
||||
else:
|
||||
nullableCol = None
|
||||
tuple = (i, dateCol, nullableCol)
|
||||
self.rawData.append(tuple)
|
||||
self.dataByKey[i] = tuple
|
||||
nullable_col = None
|
||||
data_tuple = (i, date_col, nullable_col)
|
||||
self.raw_data.append(data_tuple)
|
||||
self.data_by_key[i] = data_tuple
|
||||
|
||||
def test_2600_BindTimestamp(self):
|
||||
def test_2600_bind_timestamp(self):
|
||||
"2600 - test binding in a timestamp"
|
||||
self.cursor.setinputsizes(value = cx_Oracle.DB_TYPE_TIMESTAMP)
|
||||
self.cursor.setinputsizes(value=oracledb.DB_TYPE_TIMESTAMP)
|
||||
self.cursor.execute("""
|
||||
select * from TestTimestamps
|
||||
where TimestampCol = :value""",
|
||||
value = cx_Oracle.Timestamp(2002, 12, 14, 0, 0, 10, 250000))
|
||||
self.assertEqual(self.cursor.fetchall(), [self.dataByKey[5]])
|
||||
value=oracledb.Timestamp(2002, 12, 14, 0, 0, 10, 250000))
|
||||
self.assertEqual(self.cursor.fetchall(), [self.data_by_key[5]])
|
||||
|
||||
def test_2601_BindNull(self):
|
||||
def test_2601_bind_null(self):
|
||||
"2601 - test binding in a null"
|
||||
self.cursor.setinputsizes(value = cx_Oracle.DB_TYPE_TIMESTAMP)
|
||||
self.cursor.setinputsizes(value=oracledb.DB_TYPE_TIMESTAMP)
|
||||
self.cursor.execute("""
|
||||
select * from TestTimestamps
|
||||
where TimestampCol = :value""",
|
||||
value = None)
|
||||
value=None)
|
||||
self.assertEqual(self.cursor.fetchall(), [])
|
||||
|
||||
def test_2602_BindOutSetInputSizes(self):
|
||||
def test_2602_bind_out_set_input_sizes(self):
|
||||
"2602 - test binding out with set input sizes defined"
|
||||
vars = self.cursor.setinputsizes(value = cx_Oracle.DB_TYPE_TIMESTAMP)
|
||||
bind_vars = self.cursor.setinputsizes(value=oracledb.DB_TYPE_TIMESTAMP)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:value := to_timestamp('20021209', 'YYYYMMDD');
|
||||
end;""")
|
||||
self.assertEqual(vars["value"].getvalue(),
|
||||
cx_Oracle.Timestamp(2002, 12, 9))
|
||||
self.assertEqual(bind_vars["value"].getvalue(),
|
||||
oracledb.Timestamp(2002, 12, 9))
|
||||
|
||||
def test_2603_BindInOutSetInputSizes(self):
|
||||
def test_2603_bind_in_out_set_input_sizes(self):
|
||||
"2603 - test binding in/out with set input sizes defined"
|
||||
vars = self.cursor.setinputsizes(value = cx_Oracle.DB_TYPE_TIMESTAMP)
|
||||
bind_vars = self.cursor.setinputsizes(value=oracledb.DB_TYPE_TIMESTAMP)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:value := :value + 5.25;
|
||||
end;""",
|
||||
value = cx_Oracle.Timestamp(2002, 12, 12, 10, 0, 0))
|
||||
self.assertEqual(vars["value"].getvalue(),
|
||||
cx_Oracle.Timestamp(2002, 12, 17, 16, 0, 0))
|
||||
value = oracledb.Timestamp(2002, 12, 12, 10, 0, 0))
|
||||
self.assertEqual(bind_vars["value"].getvalue(),
|
||||
oracledb.Timestamp(2002, 12, 17, 16, 0, 0))
|
||||
|
||||
def test_2604_BindOutVar(self):
|
||||
def test_2604_bind_out_var(self):
|
||||
"2604 - test binding out with cursor.var() method"
|
||||
var = self.cursor.var(cx_Oracle.DB_TYPE_TIMESTAMP)
|
||||
var = self.cursor.var(oracledb.DB_TYPE_TIMESTAMP)
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:value := to_date('20021231 12:31:00',
|
||||
'YYYYMMDD HH24:MI:SS');
|
||||
end;""",
|
||||
value = var)
|
||||
value=var)
|
||||
self.assertEqual(var.getvalue(),
|
||||
cx_Oracle.Timestamp(2002, 12, 31, 12, 31, 0))
|
||||
oracledb.Timestamp(2002, 12, 31, 12, 31, 0))
|
||||
|
||||
def test_2605_BindInOutVarDirectSet(self):
|
||||
def test_2605_bind_in_out_var_direct_set(self):
|
||||
"2605 - test binding in/out with cursor.var() method"
|
||||
var = self.cursor.var(cx_Oracle.DB_TYPE_TIMESTAMP)
|
||||
var.setvalue(0, cx_Oracle.Timestamp(2002, 12, 9, 6, 0, 0))
|
||||
var = self.cursor.var(oracledb.DB_TYPE_TIMESTAMP)
|
||||
var.setvalue(0, oracledb.Timestamp(2002, 12, 9, 6, 0, 0))
|
||||
self.cursor.execute("""
|
||||
begin
|
||||
:value := :value + 5.25;
|
||||
end;""",
|
||||
value = var)
|
||||
self.assertEqual(var.getvalue(),
|
||||
cx_Oracle.Timestamp(2002, 12, 14, 12, 0, 0))
|
||||
oracledb.Timestamp(2002, 12, 14, 12, 0, 0))
|
||||
|
||||
def test_2606_CursorDescription(self):
|
||||
def test_2606_cursor_description(self):
|
||||
"2606 - test cursor description is accurate"
|
||||
self.cursor.execute("select * from TestTimestamps")
|
||||
self.assertEqual(self.cursor.description,
|
||||
[ ('INTCOL', cx_Oracle.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
|
||||
('TIMESTAMPCOL', cx_Oracle.DB_TYPE_TIMESTAMP, 23, None, 0, 6,
|
||||
0),
|
||||
('NULLABLECOL', cx_Oracle.DB_TYPE_TIMESTAMP, 23, None, 0, 6,
|
||||
1) ])
|
||||
expected_value = [
|
||||
('INTCOL', oracledb.DB_TYPE_NUMBER, 10, None, 9, 0, 0),
|
||||
('TIMESTAMPCOL', oracledb.DB_TYPE_TIMESTAMP, 23, None, 0, 6, 0),
|
||||
('NULLABLECOL', oracledb.DB_TYPE_TIMESTAMP, 23, None, 0, 6, 1)
|
||||
]
|
||||
self.assertEqual(self.cursor.description, expected_value)
|
||||
|
||||
def test_2607_FetchAll(self):
|
||||
def test_2607_fetchall(self):
|
||||
"2607 - test that fetching all of the data returns the correct results"
|
||||
self.cursor.execute("select * From TestTimestamps order by IntCol")
|
||||
self.assertEqual(self.cursor.fetchall(), self.rawData)
|
||||
self.assertEqual(self.cursor.fetchall(), self.raw_data)
|
||||
self.assertEqual(self.cursor.fetchall(), [])
|
||||
|
||||
def test_2608_FetchMany(self):
|
||||
def test_2608_fetchmany(self):
|
||||
"2608 - test that fetching data in chunks returns the correct results"
|
||||
self.cursor.execute("select * From TestTimestamps order by IntCol")
|
||||
self.assertEqual(self.cursor.fetchmany(3), self.rawData[0:3])
|
||||
self.assertEqual(self.cursor.fetchmany(2), self.rawData[3:5])
|
||||
self.assertEqual(self.cursor.fetchmany(4), self.rawData[5:9])
|
||||
self.assertEqual(self.cursor.fetchmany(3), self.rawData[9:])
|
||||
self.assertEqual(self.cursor.fetchmany(3), self.raw_data[0:3])
|
||||
self.assertEqual(self.cursor.fetchmany(2), self.raw_data[3:5])
|
||||
self.assertEqual(self.cursor.fetchmany(4), self.raw_data[5:9])
|
||||
self.assertEqual(self.cursor.fetchmany(3), self.raw_data[9:])
|
||||
self.assertEqual(self.cursor.fetchmany(3), [])
|
||||
|
||||
def test_2609_FetchOne(self):
|
||||
def test_2609_fetchone(self):
|
||||
"2609 - test that fetching a single row returns the correct results"
|
||||
self.cursor.execute("""
|
||||
select *
|
||||
from TestTimestamps
|
||||
where IntCol in (3, 4)
|
||||
order by IntCol""")
|
||||
self.assertEqual(self.cursor.fetchone(), self.dataByKey[3])
|
||||
self.assertEqual(self.cursor.fetchone(), self.dataByKey[4])
|
||||
self.assertEqual(self.cursor.fetchone(), self.data_by_key[3])
|
||||
self.assertEqual(self.cursor.fetchone(), self.data_by_key[4])
|
||||
self.assertEqual(self.cursor.fetchone(), None)
|
||||
|
||||
if __name__ == "__main__":
|
||||
TestEnv.RunTestCases()
|
||||
base.run_test_cases()
|
||||
|
|
|
@ -6,373 +6,370 @@
|
|||
2700 - Module for testing AQ
|
||||
"""
|
||||
|
||||
import TestEnv
|
||||
import base
|
||||
|
||||
import cx_Oracle
|
||||
import cx_Oracle as oracledb
|
||||
import decimal
|
||||
import threading
|
||||
|
||||
class TestCase(TestEnv.BaseTestCase):
|
||||
bookQueueName = "TEST_BOOK_QUEUE"
|
||||
bookData = [
|
||||
("Wings of Fire", "A.P.J. Abdul Kalam",
|
||||
decimal.Decimal("15.75")),
|
||||
("The Story of My Life", "Hellen Keller",
|
||||
decimal.Decimal("10.50")),
|
||||
("The Chronicles of Narnia", "C.S. Lewis",
|
||||
decimal.Decimal("25.25"))
|
||||
class TestCase(base.BaseTestCase):
|
||||
book_type_name = "UDT_BOOK"
|
||||
book_queue_name = "TEST_BOOK_QUEUE"
|
||||
book_data = [
|
||||
("Wings of Fire", "A.P.J. Abdul Kalam", decimal.Decimal("15.75")),
|
||||
("The Story of My Life", "Hellen Keller", decimal.Decimal("10.50")),
|
||||
("The Chronicles of Narnia", "C.S. Lewis", decimal.Decimal("25.25"))
|
||||
]
|
||||
|
||||
def __clearBooksQueue(self):
|
||||
booksType = self.connection.gettype("UDT_BOOK")
|
||||
book = booksType.newobject()
|
||||
def __clear_books_queue(self):
|
||||
books_type = self.connection.gettype(self.book_type_name)
|
||||
book = books_type.newobject()
|
||||
options = self.connection.deqoptions()
|
||||
options.wait = cx_Oracle.DEQ_NO_WAIT
|
||||
options.deliverymode = cx_Oracle.MSG_PERSISTENT_OR_BUFFERED
|
||||
options.visibility = cx_Oracle.ENQ_IMMEDIATE
|
||||
options.wait = oracledb.DEQ_NO_WAIT
|
||||
options.deliverymode = oracledb.MSG_PERSISTENT_OR_BUFFERED
|
||||
options.visibility = oracledb.ENQ_IMMEDIATE
|
||||
props = self.connection.msgproperties()
|
||||
while self.connection.deq(self.bookQueueName, options, props, book):
|
||||
while self.connection.deq(self.book_queue_name, options, props, book):
|
||||
pass
|
||||
|
||||
def __deqInThread(self, results):
|
||||
connection = TestEnv.GetConnection()
|
||||
booksType = connection.gettype("UDT_BOOK")
|
||||
book = booksType.newobject()
|
||||
def __deq_in_thread(self, results):
|
||||
connection = base.get_connection()
|
||||
books_type = connection.gettype(self.book_type_name)
|
||||
book = books_type.newobject()
|
||||
options = connection.deqoptions()
|
||||
options.wait = 10
|
||||
props = connection.msgproperties()
|
||||
if connection.deq(self.bookQueueName, options, props, book):
|
||||
if connection.deq(self.book_queue_name, options, props, book):
|
||||
results.append((book.TITLE, book.AUTHORS, book.PRICE))
|
||||
connection.commit()
|
||||
|
||||
def __verifyAttribute(self, obj, attrName, value):
|
||||
def __verify_attr(self, obj, attrName, value):
|
||||
setattr(obj, attrName, value)
|
||||
self.assertEqual(getattr(obj, attrName), value)
|
||||
|
||||
def test_2700_DeqEmpty(self):
|
||||
def test_2700_deq_empty(self):
|
||||
"2700 - test dequeuing an empty queue"
|
||||
self.__clearBooksQueue()
|
||||
booksType = self.connection.gettype("UDT_BOOK")
|
||||
book = booksType.newobject()
|
||||
self.__clear_books_queue()
|
||||
books_type = self.connection.gettype(self.book_type_name)
|
||||
book = books_type.newobject()
|
||||
options = self.connection.deqoptions()
|
||||
options.wait = cx_Oracle.DEQ_NO_WAIT
|
||||
options.wait = oracledb.DEQ_NO_WAIT
|
||||
props = self.connection.msgproperties()
|
||||
messageId = self.connection.deq(self.bookQueueName, options, props,
|
||||
book)
|
||||
self.assertTrue(messageId is None)
|
||||
message_id = self.connection.deq(self.book_queue_name, options, props,
|
||||
book)
|
||||
self.assertTrue(message_id is None)
|
||||
|
||||
def test_2701_DeqEnq(self):
|
||||
def test_2701_deq_enq(self):
|
||||
"2701 - test enqueuing and dequeuing multiple messages"
|
||||
self.__clearBooksQueue()
|
||||
booksType = self.connection.gettype("UDT_BOOK")
|
||||
self.__clear_books_queue()
|
||||
books_type = self.connection.gettype(self.book_type_name)
|
||||
options = self.connection.enqoptions()
|
||||
props = self.connection.msgproperties()
|
||||
for title, authors, price in self.bookData:
|
||||
book = booksType.newobject()
|
||||
for title, authors, price in self.book_data:
|
||||
book = books_type.newobject()
|
||||
book.TITLE = title
|
||||
book.AUTHORS = authors
|
||||
book.PRICE = price
|
||||
self.connection.enq(self.bookQueueName, options, props, book)
|
||||
self.connection.enq(self.book_queue_name, options, props, book)
|
||||
options = self.connection.deqoptions()
|
||||
options.navigation = cx_Oracle.DEQ_FIRST_MSG
|
||||
options.wait = cx_Oracle.DEQ_NO_WAIT
|
||||
options.navigation = oracledb.DEQ_FIRST_MSG
|
||||
options.wait = oracledb.DEQ_NO_WAIT
|
||||
results = []
|
||||
while self.connection.deq(self.bookQueueName, options, props, book):
|
||||
while self.connection.deq(self.book_queue_name, options, props, book):
|
||||
row = (book.TITLE, book.AUTHORS, book.PRICE)
|
||||
results.append(row)
|
||||
self.connection.commit()
|
||||
self.assertEqual(results, self.bookData)
|
||||
self.assertEqual(results, self.book_data)
|
||||
|
||||
def test_2702_DeqModeRemoveNoData(self):
|
||||
def test_2702_deq_mode_remove_no_data(self):
|
||||
"2702 - test dequeuing with DEQ_REMOVE_NODATA option"
|
||||
self.__clearBooksQueue()
|
||||
booksType = self.connection.gettype("UDT_BOOK")
|
||||
book = booksType.newobject()
|
||||
title, authors, price = self.bookData[1]
|
||||
self.__clear_books_queue()
|
||||
books_type = self.connection.gettype(self.book_type_name)
|
||||
book = books_type.newobject()
|
||||
title, authors, price = self.book_data[1]
|
||||
book.TITLE = title
|
||||
book.AUTHORS = authors
|
||||
book.PRICE = price
|
||||
options = self.connection.enqoptions()
|
||||
props = self.connection.msgproperties()
|
||||
self.connection.enq(self.bookQueueName, options, props, book)
|
||||
self.connection.enq(self.book_queue_name, options, props, book)
|
||||
options = self.connection.deqoptions()
|
||||
options.navigation = cx_Oracle.DEQ_FIRST_MSG
|
||||
options.wait = cx_Oracle.DEQ_NO_WAIT
|
||||
options.mode = cx_Oracle.DEQ_REMOVE_NODATA
|
||||
book = booksType.newobject()
|
||||
messageId = self.connection.deq(self.bookQueueName, options, props,
|
||||
book)
|
||||
options.navigation = oracledb.DEQ_FIRST_MSG
|
||||
options.wait = oracledb.DEQ_NO_WAIT
|
||||
options.mode = oracledb.DEQ_REMOVE_NODATA
|
||||
book = books_type.newobject()
|
||||
message_id = self.connection.deq(self.book_queue_name, options, props,
|
||||
book)
|
||||
self.connection.commit()
|
||||
self.assertTrue(messageId is not None)
|
||||
self.assertTrue(message_id is not None)
|
||||
self.assertEqual(book.TITLE, "")
|
||||
|
||||
def test_2703_DeqOptions(self):
|
||||
def test_2703_deq_options(self):
|
||||
"2703 - test getting/setting dequeue options attributes"
|
||||
options = self.connection.deqoptions()
|
||||
self.__verifyAttribute(options, "condition", "TEST_CONDITION")
|
||||
self.__verifyAttribute(options, "consumername", "TEST_CONSUMERNAME")
|
||||
self.__verifyAttribute(options, "correlation", "TEST_CORRELATION")
|
||||
self.__verifyAttribute(options, "mode", cx_Oracle.DEQ_LOCKED)
|
||||
self.__verifyAttribute(options, "navigation",
|
||||
cx_Oracle.DEQ_NEXT_TRANSACTION)
|
||||
self.__verifyAttribute(options, "transformation",
|
||||
"TEST_TRANSFORMATION")
|
||||
self.__verifyAttribute(options, "visibility", cx_Oracle.ENQ_IMMEDIATE)
|
||||
self.__verifyAttribute(options, "wait", 1287)
|
||||
self.__verifyAttribute(options, "msgid", b'mID')
|
||||
self.__verify_attr(options, "condition", "TEST_CONDITION")
|
||||
self.__verify_attr(options, "consumername", "TEST_CONSUMERNAME")
|
||||
self.__verify_attr(options, "correlation", "TEST_CORRELATION")
|
||||
self.__verify_attr(options, "mode", oracledb.DEQ_LOCKED)
|
||||
self.__verify_attr(options, "navigation",
|
||||
oracledb.DEQ_NEXT_TRANSACTION)
|
||||
self.__verify_attr(options, "transformation", "TEST_TRANSFORMATION")
|
||||
self.__verify_attr(options, "visibility", oracledb.ENQ_IMMEDIATE)
|
||||
self.__verify_attr(options, "wait", 1287)
|
||||
self.__verify_attr(options, "msgid", b'mID')
|
||||
|
||||
def test_2704_DeqWithWait(self):
|
||||
def test_2704_deq_with_wait(self):
|
||||
"2704 - test waiting for dequeue"
|
||||
self.__clearBooksQueue()
|
||||
self.__clear_books_queue()
|
||||
results = []
|
||||
thread = threading.Thread(target = self.__deqInThread,
|
||||
args = (results,))
|
||||
thread = threading.Thread(target = self.__deq_in_thread,
|
||||
args = (results,))
|
||||
thread.start()
|
||||
booksType = self.connection.gettype("UDT_BOOK")
|
||||
book = booksType.newobject()
|
||||
title, authors, price = self.bookData[0]
|
||||
books_type = self.connection.gettype(self.book_type_name)
|
||||
book = books_type.newobject()
|
||||
title, authors, price = self.book_data[0]
|
||||
book.TITLE = title
|
||||
book.AUTHORS = authors
|
||||
book.PRICE = price
|
||||
options = self.connection.enqoptions()
|
||||
props = self.connection.msgproperties()
|
||||
self.connection.enq(self.bookQueueName, options, props, book)
|
||||
self.connection.enq(self.book_queue_name, options, props, book)
|
||||
self.connection.commit()
|
||||
thread.join()
|
||||
self.assertEqual(results, [(title, authors, price)])
|
||||
|
||||
def test_2705_EnqOptions(self):
|
||||
def test_2705_enq_options(self):
|
||||
"2705 - test getting/setting enqueue options attributes"
|
||||
options = self.connection.enqoptions()
|
||||
self.__verifyAttribute(options, "visibility", cx_Oracle.ENQ_IMMEDIATE)
|
||||
self.__verify_attr(options, "visibility", oracledb.ENQ_IMMEDIATE)
|
||||
|
||||
def test_2706_ErrorsForInvalidValues(self):
|
||||
def test_2706_errors_for_invalid_values(self):
|
||||
"2706 - test errors for invalid values for options"
|
||||
booksType = self.connection.gettype("UDT_BOOK")
|
||||
book = booksType.newobject()
|
||||
books_type = self.connection.gettype(self.book_type_name)
|
||||
book = books_type.newobject()
|
||||
options = self.connection.enqoptions()
|
||||
props = self.connection.msgproperties()
|
||||
self.assertRaises(TypeError, self.connection.deq, self.bookQueueName,
|
||||
options, props, book)
|
||||
self.assertRaises(TypeError, self.connection.deq, self.book_queue_name,
|
||||
options, props, book)
|
||||
options = self.connection.deqoptions()
|
||||
self.assertRaises(TypeError, self.connection.enq, self.bookQueueName,
|
||||
options, props, book)
|
||||
self.assertRaises(TypeError, self.connection.enq, self.book_queue_name,
|
||||
options, props, book)
|
||||
|
||||
def test_2707_MsgProps(self):
|
||||
def test_2707_msg_props(self):
|
||||
"2707 - test getting/setting message properties attributes"
|
||||
props = self.connection.msgproperties()
|
||||
self.__verifyAttribute(props, "correlation", "TEST_CORRELATION")
|
||||
self.__verifyAttribute(props, "delay", 60)
|
||||
self.__verifyAttribute(props, "exceptionq", "TEST_EXCEPTIONQ")
|
||||
self.__verifyAttribute(props, "expiration", 30)
|
||||
self.__verify_attr(props, "correlation", "TEST_CORRELATION")
|
||||
self.__verify_attr(props, "delay", 60)
|
||||
self.__verify_attr(props, "exceptionq", "TEST_EXCEPTIONQ")
|
||||
self.__verify_attr(props, "expiration", 30)
|
||||
self.assertEqual(props.attempts, 0)
|
||||
self.__verifyAttribute(props, "priority", 1)
|
||||
self.__verifyAttribute(props, "msgid", b'mID')
|
||||
self.assertEqual(props.state, cx_Oracle.MSG_READY)
|
||||
self.__verify_attr(props, "priority", 1)
|
||||
self.__verify_attr(props, "msgid", b'mID')
|
||||
self.assertEqual(props.state, oracledb.MSG_READY)
|
||||
self.assertEqual(props.deliverymode, 0)
|
||||
|
||||
def test_2708_VisibilityModeCommit(self):
|
||||
def test_2708_visibility_mode_commit(self):
|
||||
"2708 - test enqueue visibility option - ENQ_ON_COMMIT"
|
||||
self.__clearBooksQueue()
|
||||
booksType = self.connection.gettype("UDT_BOOK")
|
||||
book = booksType.newobject()
|
||||
book.TITLE, book.AUTHORS, book.PRICE = self.bookData[0]
|
||||
enqOptions = self.connection.enqoptions()
|
||||
enqOptions.visibility = cx_Oracle.ENQ_ON_COMMIT
|
||||
self.__clear_books_queue()
|
||||
books_type = self.connection.gettype(self.book_type_name)
|
||||
book = books_type.newobject()
|
||||
book.TITLE, book.AUTHORS, book.PRICE = self.book_data[0]
|
||||
enq_options = self.connection.enqoptions()
|
||||
enq_options.visibility = oracledb.ENQ_ON_COMMIT
|
||||
props = self.connection.msgproperties()
|
||||
self.connection.enq(self.bookQueueName, enqOptions, props, book)
|
||||
self.connection.enq(self.book_queue_name, enq_options, props, book)
|
||||
|
||||
otherConnection = TestEnv.GetConnection()
|
||||
deqOptions = otherConnection.deqoptions()
|
||||
deqOptions.navigation = cx_Oracle.DEQ_FIRST_MSG
|
||||
deqOptions.wait = cx_Oracle.DEQ_NO_WAIT
|
||||
booksType = otherConnection.gettype("UDT_BOOK")
|
||||
book = booksType.newobject()
|
||||
props = otherConnection.msgproperties()
|
||||
messageId = otherConnection.deq(self.bookQueueName, deqOptions, props,
|
||||
book)
|
||||
self.assertTrue(messageId is None)
|
||||
other_connection = base.get_connection()
|
||||
deq_options = other_connection.deqoptions()
|
||||
deq_options.navigation = oracledb.DEQ_FIRST_MSG
|
||||
deq_options.wait = oracledb.DEQ_NO_WAIT
|
||||
books_type = other_connection.gettype(self.book_type_name)
|
||||
book = books_type.newobject()
|
||||
props = other_connection.msgproperties()
|
||||
message_id = other_connection.deq(self.book_queue_name, deq_options,
|
||||
props, book)
|
||||
self.assertTrue(message_id is None)
|
||||
self.connection.commit()
|
||||
messageId = otherConnection.deq(self.bookQueueName, deqOptions, props,
|
||||
book)
|
||||
self.assertTrue(messageId is not None)
|
||||
message_id = other_connection.deq(self.book_queue_name, deq_options,
|
||||
props, book)
|
||||
self.assertTrue(message_id is not None)
|
||||
|
||||
def test_2709_VisibilityModeImmediate(self):
|
||||
def test_2709_visibility_mode_immediate(self):
|
||||
"2709 - test enqueue visibility option - ENQ_IMMEDIATE"
|
||||
self.__clearBooksQueue()
|
||||
booksType = self.connection.gettype("UDT_BOOK")
|
||||
book = booksType.newobject()
|
||||
book.TITLE, book.AUTHORS, book.PRICE = self.bookData[0]
|
||||
enqOptions = self.connection.enqoptions()
|
||||
enqOptions.visibility = cx_Oracle.ENQ_IMMEDIATE
|
||||
self.__clear_books_queue()
|
||||
books_type = self.connection.gettype(self.book_type_name)
|
||||
book = books_type.newobject()
|
||||
book.TITLE, book.AUTHORS, book.PRICE = self.book_data[0]
|
||||
enq_options = self.connection.enqoptions()
|
||||
enq_options.visibility = oracledb.ENQ_IMMEDIATE
|
||||
props = self.connection.msgproperties()
|
||||
self.connection.enq(self.bookQueueName, enqOptions, props, book)
|
||||
self.connection.enq(self.book_queue_name, enq_options, props, book)
|
||||
|
||||
otherConnection = TestEnv.GetConnection()
|
||||
deqOptions = otherConnection.deqoptions()
|
||||
deqOptions.navigation = cx_Oracle.DEQ_FIRST_MSG
|
||||
deqOptions.visibility = cx_Oracle.DEQ_ON_COMMIT
|
||||
deqOptions.wait = cx_Oracle.DEQ_NO_WAIT
|
||||
booksType = otherConnection.gettype("UDT_BOOK")
|
||||
book = booksType.newobject()
|
||||
props = otherConnection.msgproperties()
|
||||
otherConnection.deq(self.bookQueueName, deqOptions, props, book)
|
||||
other_connection = base.get_connection()
|
||||
deq_options = other_connection.deqoptions()
|
||||
deq_options.navigation = oracledb.DEQ_FIRST_MSG
|
||||
deq_options.visibility = oracledb.DEQ_ON_COMMIT
|
||||
deq_options.wait = oracledb.DEQ_NO_WAIT
|
||||
books_type = other_connection.gettype(self.book_type_name)
|
||||
book = books_type.newobject()
|
||||
props = other_connection.msgproperties()
|
||||
other_connection.deq(self.book_queue_name, deq_options, props, book)
|
||||
results = (book.TITLE, book.AUTHORS, book.PRICE)
|
||||
otherConnection.commit()
|
||||
self.assertEqual(results, self.bookData[0])
|
||||
other_connection.commit()
|
||||
self.assertEqual(results, self.book_data[0])
|
||||
|
||||
def test_2710_DeliveryModeSameBuffered(self):
|
||||
def test_2710_delivery_mode_same_buffered(self):
|
||||
"2710 - test enqueue/dequeue delivery modes identical - buffered"
|
||||
self.__clearBooksQueue()
|
||||
booksType = self.connection.gettype("UDT_BOOK")
|
||||
book = booksType.newobject()
|
||||
book.TITLE, book.AUTHORS, book.PRICE = self.bookData[0]
|
||||
enqOptions = self.connection.enqoptions()
|
||||
enqOptions.deliverymode = cx_Oracle.MSG_BUFFERED
|
||||
enqOptions.visibility = cx_Oracle.ENQ_IMMEDIATE
|
||||
self.__clear_books_queue()
|
||||
books_type = self.connection.gettype(self.book_type_name)
|
||||
book = books_type.newobject()
|
||||
book.TITLE, book.AUTHORS, book.PRICE = self.book_data[0]
|
||||
enq_options = self.connection.enqoptions()
|
||||
enq_options.deliverymode = oracledb.MSG_BUFFERED
|
||||
enq_options.visibility = oracledb.ENQ_IMMEDIATE
|
||||
props = self.connection.msgproperties()
|
||||
self.connection.enq(self.bookQueueName, enqOptions, props, book)
|
||||
self.connection.enq(self.book_queue_name, enq_options, props, book)
|
||||
|
||||
otherConnection = TestEnv.GetConnection()
|
||||
deqOptions = otherConnection.deqoptions()
|
||||
deqOptions.deliverymode = cx_Oracle.MSG_BUFFERED
|
||||
deqOptions.navigation = cx_Oracle.DEQ_FIRST_MSG
|
||||
deqOptions.visibility = cx_Oracle.DEQ_IMMEDIATE
|
||||
deqOptions.wait = cx_Oracle.DEQ_NO_WAIT
|
||||
booksType = otherConnection.gettype("UDT_BOOK")
|
||||
book = booksType.newobject()
|
||||
props = otherConnection.msgproperties()
|
||||
otherConnection.deq(self.bookQueueName, deqOptions, props, book)
|
||||
other_connection = base.get_connection()
|
||||
deq_options = other_connection.deqoptions()
|
||||
deq_options.deliverymode = oracledb.MSG_BUFFERED
|
||||
deq_options.navigation = oracledb.DEQ_FIRST_MSG
|
||||
deq_options.visibility = oracledb.DEQ_IMMEDIATE
|
||||
deq_options.wait = oracledb.DEQ_NO_WAIT
|
||||
books_type = other_connection.gettype(self.book_type_name)
|
||||
book = books_type.newobject()
|
||||
props = other_connection.msgproperties()
|
||||
other_connection.deq(self.book_queue_name, deq_options, props, book)
|
||||
results = (book.TITLE, book.AUTHORS, book.PRICE)
|
||||
otherConnection.commit()
|
||||
self.assertEqual(results, self.bookData[0])
|
||||
other_connection.commit()
|
||||
self.assertEqual(results, self.book_data[0])
|
||||
|
||||
def test_2711_DeliveryModeSamePersistent(self):
|
||||
def test_2711_delivery_mode_same_persistent(self):
|
||||
"2711 - test enqueue/dequeue delivery modes identical - persistent"
|
||||
self.__clearBooksQueue()
|
||||
booksType = self.connection.gettype("UDT_BOOK")
|
||||
book = booksType.newobject()
|
||||
book.TITLE, book.AUTHORS, book.PRICE = self.bookData[0]
|
||||
enqOptions = self.connection.enqoptions()
|
||||
enqOptions.deliverymode = cx_Oracle.MSG_PERSISTENT
|
||||
enqOptions.visibility = cx_Oracle.ENQ_IMMEDIATE
|
||||
self.__clear_books_queue()
|
||||
books_type = self.connection.gettype(self.book_type_name)
|
||||
book = books_type.newobject()
|
||||
book.TITLE, book.AUTHORS, book.PRICE = self.book_data[0]
|
||||
enq_options = self.connection.enqoptions()
|
||||
enq_options.deliverymode = oracledb.MSG_PERSISTENT
|
||||
enq_options.visibility = oracledb.ENQ_IMMEDIATE
|
||||
props = self.connection.msgproperties()
|
||||
self.connection.enq(self.bookQueueName, enqOptions, props, book)
|
||||
self.connection.enq(self.book_queue_name, enq_options, props, book)
|
||||
|
||||
otherConnection = TestEnv.GetConnection()
|
||||
deqOptions = otherConnection.deqoptions()
|
||||
deqOptions.deliverymode = cx_Oracle.MSG_PERSISTENT
|
||||
deqOptions.navigation = cx_Oracle.DEQ_FIRST_MSG
|
||||
deqOptions.visibility = cx_Oracle.DEQ_IMMEDIATE
|
||||
deqOptions.wait = cx_Oracle.DEQ_NO_WAIT
|
||||
booksType = otherConnection.gettype("UDT_BOOK")
|
||||
book = booksType.newobject()
|
||||
props = otherConnection.msgproperties()
|
||||
otherConnection.deq(self.bookQueueName, deqOptions, props, book)
|
||||
other_connection = base.get_connection()
|
||||
deq_options = other_connection.deqoptions()
|
||||
deq_options.deliverymode = oracledb.MSG_PERSISTENT
|
||||
deq_options.navigation = oracledb.DEQ_FIRST_MSG
|
||||
deq_options.visibility = oracledb.DEQ_IMMEDIATE
|
||||
deq_options.wait = oracledb.DEQ_NO_WAIT
|
||||
books_type = other_connection.gettype(self.book_type_name)
|
||||
book = books_type.newobject()
|
||||
props = other_connection.msgproperties()
|
||||
other_connection.deq(self.book_queue_name, deq_options, props, book)
|
||||
results = (book.TITLE, book.AUTHORS, book.PRICE)
|
||||
otherConnection.commit()
|
||||
self.assertEqual(results, self.bookData[0])
|
||||
other_connection.commit()
|
||||
self.assertEqual(results, self.book_data[0])
|
||||
|
||||
def test_2712_DeliveryModeSamePersistentBuffered(self):
|
||||
def test_2712_delivery_mode_same_persistent_buffered(self):
|
||||
"2712 - test enqueue/dequeue delivery modes the same"
|
||||
self.__clearBooksQueue()
|
||||
booksType = self.connection.gettype("UDT_BOOK")
|
||||
book = booksType.newobject()
|
||||
book.TITLE, book.AUTHORS, book.PRICE = self.bookData[0]
|
||||
enqOptions = self.connection.enqoptions()
|
||||
enqOptions.deliverymode = cx_Oracle.MSG_PERSISTENT_OR_BUFFERED
|
||||
enqOptions.visibility = cx_Oracle.ENQ_IMMEDIATE
|
||||
self.__clear_books_queue()
|
||||
books_type = self.connection.gettype(self.book_type_name)
|
||||
book = books_type.newobject()
|
||||
book.TITLE, book.AUTHORS, book.PRICE = self.book_data[0]
|
||||
enq_options = self.connection.enqoptions()
|
||||
enq_options.deliverymode = oracledb.MSG_PERSISTENT_OR_BUFFERED
|
||||
enq_options.visibility = oracledb.ENQ_IMMEDIATE
|
||||
props = self.connection.msgproperties()
|
||||
self.connection.enq(self.bookQueueName, enqOptions, props, book)
|
||||
self.connection.enq(self.book_queue_name, enq_options, props, book)
|
||||
|
||||
otherConnection = TestEnv.GetConnection()
|
||||
deqOptions = otherConnection.deqoptions()
|
||||
deqOptions.deliverymode = cx_Oracle.MSG_PERSISTENT_OR_BUFFERED
|
||||
deqOptions.navigation = cx_Oracle.DEQ_FIRST_MSG
|
||||
deqOptions.visibility = cx_Oracle.DEQ_IMMEDIATE
|
||||
deqOptions.wait = cx_Oracle.DEQ_NO_WAIT
|
||||
booksType = otherConnection.gettype("UDT_BOOK")
|
||||
book = booksType.newobject()
|
||||
props = otherConnection.msgproperties()
|
||||
otherConnection.deq(self.bookQueueName, deqOptions, props, book)
|
||||
other_connection = base.get_connection()
|
||||
deq_options = other_connection.deqoptions()
|
||||
deq_options.deliverymode = oracledb.MSG_PERSISTENT_OR_BUFFERED
|
||||
deq_options.navigation = oracledb.DEQ_FIRST_MSG
|
||||
deq_options.visibility = oracledb.DEQ_IMMEDIATE
|
||||
deq_options.wait = oracledb.DEQ_NO_WAIT
|
||||
books_type = other_connection.gettype(self.book_type_name)
|
||||
book = books_type.newobject()
|
||||
props = other_connection.msgproperties()
|
||||
other_connection.deq(self.book_queue_name, deq_options, props, book)
|
||||
results = (book.TITLE, book.AUTHORS, book.PRICE)
|
||||
otherConnection.commit()
|
||||
self.assertEqual(results, self.bookData[0])
|
||||
other_connection.commit()
|
||||
self.assertEqual(results, self.book_data[0])
|
||||
|
||||
def test_2713_DeliveryModeDifferent(self):
|
||||
def test_2713_delivery_mode_different(self):
|
||||
"2713 - test enqueue/dequeue delivery modes different"
|
||||
self.__clearBooksQueue()
|
||||
booksType = self.connection.gettype("UDT_BOOK")
|
||||
book = booksType.newobject()
|
||||
book.TITLE, book.AUTHORS, book.PRICE = self.bookData[0]
|
||||
enqOptions = self.connection.enqoptions()
|
||||
enqOptions.deliverymode = cx_Oracle.MSG_BUFFERED
|
||||
enqOptions.visibility = cx_Oracle.ENQ_IMMEDIATE
|
||||
self.__clear_books_queue()
|
||||
books_type = self.connection.gettype(self.book_type_name)
|
||||
book = books_type.newobject()
|
||||
book.TITLE, book.AUTHORS, book.PRICE = self.book_data[0]
|
||||
enq_options = self.connection.enqoptions()
|
||||
enq_options.deliverymode = oracledb.MSG_BUFFERED
|
||||
enq_options.visibility = oracledb.ENQ_IMMEDIATE
|
||||
props = self.connection.msgproperties()
|
||||
self.connection.enq(self.bookQueueName, enqOptions, props, book)
|
||||
self.connection.enq(self.book_queue_name, enq_options, props, book)
|
||||
|
||||
otherConnection = TestEnv.GetConnection()
|
||||
deqOptions = otherConnection.deqoptions()
|
||||
deqOptions.deliverymode = cx_Oracle.MSG_PERSISTENT
|
||||
deqOptions.navigation = cx_Oracle.DEQ_FIRST_MSG
|
||||
deqOptions.visibility = cx_Oracle.DEQ_IMMEDIATE
|
||||
deqOptions.wait = cx_Oracle.DEQ_NO_WAIT
|
||||
booksType = otherConnection.gettype("UDT_BOOK")
|
||||
book = booksType.newobject()
|
||||
props = otherConnection.msgproperties()
|
||||
messageId = otherConnection.deq(self.bookQueueName, deqOptions, props,
|
||||
book)
|
||||
self.assertTrue(messageId is None)
|
||||
other_connection = base.get_connection()
|
||||
deq_options = other_connection.deqoptions()
|
||||
deq_options.deliverymode = oracledb.MSG_PERSISTENT
|
||||
deq_options.navigation = oracledb.DEQ_FIRST_MSG
|
||||
deq_options.visibility = oracledb.DEQ_IMMEDIATE
|
||||
deq_options.wait = oracledb.DEQ_NO_WAIT
|
||||
books_type = other_connection.gettype(self.book_type_name)
|
||||
book = books_type.newobject()
|
||||
props = other_connection.msgproperties()
|
||||
message_id = other_connection.deq(self.book_queue_name, deq_options,
|
||||
props, book)
|
||||
self.assertTrue(message_id is None)
|
||||
|
||||
def test_2714_DequeueTransformation(self):
|
||||
def test_2714_dequeue_transformation(self):
|
||||
"2714 - test dequeue transformation"
|
||||
self.__clearBooksQueue()
|
||||
booksType = self.connection.gettype("UDT_BOOK")
|
||||
book = booksType.newobject()
|
||||
book.TITLE, book.AUTHORS, book.PRICE = self.bookData[0]
|
||||
self.__clear_books_queue()
|
||||
books_type = self.connection.gettype(self.book_type_name)
|
||||
book = books_type.newobject()
|
||||
book.TITLE, book.AUTHORS, book.PRICE = self.book_data[0]
|
||||
expectedPrice = book.PRICE + 10
|
||||
enqOptions = self.connection.enqoptions()
|
||||
enq_options = self.connection.enqoptions()
|
||||
props = self.connection.msgproperties()
|
||||
self.connection.enq(self.bookQueueName, enqOptions, props, book)
|
||||
self.connection.enq(self.book_queue_name, enq_options, props, book)
|
||||
self.connection.commit()
|
||||
|
||||
otherConnection = TestEnv.GetConnection()
|
||||
deqOptions = otherConnection.deqoptions()
|
||||
deqOptions.navigation = cx_Oracle.DEQ_FIRST_MSG
|
||||
deqOptions.visibility = cx_Oracle.DEQ_IMMEDIATE
|
||||
deqOptions.transformation = "%s.transform2" % self.connection.username
|
||||
deqOptions.wait = cx_Oracle.DEQ_NO_WAIT
|
||||
booksType = otherConnection.gettype("UDT_BOOK")
|
||||
book = booksType.newobject()
|
||||
props = otherConnection.msgproperties()
|
||||
otherConnection.deq(self.bookQueueName, deqOptions, props, book)
|
||||
other_connection = base.get_connection()
|
||||
deq_options = other_connection.deqoptions()
|
||||
deq_options.navigation = oracledb.DEQ_FIRST_MSG
|
||||
deq_options.visibility = oracledb.DEQ_IMMEDIATE
|
||||
deq_options.transformation = "%s.transform2" % self.connection.username
|
||||
deq_options.wait = oracledb.DEQ_NO_WAIT
|
||||
books_type = other_connection.gettype(self.book_type_name)
|
||||
book = books_type.newobject()
|
||||
props = other_connection.msgproperties()
|
||||
other_connection.deq(self.book_queue_name, deq_options, props, book)
|
||||
otherPrice = book.PRICE
|
||||
self.assertEqual(otherPrice, expectedPrice)
|
||||
|
||||
def test_2715_EnqueueTransformation(self):
|
||||
def test_2715_enqueue_transformation(self):
|
||||
"2715 - test enqueue transformation"
|
||||
self.__clearBooksQueue()
|
||||
booksType = self.connection.gettype("UDT_BOOK")
|
||||
book = booksType.newobject()
|
||||
book.TITLE, book.AUTHORS, book.PRICE = self.bookData[0]
|
||||
self.__clear_books_queue()
|
||||
books_type = self.connection.gettype(self.book_type_name)
|
||||
book = books_type.newobject()
|
||||
book.TITLE, book.AUTHORS, book.PRICE = self.book_data[0]
|
||||
expectedPrice = book.PRICE + 5
|
||||
enqOptions = self.connection.enqoptions()
|
||||
enqOptions.transformation = "%s.transform1" % self.connection.username
|
||||
enq_options = self.connection.enqoptions()
|
||||
enq_options.transformation = "%s.transform1" % self.connection.username
|
||||
props = self.connection.msgproperties()
|
||||
self.connection.enq(self.bookQueueName, enqOptions, props, book)
|
||||
self.connection.enq(self.book_queue_name, enq_options, props, book)
|
||||
self.connection.commit()
|
||||
|
||||
otherConnection = TestEnv.GetConnection()
|
||||
deqOptions = otherConnection.deqoptions()
|
||||
deqOptions.navigation = cx_Oracle.DEQ_FIRST_MSG
|
||||
deqOptions.visibility = cx_Oracle.DEQ_IMMEDIATE
|
||||
deqOptions.wait = cx_Oracle.DEQ_NO_WAIT
|
||||
booksType = otherConnection.gettype("UDT_BOOK")
|
||||
book = booksType.newobject()
|
||||
props = otherConnection.msgproperties()
|
||||
otherConnection.deq(self.bookQueueName, deqOptions, props, book)
|
||||
other_connection = base.get_connection()
|
||||
deq_options = other_connection.deqoptions()
|
||||
deq_options.navigation = oracledb.DEQ_FIRST_MSG
|
||||
deq_options.visibility = oracledb.DEQ_IMMEDIATE
|
||||
deq_options.wait = oracledb.DEQ_NO_WAIT
|
||||
books_type = other_connection.gettype(self.book_type_name)
|
||||
book = books_type.newobject()
|
||||
props = other_connection.msgproperties()
|
||||
other_connection.deq(self.book_queue_name, deq_options, props, book)
|
||||
otherPrice = book.PRICE
|
||||
self.assertEqual(otherPrice, expectedPrice)
|
||||
|
||||
if __name__ == "__main__":
|
||||
TestEnv.RunTestCases()
|
||||
base.run_test_cases()
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
2800 - Module for testing AQ Bulk enqueue/dequeue
|
||||
"""
|
||||
|
||||
import TestEnv
|
||||
import base
|
||||
|
||||
import cx_Oracle
|
||||
import cx_Oracle as oracledb
|
||||
import decimal
|
||||
import threading
|
||||
|
||||
|
@ -28,13 +28,13 @@ RAW_PAYLOAD_DATA = [
|
|||
"The twelfth and final message"
|
||||
]
|
||||
|
||||
class TestCase(TestEnv.BaseTestCase):
|
||||
class TestCase(base.BaseTestCase):
|
||||
|
||||
def __deqInThread(self, results):
|
||||
connection = TestEnv.GetConnection(threaded=True)
|
||||
def __deq_in_thread(self, results):
|
||||
connection = base.get_connection(threaded=True)
|
||||
queue = connection.queue(RAW_QUEUE_NAME)
|
||||
queue.deqOptions.wait = 10
|
||||
queue.deqOptions.navigation = cx_Oracle.DEQ_FIRST_MSG
|
||||
queue.deqOptions.navigation = oracledb.DEQ_FIRST_MSG
|
||||
while len(results) < len(RAW_PAYLOAD_DATA):
|
||||
messages = queue.deqMany(5)
|
||||
if not messages:
|
||||
|
@ -43,93 +43,93 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
results.append(m.payload.decode(connection.encoding))
|
||||
connection.commit()
|
||||
|
||||
def __getAndClearRawQueue(self):
|
||||
def __get_and_clear_raw_queue(self):
|
||||
queue = self.connection.queue(RAW_QUEUE_NAME)
|
||||
queue.deqOptions.wait = cx_Oracle.DEQ_NO_WAIT
|
||||
queue.deqOptions.navigation = cx_Oracle.DEQ_FIRST_MSG
|
||||
queue.deqOptions.wait = oracledb.DEQ_NO_WAIT
|
||||
queue.deqOptions.navigation = oracledb.DEQ_FIRST_MSG
|
||||
while queue.deqOne():
|
||||
pass
|
||||
self.connection.commit()
|
||||
return queue
|
||||
|
||||
def test_2800_EnqAndDeq(self):
|
||||
def test_2800_enq_and_deq(self):
|
||||
"2800 - test bulk enqueue and dequeue"
|
||||
queue = self.__getAndClearRawQueue()
|
||||
queue = self.__get_and_clear_raw_queue()
|
||||
messages = [self.connection.msgproperties(payload=d) \
|
||||
for d in RAW_PAYLOAD_DATA]
|
||||
for d in RAW_PAYLOAD_DATA]
|
||||
queue.enqMany(messages)
|
||||
messages = queue.deqMany(len(RAW_PAYLOAD_DATA))
|
||||
data = [m.payload.decode(self.connection.encoding) for m in messages]
|
||||
self.connection.commit()
|
||||
self.assertEqual(data, RAW_PAYLOAD_DATA)
|
||||
|
||||
def test_2801_DequeueEmpty(self):
|
||||
def test_2801_dequeue_empty(self):
|
||||
"2801 - test empty bulk dequeue"
|
||||
queue = self.__getAndClearRawQueue()
|
||||
queue = self.__get_and_clear_raw_queue()
|
||||
messages = queue.deqMany(5)
|
||||
self.connection.commit()
|
||||
self.assertEqual(messages, [])
|
||||
|
||||
def test_2802_DeqWithWait(self):
|
||||
def test_2802_deq_with_wait(self):
|
||||
"2802 - test bulk dequeue with wait"
|
||||
queue = self.__getAndClearRawQueue()
|
||||
queue = self.__get_and_clear_raw_queue()
|
||||
results = []
|
||||
thread = threading.Thread(target=self.__deqInThread, args=(results,))
|
||||
thread = threading.Thread(target=self.__deq_in_thread, args=(results,))
|
||||
thread.start()
|
||||
messages = [self.connection.msgproperties(payload=d) \
|
||||
for d in RAW_PAYLOAD_DATA]
|
||||
queue.enqOptions.visibility = cx_Oracle.ENQ_IMMEDIATE
|
||||
for d in RAW_PAYLOAD_DATA]
|
||||
queue.enqOptions.visibility = oracledb.ENQ_IMMEDIATE
|
||||
queue.enqMany(messages)
|
||||
thread.join()
|
||||
self.assertEqual(results, RAW_PAYLOAD_DATA)
|
||||
|
||||
def test_2803_EnqAndDeqMultipleTimes(self):
|
||||
def test_2803_enq_and_deq_multiple_times(self):
|
||||
"2803 - test enqueue and dequeue multiple times"
|
||||
queue = self.__getAndClearRawQueue()
|
||||
dataToEnqueue = RAW_PAYLOAD_DATA
|
||||
queue = self.__get_and_clear_raw_queue()
|
||||
data_to_enqueue = RAW_PAYLOAD_DATA
|
||||
for num in (2, 6, 4):
|
||||
messages = [self.connection.msgproperties(payload=d) \
|
||||
for d in dataToEnqueue[:num]]
|
||||
dataToEnqueue = dataToEnqueue[num:]
|
||||
for d in data_to_enqueue[:num]]
|
||||
data_to_enqueue = data_to_enqueue[num:]
|
||||
queue.enqMany(messages)
|
||||
self.connection.commit()
|
||||
allData = []
|
||||
all_data = []
|
||||
for num in (3, 5, 10):
|
||||
messages = queue.deqMany(num)
|
||||
allData.extend(m.payload.decode(self.connection.encoding) \
|
||||
all_data.extend(m.payload.decode(self.connection.encoding) \
|
||||
for m in messages)
|
||||
self.connection.commit()
|
||||
self.assertEqual(allData, RAW_PAYLOAD_DATA)
|
||||
self.assertEqual(all_data, RAW_PAYLOAD_DATA)
|
||||
|
||||
def test_2804_EnqAndDeqVisibility(self):
|
||||
def test_2804_enq_and_deq_visibility(self):
|
||||
"2804 - test visibility option for enqueue and dequeue"
|
||||
queue = self.__getAndClearRawQueue()
|
||||
queue = self.__get_and_clear_raw_queue()
|
||||
|
||||
# first test with ENQ_ON_COMMIT (commit required)
|
||||
queue.enqOptions.visibility = cx_Oracle.ENQ_ON_COMMIT
|
||||
queue.enqOptions.visibility = oracledb.ENQ_ON_COMMIT
|
||||
props1 = self.connection.msgproperties(payload="A first message")
|
||||
props2 = self.connection.msgproperties(payload="A second message")
|
||||
queue.enqMany([props1, props2])
|
||||
otherConnection = TestEnv.GetConnection()
|
||||
otherQueue = otherConnection.queue(RAW_QUEUE_NAME)
|
||||
otherQueue.deqOptions.wait = cx_Oracle.DEQ_NO_WAIT
|
||||
otherQueue.deqOptions.visibility = cx_Oracle.DEQ_ON_COMMIT
|
||||
messages = otherQueue.deqMany(5)
|
||||
other_connection = base.get_connection()
|
||||
other_queue = other_connection.queue(RAW_QUEUE_NAME)
|
||||
other_queue.deqOptions.wait = oracledb.DEQ_NO_WAIT
|
||||
other_queue.deqOptions.visibility = oracledb.DEQ_ON_COMMIT
|
||||
messages = other_queue.deqMany(5)
|
||||
self.assertEqual(len(messages), 0)
|
||||
self.connection.commit()
|
||||
messages = otherQueue.deqMany(5)
|
||||
messages = other_queue.deqMany(5)
|
||||
self.assertEqual(len(messages), 2)
|
||||
otherConnection.rollback()
|
||||
other_connection.rollback()
|
||||
|
||||
# second test with ENQ_IMMEDIATE (no commit required)
|
||||
queue.enqOptions.visibility = cx_Oracle.ENQ_IMMEDIATE
|
||||
otherQueue.deqOptions.visibility = cx_Oracle.DEQ_IMMEDIATE
|
||||
queue.enqOptions.visibility = oracledb.ENQ_IMMEDIATE
|
||||
other_queue.deqOptions.visibility = oracledb.DEQ_IMMEDIATE
|
||||
queue.enqMany([props1, props2])
|
||||
messages = otherQueue.deqMany(5)
|
||||
messages = other_queue.deqMany(5)
|
||||
self.assertEqual(len(messages), 4)
|
||||
otherConnection.rollback()
|
||||
messages = otherQueue.deqMany(5)
|
||||
other_connection.rollback()
|
||||
messages = other_queue.deqMany(5)
|
||||
self.assertEqual(len(messages), 0)
|
||||
|
||||
if __name__ == "__main__":
|
||||
TestEnv.RunTestCases()
|
||||
base.run_test_cases()
|
||||
|
|
|
@ -6,40 +6,39 @@
|
|||
2900 - Module for testing Rowids
|
||||
"""
|
||||
|
||||
import TestEnv
|
||||
import base
|
||||
|
||||
import cx_Oracle
|
||||
import cx_Oracle as oracledb
|
||||
|
||||
class TestCase(TestEnv.BaseTestCase):
|
||||
class TestCase(base.BaseTestCase):
|
||||
|
||||
def __TestSelectRowids(self, tableName):
|
||||
self.cursor.execute("select rowid, IntCol from %s""" % tableName)
|
||||
rowidDict = dict(self.cursor)
|
||||
sql = "select IntCol from %s where rowid = :val" % tableName
|
||||
for rowid, intVal in rowidDict.items():
|
||||
def __test_select_rowids(self, table_name):
|
||||
self.cursor.execute("select rowid, IntCol from %s""" % table_name)
|
||||
rowid_dict = dict(self.cursor)
|
||||
sql = "select IntCol from %s where rowid = :val" % table_name
|
||||
for rowid, int_val in rowid_dict.items():
|
||||
self.cursor.execute(sql, val = rowid)
|
||||
rows = self.cursor.fetchall()
|
||||
self.assertEqual(len(rows), 1)
|
||||
self.assertEqual(rows[0][0], intVal)
|
||||
self.assertEqual(rows[0][0], int_val)
|
||||
|
||||
def test_2900_SelectRowidsRegular(self):
|
||||
def test_2900_select_rowids_regular(self):
|
||||
"2900 - test selecting all rowids from a regular table"
|
||||
self.__TestSelectRowids("TestNumbers")
|
||||
self.__test_select_rowids("TestNumbers")
|
||||
|
||||
def test_2901_SelectRowidsIndexOrganised(self):
|
||||
def test_2901_select_rowids_index_organised(self):
|
||||
"2901 - test selecting all rowids from an index organised table"
|
||||
self.__TestSelectRowids("TestUniversalRowids")
|
||||
self.__test_select_rowids("TestUniversalRowids")
|
||||
|
||||
def test_2902_InsertInvalidRowid(self):
|
||||
def test_2902_insert_invalid_rowid(self):
|
||||
"2902 - test inserting an invalid rowid"
|
||||
self.assertRaises(cx_Oracle.DatabaseError, self.cursor.execute,
|
||||
"insert into TestRowids (IntCol, RowidCol) values (1, :rid)",
|
||||
rid = 12345)
|
||||
self.assertRaises(cx_Oracle.DatabaseError, self.cursor.execute,
|
||||
"insert into TestRowids (IntCol, RowidCol) values (1, :rid)",
|
||||
rid = "523lkhlf")
|
||||
sql = "insert into TestRowids (IntCol, RowidCol) values (1, :rid)"
|
||||
self.assertRaises(oracledb.DatabaseError, self.cursor.execute, sql,
|
||||
rid=12345)
|
||||
self.assertRaises(oracledb.DatabaseError, self.cursor.execute, sql,
|
||||
rid="523lkhlf")
|
||||
|
||||
def test_2903_InsertRowids(self):
|
||||
def test_2903_insert_rowids(self):
|
||||
"2903 - test inserting rowids and verify they are inserted correctly"
|
||||
self.cursor.execute("select IntCol, rowid from TestNumbers")
|
||||
rows = self.cursor.fetchall()
|
||||
|
@ -52,11 +51,11 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
self.cursor.execute("select IntCol, RowidCol from TestRowids")
|
||||
rows = self.cursor.fetchall()
|
||||
sql = "select IntCol from TestNumbers where rowid = :val"
|
||||
for intVal, rowid in rows:
|
||||
for int_val, rowid in rows:
|
||||
self.cursor.execute(sql, val = rowid)
|
||||
rows = self.cursor.fetchall()
|
||||
self.assertEqual(len(rows), 1)
|
||||
self.assertEqual(rows[0][0], intVal)
|
||||
self.assertEqual(rows[0][0], int_val)
|
||||
|
||||
if __name__ == "__main__":
|
||||
TestEnv.RunTestCases()
|
||||
base.run_test_cases()
|
||||
|
|
|
@ -6,63 +6,71 @@
|
|||
3000 - Module for testing subscriptions
|
||||
"""
|
||||
|
||||
import TestEnv
|
||||
import base
|
||||
|
||||
import cx_Oracle
|
||||
import cx_Oracle as oracledb
|
||||
import threading
|
||||
|
||||
class SubscriptionData(object):
|
||||
|
||||
def __init__(self, numMessagesExpected):
|
||||
def __init__(self, num_messages_expected):
|
||||
self.condition = threading.Condition()
|
||||
self.numMessagesExpected = numMessagesExpected
|
||||
self.numMessagesReceived = 0
|
||||
self.tableOperations = []
|
||||
self.rowOperations = []
|
||||
self.num_messages_expected = num_messages_expected
|
||||
self.num_messages_received = 0
|
||||
self.table_operations = []
|
||||
self.row_operations = []
|
||||
self.rowids = []
|
||||
|
||||
def CallbackHandler(self, message):
|
||||
if message.type != cx_Oracle.EVENT_DEREG:
|
||||
if message.type != oracledb.EVENT_DEREG:
|
||||
table, = message.tables
|
||||
self.tableOperations.append(table.operation)
|
||||
self.table_operations.append(table.operation)
|
||||
for row in table.rows:
|
||||
self.rowOperations.append(row.operation)
|
||||
self.row_operations.append(row.operation)
|
||||
self.rowids.append(row.rowid)
|
||||
self.numMessagesReceived += 1
|
||||
if message.type == cx_Oracle.EVENT_DEREG or \
|
||||
self.numMessagesReceived == self.numMessagesExpected:
|
||||
self.num_messages_received += 1
|
||||
if message.type == oracledb.EVENT_DEREG or \
|
||||
self.num_messages_received == self.num_messages_expected:
|
||||
self.condition.acquire()
|
||||
self.condition.notify()
|
||||
self.condition.release()
|
||||
|
||||
|
||||
class TestCase(TestEnv.BaseTestCase):
|
||||
class TestCase(base.BaseTestCase):
|
||||
|
||||
def test_3000_Subscription(self):
|
||||
def test_3000_subscription(self):
|
||||
"3000 - test Subscription for insert, update, delete and truncate"
|
||||
|
||||
# skip if running on the Oracle Cloud, which does not support
|
||||
# subscriptions currently
|
||||
if self.isOnOracleCloud():
|
||||
self.skipTest("Oracle Cloud does not support subscriptions " \
|
||||
"currently")
|
||||
if self.is_on_oracle_cloud():
|
||||
message = "Oracle Cloud does not support subscriptions currently"
|
||||
self.skipTest(message)
|
||||
|
||||
# truncate table in order to run test in known state
|
||||
self.cursor.execute("truncate table TestTempTable")
|
||||
|
||||
# expected values
|
||||
tableOperations = [ cx_Oracle.OPCODE_INSERT, cx_Oracle.OPCODE_UPDATE,
|
||||
cx_Oracle.OPCODE_INSERT, cx_Oracle.OPCODE_DELETE,
|
||||
cx_Oracle.OPCODE_ALTER | cx_Oracle.OPCODE_ALLROWS ]
|
||||
rowOperations = [ cx_Oracle.OPCODE_INSERT, cx_Oracle.OPCODE_UPDATE,
|
||||
cx_Oracle.OPCODE_INSERT, cx_Oracle.OPCODE_DELETE ]
|
||||
table_operations = [
|
||||
oracledb.OPCODE_INSERT,
|
||||
oracledb.OPCODE_UPDATE,
|
||||
oracledb.OPCODE_INSERT,
|
||||
oracledb.OPCODE_DELETE,
|
||||
oracledb.OPCODE_ALTER | oracledb.OPCODE_ALLROWS
|
||||
]
|
||||
row_operations = [
|
||||
oracledb.OPCODE_INSERT,
|
||||
oracledb.OPCODE_UPDATE,
|
||||
oracledb.OPCODE_INSERT,
|
||||
oracledb.OPCODE_DELETE
|
||||
]
|
||||
rowids = []
|
||||
|
||||
# set up subscription
|
||||
data = SubscriptionData(5)
|
||||
connection = TestEnv.GetConnection(threaded=True, events=True)
|
||||
sub = connection.subscribe(callback = data.CallbackHandler,
|
||||
timeout = 10, qos = cx_Oracle.SUBSCR_QOS_ROWIDS)
|
||||
connection = base.get_connection(threaded=True, events=True)
|
||||
sub = connection.subscribe(callback=data.CallbackHandler,
|
||||
timeout=10, qos=oracledb.SUBSCR_QOS_ROWIDS)
|
||||
sub.registerquery("select * from TestTempTable")
|
||||
connection.autocommit = True
|
||||
cursor = connection.cursor()
|
||||
|
@ -101,15 +109,14 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
data.condition.wait(10)
|
||||
|
||||
# verify the correct messages were sent
|
||||
self.assertEqual(data.tableOperations, tableOperations)
|
||||
self.assertEqual(data.rowOperations, rowOperations)
|
||||
self.assertEqual(data.table_operations, table_operations)
|
||||
self.assertEqual(data.row_operations, row_operations)
|
||||
self.assertEqual(data.rowids, rowids)
|
||||
|
||||
# test string format of subscription object is as expected
|
||||
fmt = "<cx_Oracle.Subscription on <cx_Oracle.Connection to %s@%s>>"
|
||||
expectedValue = fmt % \
|
||||
(TestEnv.GetMainUser(), TestEnv.GetConnectString())
|
||||
self.assertEqual(str(sub), expectedValue)
|
||||
expected = fmt % (base.get_main_user(), base.get_connect_string())
|
||||
self.assertEqual(str(sub), expected)
|
||||
|
||||
if __name__ == "__main__":
|
||||
TestEnv.RunTestCases()
|
||||
base.run_test_cases()
|
||||
|
|
|
@ -12,67 +12,67 @@
|
|||
"""
|
||||
|
||||
import unittest
|
||||
import TestEnv
|
||||
import base
|
||||
|
||||
import cx_Oracle
|
||||
import cx_Oracle as oracledb
|
||||
|
||||
@unittest.skipUnless(TestEnv.GetClientVersion() >= (12, 1),
|
||||
@unittest.skipUnless(base.get_client_version() >= (12, 1),
|
||||
"unsupported client")
|
||||
class TestCase(TestEnv.BaseTestCase):
|
||||
class TestCase(base.BaseTestCase):
|
||||
|
||||
def __testBindValueAsBoolean(self, value):
|
||||
expectedResult = str(bool(value)).upper()
|
||||
def __test_bind_value_as_boolean(self, value):
|
||||
expected_result = str(bool(value)).upper()
|
||||
var = self.cursor.var(bool)
|
||||
var.setvalue(0, value)
|
||||
result = self.cursor.callfunc("pkg_TestBooleans.GetStringRep", str,
|
||||
(var,))
|
||||
self.assertEqual(result, expectedResult)
|
||||
(var,))
|
||||
self.assertEqual(result, expected_result)
|
||||
|
||||
def test_3100_BindFalse(self):
|
||||
def test_3100_bind_false(self):
|
||||
"3100 - test binding in a False value"
|
||||
result = self.cursor.callfunc("pkg_TestBooleans.GetStringRep", str,
|
||||
(False,))
|
||||
(False,))
|
||||
self.assertEqual(result, "FALSE")
|
||||
|
||||
def test_3101_BindFloatAsBoolean(self):
|
||||
def test_3101_bind_float_as_boolean(self):
|
||||
"3101 - test binding in a float as a boolean"
|
||||
self.__testBindValueAsBoolean(0.0)
|
||||
self.__testBindValueAsBoolean(1.0)
|
||||
self.__test_bind_value_as_boolean(0.0)
|
||||
self.__test_bind_value_as_boolean(1.0)
|
||||
|
||||
def test_3102_BindIntegerAsBoolean(self):
|
||||
def test_3102_bind_integer_as_boolean(self):
|
||||
"3102 - test binding in an integer as a boolean"
|
||||
self.__testBindValueAsBoolean(0)
|
||||
self.__testBindValueAsBoolean(1)
|
||||
self.__test_bind_value_as_boolean(0)
|
||||
self.__test_bind_value_as_boolean(1)
|
||||
|
||||
def test_3103_BindNull(self):
|
||||
def test_3103_bind_null(self):
|
||||
"3103 - test binding in a null value"
|
||||
self.cursor.setinputsizes(None, bool)
|
||||
result = self.cursor.callfunc("pkg_TestBooleans.GetStringRep", str,
|
||||
(None,))
|
||||
(None,))
|
||||
self.assertEqual(result, "NULL")
|
||||
|
||||
def test_3104_BindOutFalse(self):
|
||||
def test_3104_bind_out_false(self):
|
||||
"3104 - test binding out a boolean value (False)"
|
||||
result = self.cursor.callfunc("pkg_TestBooleans.IsLessThan10",
|
||||
cx_Oracle.DB_TYPE_BOOLEAN, (15,))
|
||||
oracledb.DB_TYPE_BOOLEAN, (15,))
|
||||
self.assertEqual(result, False)
|
||||
|
||||
def test_3105_BindOutTrue(self):
|
||||
def test_3105_bind_out_true(self):
|
||||
"3105 - test binding out a boolean value (True)"
|
||||
result = self.cursor.callfunc("pkg_TestBooleans.IsLessThan10", bool,
|
||||
(5,))
|
||||
(5,))
|
||||
self.assertEqual(result, True)
|
||||
|
||||
def test_3106_BindStringAsBoolean(self):
|
||||
def test_3106_bind_string_as_boolean(self):
|
||||
"3106 - test binding in a string as a boolean"
|
||||
self.__testBindValueAsBoolean("")
|
||||
self.__testBindValueAsBoolean("0")
|
||||
self.__test_bind_value_as_boolean("")
|
||||
self.__test_bind_value_as_boolean("0")
|
||||
|
||||
def test_3107_BindTrue(self):
|
||||
def test_3107_bind_true(self):
|
||||
"3107 - test binding in a True value"
|
||||
result = self.cursor.callfunc("pkg_TestBooleans.GetStringRep", str,
|
||||
(True,))
|
||||
(True,))
|
||||
self.assertEqual(result, "TRUE")
|
||||
|
||||
if __name__ == "__main__":
|
||||
TestEnv.RunTestCases()
|
||||
base.run_test_cases()
|
||||
|
|
|
@ -11,134 +11,142 @@
|
|||
3200 - Module for testing features introduced in 12.1
|
||||
"""
|
||||
|
||||
import TestEnv
|
||||
import base
|
||||
|
||||
import cx_Oracle
|
||||
import cx_Oracle as oracledb
|
||||
import datetime
|
||||
import unittest
|
||||
|
||||
@unittest.skipUnless(TestEnv.GetClientVersion() >= (12, 1),
|
||||
@unittest.skipUnless(base.get_client_version() >= (12, 1),
|
||||
"unsupported client")
|
||||
class TestCase(TestEnv.BaseTestCase):
|
||||
class TestCase(base.BaseTestCase):
|
||||
|
||||
def test_3200_ArrayDMLRowCountsOff(self):
|
||||
def test_3200_array_dml_row_counts_off(self):
|
||||
"3200 - test executing with arraydmlrowcounts mode disabled"
|
||||
self.cursor.execute("truncate table TestArrayDML")
|
||||
rows = [ (1, "First"),
|
||||
(2, "Second") ]
|
||||
rows = [(1, "First"), (2, "Second")]
|
||||
sql = "insert into TestArrayDML (IntCol,StringCol) values (:1,:2)"
|
||||
self.cursor.executemany(sql, rows, arraydmlrowcounts = False)
|
||||
self.assertRaises(cx_Oracle.DatabaseError,
|
||||
self.cursor.getarraydmlrowcounts)
|
||||
rows = [ (3, "Third"),
|
||||
(4, "Fourth") ]
|
||||
self.cursor.executemany(sql, rows, arraydmlrowcounts=False)
|
||||
self.assertRaises(oracledb.DatabaseError,
|
||||
self.cursor.getarraydmlrowcounts)
|
||||
rows = [(3, "Third"), (4, "Fourth")]
|
||||
self.cursor.executemany(sql, rows)
|
||||
self.assertRaises(cx_Oracle.DatabaseError,
|
||||
self.cursor.getarraydmlrowcounts)
|
||||
self.assertRaises(oracledb.DatabaseError,
|
||||
self.cursor.getarraydmlrowcounts)
|
||||
|
||||
def test_3201_ArrayDMLRowCountsOn(self):
|
||||
def test_3201_array_dml_row_counts_on(self):
|
||||
"3201 - test executing with arraydmlrowcounts mode enabled"
|
||||
self.cursor.execute("truncate table TestArrayDML")
|
||||
rows = [ ( 1, "First", 100),
|
||||
( 2, "Second", 200),
|
||||
( 3, "Third", 300),
|
||||
( 4, "Fourth", 300),
|
||||
( 5, "Fifth", 300) ]
|
||||
rows = [
|
||||
(1, "First", 100),
|
||||
(2, "Second", 200),
|
||||
(3, "Third", 300),
|
||||
(4, "Fourth", 300),
|
||||
(5, "Fifth", 300)
|
||||
]
|
||||
sql = "insert into TestArrayDML (IntCol,StringCol,IntCol2) " \
|
||||
"values (:1,:2,:3)"
|
||||
self.cursor.executemany(sql, rows, arraydmlrowcounts = True)
|
||||
self.cursor.executemany(sql, rows, arraydmlrowcounts=True)
|
||||
self.connection.commit()
|
||||
self.assertEqual(self.cursor.getarraydmlrowcounts(), [1, 1, 1, 1, 1])
|
||||
self.cursor.execute("select count(*) from TestArrayDML")
|
||||
count, = self.cursor.fetchone()
|
||||
self.assertEqual(count, len(rows))
|
||||
|
||||
def test_3202_BindPLSQLBooleanCollectionIn(self):
|
||||
def test_3202_bind_plsql_boolean_collection_in(self):
|
||||
"3202 - test binding a boolean collection (in)"
|
||||
typeObj = self.connection.gettype("PKG_TESTBOOLEANS.UDT_BOOLEANLIST")
|
||||
obj = typeObj.newobject()
|
||||
type_obj = self.connection.gettype("PKG_TESTBOOLEANS.UDT_BOOLEANLIST")
|
||||
obj = type_obj.newobject()
|
||||
obj.setelement(1, True)
|
||||
obj.extend([True, False, True, True, False, True])
|
||||
result = self.cursor.callfunc("pkg_TestBooleans.TestInArrays", int,
|
||||
(obj,))
|
||||
(obj,))
|
||||
self.assertEqual(result, 5)
|
||||
|
||||
def test_3203_BindPLSQLBooleanCollectionOut(self):
|
||||
def test_3203_bind_plsql_boolean_collection_out(self):
|
||||
"3203 - test binding a boolean collection (out)"
|
||||
typeObj = self.connection.gettype("PKG_TESTBOOLEANS.UDT_BOOLEANLIST")
|
||||
obj = typeObj.newobject()
|
||||
type_obj = self.connection.gettype("PKG_TESTBOOLEANS.UDT_BOOLEANLIST")
|
||||
obj = type_obj.newobject()
|
||||
self.cursor.callproc("pkg_TestBooleans.TestOutArrays", (6, obj))
|
||||
self.assertEqual(obj.aslist(), [True, False, True, False, True, False])
|
||||
|
||||
def test_3204_BindPLSQLDateCollectionIn(self):
|
||||
def test_3204_bind_plql_date_collection_in(self):
|
||||
"3204 - test binding a PL/SQL date collection (in)"
|
||||
typeObj = self.connection.gettype("PKG_TESTDATEARRAYS.UDT_DATELIST")
|
||||
obj = typeObj.newobject()
|
||||
type_obj = self.connection.gettype("PKG_TESTDATEARRAYS.UDT_DATELIST")
|
||||
obj = type_obj.newobject()
|
||||
obj.setelement(1, datetime.datetime(2016, 2, 5))
|
||||
obj.append(datetime.datetime(2016, 2, 8, 12, 15, 30))
|
||||
obj.append(datetime.datetime(2016, 2, 12, 5, 44, 30))
|
||||
result = self.cursor.callfunc("pkg_TestDateArrays.TestInArrays",
|
||||
cx_Oracle.NUMBER, (2, datetime.datetime(2016, 2, 1), obj))
|
||||
oracledb.NUMBER,
|
||||
(2, datetime.datetime(2016, 2, 1), obj))
|
||||
self.assertEqual(result, 24.75)
|
||||
|
||||
def test_3205_BindPLSQLDateCollectionInOut(self):
|
||||
def test_3205_bind_plqsl_date_collection_in_out(self):
|
||||
"3205 - test binding a PL/SQL date collection (in/out)"
|
||||
typeObj = self.connection.gettype("PKG_TESTDATEARRAYS.UDT_DATELIST")
|
||||
obj = typeObj.newobject()
|
||||
type_obj = self.connection.gettype("PKG_TESTDATEARRAYS.UDT_DATELIST")
|
||||
obj = type_obj.newobject()
|
||||
obj.setelement(1, datetime.datetime(2016, 1, 1))
|
||||
obj.append(datetime.datetime(2016, 1, 7))
|
||||
obj.append(datetime.datetime(2016, 1, 13))
|
||||
obj.append(datetime.datetime(2016, 1, 19))
|
||||
self.cursor.callproc("pkg_TestDateArrays.TestInOutArrays", (4, obj))
|
||||
self.assertEqual(obj.aslist(),
|
||||
[datetime.datetime(2016, 1, 8),
|
||||
datetime.datetime(2016, 1, 14),
|
||||
datetime.datetime(2016, 1, 20),
|
||||
datetime.datetime(2016, 1, 26)])
|
||||
expected_values = [
|
||||
datetime.datetime(2016, 1, 8),
|
||||
datetime.datetime(2016, 1, 14),
|
||||
datetime.datetime(2016, 1, 20),
|
||||
datetime.datetime(2016, 1, 26)
|
||||
]
|
||||
self.assertEqual(obj.aslist(), expected_values)
|
||||
|
||||
def test_3206_BindPLSQLDateCollectionOut(self):
|
||||
def test_3206_bind_plsql_date_collection_out(self):
|
||||
"3206 - test binding a PL/SQL date collection (out)"
|
||||
typeObj = self.connection.gettype("PKG_TESTDATEARRAYS.UDT_DATELIST")
|
||||
obj = typeObj.newobject()
|
||||
type_obj = self.connection.gettype("PKG_TESTDATEARRAYS.UDT_DATELIST")
|
||||
obj = type_obj.newobject()
|
||||
self.cursor.callproc("pkg_TestDateArrays.TestOutArrays", (3, obj))
|
||||
self.assertEqual(obj.aslist(),
|
||||
[datetime.datetime(2002, 12, 13, 4, 48),
|
||||
datetime.datetime(2002, 12, 14, 9, 36),
|
||||
datetime.datetime(2002, 12, 15, 14, 24)])
|
||||
expected_values = [
|
||||
datetime.datetime(2002, 12, 13, 4, 48),
|
||||
datetime.datetime(2002, 12, 14, 9, 36),
|
||||
datetime.datetime(2002, 12, 15, 14, 24)
|
||||
]
|
||||
self.assertEqual(obj.aslist(), expected_values)
|
||||
|
||||
def test_3207_BindPLSQLNumberCollectionIn(self):
|
||||
def test_3207_bind_plsql_number_collection_in(self):
|
||||
"3207 - test binding a PL/SQL number collection (in)"
|
||||
typeObj = self.connection.gettype("PKG_TESTNUMBERARRAYS.UDT_NUMBERLIST")
|
||||
obj = typeObj.newobject()
|
||||
type_name = "PKG_TESTNUMBERARRAYS.UDT_NUMBERLIST"
|
||||
type_obj = self.connection.gettype(type_name)
|
||||
obj = type_obj.newobject()
|
||||
obj.setelement(1, 10)
|
||||
obj.extend([20, 30, 40, 50])
|
||||
result = self.cursor.callfunc("pkg_TestNumberArrays.TestInArrays", int,
|
||||
(5, obj))
|
||||
(5, obj))
|
||||
self.assertEqual(result, 155)
|
||||
|
||||
def test_3208_BindPLSQLNumberCollectionInOut(self):
|
||||
def test_3208_bind_plsql_number_collection_in_out(self):
|
||||
"3208 - test binding a PL/SQL number collection (in/out)"
|
||||
typeObj = self.connection.gettype("PKG_TESTNUMBERARRAYS.UDT_NUMBERLIST")
|
||||
obj = typeObj.newobject()
|
||||
type_name = "PKG_TESTNUMBERARRAYS.UDT_NUMBERLIST"
|
||||
type_obj = self.connection.gettype(type_name)
|
||||
obj = type_obj.newobject()
|
||||
obj.setelement(1, 5)
|
||||
obj.extend([8, 3, 2])
|
||||
self.cursor.callproc("pkg_TestNumberArrays.TestInOutArrays", (4, obj))
|
||||
self.assertEqual(obj.aslist(), [50, 80, 30, 20])
|
||||
|
||||
def test_3209_BindPLSQLNumberCollectionOut(self):
|
||||
def test_3209_bind_plsql_number_collection_out(self):
|
||||
"3209 - test binding a PL/SQL number collection (out)"
|
||||
typeObj = self.connection.gettype("PKG_TESTNUMBERARRAYS.UDT_NUMBERLIST")
|
||||
obj = typeObj.newobject()
|
||||
type_name = "PKG_TESTNUMBERARRAYS.UDT_NUMBERLIST"
|
||||
type_obj = self.connection.gettype(type_name)
|
||||
obj = type_obj.newobject()
|
||||
self.cursor.callproc("pkg_TestNumberArrays.TestOutArrays", (3, obj))
|
||||
self.assertEqual(obj.aslist(), [100, 200, 300])
|
||||
|
||||
def test_3210_BindPLSQLRecordArray(self):
|
||||
def test_3210_bind_plsql_record_array(self):
|
||||
"3210 - test binding an array of PL/SQL records (in)"
|
||||
recType = self.connection.gettype("PKG_TESTRECORDS.UDT_RECORD")
|
||||
arrayType = self.connection.gettype("PKG_TESTRECORDS.UDT_RECORDARRAY")
|
||||
arrayObj = arrayType.newobject()
|
||||
rec_type = self.connection.gettype("PKG_TESTRECORDS.UDT_RECORD")
|
||||
array_type = self.connection.gettype("PKG_TESTRECORDS.UDT_RECORDARRAY")
|
||||
array_obj = array_type.newobject()
|
||||
for i in range(3):
|
||||
obj = recType.newobject()
|
||||
obj = rec_type.newobject()
|
||||
obj.NUMBERVALUE = i + 1
|
||||
obj.STRINGVALUE = "String in record #%d" % (i + 1)
|
||||
obj.DATEVALUE = datetime.datetime(2017, i + 1, 1)
|
||||
|
@ -146,27 +154,27 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
obj.BOOLEANVALUE = (i % 2) == 1
|
||||
obj.PLSINTEGERVALUE = i * 5
|
||||
obj.BINARYINTEGERVALUE = i * 2
|
||||
arrayObj.append(obj)
|
||||
array_obj.append(obj)
|
||||
result = self.cursor.callfunc("pkg_TestRecords.TestInArrays", str,
|
||||
(arrayObj,))
|
||||
(array_obj,))
|
||||
self.assertEqual(result,
|
||||
"udt_Record(1, 'String in record #1', " \
|
||||
"to_date('2017-01-01', 'YYYY-MM-DD'), " \
|
||||
"to_timestamp('2017-01-01 00:00:00', " \
|
||||
"'YYYY-MM-DD HH24:MI:SS'), false, 0, 0); " \
|
||||
"udt_Record(2, 'String in record #2', " \
|
||||
"to_date('2017-02-01', 'YYYY-MM-DD'), " \
|
||||
"to_timestamp('2017-01-02 00:00:00', " \
|
||||
"'YYYY-MM-DD HH24:MI:SS'), true, 5, 2); " \
|
||||
"udt_Record(3, 'String in record #3', " \
|
||||
"to_date('2017-03-01', 'YYYY-MM-DD'), " \
|
||||
"to_timestamp('2017-01-03 00:00:00', " \
|
||||
"'YYYY-MM-DD HH24:MI:SS'), false, 10, 4)")
|
||||
"udt_Record(1, 'String in record #1', " \
|
||||
"to_date('2017-01-01', 'YYYY-MM-DD'), " \
|
||||
"to_timestamp('2017-01-01 00:00:00', " \
|
||||
"'YYYY-MM-DD HH24:MI:SS'), false, 0, 0); " \
|
||||
"udt_Record(2, 'String in record #2', " \
|
||||
"to_date('2017-02-01', 'YYYY-MM-DD'), " \
|
||||
"to_timestamp('2017-01-02 00:00:00', " \
|
||||
"'YYYY-MM-DD HH24:MI:SS'), true, 5, 2); " \
|
||||
"udt_Record(3, 'String in record #3', " \
|
||||
"to_date('2017-03-01', 'YYYY-MM-DD'), " \
|
||||
"to_timestamp('2017-01-03 00:00:00', " \
|
||||
"'YYYY-MM-DD HH24:MI:SS'), false, 10, 4)")
|
||||
|
||||
def test_3211_BindPLSQLRecordIn(self):
|
||||
def test_3211_bind_plsql_record_in(self):
|
||||
"3211 - test binding a PL/SQL record (in)"
|
||||
typeObj = self.connection.gettype("PKG_TESTRECORDS.UDT_RECORD")
|
||||
obj = typeObj.newobject()
|
||||
type_obj = self.connection.gettype("PKG_TESTRECORDS.UDT_RECORD")
|
||||
obj = type_obj.newobject()
|
||||
obj.NUMBERVALUE = 18
|
||||
obj.STRINGVALUE = "A string in a record"
|
||||
obj.DATEVALUE = datetime.datetime(2016, 2, 15)
|
||||
|
@ -175,17 +183,17 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
obj.PLSINTEGERVALUE = 21
|
||||
obj.BINARYINTEGERVALUE = 5
|
||||
result = self.cursor.callfunc("pkg_TestRecords.GetStringRep", str,
|
||||
(obj,))
|
||||
(obj,))
|
||||
self.assertEqual(result,
|
||||
"udt_Record(18, 'A string in a record', " \
|
||||
"to_date('2016-02-15', 'YYYY-MM-DD'), " \
|
||||
"to_timestamp('2016-02-12 14:25:36', " \
|
||||
"'YYYY-MM-DD HH24:MI:SS'), false, 21, 5)")
|
||||
"udt_Record(18, 'A string in a record', " \
|
||||
"to_date('2016-02-15', 'YYYY-MM-DD'), " \
|
||||
"to_timestamp('2016-02-12 14:25:36', " \
|
||||
"'YYYY-MM-DD HH24:MI:SS'), false, 21, 5)")
|
||||
|
||||
def test_3212_BindPLSQLRecordOut(self):
|
||||
def test_3212_bind_plsql_record_out(self):
|
||||
"3212 - test binding a PL/SQL record (out)"
|
||||
typeObj = self.connection.gettype("PKG_TESTRECORDS.UDT_RECORD")
|
||||
obj = typeObj.newobject()
|
||||
type_obj = self.connection.gettype("PKG_TESTRECORDS.UDT_RECORD")
|
||||
obj = type_obj.newobject()
|
||||
obj.NUMBERVALUE = 5
|
||||
obj.STRINGVALUE = "Test value"
|
||||
obj.DATEVALUE = datetime.datetime.today()
|
||||
|
@ -198,50 +206,58 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
self.assertEqual(obj.STRINGVALUE, "String in record")
|
||||
self.assertEqual(obj.DATEVALUE, datetime.datetime(2016, 2, 16))
|
||||
self.assertEqual(obj.TIMESTAMPVALUE,
|
||||
datetime.datetime(2016, 2, 16, 18, 23, 55))
|
||||
datetime.datetime(2016, 2, 16, 18, 23, 55))
|
||||
self.assertEqual(obj.BOOLEANVALUE, True)
|
||||
self.assertEqual(obj.PLSINTEGERVALUE, 45)
|
||||
self.assertEqual(obj.BINARYINTEGERVALUE, 10)
|
||||
|
||||
def test_3213_BindPLSQLStringCollectionIn(self):
|
||||
def test_3213_bind_plsql_string_collection_in(self):
|
||||
"3213 - test binding a PL/SQL string collection (in)"
|
||||
typeObj = self.connection.gettype("PKG_TESTSTRINGARRAYS.UDT_STRINGLIST")
|
||||
obj = typeObj.newobject()
|
||||
type_name = "PKG_TESTSTRINGARRAYS.UDT_STRINGLIST"
|
||||
type_obj = self.connection.gettype(type_name)
|
||||
obj = type_obj.newobject()
|
||||
obj.setelement(1, "First element")
|
||||
obj.setelement(2, "Second element")
|
||||
obj.setelement(3, "Third element")
|
||||
result = self.cursor.callfunc("pkg_TestStringArrays.TestInArrays", int,
|
||||
(5, obj))
|
||||
(5, obj))
|
||||
self.assertEqual(result, 45)
|
||||
|
||||
def test_3214_BindPLSQLStringCollectionInOut(self):
|
||||
def test_3214_bind_plsql_string_collection_in_out(self):
|
||||
"3214 - test binding a PL/SQL string collection (in/out)"
|
||||
typeObj = self.connection.gettype("PKG_TESTSTRINGARRAYS.UDT_STRINGLIST")
|
||||
obj = typeObj.newobject()
|
||||
type_name = "PKG_TESTSTRINGARRAYS.UDT_STRINGLIST"
|
||||
type_obj = self.connection.gettype(type_name)
|
||||
obj = type_obj.newobject()
|
||||
obj.setelement(1, "The first element")
|
||||
obj.append("The second element")
|
||||
obj.append("The third and final element")
|
||||
self.cursor.callproc("pkg_TestStringArrays.TestInOutArrays", (3, obj))
|
||||
self.assertEqual(obj.aslist(),
|
||||
['Converted element # 1 originally had length 17',
|
||||
'Converted element # 2 originally had length 18',
|
||||
'Converted element # 3 originally had length 27'])
|
||||
expected_values = [
|
||||
'Converted element # 1 originally had length 17',
|
||||
'Converted element # 2 originally had length 18',
|
||||
'Converted element # 3 originally had length 27'
|
||||
]
|
||||
self.assertEqual(obj.aslist(), expected_values)
|
||||
|
||||
def test_3215_BindPLSQLStringCollectionOut(self):
|
||||
def test_3215_bind_plsql_string_collection_out(self):
|
||||
"3215 - test binding a PL/SQL string collection (out)"
|
||||
typeObj = self.connection.gettype("PKG_TESTSTRINGARRAYS.UDT_STRINGLIST")
|
||||
obj = typeObj.newobject()
|
||||
type_name = "PKG_TESTSTRINGARRAYS.UDT_STRINGLIST"
|
||||
type_obj = self.connection.gettype(type_name)
|
||||
obj = type_obj.newobject()
|
||||
self.cursor.callproc("pkg_TestStringArrays.TestOutArrays", (4, obj))
|
||||
self.assertEqual(obj.aslist(),
|
||||
['Test out element # 1',
|
||||
'Test out element # 2',
|
||||
'Test out element # 3',
|
||||
'Test out element # 4'])
|
||||
expected_values = [
|
||||
'Test out element # 1',
|
||||
'Test out element # 2',
|
||||
'Test out element # 3',
|
||||
'Test out element # 4'
|
||||
]
|
||||
self.assertEqual(obj.aslist(), expected_values)
|
||||
|
||||
def test_3216_BindPLSQLStringCollectionOutWithHoles(self):
|
||||
def test_3216_bind_plsql_string_collection_out_with_holes(self):
|
||||
"3216 - test binding a PL/SQL string collection (out with holes)"
|
||||
typeObj = self.connection.gettype("PKG_TESTSTRINGARRAYS.UDT_STRINGLIST")
|
||||
obj = typeObj.newobject()
|
||||
type_name = "PKG_TESTSTRINGARRAYS.UDT_STRINGLIST"
|
||||
type_obj = self.connection.gettype(type_name)
|
||||
obj = type_obj.newobject()
|
||||
self.cursor.callproc("pkg_TestStringArrays.TestIndexBy", (obj,))
|
||||
self.assertEqual(obj.first(), -1048576)
|
||||
self.assertEqual(obj.last(), 8388608)
|
||||
|
@ -251,77 +267,93 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
self.assertEqual(obj.exists(-576), True)
|
||||
self.assertEqual(obj.exists(-577), False)
|
||||
self.assertEqual(obj.getelement(284), 'Third element')
|
||||
self.assertEqual(obj.aslist(),
|
||||
["First element", "Second element", "Third element",
|
||||
"Fourth element"])
|
||||
self.assertEqual(obj.asdict(),
|
||||
{ -1048576 : 'First element',
|
||||
-576 : 'Second element',
|
||||
284 : 'Third element',
|
||||
8388608: 'Fourth element' })
|
||||
expected_list = [
|
||||
"First element",
|
||||
"Second element",
|
||||
"Third element",
|
||||
"Fourth element"
|
||||
]
|
||||
self.assertEqual(obj.aslist(), expected_list)
|
||||
expected_dict = {
|
||||
-1048576: 'First element',
|
||||
-576: 'Second element',
|
||||
284: 'Third element',
|
||||
8388608: 'Fourth element'
|
||||
}
|
||||
self.assertEqual(obj.asdict(), expected_dict)
|
||||
obj.delete(-576)
|
||||
obj.delete(284)
|
||||
self.assertEqual(obj.aslist(), ["First element", "Fourth element"])
|
||||
self.assertEqual(obj.asdict(),
|
||||
{ -1048576 : 'First element',
|
||||
8388608: 'Fourth element' })
|
||||
expected_list.pop(2)
|
||||
expected_list.pop(1)
|
||||
self.assertEqual(obj.aslist(), expected_list)
|
||||
expected_dict.pop(-576)
|
||||
expected_dict.pop(284)
|
||||
self.assertEqual(obj.asdict(), expected_dict)
|
||||
|
||||
def test_3217_ExceptionInIteration(self):
|
||||
def test_3217_exception_in_iteration(self):
|
||||
"3217 - test executing with arraydmlrowcounts with exception"
|
||||
self.cursor.execute("truncate table TestArrayDML")
|
||||
rows = [ (1, "First"),
|
||||
(2, "Second"),
|
||||
(2, "Third"),
|
||||
(4, "Fourth") ]
|
||||
rows = [
|
||||
(1, "First"),
|
||||
(2, "Second"),
|
||||
(2, "Third"),
|
||||
(4, "Fourth")
|
||||
]
|
||||
sql = "insert into TestArrayDML (IntCol,StringCol) values (:1,:2)"
|
||||
self.assertRaises(cx_Oracle.DatabaseError, self.cursor.executemany,
|
||||
sql, rows, arraydmlrowcounts = True)
|
||||
self.assertRaises(oracledb.DatabaseError, self.cursor.executemany,
|
||||
sql, rows, arraydmlrowcounts=True)
|
||||
self.assertEqual(self.cursor.getarraydmlrowcounts(), [1, 1])
|
||||
|
||||
def test_3218_ExecutingDelete(self):
|
||||
def test_3218_executing_delete(self):
|
||||
"3218 - test executing delete statement with arraydmlrowcount mode"
|
||||
self.cursor.execute("truncate table TestArrayDML")
|
||||
rows = [ (1, "First", 100),
|
||||
(2, "Second", 200),
|
||||
(3, "Third", 300),
|
||||
(4, "Fourth", 300),
|
||||
(5, "Fifth", 300),
|
||||
(6, "Sixth", 400),
|
||||
(7, "Seventh", 400),
|
||||
(8, "Eighth", 500) ]
|
||||
rows = [
|
||||
(1, "First", 100),
|
||||
(2, "Second", 200),
|
||||
(3, "Third", 300),
|
||||
(4, "Fourth", 300),
|
||||
(5, "Fifth", 300),
|
||||
(6, "Sixth", 400),
|
||||
(7, "Seventh", 400),
|
||||
(8, "Eighth", 500)
|
||||
]
|
||||
sql = "insert into TestArrayDML (IntCol,StringCol,IntCol2) " \
|
||||
"values (:1, :2, :3)"
|
||||
self.cursor.executemany(sql, rows)
|
||||
rows = [ (200,), (300,), (400,) ]
|
||||
rows = [(200,), (300,), (400,)]
|
||||
statement = "delete from TestArrayDML where IntCol2 = :1"
|
||||
self.cursor.executemany(statement, rows, arraydmlrowcounts = True)
|
||||
self.cursor.executemany(statement, rows, arraydmlrowcounts=True)
|
||||
self.assertEqual(self.cursor.getarraydmlrowcounts(), [1, 3, 2])
|
||||
self.assertEqual(self.cursor.rowcount, 6)
|
||||
|
||||
def test_3219_ExecutingUpdate(self):
|
||||
def test_3219_executing_update(self):
|
||||
"3219 - test executing update statement with arraydmlrowcount mode"
|
||||
self.cursor.execute("truncate table TestArrayDML")
|
||||
rows = [ (1, "First",100),
|
||||
(2, "Second",200),
|
||||
(3, "Third",300),
|
||||
(4, "Fourth",300),
|
||||
(5, "Fifth",300),
|
||||
(6, "Sixth",400),
|
||||
(7, "Seventh",400),
|
||||
(8, "Eighth",500) ]
|
||||
rows = [
|
||||
(1, "First",100),
|
||||
(2, "Second",200),
|
||||
(3, "Third",300),
|
||||
(4, "Fourth",300),
|
||||
(5, "Fifth",300),
|
||||
(6, "Sixth",400),
|
||||
(7, "Seventh",400),
|
||||
(8, "Eighth",500)
|
||||
]
|
||||
sql = "insert into TestArrayDML (IntCol,StringCol,IntCol2) " \
|
||||
"values (:1, :2, :3)"
|
||||
self.cursor.executemany(sql, rows)
|
||||
rows = [ ("One", 100),
|
||||
("Two", 200),
|
||||
("Three", 300),
|
||||
("Four", 400) ]
|
||||
rows = [
|
||||
("One", 100),
|
||||
("Two", 200),
|
||||
("Three", 300),
|
||||
("Four", 400)
|
||||
]
|
||||
sql = "update TestArrayDML set StringCol = :1 where IntCol2 = :2"
|
||||
self.cursor.executemany(sql, rows, arraydmlrowcounts = True)
|
||||
self.cursor.executemany(sql, rows, arraydmlrowcounts=True)
|
||||
self.assertEqual(self.cursor.getarraydmlrowcounts(), [1, 1, 3, 2])
|
||||
self.assertEqual(self.cursor.rowcount, 7)
|
||||
|
||||
def test_3220_ImplicitResults(self):
|
||||
def test_3220_implicit_results(self):
|
||||
"3220 - test getimplicitresults() returns the correct data"
|
||||
self.cursor.execute("""
|
||||
declare
|
||||
|
@ -349,86 +381,93 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
self.assertEqual([n for n, in results[0]], [3.75, 5, 6.25])
|
||||
self.assertEqual([n for n, in results[1]], [8.75, 10, 11.25, 12.5])
|
||||
|
||||
def test_3221_ImplicitResultsNoStatement(self):
|
||||
def test_3221_implicit_results_no_statement(self):
|
||||
"3221 - test getimplicitresults() without executing a statement"
|
||||
self.assertRaises(cx_Oracle.InterfaceError,
|
||||
self.cursor.getimplicitresults)
|
||||
self.assertRaises(oracledb.InterfaceError,
|
||||
self.cursor.getimplicitresults)
|
||||
|
||||
def test_3222_InsertWithBatchError(self):
|
||||
def test_3222_insert_with_batch_error(self):
|
||||
"3222 - test executing insert with multiple distinct batch errors"
|
||||
self.cursor.execute("truncate table TestArrayDML")
|
||||
rows = [ (1, "First", 100),
|
||||
(2, "Second", 200),
|
||||
(2, "Third", 300),
|
||||
(4, "Fourth", 400),
|
||||
(5, "Fourth", 1000)]
|
||||
rows = [
|
||||
(1, "First", 100),
|
||||
(2, "Second", 200),
|
||||
(2, "Third", 300),
|
||||
(4, "Fourth", 400),
|
||||
(5, "Fourth", 1000)
|
||||
]
|
||||
sql = "insert into TestArrayDML (IntCol, StringCol, IntCol2) " \
|
||||
"values (:1, :2, :3)"
|
||||
self.cursor.executemany(sql, rows, batcherrors = True,
|
||||
arraydmlrowcounts = True)
|
||||
user = TestEnv.GetMainUser()
|
||||
expectedErrors = [
|
||||
( 4, 1438, "ORA-01438: value larger than specified " \
|
||||
"precision allowed for this column" ),
|
||||
( 2, 1, "ORA-00001: unique constraint " \
|
||||
"(%s.TESTARRAYDML_PK) violated" % user.upper())
|
||||
self.cursor.executemany(sql, rows, batcherrors=True,
|
||||
arraydmlrowcounts=True)
|
||||
user = base.get_main_user()
|
||||
expected_errors = [
|
||||
( 4, 1438, "ORA-01438: value larger than specified " \
|
||||
"precision allowed for this column" ),
|
||||
( 2, 1, "ORA-00001: unique constraint " \
|
||||
"(%s.TESTARRAYDML_PK) violated" % user.upper())
|
||||
]
|
||||
actualErrors = [(e.offset, e.code, e.message) \
|
||||
for e in self.cursor.getbatcherrors()]
|
||||
self.assertEqual(actualErrors, expectedErrors)
|
||||
actual_errors = [(e.offset, e.code, e.message) \
|
||||
for e in self.cursor.getbatcherrors()]
|
||||
self.assertEqual(actual_errors, expected_errors)
|
||||
self.assertEqual(self.cursor.getarraydmlrowcounts(), [1, 1, 0, 1, 0])
|
||||
|
||||
def test_3223_BatchErrorFalse(self):
|
||||
def test_3223_batch_error_false(self):
|
||||
"3223 - test batcherrors mode set to False"
|
||||
self.cursor.execute("truncate table TestArrayDML")
|
||||
rows = [ (1, "First", 100),
|
||||
(2, "Second", 200),
|
||||
(2, "Third", 300) ]
|
||||
rows = [
|
||||
(1, "First", 100),
|
||||
(2, "Second", 200),
|
||||
(2, "Third", 300)
|
||||
]
|
||||
sql = "insert into TestArrayDML (IntCol, StringCol, IntCol2) " \
|
||||
"values (:1, :2, :3)"
|
||||
self.assertRaises(cx_Oracle.IntegrityError,
|
||||
self.cursor.executemany, sql, rows, batcherrors = False)
|
||||
self.assertRaises(oracledb.IntegrityError, self.cursor.executemany,
|
||||
sql, rows, batcherrors=False)
|
||||
|
||||
def test_3224_UpdatewithBatchError(self):
|
||||
def test_3224_update_with_batch_error(self):
|
||||
"3224 - test executing in succession with batch error"
|
||||
self.cursor.execute("truncate table TestArrayDML")
|
||||
rows = [ (1, "First", 100),
|
||||
(2, "Second", 200),
|
||||
(3, "Third", 300),
|
||||
(4, "Second", 300),
|
||||
(5, "Fifth", 300),
|
||||
(6, "Sixth", 400),
|
||||
(6, "Seventh", 400),
|
||||
(8, "Eighth", 100) ]
|
||||
rows = [
|
||||
(1, "First", 100),
|
||||
(2, "Second", 200),
|
||||
(3, "Third", 300),
|
||||
(4, "Second", 300),
|
||||
(5, "Fifth", 300),
|
||||
(6, "Sixth", 400),
|
||||
(6, "Seventh", 400),
|
||||
(8, "Eighth", 100)
|
||||
]
|
||||
sql = "insert into TestArrayDML (IntCol, StringCol, IntCol2) " \
|
||||
"values (:1, :2, :3)"
|
||||
self.cursor.executemany(sql, rows, batcherrors = True)
|
||||
user = TestEnv.GetMainUser()
|
||||
expectedErrors = [
|
||||
( 6, 1, "ORA-00001: unique constraint " \
|
||||
"(%s.TESTARRAYDML_PK) violated" % user.upper())
|
||||
self.cursor.executemany(sql, rows, batcherrors=True)
|
||||
user = base.get_main_user()
|
||||
expected_errors = [
|
||||
( 6, 1, "ORA-00001: unique constraint " \
|
||||
"(%s.TESTARRAYDML_PK) violated" % user.upper())
|
||||
]
|
||||
actual_errors = [(e.offset, e.code, e.message) \
|
||||
for e in self.cursor.getbatcherrors()]
|
||||
self.assertEqual(actual_errors, expected_errors)
|
||||
rows = [
|
||||
(101, "First"),
|
||||
(201, "Second"),
|
||||
(3000, "Third"),
|
||||
(900, "Ninth"),
|
||||
(301, "Third")
|
||||
]
|
||||
actualErrors = [(e.offset, e.code, e.message) \
|
||||
for e in self.cursor.getbatcherrors()]
|
||||
self.assertEqual(actualErrors, expectedErrors)
|
||||
rows = [ (101, "First"),
|
||||
(201, "Second"),
|
||||
(3000, "Third"),
|
||||
(900, "Ninth"),
|
||||
(301, "Third") ]
|
||||
sql = "update TestArrayDML set IntCol2 = :1 where StringCol = :2"
|
||||
self.cursor.executemany(sql, rows, arraydmlrowcounts = True,
|
||||
batcherrors = True)
|
||||
expectedErrors = [
|
||||
( 2, 1438, "ORA-01438: value larger than specified " \
|
||||
"precision allowed for this column" )
|
||||
self.cursor.executemany(sql, rows, arraydmlrowcounts=True,
|
||||
batcherrors=True)
|
||||
expected_errors = [
|
||||
(2, 1438, "ORA-01438: value larger than specified " \
|
||||
"precision allowed for this column")
|
||||
]
|
||||
actualErrors = [(e.offset, e.code, e.message) \
|
||||
for e in self.cursor.getbatcherrors()]
|
||||
self.assertEqual(actualErrors, expectedErrors)
|
||||
self.assertEqual(self.cursor.getarraydmlrowcounts(),
|
||||
[1, 2, 0, 0, 1])
|
||||
actual_errors = [(e.offset, e.code, e.message) \
|
||||
for e in self.cursor.getbatcherrors()]
|
||||
self.assertEqual(actual_errors, expected_errors)
|
||||
self.assertEqual(self.cursor.getarraydmlrowcounts(), [1, 2, 0, 0, 1])
|
||||
self.assertEqual(self.cursor.rowcount, 4)
|
||||
|
||||
if __name__ == "__main__":
|
||||
TestEnv.RunTestCases()
|
||||
base.run_test_cases()
|
||||
|
|
|
@ -6,106 +6,104 @@
|
|||
3300 - Module for testing Simple Oracle Document Access (SODA) Database
|
||||
"""
|
||||
|
||||
import TestEnv
|
||||
import base
|
||||
|
||||
import cx_Oracle
|
||||
import cx_Oracle as oracledb
|
||||
import json
|
||||
import unittest
|
||||
|
||||
@unittest.skipIf(TestEnv.SkipSodaTests(),
|
||||
@unittest.skipIf(base.skip_soda_tests(),
|
||||
"unsupported client/server combination")
|
||||
class TestCase(TestEnv.BaseTestCase):
|
||||
class TestCase(base.BaseTestCase):
|
||||
|
||||
def __dropExistingCollections(self, sodaDatabase):
|
||||
for name in sodaDatabase.getCollectionNames():
|
||||
sodaDatabase.openCollection(name).drop()
|
||||
def __drop_existing_collections(self, soda_db):
|
||||
for name in soda_db.getCollectionNames():
|
||||
soda_db.openCollection(name).drop()
|
||||
|
||||
def __verifyDocument(self, doc, rawContent, strContent=None, content=None,
|
||||
key=None, mediaType='application/json'):
|
||||
self.assertEqual(doc.getContentAsBytes(), rawContent)
|
||||
if strContent is not None:
|
||||
self.assertEqual(doc.getContentAsString(), strContent)
|
||||
def __verify_doc(self, doc, raw_content, str_content=None, content=None,
|
||||
key=None, media_type='application/json'):
|
||||
self.assertEqual(doc.getContentAsBytes(), raw_content)
|
||||
if str_content is not None:
|
||||
self.assertEqual(doc.getContentAsString(), str_content)
|
||||
if content is not None:
|
||||
self.assertEqual(doc.getContent(), content)
|
||||
self.assertEqual(doc.key, key)
|
||||
self.assertEqual(doc.mediaType, mediaType)
|
||||
self.assertEqual(doc.mediaType, media_type)
|
||||
|
||||
def test_3300_CreateDocumentWithJson(self):
|
||||
def test_3300_create_document_with_json(self):
|
||||
"3300 - test creating documents with JSON data"
|
||||
sodaDatabase = self.connection.getSodaDatabase()
|
||||
val = {"testKey1" : "testValue1", "testKey2" : "testValue2" }
|
||||
strVal = json.dumps(val)
|
||||
bytesVal = strVal.encode("UTF-8")
|
||||
soda_db = self.connection.getSodaDatabase()
|
||||
val = {"testKey1": "testValue1", "testKey2": "testValue2"}
|
||||
str_val = json.dumps(val)
|
||||
bytes_val = str_val.encode()
|
||||
key = "MyKey"
|
||||
mediaType = "text/plain"
|
||||
doc = sodaDatabase.createDocument(val)
|
||||
self.__verifyDocument(doc, bytesVal, strVal, val)
|
||||
doc = sodaDatabase.createDocument(strVal, key)
|
||||
self.__verifyDocument(doc, bytesVal, strVal, val, key)
|
||||
doc = sodaDatabase.createDocument(bytesVal, key, mediaType)
|
||||
self.__verifyDocument(doc, bytesVal, strVal, val, key, mediaType)
|
||||
media_type = "text/plain"
|
||||
doc = soda_db.createDocument(val)
|
||||
self.__verify_doc(doc, bytes_val, str_val, val)
|
||||
doc = soda_db.createDocument(str_val, key)
|
||||
self.__verify_doc(doc, bytes_val, str_val, val, key)
|
||||
doc = soda_db.createDocument(bytes_val, key, media_type)
|
||||
self.__verify_doc(doc, bytes_val, str_val, val, key, media_type)
|
||||
|
||||
def test_3301_CreateDocumentWithRaw(self):
|
||||
def test_3301_create_document_with_raw(self):
|
||||
"3301 - test creating documents with raw data"
|
||||
sodaDatabase = self.connection.getSodaDatabase()
|
||||
soda_db = self.connection.getSodaDatabase()
|
||||
val = b"<html/>"
|
||||
key = "MyRawKey"
|
||||
mediaType = "text/html"
|
||||
doc = sodaDatabase.createDocument(val)
|
||||
self.__verifyDocument(doc, val)
|
||||
doc = sodaDatabase.createDocument(val, key)
|
||||
self.__verifyDocument(doc, val, key=key)
|
||||
doc = sodaDatabase.createDocument(val, key, mediaType)
|
||||
self.__verifyDocument(doc, val, key=key, mediaType=mediaType)
|
||||
media_type = "text/html"
|
||||
doc = soda_db.createDocument(val)
|
||||
self.__verify_doc(doc, val)
|
||||
doc = soda_db.createDocument(val, key)
|
||||
self.__verify_doc(doc, val, key=key)
|
||||
doc = soda_db.createDocument(val, key, media_type)
|
||||
self.__verify_doc(doc, val, key=key, media_type=media_type)
|
||||
|
||||
def test_3302_GetCollectionNames(self):
|
||||
def test_3302_get_collection_names(self):
|
||||
"3302 - test getting collection names from the database"
|
||||
sodaDatabase = self.connection.getSodaDatabase()
|
||||
self.__dropExistingCollections(sodaDatabase)
|
||||
self.assertEqual(sodaDatabase.getCollectionNames(), [])
|
||||
soda_db = self.connection.getSodaDatabase()
|
||||
self.__drop_existing_collections(soda_db)
|
||||
self.assertEqual(soda_db.getCollectionNames(), [])
|
||||
names = ["zCol", "dCol", "sCol", "aCol", "gCol"]
|
||||
sortedNames = list(sorted(names))
|
||||
sorted_names = list(sorted(names))
|
||||
for name in names:
|
||||
sodaDatabase.createCollection(name)
|
||||
self.assertEqual(sodaDatabase.getCollectionNames(), sortedNames)
|
||||
self.assertEqual(sodaDatabase.getCollectionNames(limit=2),
|
||||
sortedNames[:2])
|
||||
self.assertEqual(sodaDatabase.getCollectionNames("a"), sortedNames)
|
||||
self.assertEqual(sodaDatabase.getCollectionNames("C"), sortedNames)
|
||||
self.assertEqual(sodaDatabase.getCollectionNames("b", limit=3),
|
||||
sortedNames[1:4])
|
||||
self.assertEqual(sodaDatabase.getCollectionNames("z"),
|
||||
sortedNames[-1:])
|
||||
soda_db.createCollection(name)
|
||||
self.assertEqual(soda_db.getCollectionNames(), sorted_names)
|
||||
self.assertEqual(soda_db.getCollectionNames(limit=2), sorted_names[:2])
|
||||
self.assertEqual(soda_db.getCollectionNames("a"), sorted_names)
|
||||
self.assertEqual(soda_db.getCollectionNames("C"), sorted_names)
|
||||
self.assertEqual(soda_db.getCollectionNames("b", limit=3),
|
||||
sorted_names[1:4])
|
||||
self.assertEqual(soda_db.getCollectionNames("z"), sorted_names[-1:])
|
||||
|
||||
def test_3303_OpenCollection(self):
|
||||
def test_3303_open_collection(self):
|
||||
"3303 - test opening a collection"
|
||||
sodaDatabase = self.connection.getSodaDatabase()
|
||||
self.__dropExistingCollections(sodaDatabase)
|
||||
coll = sodaDatabase.openCollection("CollectionThatDoesNotExist")
|
||||
soda_db = self.connection.getSodaDatabase()
|
||||
self.__drop_existing_collections(soda_db)
|
||||
coll = soda_db.openCollection("CollectionThatDoesNotExist")
|
||||
self.assertEqual(coll, None)
|
||||
createdColl = sodaDatabase.createCollection("cxoTestOpenCollection")
|
||||
coll = sodaDatabase.openCollection(createdColl.name)
|
||||
self.assertEqual(coll.name, createdColl.name)
|
||||
created_coll = soda_db.createCollection("TestOpenCollection")
|
||||
coll = soda_db.openCollection(created_coll.name)
|
||||
self.assertEqual(coll.name, created_coll.name)
|
||||
coll.drop()
|
||||
|
||||
def test_3304_Repr(self):
|
||||
def test_3304_repr(self):
|
||||
"3304 - test SodaDatabase representation"
|
||||
con1 = self.connection
|
||||
con2 = TestEnv.GetConnection()
|
||||
sodaDatabase1 = self.connection.getSodaDatabase()
|
||||
sodaDatabase2 = con1.getSodaDatabase()
|
||||
sodaDatabase3 = con2.getSodaDatabase()
|
||||
self.assertEqual(str(sodaDatabase1), str(sodaDatabase2))
|
||||
self.assertEqual(str(sodaDatabase2), str(sodaDatabase3))
|
||||
con2 = base.get_connection()
|
||||
soda_db1 = self.connection.getSodaDatabase()
|
||||
soda_db2 = con1.getSodaDatabase()
|
||||
soda_db3 = con2.getSodaDatabase()
|
||||
self.assertEqual(str(soda_db1), str(soda_db2))
|
||||
self.assertEqual(str(soda_db2), str(soda_db3))
|
||||
|
||||
def test_3305_Negative(self):
|
||||
def test_3305_negative(self):
|
||||
"3305 - test negative cases for SODA database methods"
|
||||
sodaDatabase = self.connection.getSodaDatabase()
|
||||
self.assertRaises(TypeError, sodaDatabase.createCollection)
|
||||
self.assertRaises(TypeError, sodaDatabase.createCollection, 1)
|
||||
self.assertRaises(cx_Oracle.DatabaseError,
|
||||
sodaDatabase.createCollection, None)
|
||||
self.assertRaises(TypeError, sodaDatabase.getCollectionNames, 1)
|
||||
soda_db = self.connection.getSodaDatabase()
|
||||
self.assertRaises(TypeError, soda_db.createCollection)
|
||||
self.assertRaises(TypeError, soda_db.createCollection, 1)
|
||||
self.assertRaises(oracledb.DatabaseError, soda_db.createCollection,
|
||||
None)
|
||||
self.assertRaises(TypeError, soda_db.getCollectionNames, 1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
TestEnv.RunTestCases()
|
||||
base.run_test_cases()
|
||||
|
|
|
@ -6,90 +6,90 @@
|
|||
3400 - Module for testing Simple Oracle Document Access (SODA) Collections
|
||||
"""
|
||||
|
||||
import TestEnv
|
||||
import base
|
||||
|
||||
import cx_Oracle
|
||||
import cx_Oracle as oracledb
|
||||
import unittest
|
||||
|
||||
@unittest.skipIf(TestEnv.SkipSodaTests(),
|
||||
@unittest.skipIf(base.skip_soda_tests(),
|
||||
"unsupported client/server combination")
|
||||
class TestCase(TestEnv.BaseTestCase):
|
||||
class TestCase(base.BaseTestCase):
|
||||
|
||||
def __testSkip(self, coll, numToSkip, expectedContent):
|
||||
filterSpec = {'$orderby': [{'path': 'name', 'order': 'desc'}]}
|
||||
doc = coll.find().filter(filterSpec).skip(numToSkip).getOne()
|
||||
def __test_skip(self, coll, num_to_skip, expected_content):
|
||||
filter_spec = {'$orderby': [{'path': 'name', 'order': 'desc'}]}
|
||||
doc = coll.find().filter(filter_spec).skip(num_to_skip).getOne()
|
||||
content = doc.getContent() if doc is not None else None
|
||||
self.assertEqual(content, expectedContent)
|
||||
self.assertEqual(content, expected_content)
|
||||
|
||||
def test_3400_InvalidJson(self):
|
||||
def test_3400_invalid_json(self):
|
||||
"3400 - test inserting invalid JSON value into SODA collection"
|
||||
invalidJson = "{testKey:testValue}"
|
||||
sodaDatabase = self.connection.getSodaDatabase()
|
||||
coll = sodaDatabase.createCollection("cxoInvalidJSON")
|
||||
doc = sodaDatabase.createDocument(invalidJson)
|
||||
self.assertRaises(cx_Oracle.IntegrityError, coll.insertOne, doc)
|
||||
invalid_json = "{testKey:testValue}"
|
||||
soda_db = self.connection.getSodaDatabase()
|
||||
coll = soda_db.createCollection("InvalidJSON")
|
||||
doc = soda_db.createDocument(invalid_json)
|
||||
self.assertRaises(oracledb.DatabaseError, coll.insertOne, doc)
|
||||
coll.drop()
|
||||
|
||||
def test_3401_InsertDocuments(self):
|
||||
def test_3401_insert_documents(self):
|
||||
"3401 - test inserting documents into a SODA collection"
|
||||
sodaDatabase = self.connection.getSodaDatabase()
|
||||
coll = sodaDatabase.createCollection("cxoInsertDocs")
|
||||
soda_db = self.connection.getSodaDatabase()
|
||||
coll = soda_db.createCollection("cxoInsertDocs")
|
||||
coll.find().remove()
|
||||
valuesToInsert = [
|
||||
{ "name" : "George", "age" : 47 },
|
||||
{ "name" : "Susan", "age" : 39 },
|
||||
{ "name" : "John", "age" : 50 },
|
||||
{ "name" : "Jill", "age" : 54 }
|
||||
values_to_insert = [
|
||||
{"name": "George", "age": 47},
|
||||
{"name": "Susan", "age": 39},
|
||||
{"name": "John", "age": 50},
|
||||
{"name": "Jill", "age": 54}
|
||||
]
|
||||
insertedKeys = []
|
||||
for value in valuesToInsert:
|
||||
inserted_keys = []
|
||||
for value in values_to_insert:
|
||||
doc = coll.insertOneAndGet(value)
|
||||
insertedKeys.append(doc.key)
|
||||
inserted_keys.append(doc.key)
|
||||
self.connection.commit()
|
||||
self.assertEqual(coll.find().count(), len(valuesToInsert))
|
||||
for key, value in zip(insertedKeys, valuesToInsert):
|
||||
self.assertEqual(coll.find().count(), len(values_to_insert))
|
||||
for key, value in zip(inserted_keys, values_to_insert):
|
||||
doc = coll.find().key(key).getOne()
|
||||
self.assertEqual(doc.getContent(), value)
|
||||
coll.drop()
|
||||
|
||||
def test_3402_SkipDocuments(self):
|
||||
def test_3402_skip_documents(self):
|
||||
"3402 - test skipping documents in a SODA collection"
|
||||
sodaDatabase = self.connection.getSodaDatabase()
|
||||
coll = sodaDatabase.createCollection("cxoSkipDocs")
|
||||
soda_db = self.connection.getSodaDatabase()
|
||||
coll = soda_db.createCollection("cxoSkipDocs")
|
||||
coll.find().remove()
|
||||
valuesToInsert = [
|
||||
{ "name" : "Anna", "age" : 62 },
|
||||
{ "name" : "Mark", "age" : 37 },
|
||||
{ "name" : "Martha", "age" : 43 },
|
||||
{ "name" : "Matthew", "age" : 28 }
|
||||
values_to_insert = [
|
||||
{"name": "Anna", "age": 62},
|
||||
{"name": "Mark", "age": 37},
|
||||
{"name": "Martha", "age": 43},
|
||||
{"name": "Matthew", "age": 28}
|
||||
]
|
||||
for value in valuesToInsert:
|
||||
for value in values_to_insert:
|
||||
coll.insertOne(value)
|
||||
self.connection.commit()
|
||||
self.__testSkip(coll, 0, valuesToInsert[3])
|
||||
self.__testSkip(coll, 1, valuesToInsert[2])
|
||||
self.__testSkip(coll, 3, valuesToInsert[0])
|
||||
self.__testSkip(coll, 4, None)
|
||||
self.__testSkip(coll, 125, None)
|
||||
self.__test_skip(coll, 0, values_to_insert[3])
|
||||
self.__test_skip(coll, 1, values_to_insert[2])
|
||||
self.__test_skip(coll, 3, values_to_insert[0])
|
||||
self.__test_skip(coll, 4, None)
|
||||
self.__test_skip(coll, 125, None)
|
||||
|
||||
def test_3403_ReplaceDocument(self):
|
||||
def test_3403_replace_document(self):
|
||||
"3403 - test replace documents in SODA collection"
|
||||
sodaDatabase = self.connection.getSodaDatabase()
|
||||
coll = sodaDatabase.createCollection("cxoReplaceDoc")
|
||||
soda_db = self.connection.getSodaDatabase()
|
||||
coll = soda_db.createCollection("cxoReplaceDoc")
|
||||
coll.find().remove()
|
||||
content = {'name': 'John', 'address': {'city': 'Sydney'}}
|
||||
doc = coll.insertOneAndGet(content)
|
||||
newContent = {'name': 'John', 'address': {'city':'Melbourne'}}
|
||||
coll.find().key(doc.key).replaceOne(newContent)
|
||||
new_content = {'name': 'John', 'address': {'city':'Melbourne'}}
|
||||
coll.find().key(doc.key).replaceOne(new_content)
|
||||
self.connection.commit()
|
||||
self.assertEqual(coll.find().key(doc.key).getOne().getContent(),
|
||||
newContent)
|
||||
new_content)
|
||||
coll.drop()
|
||||
|
||||
def test_3404_SearchDocumentsWithContent(self):
|
||||
def test_3404_search_documents_with_content(self):
|
||||
"3404 - test search documents with content using $like and $regex"
|
||||
sodaDatabase = self.connection.getSodaDatabase()
|
||||
coll = sodaDatabase.createCollection("cxoSearchDocContent")
|
||||
soda_db = self.connection.getSodaDatabase()
|
||||
coll = soda_db.createCollection("cxoSearchDocContent")
|
||||
coll.find().remove()
|
||||
data = [
|
||||
{'name': 'John', 'address': {'city': 'Bangalore'}},
|
||||
|
@ -102,7 +102,7 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
for value in data:
|
||||
coll.insertOne(value)
|
||||
self.connection.commit()
|
||||
filterSpecs = [
|
||||
filter_specs = [
|
||||
({'name': {'$like': 'And%'}}, 1),
|
||||
({'name': {'$like': 'J%n'}}, 3),
|
||||
({'name': {'$like': '%hn%'}}, 2),
|
||||
|
@ -118,15 +118,15 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
({'address.city': {'$regex': 'Hyderabad'}}, 1),
|
||||
({'name': {'$regex': 'Js.*n'}}, 0)
|
||||
]
|
||||
for filterSpec, expectedCount in filterSpecs:
|
||||
self.assertEqual(coll.find().filter(filterSpec).count(),
|
||||
expectedCount, filterSpec)
|
||||
for filter_spec, expected_count in filter_specs:
|
||||
self.assertEqual(coll.find().filter(filter_spec).count(),
|
||||
expected_count, filter_spec)
|
||||
coll.drop()
|
||||
|
||||
def test_3405_DocumentRemove(self):
|
||||
def test_3405_document_remove(self):
|
||||
"3405 - test removing documents"
|
||||
sodaDatabase = self.connection.getSodaDatabase()
|
||||
coll = sodaDatabase.createCollection("cxoRemoveDocs")
|
||||
soda_db = self.connection.getSodaDatabase()
|
||||
coll = soda_db.createCollection("cxoRemoveDocs")
|
||||
coll.find().remove()
|
||||
data = [
|
||||
{'name': 'John', 'address': {'city': 'Bangalore'}},
|
||||
|
@ -150,9 +150,9 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
|
||||
def test_3406_CreateAndDropIndex(self):
|
||||
"3406 - test create and drop Index"
|
||||
indexName = "cxoTestIndexes_ix_1"
|
||||
indexSpec = {
|
||||
'name': indexName,
|
||||
index_name = "cxoTestIndexes_ix_1"
|
||||
index_spec = {
|
||||
'name': index_name,
|
||||
'fields': [
|
||||
{
|
||||
'path': 'address.city',
|
||||
|
@ -161,22 +161,22 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
}
|
||||
]
|
||||
}
|
||||
sodaDatabase = self.connection.getSodaDatabase()
|
||||
coll = sodaDatabase.createCollection("cxoTestIndexes")
|
||||
soda_db = self.connection.getSodaDatabase()
|
||||
coll = soda_db.createCollection("TestIndexes")
|
||||
coll.find().remove()
|
||||
self.connection.commit()
|
||||
coll.dropIndex(indexName)
|
||||
coll.createIndex(indexSpec)
|
||||
self.assertRaises(cx_Oracle.DatabaseError, coll.createIndex, indexSpec)
|
||||
self.assertEqual(coll.dropIndex(indexName), True)
|
||||
self.assertEqual(coll.dropIndex(indexName), False)
|
||||
coll.dropIndex(index_name)
|
||||
coll.createIndex(index_spec)
|
||||
self.assertRaises(oracledb.DatabaseError, coll.createIndex, index_spec)
|
||||
self.assertEqual(coll.dropIndex(index_name), True)
|
||||
self.assertEqual(coll.dropIndex(index_name), False)
|
||||
coll.drop()
|
||||
|
||||
def test_3407_GetDocuments(self):
|
||||
def test_3407_get_documents(self):
|
||||
"3407 - test getting documents from Collection"
|
||||
self.connection.autocommit = True
|
||||
sodaDatabase = self.connection.getSodaDatabase()
|
||||
coll = sodaDatabase.createCollection("cxoTestGetDocs")
|
||||
soda_db = self.connection.getSodaDatabase()
|
||||
coll = soda_db.createCollection("cxoTestGetDocs")
|
||||
coll.find().remove()
|
||||
data = [
|
||||
{'name': 'John', 'address': {'city': 'Bangalore'}},
|
||||
|
@ -185,31 +185,31 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
{'name': 'Jibin', 'address': {'city': 'Secunderabad'}},
|
||||
{'name': 'Andrew', 'address': {'city': 'Hyderabad'}}
|
||||
]
|
||||
insertedKeys = list(sorted(coll.insertOneAndGet(v).key for v in data))
|
||||
fetchedKeys = list(sorted(d.key for d in coll.find().getDocuments()))
|
||||
self.assertEqual(fetchedKeys, insertedKeys)
|
||||
inserted_keys = list(sorted(coll.insertOneAndGet(v).key for v in data))
|
||||
fetched_keys = list(sorted(d.key for d in coll.find().getDocuments()))
|
||||
self.assertEqual(fetched_keys, inserted_keys)
|
||||
coll.drop()
|
||||
|
||||
def test_3408_Cursor(self):
|
||||
def test_3408_cursor(self):
|
||||
"3408 - test fetching documents from a cursor"
|
||||
self.connection.autocommit = True
|
||||
sodaDatabase = self.connection.getSodaDatabase()
|
||||
coll = sodaDatabase.createCollection("cxoFindViaCursor")
|
||||
soda_db = self.connection.getSodaDatabase()
|
||||
coll = soda_db.createCollection("cxoFindViaCursor")
|
||||
coll.find().remove()
|
||||
data = [
|
||||
{'name': 'John', 'address': {'city': 'Bangalore'}},
|
||||
{'name': 'Johnson', 'address': {'city': 'Banaras'}},
|
||||
{'name': 'Joseph', 'address': {'city': 'Mangalore'}},
|
||||
]
|
||||
insertedKeys = list(sorted(coll.insertOneAndGet(v).key for v in data))
|
||||
fetchedKeys = list(sorted(d.key for d in coll.find().getCursor()))
|
||||
self.assertEqual(fetchedKeys, insertedKeys)
|
||||
inserted_keys = list(sorted(coll.insertOneAndGet(v).key for v in data))
|
||||
fetched_keys = list(sorted(d.key for d in coll.find().getCursor()))
|
||||
self.assertEqual(fetched_keys, inserted_keys)
|
||||
coll.drop()
|
||||
|
||||
def test_3409_MultipleDocumentRemove(self):
|
||||
def test_3409_multiple_document_remove(self):
|
||||
"3409 - test removing multiple documents using multiple keys"
|
||||
sodaDatabase = self.connection.getSodaDatabase()
|
||||
coll = sodaDatabase.createCollection("cxoRemoveMultipleDocs")
|
||||
soda_db = self.connection.getSodaDatabase()
|
||||
coll = soda_db.createCollection("cxoRemoveMultipleDocs")
|
||||
coll.find().remove()
|
||||
data = [
|
||||
{'name': 'John', 'address': {'city': 'Bangalore'}},
|
||||
|
@ -221,40 +221,40 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
]
|
||||
docs = [coll.insertOneAndGet(v) for v in data]
|
||||
keys = [docs[i].key for i in (1, 3, 5)]
|
||||
numRemoved = coll.find().keys(keys).remove()
|
||||
self.assertEqual(numRemoved, len(keys))
|
||||
num_removed = coll.find().keys(keys).remove()
|
||||
self.assertEqual(num_removed, len(keys))
|
||||
self.assertEqual(coll.find().count(), len(data) - len(keys))
|
||||
self.connection.commit()
|
||||
coll.drop()
|
||||
|
||||
def test_3410_DocumentVersion(self):
|
||||
def test_3410_document_version(self):
|
||||
"3410 - test using version to get documents and remove them"
|
||||
sodaDatabase = self.connection.getSodaDatabase()
|
||||
coll = sodaDatabase.createCollection("cxoDocumentVersion")
|
||||
soda_db = self.connection.getSodaDatabase()
|
||||
coll = soda_db.createCollection("cxoDocumentVersion")
|
||||
coll.find().remove()
|
||||
content = {'name': 'John', 'address': {'city': 'Bangalore'}}
|
||||
insertedDoc = coll.insertOneAndGet(content)
|
||||
key = insertedDoc.key
|
||||
version = insertedDoc.version
|
||||
inserted_doc = coll.insertOneAndGet(content)
|
||||
key = inserted_doc.key
|
||||
version = inserted_doc.version
|
||||
doc = coll.find().key(key).version(version).getOne()
|
||||
self.assertEqual(doc.getContent(), content)
|
||||
newContent = {'name': 'James', 'address': {'city': 'Delhi'}}
|
||||
replacedDoc = coll.find().key(key).replaceOneAndGet(newContent)
|
||||
newVersion = replacedDoc.version
|
||||
new_content = {'name': 'James', 'address': {'city': 'Delhi'}}
|
||||
replacedDoc = coll.find().key(key).replaceOneAndGet(new_content)
|
||||
new_version = replacedDoc.version
|
||||
doc = coll.find().key(key).version(version).getOne()
|
||||
self.assertEqual(doc, None)
|
||||
doc = coll.find().key(key).version(newVersion).getOne()
|
||||
self.assertEqual(doc.getContent(), newContent)
|
||||
doc = coll.find().key(key).version(new_version).getOne()
|
||||
self.assertEqual(doc.getContent(), new_content)
|
||||
self.assertEqual(coll.find().key(key).version(version).remove(), 0)
|
||||
self.assertEqual(coll.find().key(key).version(newVersion).remove(), 1)
|
||||
self.assertEqual(coll.find().key(key).version(new_version).remove(), 1)
|
||||
self.assertEqual(coll.find().count(), 0)
|
||||
self.connection.commit()
|
||||
coll.drop()
|
||||
|
||||
def test_3411_GetCursor(self):
|
||||
def test_3411_get_cursor(self):
|
||||
"3411 - test keys with GetCursor"
|
||||
sodaDatabase = self.connection.getSodaDatabase()
|
||||
coll = sodaDatabase.createCollection("cxoKeysWithGetCursor")
|
||||
soda_db = self.connection.getSodaDatabase()
|
||||
coll = soda_db.createCollection("cxoKeysWithGetCursor")
|
||||
coll.find().remove()
|
||||
data = [
|
||||
{'name': 'John', 'address': {'city': 'Bangalore'}},
|
||||
|
@ -266,40 +266,39 @@ class TestCase(TestEnv.BaseTestCase):
|
|||
]
|
||||
docs = [coll.insertOneAndGet(v) for v in data]
|
||||
keys = [docs[i].key for i in (2, 4, 5)]
|
||||
fetchedKeys = [d.key for d in coll.find().keys(keys).getCursor()]
|
||||
self.assertEqual(list(sorted(fetchedKeys)), list(sorted(keys)))
|
||||
fetched_keys = [d.key for d in coll.find().keys(keys).getCursor()]
|
||||
self.assertEqual(list(sorted(fetched_keys)), list(sorted(keys)))
|
||||
self.connection.commit()
|
||||
coll.drop()
|
||||
|
||||
def test_3412_CreatedOn(self):
|
||||
def test_3412_created_on(self):
|
||||
"3412 - test createdOn attribute of Document"
|
||||
sodaDatabase = self.connection.getSodaDatabase()
|
||||
coll = sodaDatabase.createCollection("cxoCreatedOn")
|
||||
soda_db = self.connection.getSodaDatabase()
|
||||
coll = soda_db.createCollection("CreatedOn")
|
||||
coll.find().remove()
|
||||
data = {'name': 'John', 'address': {'city': 'Bangalore'}}
|
||||
doc = coll.insertOneAndGet(data)
|
||||
self.assertEqual(doc.createdOn, doc.lastModified)
|
||||
|
||||
@unittest.skipIf(TestEnv.GetClientVersion() < (20, 1),
|
||||
"unsupported client")
|
||||
def test_3413_SodaTruncate(self):
|
||||
@unittest.skipIf(base.get_client_version() < (20, 1), "unsupported client")
|
||||
def test_3413_soda_truncate(self):
|
||||
"3413 - test Soda truncate"
|
||||
sodaDatabase = self.connection.getSodaDatabase()
|
||||
coll = sodaDatabase.createCollection("cxoTruncateDocs")
|
||||
soda_db = self.connection.getSodaDatabase()
|
||||
coll = soda_db.createCollection("cxoTruncateDocs")
|
||||
coll.find().remove()
|
||||
valuesToInsert = [
|
||||
{ "name" : "George", "age" : 47 },
|
||||
{ "name" : "Susan", "age" : 39 },
|
||||
{ "name" : "John", "age" : 50 },
|
||||
{ "name" : "Jill", "age" : 54 }
|
||||
values_to_insert = [
|
||||
{"name": "George", "age": 47},
|
||||
{"name": "Susan", "age": 39},
|
||||
{"name": "John", "age": 50},
|
||||
{"name": "Jill", "age": 54}
|
||||
]
|
||||
for value in valuesToInsert:
|
||||
for value in values_to_insert:
|
||||
coll.insertOne(value)
|
||||
self.connection.commit()
|
||||
self.assertEqual(coll.find().count(), len(valuesToInsert))
|
||||
self.assertEqual(coll.find().count(), len(values_to_insert))
|
||||
coll.truncate()
|
||||
self.assertEqual(coll.find().count(), 0)
|
||||
coll.drop()
|
||||
|
||||
if __name__ == "__main__":
|
||||
TestEnv.RunTestCases()
|
||||
base.run_test_cases()
|
||||
|
|
Loading…
Reference in New Issue