mirror of
https://github.com/fluencelabs/sqlite-wasm-connector
synced 2025-03-15 06:20:50 +00:00
Make execute and statement take immutable self
This commit is contained in:
parent
c5c87066e9
commit
0e6ee0c10d
@ -19,7 +19,7 @@ use std::path::PathBuf;
|
||||
|
||||
fn main() {
|
||||
let path = setup();
|
||||
let mut database = sqlite::open(&path).unwrap();
|
||||
let database = sqlite::open(&path).unwrap();
|
||||
|
||||
database.execute(r#"
|
||||
CREATE TABLE `users` (id INTEGER, name VARCHAR(255));
|
||||
|
@ -4,7 +4,7 @@ use std::path::PathBuf;
|
||||
|
||||
fn main() {
|
||||
let path = setup();
|
||||
let mut database = sqlite::open(&path).unwrap();
|
||||
let database = sqlite::open(&path).unwrap();
|
||||
|
||||
database.execute(r#"
|
||||
CREATE TABLE `users` (id INTEGER, name VARCHAR(255));
|
||||
|
@ -25,8 +25,8 @@ impl Database {
|
||||
}
|
||||
|
||||
/// Execute an SQL statement.
|
||||
pub fn execute<'l>(&mut self, sql: &str,
|
||||
callback: Option<&mut ExecuteCallback<'l>>) -> Result<()> {
|
||||
pub fn execute<'l>(&self, sql: &str, callback: Option<&mut ExecuteCallback<'l>>)
|
||||
-> Result<()> {
|
||||
|
||||
unsafe {
|
||||
match callback {
|
||||
@ -49,7 +49,7 @@ impl Database {
|
||||
|
||||
/// Create a prepared statement.
|
||||
#[inline]
|
||||
pub fn statement<'l>(&'l mut self, sql: &str) -> Result<Statement<'l>> {
|
||||
pub fn statement<'l>(&'l self, sql: &str) -> Result<Statement<'l>> {
|
||||
::statement::new(self, sql)
|
||||
}
|
||||
}
|
||||
@ -62,7 +62,7 @@ impl Drop for Database {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn as_raw(database: &mut Database) -> *mut raw::sqlite3 {
|
||||
pub fn as_raw(database: &Database) -> *mut raw::sqlite3 {
|
||||
database.raw
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ pub struct Error {
|
||||
|
||||
impl Error {
|
||||
/// Return the last occurred error if any.
|
||||
pub fn last(database: &mut Database) -> Option<Error> {
|
||||
pub fn last(database: &Database) -> Option<Error> {
|
||||
unsafe {
|
||||
let code = raw::sqlite3_errcode(::database::as_raw(database));
|
||||
if code == raw::SQLITE_OK {
|
||||
|
@ -101,7 +101,7 @@ impl Value for String {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn new<'l>(database: &'l mut Database, sql: &str) -> Result<Statement<'l>> {
|
||||
pub fn new<'l>(database: &'l Database, sql: &str) -> Result<Statement<'l>> {
|
||||
let mut raw = 0 as *mut _;
|
||||
unsafe {
|
||||
success!(database, raw::sqlite3_prepare(::database::as_raw(database), str_to_c_str!(sql),
|
||||
|
@ -18,7 +18,7 @@ fn workflow() {
|
||||
);
|
||||
|
||||
let (path, _directory) = setup();
|
||||
let mut database = ok!(sqlite::open(&path));
|
||||
let database = ok!(sqlite::open(&path));
|
||||
|
||||
let sql = r#"CREATE TABLE `users` (id INTEGER, name VARCHAR(255), age REAL);"#;
|
||||
ok!(database.execute(sql, None));
|
||||
@ -58,7 +58,7 @@ fn workflow() {
|
||||
#[test]
|
||||
fn failure() {
|
||||
let (path, _directory) = setup();
|
||||
let mut database = ok!(sqlite::open(&path));
|
||||
let database = ok!(sqlite::open(&path));
|
||||
match database.execute(":)", None) {
|
||||
Err(error) => assert_eq!(error.message, Some(String::from(r#"unrecognized token: ":""#))),
|
||||
_ => assert!(false),
|
||||
|
Loading…
x
Reference in New Issue
Block a user