Esempio n. 1
0
    def _get_id(self, continue_transaction=False, action='draw'):
        """
        Get the appropriate transaction id.
        """
        self._cursor.execute(
            'SELECT MAX(id) FROM transactions WHERE time IS NOT NULL;'
        )

        (max_transaction,) = self._cursor.fetchone()

        if continue_transaction:
            return max_transaction

        timestamp = from_date(datetime.utcnow())

        self._cursor.execute(
            'DELETE FROM transactions WHERE time IS NULL;'
        )
        self._cursor.execute(
            'DELETE FROM draws WHERE transaction_id > ?;',
            (max_transaction,)
        )

        self._cursor.execute(
            'INSERT INTO transactions (time, action) '
            'VALUES (:timestamp, :action);',
            {'timestamp': timestamp, 'action': action}
        )

        transaction = self._cursor.lastrowid

        return transaction
Esempio n. 2
0
 def redo(self):
     """
     Redo the next uncommitted transaction. Does nothing if none
     exist
     """
     self._cursor.execute(
         'UPDATE transactions SET time=:timestamp WHERE id = ('
         '   SELECT MIN(id) FROM transactions WHERE time IS NULL'
         ');',
         {'timestamp': from_date(datetime.utcnow())}
     )