sqlx icon indicating copy to clipboard operation
sqlx copied to clipboard

Support SQLITE_LIMIT_* Run-Time Limit

Open RinCat opened this issue 1 year ago • 2 comments

Is your feature request related to a problem? Please describe. I try to change the Sqlite Run-Time Limit , but found no way to do it in sqlx.

Describe the solution you'd like It should able to set in sqlite::SqliteConnectOptions or other place like .limit(SQLITE_LIMIT_ATTACHED, 0)

Describe alternatives you've considered I don't think I can call sqlite3_limit() directly.

Additional context N/A

RinCat avatar Sep 25 '24 16:09 RinCat

There are two ways you could do this right now:

You can pass the flags at compile time with an environment variable: https://github.com/rusqlite/rusqlite?tab=readme-ov-file#notes-on-building-rusqlite-and-libsqlite3-sys

export LIBSQLITE3_FLAGS="-DSQLITE_MAX_LENGTH=123456789 -DSQLITE_MAX_COLUMN=100"

cargo build

You can put this in a .cargo/config.toml file in your project so it's always added: https://doc.rust-lang.org/cargo/reference/config.html#env

[env]
LIBSQLITE3_FLAGS="-DSQLITE_MAX_LENGTH=123456789 -DSQLITE_MAX_COLUMN=100"

Or you can call .lock_handle().await? on the connection: https://docs.rs/sqlx/latest/sqlx/struct.SqliteConnection.html#method.lock_handle

Which gives you direct access to the sqlite3* pointer: https://docs.rs/sqlx/latest/sqlx/sqlite/struct.LockedSqliteHandle.html#method.as_raw_handle

And then import libsqlite3-sys and call sqlite3_limit() yourself. Note that the version needs to match that used by SQLx: https://docs.rs/sqlx/latest/sqlx/sqlite/index.html#note-linkage-is-semver-exempt


I could see putting a nicer API on this, but I'd need to think about what that should look like and where it should go. I would probably put it on SqliteConnectOptions.

abonander avatar Sep 25 '24 17:09 abonander

Thanks, I will use the LIBSQLITE3_FLAGS for now. Looking forward to the APIs. :)

RinCat avatar Sep 25 '24 17:09 RinCat