register_bzip2_functions

Function register_bzip2_functions 

Source
pub fn register_bzip2_functions(conn: &Connection) -> Result<()>
Expand description

Register the bzip2 SQL functions with the given SQLite connection. The function takes a single argument and returns the bzip2 compression (blob) of that argument. The argument can be either a string or a blob. If the argument is NULL, the result is NULL.

ยงExample

let db = Connection::open_in_memory()?;
register_bzip2_functions(&db)?;
let result: Vec<u8> = db.query_row("SELECT bzip2('hello')", [], |r| r.get(0))?;
let expected = b"\x42\x5a\x68\x36\x31\x41\x59\x26\x53\x59\x19\x31\x65\x3d\x00\x00\x00\x81\x00\x02\x44\xa0\x00\x21\x9a\x68\x33\x4d\x07\x33\x8b\xb9\x22\x9c\x28\x48\x0c\x98\xb2\x9e\x80";
assert_eq!(result, expected);
let result: String = db.query_row("SELECT CAST(bzip2_decode(bzip2('world')) AS TEXT)", [], |r| r.get(0))?;
let expected = "world";
assert_eq!(result, expected);
let result: bool = db.query_row("SELECT bzip2_test(bzip2('world'))", [], |r| r.get(0))?;
let expected = true;
assert_eq!(result, expected);