diff options
| author | 2020-12-30 22:38:44 +0100 | |
|---|---|---|
| committer | 2020-12-30 22:38:46 +0100 | |
| commit | 6f6953bcc8bc02056bf744fe26203e9497c093bc (patch) | |
| tree | 6b73835ce9123553ad2d059f486c66b0b68790a3 /sqlite.zig | |
| parent | ci: use the github repo (diff) | |
| download | zig-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.zig | 21 |
1 files changed, 21 insertions, 0 deletions
| @@ -1258,6 +1258,27 @@ test "sqlite: statement iterator" { | |||
| 1258 | } | 1258 | } |
| 1259 | } | 1259 | } |
| 1260 | 1260 | ||
| 1261 | test "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 | |||
| 1270 | test "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 | |||
| 1261 | fn initOptions() InitOptions { | 1282 | fn initOptions() InitOptions { |
| 1262 | return .{ | 1283 | return .{ |
| 1263 | .open_flags = .{ | 1284 | .open_flags = .{ |