Sqlite: expose native primary/extended result codes structurally (VL-SQLITE-01)
This commit is contained in:
1 parent
a29c9475f2
commit
0e8ee1848d
2 files changed
+97
-1
No files matched your search
@@ -637,3 +637,40 @@ Void::Testing::Test sqlite_transaction_reports_automatic_rollback()
|
||||
Void::Testing::require(db.exec("PRAGMA max_page_count=1073741823").has_value());
|
||||
}
|
||||
}
|
||||
|
||||
Void::Testing::Test sqlite_native_result_codes_are_structural()
|
||||
{
|
||||
TempSqliteDir dir;
|
||||
const auto db_path = dir.path / "native.db";
|
||||
auto db_res = open_database(db_path);
|
||||
Void::Testing::require(db_res.has_value());
|
||||
auto db = std::move(*db_res);
|
||||
|
||||
Void::Testing::require(
|
||||
db.exec("CREATE TABLE u(id INTEGER PRIMARY KEY, email TEXT UNIQUE NOT NULL)")
|
||||
.has_value());
|
||||
Void::Testing::require(
|
||||
db.exec("INSERT INTO u(id, email) VALUES(1, 'a@example.com')").has_value());
|
||||
|
||||
// A UNIQUE violation exposes the fine-grained extended code structurally.
|
||||
auto duplicate = db.exec("INSERT INTO u(id, email) VALUES(2, 'a@example.com')");
|
||||
Void::Testing::require(!duplicate.has_value());
|
||||
auto native = sqlite_native_code(duplicate.error());
|
||||
Void::Testing::require(native.has_value());
|
||||
Void::Testing::expect_eq(native->primary, SQLITE_CONSTRAINT);
|
||||
Void::Testing::expect_eq(native->extended, SQLITE_CONSTRAINT_UNIQUE);
|
||||
|
||||
// Same primary code, different extended reason.
|
||||
auto null_email = db.exec("INSERT INTO u(id, email) VALUES(3, NULL)");
|
||||
Void::Testing::require(!null_email.has_value());
|
||||
auto null_native = sqlite_native_code(null_email.error());
|
||||
Void::Testing::require(null_native.has_value());
|
||||
Void::Testing::expect_eq(null_native->primary, SQLITE_CONSTRAINT);
|
||||
Void::Testing::expect_eq(null_native->extended, SQLITE_CONSTRAINT_NOTNULL);
|
||||
Void::Testing::expect(null_native->extended != native->extended);
|
||||
|
||||
// Validation errors carry no native SQLite code.
|
||||
auto invalid = db.prepare("SELECT 1; SELECT 2");
|
||||
Void::Testing::require(!invalid.has_value());
|
||||
Void::Testing::expect(!sqlite_native_code(invalid.error()).has_value());
|
||||
}
|
||||
Reference in new issue
Block a user