sqlite icon indicating copy to clipboard operation
sqlite copied to clipboard

Add support for binding arrays

Open boneyard93501 opened this issue 3 years ago • 2 comments

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 ?

boneyard93501 avatar Apr 06 '21 21:04 boneyard93501

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.

IvanUkhov avatar Apr 07 '21 06:04 IvanUkhov

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, ","));

boneyard93501 avatar Apr 07 '21 07:04 boneyard93501