fix null testing

This commit is contained in:
danawan
2025-08-20 11:59:27 +07:00
parent 804bb868c7
commit 72cdd32ba1
3 changed files with 28 additions and 11 deletions

View File

@@ -2095,7 +2095,7 @@ impl Statement {
crate::schema::Type::Text => Some("TEXT".to_string()),
crate::schema::Type::Blob => Some("BLOB".to_string()),
crate::schema::Type::Numeric => Some("NUMERIC".to_string()),
crate::schema::Type::Null => Some("NULL".to_string()),
crate::schema::Type::Null => None,
}
}
_ => None,

View File

@@ -752,16 +752,25 @@ mod tests {
SQLITE_OK
);
let expected = ["INTEGER", "REAL", "TEXT", "BLOB", "NULL"];
let expected = [
Some("INTEGER"),
Some("REAL"),
Some("TEXT"),
Some("BLOB"),
None,
];
for i in 0..sqlite3_column_count(stmt) {
let decl = sqlite3_column_decltype(stmt, i);
assert!(!decl.is_null());
let s = std::ffi::CStr::from_ptr(decl)
.to_string_lossy()
.into_owned();
println!("{s}");
assert_eq!(s, expected[i as usize]);
if decl.is_null() {
assert!(expected[i as usize].is_none());
} else {
let s = std::ffi::CStr::from_ptr(decl)
.to_string_lossy()
.into_owned();
assert_eq!(Some(s.as_str()), expected[i as usize]);
}
}
assert_eq!(sqlite3_finalize(stmt), SQLITE_OK);

View File

@@ -549,12 +549,20 @@ void test_sqlite3_column_decltype()
-1, &stmt, NULL);
assert(rc == SQLITE_OK);
const char* expected[] = { "INTEGER", "REAL", "TEXT", "BLOB", "NULL"};
const char* expected[] = { "INTEGER", "REAL", "TEXT", "BLOB", NULL};
for (int i = 0; i < sqlite3_column_count(stmt); i++) {
const char* decl = sqlite3_column_decltype(stmt, i);
assert(decl != NULL);
assert(strcmp(decl, expected[i]) == 0);
//printf("DECL %s \n", decl);
//assert(decl != NULL);
//assert(strcmp(decl, expected[i]) == 0);
if (decl == NULL) {
printf("DECL (null)\n");
assert(expected[i] == NULL);
} else {
printf("DECL %s\n", decl);
assert(strcmp(decl, expected[i]) == 0);
}
}
printf("sqlite3_column_decltype test completed!\n");