Skip to content

Commit 34a30e4

Browse files
author
Greg Turnquist
committed
Merge branch 'SESPRINGPYTHONPY-159' into 1.1.x
2 parents 89c468b + 07e3c82 commit 34a30e4

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

src/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
setup.py
2+
springpython.egg-info

src/springpython/database/core.py

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ def __setattr__(self, name, value):
5454

5555
def execute(self, sql_statement, args = None):
5656
"""Issue a single SQL execute, typically a DDL statement."""
57+
58+
if args and type(args) not in self.connection_factory.acceptable_types:
59+
raise InvalidArgumentType(type(args), self.connection_factory.acceptable_types)
60+
5761
sql_statement = self.connection_factory.convert_sql_binding(sql_statement)
5862

5963
cursor = self.__db.cursor()

test/springpythontest/databaseCoreTestCases.py

+32
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,38 @@ def testQueryingOracleWithValidlyFormattedArguments(self):
123123

124124
del(sys.modules["cx_Oracle"])
125125

126+
def testInsertingIntoOracleWithInvalidlyFormattedArguments(self):
127+
cursor = self.mock()
128+
conn = self.mock()
129+
130+
sys.modules["cx_Oracle"] = self.mock()
131+
sys.modules["cx_Oracle"].expects(once()).method("connect").will(return_value(conn))
132+
133+
connection_factory = factory.cxoraConnectionFactory(username="foo", password="bar", hostname="localhost", db="mock")
134+
dt = DatabaseTemplate(connection_factory)
135+
136+
self.assertRaises(InvalidArgumentType, dt.execute,
137+
"INSERT INTO T_UNIT (F_UNIT_PK, F_UNIT_ID, F_NAME) VALUES (?, ?, ?)",
138+
(1,1,1))
139+
140+
del(sys.modules["cx_Oracle"])
141+
142+
def testInsertingIntoOracleWithInvalidlyFormattedArgumentsWithUpdateApi(self):
143+
cursor = self.mock()
144+
conn = self.mock()
145+
146+
sys.modules["cx_Oracle"] = self.mock()
147+
sys.modules["cx_Oracle"].expects(once()).method("connect").will(return_value(conn))
148+
149+
connection_factory = factory.cxoraConnectionFactory(username="foo", password="bar", hostname="localhost", db="mock")
150+
dt = DatabaseTemplate(connection_factory)
151+
152+
self.assertRaises(InvalidArgumentType, dt.update,
153+
"INSERT INTO T_UNIT (F_UNIT_PK, F_UNIT_ID, F_NAME) VALUES (?, ?, ?)",
154+
(1,1,1))
155+
156+
del(sys.modules["cx_Oracle"])
157+
126158
class DatabaseTemplateMockTestCase(MockTestCase):
127159
"""Testing the DatabaseTemplate utilizes stubbing and mocking, in order to isolate from different
128160
vendor implementations. This reduces the overhead in making changes to core functionality."""

0 commit comments

Comments
 (0)