'+mxodbc', '+zxjdbc', 'mysql+oursql',
'informix+informixdb')
def test_raw_qmark(self):
- for conn in testing.db, testing.db.connect():
+ def go(conn):
conn.execute('insert into users (user_id, user_name) '
'values (?, ?)', (1, 'jack'))
conn.execute('insert into users (user_id, user_name) '
]
conn.execute('delete from users')
+ go(testing.db)
+ conn = testing.db.connect()
+ try:
+ go(conn)
+ finally:
+ conn.close()
+
# some psycopg2 versions bomb this.
@testing.fails_on_everything_except('mysql+mysqldb', 'mysql+pymysql',
'mysql+mysqlconnector', 'postgresql')
@testing.fails_on('postgresql+zxjdbc', 'sprintf not supported')
def test_raw_sprintf(self):
- for conn in testing.db, testing.db.connect():
+ def go(conn):
conn.execute('insert into users (user_id, user_name) '
'values (%s, %s)', [1, 'jack'])
conn.execute('insert into users (user_id, user_name) '
assert res.fetchall() == [(1, 'jack'), (2, 'ed'), (3,
'horse'), (4, 'sally'), (5, None)]
conn.execute('delete from users')
+ go(testing.db)
+ conn = testing.db.connect()
+ try:
+ go(conn)
+ finally:
+ conn.close()
# pyformat is supported for mysql, but skipping because a few driver
# versions have a bug that bombs out on this test. (1.2.2b3,
'postgresql+pypostgresql', 'mysql+mysqlconnector',
'mysql+pymysql')
def test_raw_python(self):
- for conn in testing.db, testing.db.connect():
+ def go(conn):
conn.execute('insert into users (user_id, user_name) '
'values (%(id)s, %(name)s)', {'id': 1, 'name'
: 'jack'})
assert res.fetchall() == [(1, 'jack'), (2, 'ed'), (3,
'horse'), (4, 'sally')]
conn.execute('delete from users')
+ go(testing.db)
+ conn = testing.db.connect()
+ try:
+ go(conn)
+ finally:
+ conn.close()
@testing.fails_on_everything_except('sqlite', 'oracle+cx_oracle', 'informix+informixdb')
def test_raw_named(self):
- for conn in testing.db, testing.db.connect():
+ def go(conn):
conn.execute('insert into users (user_id, user_name) '
'values (:id, :name)', {'id': 1, 'name': 'jack'
})
assert res.fetchall() == [(1, 'jack'), (2, 'ed'), (3,
'horse'), (4, 'sally')]
conn.execute('delete from users')
+ go(testing.db)
+ conn= testing.db.connect()
+ try:
+ go(conn)
+ finally:
+ conn.close()
def test_exception_wrapping_dbapi(self):
- for conn in testing.db, testing.db.connect():
+ def go(conn):
assert_raises_message(
tsa.exc.DBAPIError,
r"not_a_valid_statement",
conn.execute, 'not_a_valid_statement'
)
+ go(testing.db)
+ conn = testing.db.connect()
+ try:
+ go(conn)
+ finally:
+ conn.close()
def test_exception_wrapping_non_dbapi_statement(self):
class MyType(TypeDecorator):
def process_bind_param(self, value, dialect):
raise Exception("nope")
- for conn in testing.db, testing.db.connect():
+ def _go(conn):
assert_raises_message(
tsa.exc.StatementError,
"nope 'SELECT 1 ",
column('foo') == literal('bar', MyType())
)
)
+ _go(testing.db)
+ conn = testing.db.connect()
+ try:
+ _go(conn)
+ finally:
+ conn.close()
def test_empty_insert(self):
"""test that execute() interprets [] as a list with no params"""