Function sqlite_loadable::api::value_text
source · pub fn value_text<'a>(value: &*mut sqlite3_value) -> Result<&'a str, Utf8Error>
Expand description
Returns the sqlite3_value_text
result
from the given sqlite3_value, as a str. If the number of bytes of the underlying value
is 0, then an empty string is returned. A UTF8 Error is returned if there are problems
encoding the string.
Examples found in repository?
examples/scalar.rs (line 15)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
fn surround(context: *mut sqlite3_context, values: &[*mut sqlite3_value]) -> Result<()> {
let value = api::value_text(values.get(0).expect("1st argument as name"))?;
api::result_text(context, format!("x{}x", value))?;
Ok(())
}
// add_rs(a, b)
fn add(context: *mut sqlite3_context, values: &[*mut sqlite3_value]) -> Result<()> {
let a = api::value_int(values.get(0).expect("1st argument"));
let b = api::value_int(values.get(1).expect("2nd argument"));
api::result_int(context, a + b);
Ok(())
}
// connect(seperator, string1, ...)
fn connect(context: *mut sqlite3_context, values: &[*mut sqlite3_value]) -> Result<()> {
let seperator = api::value_text(values.get(0).expect("1st argument"))?;
let strings: Vec<&str> = values
.get(1..)
.expect("more than 1 argument to be given")
.iter()
.filter_map(|v| api::value_text(v).ok())
.collect();
api::result_text(context, strings.join(seperator))?;
Ok(())
}
More examples
examples/characters.rs (line 107)
100 101 102 103 104 105 106 107 108 109 110 111 112
fn filter(
&mut self,
_idx_num: i32,
_idx_str: Option<&str>,
values: &[*mut sqlite3_value],
) -> Result<()> {
let input =
api::value_text(values.get(0).expect("1st input constraint is required"))?.to_owned();
self.characters = Some(input.chars().collect());
self.input = Some(input);
self.idx = 0;
Ok(())
}