mod common;
#[test]
fn test_unload_database_and_release() {
let params = common::test_hyper_params("test_unload_database_and_release")
.expect("Failed to create test parameters");
let hyper = hyperdb_api::HyperProcess::new(None, Some(¶ms))
.expect("Failed to create Hyper process");
let temp_dir = tempfile::tempdir().expect("Failed to create temp directory");
let db_path = temp_dir.path().join("test_unload.hyper");
let conn =
hyperdb_api::Connection::new(&hyper, &db_path, hyperdb_api::CreateMode::CreateAndReplace)
.expect("Failed to create database");
conn.execute_command("CREATE TABLE test (id INT, name TEXT)")
.expect("Failed to create table");
conn.execute_command("INSERT INTO test VALUES (1, 'Hello')")
.expect("Failed to insert data");
let count: i64 = conn
.fetch_scalar("SELECT COUNT(*) FROM test")
.expect("Failed to fetch count");
assert_eq!(count, 1);
let unload_result = conn.unload_database();
if unload_result.is_err() {
eprintln!("UNLOAD DATABASE not supported, skipping test");
return;
}
let count_after_unload: i64 = conn
.fetch_scalar("SELECT COUNT(*) FROM test")
.expect("Query after UNLOAD DATABASE should succeed");
assert_eq!(count_after_unload, 1);
conn.unload_database()
.expect("UNLOAD DATABASE should succeed again");
conn.unload_release()
.expect("UNLOAD RELEASE should succeed");
let result = conn.fetch_scalar::<i64, _>("SELECT COUNT(*) FROM test");
assert!(result.is_err(), "Query after UNLOAD RELEASE should fail");
}