Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit ed1a2cb

Browse files
committed
fix eid to cstr lifetime issue, fix #41
1 parent 0aa4247 commit ed1a2cb

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/volume/storage/sqlite/sqlite.rs

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::ffi::CString;
1+
use std::ffi::{CStr, CString};
22
use std::fmt::{self, Debug};
33
use std::os::raw::{c_int, c_void};
44
use std::ptr;
@@ -45,9 +45,8 @@ fn bind_int(
4545
fn bind_id(
4646
stmt: *mut ffi::sqlite3_stmt,
4747
col_idx: c_int,
48-
id: &Eid,
48+
id_str: &CStr,
4949
) -> Result<()> {
50-
let id_str = CString::new(id.to_string()).unwrap();
5150
let result = unsafe {
5251
ffi::sqlite3_bind_text(
5352
stmt,
@@ -360,7 +359,8 @@ impl Storable for SqliteStorage {
360359
reset_stmt(stmt)?;
361360

362361
// bind parameters and run sql
363-
bind_id(stmt, 1, id)?;
362+
let id_str = CString::new(id.to_string()).unwrap();
363+
bind_id(stmt, 1, &id_str)?;
364364
run_select_blob(stmt)
365365
}
366366

@@ -369,7 +369,8 @@ impl Storable for SqliteStorage {
369369
reset_stmt(stmt)?;
370370

371371
// bind parameters and run sql
372-
bind_id(stmt, 1, id)?;
372+
let id_str = CString::new(id.to_string()).unwrap();
373+
bind_id(stmt, 1, &id_str)?;
373374
bind_blob(stmt, 2, wal)?;
374375
run_dml(stmt)
375376
}
@@ -379,7 +380,8 @@ impl Storable for SqliteStorage {
379380
reset_stmt(stmt)?;
380381

381382
// bind parameters and run sql
382-
bind_id(stmt, 1, id)?;
383+
let id_str = CString::new(id.to_string()).unwrap();
384+
bind_id(stmt, 1, &id_str)?;
383385
run_dml(stmt)
384386
}
385387

@@ -388,7 +390,8 @@ impl Storable for SqliteStorage {
388390
reset_stmt(stmt)?;
389391

390392
// bind parameters and run sql
391-
bind_id(stmt, 1, id)?;
393+
let id_str = CString::new(id.to_string()).unwrap();
394+
bind_id(stmt, 1, &id_str)?;
392395
run_select_blob(stmt)
393396
}
394397

@@ -397,7 +400,8 @@ impl Storable for SqliteStorage {
397400
reset_stmt(stmt)?;
398401

399402
// bind parameters and run sql
400-
bind_id(stmt, 1, id)?;
403+
let id_str = CString::new(id.to_string()).unwrap();
404+
bind_id(stmt, 1, &id_str)?;
401405
bind_blob(stmt, 2, addr)?;
402406
run_dml(stmt)
403407
}
@@ -407,7 +411,8 @@ impl Storable for SqliteStorage {
407411
reset_stmt(stmt)?;
408412

409413
// bind parameters and run sql
410-
bind_id(stmt, 1, id)?;
414+
let id_str = CString::new(id.to_string()).unwrap();
415+
bind_id(stmt, 1, &id_str)?;
411416
run_dml(stmt)
412417
}
413418

0 commit comments

Comments
 (0)