Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for binding arrays #38

Open
boneyard93501 opened this issue Apr 6, 2021 · 2 comments
Open

Add support for binding arrays #38

boneyard93501 opened this issue Apr 6, 2021 · 2 comments

Comments

@boneyard93501
Copy link

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 ?

@IvanUkhov
Copy link
Member

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.

@boneyard93501
Copy link
Author

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

@IvanUkhov IvanUkhov changed the title carray support Add support for binding arrays Sep 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants