Function define_scalar_function

Source
pub fn define_scalar_function<F>(
    db: *mut sqlite3,
    name: &str,
    num_args: c_int,
    x_func: F,
    func_flags: FunctionFlags,
) -> Result<()>
Expand description

Defines a new scalar function on the given database connection.

ยงExample

fn xyz_version(context: *mut sqlite3_context, _values: &[*mut sqlite3_value]) -> Result<()> {
  context_result_text(context, &format!("v{}", env!("CARGO_PKG_VERSION")))?;
  Ok(())
}

define_scalar_function(db, "xyz_version", 0, xyz_version)?;
Examples found in repository?
examples/hello.rs (line 26)
24pub fn sqlite3_hello_init(db: *mut sqlite3) -> Result<()> {
25    let flags = FunctionFlags::UTF8 | FunctionFlags::DETERMINISTIC;
26    define_scalar_function(db, "hello", 1, hello, flags)?;
27    Ok(())
28}
More examples
Hide additional examples
examples/scalar.rs (line 44)
42pub fn sqlite3_scalarrs_init(db: *mut sqlite3) -> Result<()> {
43    let flags = FunctionFlags::UTF8 | FunctionFlags::DETERMINISTIC;
44    define_scalar_function(db, "surround_rs", 1, surround, flags)?;
45    define_scalar_function(db, "connect", -1, connect, flags)?;
46    define_scalar_function(db, "yo_rs", 0, yo, flags)?;
47    define_scalar_function(db, "add_rs", 2, add, flags)?;
48    Ok(())
49}