sqlite
sqlite copied to clipboard
Add support for binding arrays
Greetings,
i'm trying to use a select in
statement but don't seem to able to.
let mut cursor = conn
.prepare("SELECT * FROM users WHERE age in (?)"). // <-- carray
.unwrap()
.into_cursor();
cursor.bind(&[[Value::Integer(42),Value::Integer(50)]]).unwrap(); // <-- fails since expectation is Value not array/tuple
is this currently possible ?
Hello, thank you for the note. Does SQLite have support for this? Which binding function is this? As a workaround, I suppose you can have as many placeholders as you like.
thanks for the quick reply.
support for in
: https://sqlite.org/lang_select.html#whereclause
support for carray
: https://www.sqlite.org/carray.html
being able to pass a Vec<Values> to bind might just do
here's how rusqlite is doing it: https://github.com/rusqlite/rusqlite/blob/master/src/vtab/array.rs
as a workaround , i'm construct the stmt string with params in place, e.g.
let stmt = "select * from users where age in (?)";
let params = vec![
Value::Integer(42).as_integer().unwrap(),
Value::Integer(50).as_integer().unwrap(),
];
let stmt = stmt.replace("?", &join(params, ","));