本文整理汇总了Python中DBUtils.SteadyDB.connect类的典型用法代码示例。如果您正苦于以下问题:Python connect类的具体用法?Python connect怎么用?Python connect使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了connect类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test05_ConnectionCreatorFunction
def test05_ConnectionCreatorFunction(self):
db1 = SteadyDBconnect(
dbapi,
0,
None,
None,
None,
True,
'SteadyDBTestDB',
user='SteadyDBTestUser')
db2 = SteadyDBconnect(
connect,
0,
None,
None,
None,
True,
'SteadyDBTestDB',
user='SteadyDBTestUser')
self.assertEqual(db1.dbapi(), db2.dbapi())
self.assertEqual(db1.threadsafety(), db2.threadsafety())
self.assertEqual(db1._creator, db2._creator)
self.assertEqual(db1._args, db2._args)
self.assertEqual(db1._kwargs, db2._kwargs)
db2.close()
db1.close()
示例2: test16_ResetTransaction
def test16_ResetTransaction(self):
db = SteadyDBconnect(dbapi, database='ok')
db.begin()
self.assert_(not db._con.session)
db.close()
self.assert_(not db._con.session)
db = SteadyDBconnect(dbapi, database='ok', closeable=False)
db.begin()
self.assert_(not db._con.session)
db.close()
self.assertEqual(db._con.session, ['rollback'])
示例3: test13_WithBeginExtension
def test13_WithBeginExtension(self):
db = SteadyDBconnect(dbapi, database='ok')
db._con._begin_called_with = None
def begin(a, b=None, c=7):
db._con._begin_called_with = (a, b, c)
db._con.begin = begin
db.begin(42, 6)
cursor = db.cursor()
cursor.execute('select test13')
self.assertEqual(cursor.fetchone(), 'test13')
self.assertEqual(db._con._begin_called_with, (42, 6, 7))
示例4: test03_Close
def test03_Close(self):
for closeable in (False, True):
db = SteadyDBconnect(dbapi, closeable=closeable)
self.assert_(db._con.valid)
db.close()
self.assert_(closeable ^ db._con.valid)
db.close()
self.assert_(closeable ^ db._con.valid)
db._close()
self.assert_(not db._con.valid)
db._close()
self.assert_(not db._con.valid)
示例5: test06_ConnectionMaxUsage
def test06_ConnectionMaxUsage(self):
db = SteadyDBconnect(dbapi, 10)
cursor = db.cursor()
for i in range(100):
cursor.execute('select test%d' % i)
r = cursor.fetchone()
self.assertEqual(r, 'test%d' % i)
self.assert_(db._con.valid)
j = i % 10 + 1
self.assertEqual(db._usage, j)
self.assertEqual(db._con.num_uses, j)
self.assertEqual(db._con.num_queries, j)
self.assertEqual(db._con.open_cursors, 1)
for i in range(100):
cursor.callproc('test')
self.assert_(db._con.valid)
j = i % 10 + 1
self.assertEqual(db._usage, j)
self.assertEqual(db._con.num_uses, j)
self.assertEqual(db._con.num_queries, 0)
for i in range(10):
if i == 7:
db._con.valid = cursor._cursor.valid = False
cursor.execute('select test%d' % i)
r = cursor.fetchone()
self.assertEqual(r, 'test%d' % i)
j = i % 7 + 1
self.assertEqual(db._usage, j)
self.assertEqual(db._con.num_uses, j)
self.assertEqual(db._con.num_queries, j)
for i in range(10):
if i == 5:
db._con.valid = cursor._cursor.valid = False
cursor.callproc('test')
j = (i + (i < 5 and 3 or -5)) % 10 + 1
self.assertEqual(db._usage, j)
self.assertEqual(db._con.num_uses, j)
j = i < 5 and 3 or 0
self.assertEqual(db._con.num_queries, j)
db.close()
cursor.execute('select test1')
self.assertEqual(cursor.fetchone(), 'test1')
self.assertEqual(db._usage, 1)
self.assertEqual(db._con.num_uses, 1)
self.assertEqual(db._con.num_queries, 1)
示例6: test09_ConnectionFailureError
def test09_ConnectionFailureError(self):
db = SteadyDBconnect(dbapi)
cursor = db.cursor()
db.close()
cursor.execute('select test')
cursor = db.cursor()
db.close()
self.assertRaises(ProgrammingError, cursor.execute, 'error')
示例7: test14_CancelTransaction
def test14_CancelTransaction(self):
db = SteadyDBconnect(dbapi, database='ok')
cursor = db.cursor()
db.begin()
cursor.execute('select test14')
self.assertEqual(cursor.fetchone(), 'test14')
db.cancel()
cursor.execute('select test14')
self.assertEqual(cursor.fetchone(), 'test14')
示例8: test10_ConnectionSetSizes
def test10_ConnectionSetSizes(self):
db = SteadyDBconnect(dbapi)
cursor = db.cursor()
cursor.execute('get sizes')
result = cursor.fetchone()
self.assertEqual(result, ([], {}))
cursor.setinputsizes([7, 42, 6])
cursor.setoutputsize(9)
cursor.setoutputsize(15, 3)
cursor.setoutputsize(42, 7)
cursor.execute('get sizes')
result = cursor.fetchone()
self.assertEqual(result, ([7, 42, 6], {None: 9, 3: 15, 7: 42}))
cursor.execute('get sizes')
result = cursor.fetchone()
self.assertEqual(result, ([], {}))
cursor.setinputsizes([6, 42, 7])
cursor.setoutputsize(7)
cursor.setoutputsize(15, 3)
cursor.setoutputsize(42, 9)
db.close()
cursor.execute('get sizes')
result = cursor.fetchone()
self.assertEqual(result, ([6, 42, 7], {None: 7, 3: 15, 9: 42}))
示例9: test15_WithCancelExtension
def test15_WithCancelExtension(self):
db = SteadyDBconnect(dbapi, database='ok')
db._con._cancel_called = None
def cancel():
db._con._cancel_called = 'yes'
db._con.cancel = cancel
db.begin()
cursor = db.cursor()
cursor.execute('select test15')
self.assertEqual(cursor.fetchone(), 'test15')
db.cancel()
self.assertEqual(db._con._cancel_called, 'yes')
示例10: test02_BrokenConnection
def test02_BrokenConnection(self):
self.assertRaises(TypeError, SteadyDBConnection, None)
self.assertRaises(TypeError, SteadyDBCursor, None)
db = SteadyDBconnect(dbapi, database='ok')
for i in range(3):
db.close()
del db
self.assertRaises(OperationalError, SteadyDBconnect,
dbapi, database='error')
db = SteadyDBconnect(dbapi, database='ok')
cursor = db.cursor()
for i in range(3):
cursor.close()
cursor = db.cursor('ok')
for i in range(3):
cursor.close()
self.assertRaises(OperationalError, db.cursor, 'error')
示例11: test12_BeginTransaction
def test12_BeginTransaction(self):
db = SteadyDBconnect(dbapi, database='ok')
cursor = db.cursor()
cursor.close()
cursor.execute('select test12')
self.assertEqual(cursor.fetchone(), 'test12')
db.begin()
cursor = db.cursor()
cursor.close()
self.assertRaises(InternalError, cursor.execute, 'select test12')
cursor.execute('select test12')
self.assertEqual(cursor.fetchone(), 'test12')
db.close()
db.begin()
self.assertRaises(InternalError, cursor.execute, 'select test12')
cursor.execute('select test12')
self.assertEqual(cursor.fetchone(), 'test12')
db.begin()
self.assertRaises(ProgrammingError, cursor.execute, 'error')
cursor.close()
cursor.execute('select test12')
self.assertEqual(cursor.fetchone(), 'test12')
示例12: test11_ConnectionPingCheck
def test11_ConnectionPingCheck(self):
Connection.has_ping = False
Connection.num_pings = 0
db = SteadyDBconnect(dbapi)
db.cursor().execute('select test')
self.assertEqual(Connection.num_pings, 0)
db.close()
db.cursor().execute('select test')
self.assertEqual(Connection.num_pings, 0)
self.assert_(db._ping_check() is None)
self.assertEqual(Connection.num_pings, 1)
db = SteadyDBconnect(dbapi, ping=7)
db.cursor().execute('select test')
self.assertEqual(Connection.num_pings, 2)
db.close()
db.cursor().execute('select test')
self.assertEqual(Connection.num_pings, 2)
self.assert_(db._ping_check() is None)
self.assertEqual(Connection.num_pings, 2)
Connection.has_ping = True
db = SteadyDBconnect(dbapi)
db.cursor().execute('select test')
self.assertEqual(Connection.num_pings, 2)
db.close()
db.cursor().execute('select test')
self.assertEqual(Connection.num_pings, 2)
self.assert_(db._ping_check())
self.assertEqual(Connection.num_pings, 3)
db = SteadyDBconnect(dbapi, ping=1)
db.cursor().execute('select test')
self.assertEqual(Connection.num_pings, 3)
db.close()
db.cursor().execute('select test')
self.assertEqual(Connection.num_pings, 3)
self.assert_(db._ping_check())
self.assertEqual(Connection.num_pings, 4)
db.close()
self.assert_(db._ping_check())
self.assertEqual(Connection.num_pings, 5)
db = SteadyDBconnect(dbapi, ping=7)
db.cursor().execute('select test')
self.assertEqual(Connection.num_pings, 7)
db.close()
db.cursor().execute('select test')
self.assertEqual(Connection.num_pings, 9)
db = SteadyDBconnect(dbapi, ping=3)
self.assertEqual(Connection.num_pings, 9)
db.cursor()
self.assertEqual(Connection.num_pings, 10)
db.close()
cursor = db.cursor()
self.assertEqual(Connection.num_pings, 11)
cursor.execute('select test')
self.assertEqual(Connection.num_pings, 11)
db = SteadyDBconnect(dbapi, ping=5)
self.assertEqual(Connection.num_pings, 11)
db.cursor()
self.assertEqual(Connection.num_pings, 11)
db.close()
cursor = db.cursor()
self.assertEqual(Connection.num_pings, 11)
cursor.execute('select test')
self.assertEqual(Connection.num_pings, 12)
db.close()
cursor = db.cursor()
self.assertEqual(Connection.num_pings, 12)
cursor.execute('select test')
self.assertEqual(Connection.num_pings, 13)
db = SteadyDBconnect(dbapi, ping=7)
self.assertEqual(Connection.num_pings, 13)
db.cursor()
self.assertEqual(Connection.num_pings, 14)
db.close()
cursor = db.cursor()
self.assertEqual(Connection.num_pings, 15)
cursor.execute('select test')
self.assertEqual(Connection.num_pings, 16)
db.close()
cursor = db.cursor()
self.assertEqual(Connection.num_pings, 17)
cursor.execute('select test')
self.assertEqual(Connection.num_pings, 18)
db.close()
cursor.execute('select test')
self.assertEqual(Connection.num_pings, 20)
Connection.has_ping = False
Connection.num_pings = 0
示例13: test08_ConnectionFailures
def test08_ConnectionFailures(self):
db = SteadyDBconnect(dbapi)
db.close()
db.cursor()
db = SteadyDBconnect(dbapi, failures=InternalError)
db.close()
db.cursor()
db = SteadyDBconnect(dbapi, failures=OperationalError)
db.close()
self.assertRaises(InternalError, db.cursor)
db = SteadyDBconnect(dbapi,
failures=(OperationalError, InternalError))
db.close()
db.cursor()
示例14: test07_ConnectionSetSession
def test07_ConnectionSetSession(self):
db = SteadyDBconnect(dbapi, 3, ('set time zone', 'set datestyle'))
self.assert_(hasattr(db, '_usage'))
self.assertEqual(db._usage, 0)
self.assert_(hasattr(db._con, 'open_cursors'))
self.assertEqual(db._con.open_cursors, 0)
self.assert_(hasattr(db._con, 'num_uses'))
self.assertEqual(db._con.num_uses, 2)
self.assert_(hasattr(db._con, 'num_queries'))
self.assertEqual(db._con.num_queries, 0)
self.assert_(hasattr(db._con, 'session'))
self.assertEqual(tuple(db._con.session), ('time zone', 'datestyle'))
for i in range(11):
db.cursor().execute('select test')
self.assertEqual(db._con.open_cursors, 0)
self.assertEqual(db._usage, 2)
self.assertEqual(db._con.num_uses, 4)
self.assertEqual(db._con.num_queries, 2)
self.assertEqual(db._con.session, ['time zone', 'datestyle'])
db.cursor().execute('set test')
self.assertEqual(db._con.open_cursors, 0)
self.assertEqual(db._usage, 3)
self.assertEqual(db._con.num_uses, 5)
self.assertEqual(db._con.num_queries, 2)
self.assertEqual(db._con.session, ['time zone', 'datestyle', 'test'])
db.cursor().execute('select test')
self.assertEqual(db._con.open_cursors, 0)
self.assertEqual(db._usage, 1)
self.assertEqual(db._con.num_uses, 3)
self.assertEqual(db._con.num_queries, 1)
self.assertEqual(db._con.session, ['time zone', 'datestyle'])
db.cursor().execute('set test')
self.assertEqual(db._con.open_cursors, 0)
self.assertEqual(db._usage, 2)
self.assertEqual(db._con.num_uses, 4)
self.assertEqual(db._con.num_queries, 1)
self.assertEqual(db._con.session, ['time zone', 'datestyle', 'test'])
db.cursor().execute('select test')
self.assertEqual(db._con.open_cursors, 0)
self.assertEqual(db._usage, 3)
self.assertEqual(db._con.num_uses, 5)
self.assertEqual(db._con.num_queries, 2)
self.assertEqual(db._con.session, ['time zone', 'datestyle', 'test'])
db.close()
db.cursor().execute('set test')
self.assertEqual(db._con.open_cursors, 0)
self.assertEqual(db._usage, 1)
self.assertEqual(db._con.num_uses, 3)
self.assertEqual(db._con.num_queries, 0)
self.assertEqual(db._con.session, ['time zone', 'datestyle', 'test'])
db.close()
db.cursor().execute('select test')
self.assertEqual(db._con.open_cursors, 0)
self.assertEqual(db._usage, 1)
self.assertEqual(db._con.num_uses, 3)
self.assertEqual(db._con.num_queries, 1)
self.assertEqual(db._con.session, ['time zone', 'datestyle'])
示例15: test04_Connection
def test04_Connection(self):
db = SteadyDBconnect(dbapi, 0, None, None, None, True,
'SteadyDBTestDB', user='SteadyDBTestUser')
self.assert_(isinstance(db, SteadyDBConnection))
self.assert_(hasattr(db, '_con'))
self.assert_(hasattr(db, '_usage'))
self.assertEqual(db._usage, 0)
self.assert_(hasattr(db._con, 'valid'))
self.assert_(db._con.valid)
self.assert_(hasattr(db._con, 'cursor'))
self.assert_(hasattr(db._con, 'close'))
self.assert_(hasattr(db._con, 'open_cursors'))
self.assert_(hasattr(db._con, 'num_uses'))
self.assert_(hasattr(db._con, 'num_queries'))
self.assert_(hasattr(db._con, 'session'))
self.assert_(hasattr(db._con, 'database'))
self.assertEqual(db._con.database, 'SteadyDBTestDB')
self.assert_(hasattr(db._con, 'user'))
self.assertEqual(db._con.user, 'SteadyDBTestUser')
self.assert_(hasattr(db, 'cursor'))
self.assert_(hasattr(db, 'close'))
self.assertEqual(db._con.open_cursors, 0)
for i in range(3):
cursor = db.cursor()
self.assertEqual(db._con.open_cursors, 1)
cursor.close()
self.assertEqual(db._con.open_cursors, 0)
cursor = []
for i in range(3):
cursor.append(db.cursor())
self.assertEqual(db._con.open_cursors, i + 1)
del cursor
self.assertEqual(db._con.open_cursors, 0)
cursor = db.cursor()
self.assert_(hasattr(cursor, 'execute'))
self.assert_(hasattr(cursor, 'fetchone'))
self.assert_(hasattr(cursor, 'callproc'))
self.assert_(hasattr(cursor, 'close'))
self.assert_(hasattr(cursor, 'valid'))
self.assert_(cursor.valid)
self.assertEqual(db._con.open_cursors, 1)
for i in range(3):
self.assertEqual(db._usage, i)
self.assertEqual(db._con.num_uses, i)
self.assertEqual(db._con.num_queries, i)
cursor.execute('select test%d' % i)
self.assertEqual(cursor.fetchone(), 'test%d' % i)
self.assert_(cursor.valid)
self.assertEqual(db._con.open_cursors, 1)
for i in range(4):
cursor.callproc('test')
cursor.close()
self.assert_(not cursor.valid)
self.assertEqual(db._con.open_cursors, 0)
self.assertEqual(db._usage, 7)
self.assertEqual(db._con.num_uses, 7)
self.assertEqual(db._con.num_queries, 3)
cursor.close()
cursor.execute('select test8')
self.assert_(cursor.valid)
self.assertEqual(db._con.open_cursors, 1)
self.assertEqual(cursor.fetchone(), 'test8')
self.assertEqual(db._usage, 8)
self.assertEqual(db._con.num_uses, 8)
self.assertEqual(db._con.num_queries, 4)
self.assert_(db._con.valid)
db.close()
self.assert_(not db._con.valid)
self.assertEqual(db._con.open_cursors, 0)
self.assertEqual(db._usage, 8)
self.assertEqual(db._con.num_uses, 0)
self.assertEqual(db._con.num_queries, 0)
self.assertRaises(InternalError, db._con.close)
db.close()
self.assertRaises(InternalError, db._con.cursor)
cursor = db.cursor()
self.assert_(db._con.valid)
cursor.execute('select test11')
self.assertEqual(cursor.fetchone(), 'test11')
cursor.execute('select test12')
self.assertEqual(cursor.fetchone(), 'test12')
cursor.callproc('test')
self.assertEqual(db._usage, 3)
self.assertEqual(db._con.num_uses, 3)
self.assertEqual(db._con.num_queries, 2)
cursor2 = db.cursor()
self.assertEqual(db._con.open_cursors, 2)
cursor2.execute('select test13')
self.assertEqual(cursor2.fetchone(), 'test13')
self.assertEqual(db._con.num_queries, 3)
db.close()
self.assertEqual(db._con.open_cursors, 0)
self.assertEqual(db._con.num_queries, 0)
cursor = db.cursor()
self.assert_(cursor.valid)
cursor.callproc('test')
cursor._cursor.valid = False
self.assert_(not cursor.valid)
self.assertRaises(InternalError, cursor._cursor.callproc, 'test')
cursor.callproc('test')
#.........这里部分代码省略.........