/// The possible cases for when a PreUpdateHook gets triggered. Allows access to the relevant /// functions for each case through the contained values. #[derive(Debug)] pubenum PreUpdateCase { /// Pre-update hook was triggered by an insert.
Insert(PreUpdateNewValueAccessor), /// Pre-update hook was triggered by a delete.
Delete(PreUpdateOldValueAccessor), /// Pre-update hook was triggered by an update.
Update { #[allow(missing_docs)]
old_value_accessor: PreUpdateOldValueAccessor, #[allow(missing_docs)]
new_value_accessor: PreUpdateNewValueAccessor,
}, /// This variant is not normally produced by SQLite. You may encounter it /// if you're using a different version than what's supported by this library.
Unknown,
}
/// An accessor to access the old values of the row being deleted/updated during the preupdate callback. #[derive(Debug)] pubstruct PreUpdateOldValueAccessor {
db: *mut ffi::sqlite3,
old_row_id: i64,
}
impl PreUpdateOldValueAccessor { /// Get the amount of columns in the row being deleted/updated. pubfn get_column_count(&self) -> i32 { unsafe { ffi::sqlite3_preupdate_count(self.db) }
}
/// Get the depth of the query that triggered the preupdate hook. /// Returns 0 if the preupdate callback was invoked as a result of /// a direct insert, update, or delete operation; /// 1 for inserts, updates, or deletes invoked by top-level triggers; /// 2 for changes resulting from triggers called by top-level triggers; and so forth. pubfn get_query_depth(&self) -> i32 { unsafe { ffi::sqlite3_preupdate_depth(self.db) }
}
/// Get the row id of the row being updated/deleted. pubfn get_old_row_id(&self) -> i64 { self.old_row_id
}
/// Get the value of the row being updated/deleted at the specified index. pubfn get_old_column_value(&self, i: i32) -> Result<ValueRef<'_>> { letmut p_value: *mut ffi::sqlite3_value = ptr::null_mut(); unsafe {
check(ffi::sqlite3_preupdate_old(self.db, i, &mut p_value))?;
Ok(ValueRef::from_value(p_value))
}
}
}
/// An accessor to access the new values of the row being inserted/updated /// during the preupdate callback. #[derive(Debug)] pubstruct PreUpdateNewValueAccessor {
db: *mut ffi::sqlite3,
new_row_id: i64,
}
impl PreUpdateNewValueAccessor { /// Get the amount of columns in the row being inserted/updated. pubfn get_column_count(&self) -> i32 { unsafe { ffi::sqlite3_preupdate_count(self.db) }
}
/// Get the depth of the query that triggered the preupdate hook. /// Returns 0 if the preupdate callback was invoked as a result of /// a direct insert, update, or delete operation; /// 1 for inserts, updates, or deletes invoked by top-level triggers; /// 2 for changes resulting from triggers called by top-level triggers; and so forth. pubfn get_query_depth(&self) -> i32 { unsafe { ffi::sqlite3_preupdate_depth(self.db) }
}
/// Get the row id of the row being inserted/updated. pubfn get_new_row_id(&self) -> i64 { self.new_row_id
}
/// Get the value of the row being updated/deleted at the specified index. pubfn get_new_column_value(&self, i: i32) -> Result<ValueRef<'_>> { letmut p_value: *mut ffi::sqlite3_value = ptr::null_mut(); unsafe {
check(ffi::sqlite3_preupdate_new(self.db, i, &mut p_value))?;
Ok(ValueRef::from_value(p_value))
}
}
}
impl Connection { /// Register a callback function to be invoked before /// a row is updated, inserted or deleted. /// /// The callback parameters are: /// /// - the name of the database ("main", "temp", ...), /// - the name of the table that is updated, /// - a variant of the PreUpdateCase enum which allows access to extra functions depending /// on whether it's an update, delete or insert. #[inline] pubfn preupdate_hook<F>(&self, hook: Option<F>) where
F: FnMut(Action, &str, &str, &PreUpdateCase) + Send + 'static,
{ self.db.borrow_mut().preupdate_hook(hook);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.