Skip to content
This repository has been archived by the owner on Apr 5, 2022. It is now read-only.

Commit

Permalink
[SESPRINGPYTHONPY-159] Added check to execute method to trap invalid …
Browse files Browse the repository at this point in the history
…variable bindings.
  • Loading branch information
Greg Turnquist committed Feb 15, 2011
1 parent 78c678f commit 07e3c82
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/springpython/database/core.py
Expand Up @@ -54,6 +54,10 @@ def __setattr__(self, name, value):

def execute(self, sql_statement, args = None):
"""Issue a single SQL execute, typically a DDL statement."""

if args and type(args) not in self.connection_factory.acceptable_types:
raise InvalidArgumentType(type(args), self.connection_factory.acceptable_types)

sql_statement = self.connection_factory.convert_sql_binding(sql_statement)

cursor = self.__db.cursor()
Expand Down
32 changes: 32 additions & 0 deletions test/springpythontest/databaseCoreTestCases.py
Expand Up @@ -123,6 +123,38 @@ def testQueryingOracleWithValidlyFormattedArguments(self):

del(sys.modules["cx_Oracle"])

def testInsertingIntoOracleWithInvalidlyFormattedArguments(self):
cursor = self.mock()
conn = self.mock()

sys.modules["cx_Oracle"] = self.mock()
sys.modules["cx_Oracle"].expects(once()).method("connect").will(return_value(conn))

connection_factory = factory.cxoraConnectionFactory(username="foo", password="bar", hostname="localhost", db="mock")
dt = DatabaseTemplate(connection_factory)

self.assertRaises(InvalidArgumentType, dt.execute,
"INSERT INTO T_UNIT (F_UNIT_PK, F_UNIT_ID, F_NAME) VALUES (?, ?, ?)",
(1,1,1))

del(sys.modules["cx_Oracle"])

def testInsertingIntoOracleWithInvalidlyFormattedArgumentsWithUpdateApi(self):
cursor = self.mock()
conn = self.mock()

sys.modules["cx_Oracle"] = self.mock()
sys.modules["cx_Oracle"].expects(once()).method("connect").will(return_value(conn))

connection_factory = factory.cxoraConnectionFactory(username="foo", password="bar", hostname="localhost", db="mock")
dt = DatabaseTemplate(connection_factory)

self.assertRaises(InvalidArgumentType, dt.update,
"INSERT INTO T_UNIT (F_UNIT_PK, F_UNIT_ID, F_NAME) VALUES (?, ?, ?)",
(1,1,1))

del(sys.modules["cx_Oracle"])

class DatabaseTemplateMockTestCase(MockTestCase):
"""Testing the DatabaseTemplate utilizes stubbing and mocking, in order to isolate from different
vendor implementations. This reduces the overhead in making changes to core functionality."""
Expand Down

0 comments on commit 07e3c82

Please sign in to comment.