Comments (6)
There is one thing that can greatly reduce copy but not currently supported by rusqlite
is binding reuse:
sqlite3 *db = NULL;
sqlite3_stmt *stmt = NULL;
int rc = 0;
rc = sqlite3_open_v2(":memory:", &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
if (db == NULL || SQLITE_OK != rc) {
fprintf(stderr, "Error: unable to open database: %s\n", sqlite3_errmsg(db));
exit(1);
}
rc = sqlite3_prepare_v2(db, "SELECT ?", -1, &stmt, NULL);
if (stmt == NULL || SQLITE_OK != rc) {
fprintf(stderr, "Error: prepare stmt: %s\n", sqlite3_errmsg(db));
exit(1);
}
// Bind once
rc = sqlite3_bind_int(stmt, 1, 1);
if (SQLITE_OK != rc) {
fprintf(stderr, "Error: bind param: %s\n", sqlite3_errmsg(db));
exit(1);
}
// Reuse many times...
for (int i = 0; i < 10; i++) {
rc = sqlite3_step(stmt);
if (SQLITE_OK != rc && SQLITE_DONE != rc && SQLITE_ROW != rc) {
fprintf(stderr, "Error: %s\n", sqlite3_errmsg(db));
exit(1);
}
sqlite3_reset(stmt);
}
sqlite3_finalize(stmt);
sqlite3_close(db);
It seems difficult to make binding reusable when the data is borrowed...
from rusqlite.
Ahh, yeah, that's interesting. I don't think it affects the ToSql
trait, since that's used in the "binding" step. Getting this reuse would require a different way of calling query/execute. Something like query_with_previous_parameters
? I don't think borrowed data is a concern with this since SQLite makes its own copy when you bind, right?
from rusqlite.
SQLite makes its own copy when you bind
only when SQLITE_TRANSIENT
is specified.
from rusqlite.
True, but we always specify it. :-)
So there are at least two things we could do:
- (Easy, I think) Add ability to reuse bound parameters. Maybe
Statement
gets a method likebind_parameters(&[&ToSql]) -> BoundStatement
, andBoundStatement
has all thequery...
methods but they don't need params. - (Hard, I think) Add ability to bind text/blobs without
SQLITE_TRANSIENT
.
The first one is orthogonal to a new ToSql
interface. The second definitely isn't, but I don't have any ideas off the top of my head how we could allow that safely.
from rusqlite.
At least, we can use SQLITE_STATIC
with sqlite3_bind_text
when the text is empty ("").
And we can use sqlite3_bind_zeroblob
instead of sqlite3_bind_blob
when the byte slice is empty.
from rusqlite.
True - both of those can be done internally. I'm not sure what the lifetimes on a variant of prepare(&[&ToSql])
would look like if we wanted to tie them to the lifetime of the returned statement, or if it's even possible to express that. I wonder if we could use borrowed data more easily for the one-shot functions like Connection::execute
and Connection::query_row
.
from rusqlite.
Related Issues (20)
- release the latest version HOT 4
- FromSql vs TryFrom / ToSql vs TryInto HOT 1
- `sqlite3_compileoption_used` and Rust `const fn`
- called `Result::unwrap()` on an `Err` value: SqliteFailure(Error { code: Unknown, extended_code: 1 }, Some("json_object() requires an even number of arguments")) HOT 2
- Apps using `winsqlite3` feature no longer builds HOT 5
- Question: Is there any way to use SQLite 3.45 with rusqlite 0.30.0? HOT 2
- Trait for abstracting over `Connection`/`Transaction`? HOT 3
- SqlInputError { error: Error { code: Unknown, extended_code: 1 }, msg: "unrecognized token: \"{\"" HOT 1
- Release 0.31.0 with SQLite 3.45? HOT 2
- Type issue on select with digits only in a "string" colums. HOT 2
- wasm32-wasi target fails on Apple M3
- How to get "returning *" from insert HOT 2
- Stale Connection Handler on Multi-Threaded Situation HOT 1
- sqlite3_snapshot iteration HOT 2
- Creating `Value::Blob` without necessarily allocating heap HOT 5
- Using rusqlite::vtab::VTabConnection::handle() HOT 4
- Add bindings for `sqlite3_trace_v2` API HOT 4
- iOS Linker Warning: SQLite was build for newer version than being linked HOT 2
- the first query is failure due to below error HOT 1
- Segmentation fault when writing encrypted database with vendored SQLCipher and OpenSSL on OpenBSD
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rusqlite.