-
Notifications
You must be signed in to change notification settings - Fork 333
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
Cannot insert heterogeneous elements with .execute #462
Comments
Why can't you access ToSql? It's public, just on |
See the example here: conn.execute(
"INSERT INTO person (name, time_created, data)
VALUES (?1, ?2, ?3)",
&[&me.name as &ToSql, &me.time_created, &me.data],
).unwrap(); The first element must be cast: |
This inconvenient syntax is related to https://github.com/jgallagher/rusqlite/issues/312#issuecomment-420028030 |
Oh, thanks for the clarification! Perhaps it's possible to use a technique like Rocket uses and have a |
@NoraCodes We want to support parameter values specified as: |
This would probably work. macro_rules! to_sql {
() => {
$crate::NO_PARAMS
};
($($param:expr),+ $(,)?) => {
&[$(&$param as &dyn $crate::types::ToSql),+]
};
} I'm not sure about it doing A version that supports named params too would be nice, but is a decent amount more work due to annoying macro expansion matching weirdness (I think it needs to be tt muncher, sadly). It might be nice to export |
Great, thanks a lot! |
I have a database created by:
and I want to run the following query:
With the code:
Here,
quote.source
is anOption<String>
, while the others areString
, so there's no way (that I can see) to insert it, because I can't accessToSql
to make the elements of the array into&dyn ToSql
, and the array has to be homogeneous.What's the correct way to do this?
The text was updated successfully, but these errors were encountered: