Optimize blob passing

This commit is contained in:
vms 2021-09-03 14:26:39 +03:00
parent f821a3c891
commit b88cedea9d
4 changed files with 12 additions and 10 deletions

2
.gitignore vendored
View File

@ -1,5 +1,7 @@
.idea/* .idea/*
/artifacts
.repl_history
*.sqlite3 *.sqlite3
Cargo.lock Cargo.lock
target target

View File

@ -28,7 +28,7 @@ impl Connection {
unsafe { unsafe {
let path = path.as_ref(); let path = path.as_ref();
let path = path.to_string_lossy().into_owned(); 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 { match result.ret_code {
ffi::SQLITE_OK => {} ffi::SQLITE_OK => {}

View File

@ -38,7 +38,7 @@ extern "C" {
const char *zVfs /* Name of VFS module to use */ 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*); // SQLITE_API int sqlite3_close(sqlite3*);
pub fn sqlite3_close(db_handle: u32) -> i32; pub fn sqlite3_close(db_handle: u32) -> i32;
@ -52,7 +52,7 @@ extern "C" {
const char **pzTail /* OUT: Pointer to unused portion of zSql */ 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( SQLITE_API int sqlite3_exec(
@ -65,7 +65,7 @@ extern "C" {
*/ */
pub fn sqlite3_exec( pub fn sqlite3_exec(
db_handle: u32, db_handle: u32,
sql: String, sql: &str,
callback_id: i32, callback_id: i32,
callback_arg: i32, callback_arg: i32,
) -> DBExecDescriptor; ) -> DBExecDescriptor;
@ -101,7 +101,7 @@ extern "C" {
pub fn sqlite3_reset(stmt_handle: u32) -> i32; pub fn sqlite3_reset(stmt_handle: u32) -> i32;
// SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*)); // 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<u8>, xDel: i32) -> i32; pub fn sqlite3_bind_blob(stmt_handle: u32, pos: i32, blob: &Vec<u8>, xDel: i32) -> i32;
// SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double); // SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double);
pub fn sqlite3_bind_double(stmt_handle: u32, pos: i32, value: f64) -> i32; 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; 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*)); // 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) // SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt)
pub fn sqlite3_column_count(stmt_handle: u32) -> i32; pub fn sqlite3_column_count(stmt_handle: u32) -> i32;

View File

@ -128,16 +128,16 @@ impl<'l> Drop for Statement {
impl Bindable for &Value { impl Bindable for &Value {
fn bind(self, statement: &mut Statement, i: usize) -> Result<()> { fn bind(self, statement: &mut Statement, i: usize) -> Result<()> {
match self { 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::Float(value) => value.bind(statement, i),
&Value::Integer(value) => value.bind(statement, i), &Value::Integer(value) => value.bind(statement, i),
&Value::String(ref value) => (value as &str).bind(statement, i), Value::String(value) => value.as_str().bind(statement, i),
&Value::Null => ().bind(statement, i), Value::Null => ().bind(statement, i),
} }
} }
} }
impl Bindable for &[u8] { impl Bindable for &Vec<u8> {
#[inline] #[inline]
fn bind(self, statement: &mut Statement, i: usize) -> Result<()> { fn bind(self, statement: &mut Statement, i: usize) -> Result<()> {
debug_assert!(i > 0, "the indexing starts from 1"); debug_assert!(i > 0, "the indexing starts from 1");