summaryrefslogtreecommitdiff
path: root/sqlite.zig
diff options
context:
space:
mode:
authorGravatar Vincent Rischmann2020-12-30 22:38:44 +0100
committerGravatar Vincent Rischmann2020-12-30 22:38:46 +0100
commit6f6953bcc8bc02056bf744fe26203e9497c093bc (patch)
tree6b73835ce9123553ad2d059f486c66b0b68790a3 /sqlite.zig
parentci: use the github repo (diff)
downloadzig-sqlite-6f6953bcc8bc02056bf744fe26203e9497c093bc.tar.gz
zig-sqlite-6f6953bcc8bc02056bf744fe26203e9497c093bc.tar.xz
zig-sqlite-6f6953bcc8bc02056bf744fe26203e9497c093bc.zip
add more tests for failures
* one for Db.init * one for Db.prepare
Diffstat (limited to 'sqlite.zig')
-rw-r--r--sqlite.zig21
1 files changed, 21 insertions, 0 deletions
diff --git a/sqlite.zig b/sqlite.zig
index 5c0271d..0f901de 100644
--- a/sqlite.zig
+++ b/sqlite.zig
@@ -1258,6 +1258,27 @@ test "sqlite: statement iterator" {
1258 } 1258 }
1259} 1259}
1260 1260
1261test "sqlite: failing open" {
1262 var db: Db = undefined;
1263 const res = db.init(.{
1264 .open_flags = .{},
1265 .mode = .{ .File = "/tmp/not_existing.db" },
1266 });
1267 testing.expectError(error.CannotOpenDatabase, res);
1268}
1269
1270test "sqlite: failing prepare statement" {
1271 var db: Db = undefined;
1272 try db.init(initOptions());
1273
1274 const result = db.prepare("SELECT id FROM foobar");
1275 testing.expectError(error.CannotPrepareStatement, result);
1276
1277 const detailed_err = db.getDetailedError();
1278 testing.expectEqual(@as(usize, 1), detailed_err.code);
1279 testing.expectEqualStrings("no such table: foobar", detailed_err.message);
1280}
1281
1261fn initOptions() InitOptions { 1282fn initOptions() InitOptions {
1262 return .{ 1283 return .{
1263 .open_flags = .{ 1284 .open_flags = .{