Use C string literal for database name

No alloc for "main" and "temp".
No alloc possible when the attached database name is known at compile time / a C
string literal can be usd.
No alloc when the database name is given by SQLite (`sqlite3_wal_hook`).
This commit is contained in:
gwenn
2024-11-10 16:56:03 +01:00
parent 0af8bfc603
commit 3d85c79891
6 changed files with 28 additions and 19 deletions

View File

@@ -346,7 +346,7 @@ impl InnerConnection {
fn remove_preupdate_hook(&mut self) {}
pub fn db_readonly(&self, db_name: super::DatabaseName<'_>) -> Result<bool> {
let name = db_name.as_cstring()?;
let name = db_name.as_cstr()?;
let r = unsafe { ffi::sqlite3_db_readonly(self.db, name.as_ptr()) };
match r {
0 => Ok(false),
@@ -368,7 +368,7 @@ impl InnerConnection {
db_name: Option<super::DatabaseName<'_>>,
) -> Result<super::transaction::TransactionState> {
let r = if let Some(ref name) = db_name {
let name = name.as_cstring()?;
let name = name.as_cstr()?;
unsafe { ffi::sqlite3_txn_state(self.db, name.as_ptr()) }
} else {
unsafe { ffi::sqlite3_txn_state(self.db, ptr::null()) }