Skip to content

Commit 9c9b92a

Browse files
Added new tests.
1 parent b59fe3b commit 9c9b92a

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

test/test_1200_cursor.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,5 +848,90 @@ def test_1269_bind_names_with_multi_line_comments(self):
848848
""")
849849
self.assertEqual(self.cursor.bindnames(), ["TABLE_NAME", "VALUE"])
850850

851+
def test_1270_execute_bind_names_with_incorrect_bind(self):
852+
"1270 - test executing a statement with an incorrect named bind"
853+
statement = "select * from TestStrings where IntCol = :value"
854+
self.assertRaises(oracledb.DatabaseError, self.cursor.execute,
855+
statement, value2=3)
856+
857+
def test_1271_execute_with_named_binds(self):
858+
"1271 - test executing a statement with named binds"
859+
statement = "select * from TestNumbers where IntCol = :value1 " + \
860+
"and LongIntCol = :value2"
861+
result = self.cursor.execute(statement, value1=1, value2=38)
862+
self.assertEqual(len(result.fetchall()), 1)
863+
864+
def test_1272_execute_bind_position_with_incorrect_bind(self):
865+
"1272 - test executing a statement with an incorrect positional bind"
866+
statement = "select * from TestNumbers where IntCol = :value " + \
867+
"and LongIntCol = :value2"
868+
self.assertRaises(oracledb.DatabaseError, self.cursor.execute,
869+
statement, [3])
870+
871+
def test_1273_execute_with_positional_binds(self):
872+
"1273 - test executing a statement with positional binds"
873+
statement = "select * from TestNumbers where IntCol = :value " + \
874+
"and LongIntCol = :value2"
875+
result = self.cursor.execute(statement, [1,38])
876+
self.assertEqual(len(result.fetchall()), 1)
877+
878+
def test_1274_execute_with_rebinding_bind_name(self):
879+
"1274 - test executing a statement after rebinding a named bind"
880+
statement = "begin :value := :value2 + 5; end;"
881+
simple_var = self.cursor.var(oracledb.NUMBER)
882+
simple_var2 = self.cursor.var(oracledb.NUMBER)
883+
simple_var2.setvalue(0, 5)
884+
result = self.cursor.execute(statement, value=simple_var,
885+
value2=simple_var2)
886+
self.assertEqual(result, None)
887+
self.assertEqual(simple_var.getvalue(), 10)
888+
889+
simple_var = self.cursor.var(oracledb.NATIVE_FLOAT)
890+
simple_var2 = self.cursor.var(oracledb.NATIVE_FLOAT)
891+
simple_var2.setvalue(0, 10)
892+
result = self.cursor.execute(statement, value=simple_var,
893+
value2=simple_var2)
894+
self.assertEqual(result, None)
895+
self.assertEqual(simple_var.getvalue(), 15)
896+
897+
def test_1275_bind_names_with_strings(self):
898+
"1275 - test bindnames() with strings in the statement"
899+
statement = """
900+
begin
901+
:value := to_date('20021231 12:31:00',
902+
'YYYYMMDD HH24:MI:SS');
903+
end;"""
904+
self.cursor.prepare(statement)
905+
self.assertEqual(self.cursor.bindnames(), ["VALUE"])
906+
907+
def test_1276_bind_by_name_with_duplicates(self):
908+
"1276 - test executing a PL/SQL statement with duplicate binds"
909+
statement = "begin :value := :value + 5; end;"
910+
simple_var = self.cursor.var(oracledb.NUMBER)
911+
simple_var.setvalue(0, 5)
912+
result = self.cursor.execute(statement, value=simple_var)
913+
self.assertEqual(result, None)
914+
self.assertEqual(simple_var.getvalue(), 10)
915+
916+
def test_1277_positional_bind_with_duplicates(self):
917+
"1277 - test executing a PL/SQL statement with duplicate binds"
918+
statement = "begin :value := :value + 5; end;"
919+
simple_var = self.cursor.var(oracledb.NUMBER)
920+
simple_var.setvalue(0, 5)
921+
self.cursor.execute(statement, [simple_var])
922+
self.assertEqual(simple_var.getvalue(), 10)
923+
924+
def test_1278_execute_with_incorrect_bind_values(self):
925+
"1278 - test executing a statement with an incorrect number of binds"
926+
statement = "begin :value := :value2 + 5; end;"
927+
var = self.cursor.var(oracledb.NUMBER)
928+
var.setvalue(0, 5)
929+
self.assertRaises(oracledb.DatabaseError, self.cursor.execute,
930+
statement)
931+
self.assertRaises(oracledb.DatabaseError, self.cursor.execute,
932+
statement, value=var)
933+
self.assertRaises(oracledb.DatabaseError, self.cursor.execute,
934+
statement, value=var, value2=var, value3=var)
935+
851936
if __name__ == "__main__":
852937
base.run_test_cases()

0 commit comments

Comments
 (0)