当前位置: 首页>>代码示例>>Python>>正文


Python connect.cursor方法代码示例

本文整理汇总了Python中DBUtils.SteadyDB.connect.cursor方法的典型用法代码示例。如果您正苦于以下问题:Python connect.cursor方法的具体用法?Python connect.cursor怎么用?Python connect.cursor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DBUtils.SteadyDB.connect的用法示例。


在下文中一共展示了connect.cursor方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test09_ConnectionFailureError

# 需要导入模块: from DBUtils.SteadyDB import connect [as 别名]
# 或者: from DBUtils.SteadyDB.connect import cursor [as 别名]
 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')
开发者ID:SongJLG,项目名称:johan-doc,代码行数:10,代码来源:TestSteadyDB.py

示例2: test02_BrokenConnection

# 需要导入模块: from DBUtils.SteadyDB import connect [as 别名]
# 或者: from DBUtils.SteadyDB.connect import cursor [as 别名]
 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')
开发者ID:SongJLG,项目名称:johan-doc,代码行数:19,代码来源:TestSteadyDB.py

示例3: test14_CancelTransaction

# 需要导入模块: from DBUtils.SteadyDB import connect [as 别名]
# 或者: from DBUtils.SteadyDB.connect import cursor [as 别名]
 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')
开发者ID:SongJLG,项目名称:johan-doc,代码行数:11,代码来源:TestSteadyDB.py

示例4: test13_WithBeginExtension

# 需要导入模块: from DBUtils.SteadyDB import connect [as 别名]
# 或者: from DBUtils.SteadyDB.connect import cursor [as 别名]
 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))
开发者ID:SongJLG,项目名称:johan-doc,代码行数:13,代码来源:TestSteadyDB.py

示例5: test15_WithCancelExtension

# 需要导入模块: from DBUtils.SteadyDB import connect [as 别名]
# 或者: from DBUtils.SteadyDB.connect import cursor [as 别名]
 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')
开发者ID:SongJLG,项目名称:johan-doc,代码行数:14,代码来源:TestSteadyDB.py

示例6: test12_BeginTransaction

# 需要导入模块: from DBUtils.SteadyDB import connect [as 别名]
# 或者: from DBUtils.SteadyDB.connect import cursor [as 别名]
 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')
开发者ID:SongJLG,项目名称:johan-doc,代码行数:24,代码来源:TestSteadyDB.py

示例7: test06_ConnectionMaxUsage

# 需要导入模块: from DBUtils.SteadyDB import connect [as 别名]
# 或者: from DBUtils.SteadyDB.connect import cursor [as 别名]
 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)
开发者ID:SongJLG,项目名称:johan-doc,代码行数:47,代码来源:TestSteadyDB.py

示例8: test08_ConnectionFailures

# 需要导入模块: from DBUtils.SteadyDB import connect [as 别名]
# 或者: from DBUtils.SteadyDB.connect import cursor [as 别名]
 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()
开发者ID:Mohanson,项目名称:DButils,代码行数:15,代码来源:TestSteadyDB.py

示例9: test10_ConnectionSetSizes

# 需要导入模块: from DBUtils.SteadyDB import connect [as 别名]
# 或者: from DBUtils.SteadyDB.connect import cursor [as 别名]
 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}))
开发者ID:SongJLG,项目名称:johan-doc,代码行数:26,代码来源:TestSteadyDB.py

示例10: test11_ConnectionPingCheck

# 需要导入模块: from DBUtils.SteadyDB import connect [as 别名]
# 或者: from DBUtils.SteadyDB.connect import cursor [as 别名]
 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
开发者ID:SongJLG,项目名称:johan-doc,代码行数:89,代码来源:TestSteadyDB.py

示例11: test07_ConnectionSetSession

# 需要导入模块: from DBUtils.SteadyDB import connect [as 别名]
# 或者: from DBUtils.SteadyDB.connect import cursor [as 别名]
 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'])
开发者ID:SongJLG,项目名称:johan-doc,代码行数:59,代码来源:TestSteadyDB.py

示例12: test04_Connection

# 需要导入模块: from DBUtils.SteadyDB import connect [as 别名]
# 或者: from DBUtils.SteadyDB.connect import cursor [as 别名]
 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')
#.........这里部分代码省略.........
开发者ID:SongJLG,项目名称:johan-doc,代码行数:103,代码来源:TestSteadyDB.py


注:本文中的DBUtils.SteadyDB.connect.cursor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。