diff --git a/Cargo.toml b/Cargo.toml index 4a6f4fc..f8fc137 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "marine-sqlite-connector" -version = "0.7.0" +version = "0.8.0" license = "Apache-2.0/MIT" authors = [ "Daniel Dulaney ", @@ -37,7 +37,9 @@ path = "src/test.rs" [dependencies] marine-rs-sdk = "0.7.0" +bytesize = "1.2.0" [dev-dependencies] -temporary = "0.6" marine-rs-sdk-test = "0.2.0" +temporary = "0.6" + diff --git a/src/lib.rs b/src/lib.rs index 0d2908e..0fe536a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -314,7 +314,7 @@ fn last_error(raw: ffi::Sqlite3DbHandle) -> Option { /// to stay below the limit, it will exceed the limit rather than generate an SQLITE_NOMEM error. /// In other words, the soft heap limit is advisory only. pub fn soft_soft_heap_limit64(limit: i64) -> i64 { - unsafe { ffi::sqlite3_hard_heap_limit64(limit) } + unsafe { ffi::sqlite3_soft_heap_limit64(limit) } } /// From the SQLite docs: diff --git a/src/test.rs b/src/test.rs index 812545f..cd0490e 100644 --- a/src/test.rs +++ b/src/test.rs @@ -1,5 +1,5 @@ use marine_rs_sdk::marine; -use marine_sqlite_connector::{version, State, Value}; +use marine_sqlite_connector::{version, Connection, State, Value}; pub fn main() {} @@ -648,3 +648,40 @@ pub fn test12() { assert_eq!(row[4].as_string().unwrap(), "UPDATE"); } } + +#[marine] +pub fn test13() { + fn insert_data(connection: &Connection) -> marine_sqlite_connector::Result<()> { + connection + .execute("INSERT INTO email VALUES ('Alice', 'How deep is the hole', 'Nobody knows')") + } + + let connection = marine_sqlite_connector::open(":memory:").unwrap(); + + connection + .execute( + " + CREATE TABLE email(sender, subject, body); + ", + ) + .unwrap(); + + for _ in 0..10 { + let insert_result = insert_data(&connection); + assert!(insert_result.is_ok()); + } + + marine_sqlite_connector::set_hard_heap_limit64(bytesize::KB as i64); + + for _ in 0..10 { + let insert_result = insert_data(&connection); + assert!(insert_result.is_err()); + } + + marine_sqlite_connector::set_hard_heap_limit64(bytesize::MB as i64); + + for _ in 0..10 { + let insert_result = insert_data(&connection); + assert!(insert_result.is_ok()); + } +} diff --git a/tests/tests.rs b/tests/tests.rs index 1030d6a..e7e3e31 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -76,4 +76,9 @@ mod tests { fn test12(test: marine_test_env::test::ModuleInterface) { test.test12() } + + #[marine_test(config_path = "../Config.toml", modules_dir = "../artifacts/")] + fn test13(test: marine_test_env::test::ModuleInterface) { + test.test13() + } }