def do_insert(cursor: adbapi.Transaction, container): # 会从dbpool取出cursor # 执行具体的插入 cursor._connection.ping(reconnect=True) for key, value in container.items(): sql = get_insert_sql(key, value) cursor.execute(*sql)
def test_reopenLogErrorIfReconnect(self): """ If the cursor creation raises an error in L{Transaction.reopen}, it reconnects but log the error occurred. """ class ConnectionCursorRaise(object): count = 0 def reconnect(self): pass def cursor(self): if self.count == 0: self.count += 1 raise RuntimeError("problem!") pool = FakePool(None) transaction = Transaction(pool, ConnectionCursorRaise()) transaction.reopen() errors = self.flushLoggedErrors(RuntimeError) self.assertEquals(len(errors), 1) self.assertEquals(errors[0].value.args[0], "problem!")
def test_reopenLogErrorIfReconnect(self): """ If the cursor creation raises an error in L{Transaction.reopen}, it reconnects but log the error occurred. """ class ConnectionCursorRaise: count = 0 def reconnect(self): pass def cursor(self): if self.count == 0: self.count += 1 raise RuntimeError("problem!") pool = FakePool(None) transaction = Transaction(pool, ConnectionCursorRaise()) transaction.reopen() errors = self.flushLoggedErrors(RuntimeError) self.assertEqual(len(errors), 1) self.assertEqual(errors[0].value.args[0], "problem!")
def __init__(self, pool, connection, parent): Transaction.__init__(self, pool, connection) self.parent = parent
def dbCursor(pool, conn): return Transaction(pool, conn)