Beispiel #1
0
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)
Beispiel #2
0
    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!")
Beispiel #3
0
    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!")
Beispiel #4
0
 def __init__(self, pool, connection, parent):
     Transaction.__init__(self, pool, connection)
     self.parent = parent
Beispiel #5
0
def dbCursor(pool, conn):
    return Transaction(pool, conn)