rusqlite icon indicating copy to clipboard operation
rusqlite copied to clipboard

Allow binding of text/blobs without SQLITE_TRANSIENT?

Open jgallagher opened this issue 8 years ago • 4 comments

Currently, we always pass the SQLITE_TRANSIENT flag when binding a text or blob parameter, instructing SQLite to make its own copy of the data. It would be nice to be able to avoid that copy if we can come up with a safe interface that allows it. (Initially discussed on #162.)

jgallagher avatar May 26 '16 04:05 jgallagher

If we merge #163, we'll know from the ToSqlOutput case if SQLITE_TRANSIENT is definitely required (if we get a ToSqlOutput::Owned, the value will be dropped immediately after it's bound). If we get a ToSqlOutput::Borrowed, it's conceivably safe to use SQLITE_STATIC if we can structure the API in such a way as to know the parameter(s) will still be alive when the query is executed.

jgallagher avatar May 26 '16 04:05 jgallagher

Note that ToSqlOutput::Owned Strings and Boxs could conceivably be handled by passing in a deleter function pointer to Sqlite, thus allowing us to avoid a copy in the owned case as well.

obsgolem avatar Dec 08 '22 19:12 obsgolem

Vec::into_boxed_slice / String::into_boxed_str + Box::into_raw / drop(Box::from_raw)

gwenn avatar Dec 08 '22 20:12 gwenn

To be fixed here: https://github.com/rusqlite/rusqlite/blob/51a69b1b7487aa41786570ed95abc2699ac02c1e/src/statement.rs#L730-L732

gwenn avatar Dec 09 '22 21:12 gwenn