Method: Extralite::Changeset#track
- Defined in:
- ext/extralite/changeset.c
#track(db, tables) ⇒ Extralite::Changeset
Tracks changes in the given block and collects them into the changeset. Changes are tracked only for the given tables. If nil is supplied as the given tables, changes are tracked for all tables.
# track changes for the foo and bar tables
changeset.track(db, [:foo, :bar]) do
run_some_queries
end
store_changes(changeset.to_blob)
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'ext/extralite/changeset.c', line 131 VALUE Changeset_track(VALUE self, VALUE db, VALUE tables) { Changeset_t *changeset = self_to_changeset(self); Database_t *db_struct = self_to_database(db); sqlite3 *sqlite3_db = db_struct->sqlite3_db; if (changeset->changeset_ptr) { sqlite3_free(changeset->changeset_ptr); changeset->changeset_len = 0; changeset->changeset_ptr = NULL; } struct track_ctx ctx = { .changeset = changeset, .sqlite3_db = sqlite3_db, .session = NULL, .db = db, .tables = tables }; int rc = sqlite3session_create(sqlite3_db, "main", &ctx.session); if (rc != SQLITE_OK) rb_raise(cError, "Error while creating session: %s", sqlite3_errstr(rc)); rb_ensure(SAFE(safe_track), (VALUE)&ctx, SAFE(cleanup_track), (VALUE)&ctx); return self; } |