From b88cedea9df932266c65869a6c0ea1785bc6f043 Mon Sep 17 00:00:00 2001 From: vms Date: Fri, 3 Sep 2021 14:26:39 +0300 Subject: [PATCH 1/2] Optimize blob passing --- .gitignore | 2 ++ src/connection.rs | 2 +- src/sqlite3_connector/import_functions.rs | 10 +++++----- src/statement.rs | 8 ++++---- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index e0fcc69..9af404a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ .idea/* +/artifacts +.repl_history *.sqlite3 Cargo.lock target diff --git a/src/connection.rs b/src/connection.rs index 8f7c30c..ee6816e 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -28,7 +28,7 @@ impl Connection { unsafe { let path = path.as_ref(); let path = path.to_string_lossy().into_owned(); - let result = ffi::sqlite3_open_v2(path, flags.0, String::new()); + let result = ffi::sqlite3_open_v2(&path, flags.0, &String::new()); match result.ret_code { ffi::SQLITE_OK => {} diff --git a/src/sqlite3_connector/import_functions.rs b/src/sqlite3_connector/import_functions.rs index 7848c0c..e9900d7 100644 --- a/src/sqlite3_connector/import_functions.rs +++ b/src/sqlite3_connector/import_functions.rs @@ -38,7 +38,7 @@ extern "C" { const char *zVfs /* Name of VFS module to use */ ); */ - pub fn sqlite3_open_v2(filename: String, flags: i32, vfs: String) -> DBOpenDescriptor; + pub fn sqlite3_open_v2(filename: &str, flags: i32, vfs: &str) -> DBOpenDescriptor; // SQLITE_API int sqlite3_close(sqlite3*); pub fn sqlite3_close(db_handle: u32) -> i32; @@ -52,7 +52,7 @@ extern "C" { const char **pzTail /* OUT: Pointer to unused portion of zSql */ ); */ - pub fn sqlite3_prepare_v2(db_handle: u32, sql: String) -> DBPrepareDescriptor; + pub fn sqlite3_prepare_v2(db_handle: u32, sql: &str) -> DBPrepareDescriptor; /* SQLITE_API int sqlite3_exec( @@ -65,7 +65,7 @@ extern "C" { */ pub fn sqlite3_exec( db_handle: u32, - sql: String, + sql: &str, callback_id: i32, callback_arg: i32, ) -> DBExecDescriptor; @@ -101,7 +101,7 @@ extern "C" { pub fn sqlite3_reset(stmt_handle: u32) -> i32; // SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*)); - pub fn sqlite3_bind_blob(stmt_handle: u32, pos: i32, blob: Vec, xDel: i32) -> i32; + pub fn sqlite3_bind_blob(stmt_handle: u32, pos: i32, blob: &Vec, xDel: i32) -> i32; // SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double); pub fn sqlite3_bind_double(stmt_handle: u32, pos: i32, value: f64) -> i32; @@ -113,7 +113,7 @@ extern "C" { pub fn sqlite3_bind_null(stmt_handle: u32, pos: i32) -> i32; // SQLITE_API int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*)); - pub fn sqlite3_bind_text(stmt_handle: u32, pos: i32, text: String, xDel: i32) -> i32; + pub fn sqlite3_bind_text(stmt_handle: u32, pos: i32, text: &str, xDel: i32) -> i32; // SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt) pub fn sqlite3_column_count(stmt_handle: u32) -> i32; diff --git a/src/statement.rs b/src/statement.rs index 1920c9e..63d1a05 100644 --- a/src/statement.rs +++ b/src/statement.rs @@ -128,16 +128,16 @@ impl<'l> Drop for Statement { impl Bindable for &Value { fn bind(self, statement: &mut Statement, i: usize) -> Result<()> { match self { - &Value::Binary(ref value) => (value as &[u8]).bind(statement, i), + Value::Binary(value) => value.bind(statement, i), &Value::Float(value) => value.bind(statement, i), &Value::Integer(value) => value.bind(statement, i), - &Value::String(ref value) => (value as &str).bind(statement, i), - &Value::Null => ().bind(statement, i), + Value::String(value) => value.as_str().bind(statement, i), + Value::Null => ().bind(statement, i), } } } -impl Bindable for &[u8] { +impl Bindable for &Vec { #[inline] fn bind(self, statement: &mut Statement, i: usize) -> Result<()> { debug_assert!(i > 0, "the indexing starts from 1"); From 3309725d2ec6c30b9d55c101fc924f80c115446f Mon Sep 17 00:00:00 2001 From: vms Date: Fri, 3 Sep 2021 20:13:49 +0300 Subject: [PATCH 2/2] bump version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 464849f..74951c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "marine-sqlite-connector" -version = "0.5.0" +version = "0.5.1" license = "Apache-2.0/MIT" authors = [ "Daniel Dulaney ",