Automatic Undo/Redo With SQLite

Automatic Undo/Redo Using SQLite

This page demonstrates how to use triggers to implement undo/redo logic for an application that uses SQLite as its application file format.

Object-Oriented Design

This design note considers the database to be a collection of objects. Each SQL table is a class. Each row is an instance of that class. There are, of course, other ways to interpret an SQL database schema, and the techniques described here work equally well under alternative interpretations, but an object-oriented view seems be more natural to most contemporary programmers.

Capture Changes Using Triggers

The core idea is to create a special table (named "UNDOLOG" in the example) that holds information needed to undo/redo changes to the database. For each class (table) in the database that wants to participate in the undo/redo, triggers are created that cause entries to be made in