示例#1
0
文件: image.py 项目: bcj/painterm
    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
示例#2
0
文件: image.py 项目: bcj/painterm
 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())}
     )