summaryrefslogtreecommitdiff
path: root/sqlite.zig
diff options
context:
space:
mode:
Diffstat (limited to 'sqlite.zig')
-rw-r--r--sqlite.zig45
1 files changed, 1 insertions, 44 deletions
diff --git a/sqlite.zig b/sqlite.zig
index 6c6f6af..6af1d04 100644
--- a/sqlite.zig
+++ b/sqlite.zig
@@ -19,6 +19,7 @@ pub const DetailedError = errors.DetailedError;
19const getLastDetailedErrorFromDb = errors.getLastDetailedErrorFromDb; 19const getLastDetailedErrorFromDb = errors.getLastDetailedErrorFromDb;
20const getDetailedErrorFromResultCode = errors.getDetailedErrorFromResultCode; 20const getDetailedErrorFromResultCode = errors.getDetailedErrorFromResultCode;
21 21
22const getTestDb = @import("test.zig").getTestDb;
22const helpers = @import("helpers.zig"); 23const helpers = @import("helpers.zig");
23 24
24const logger = std.log.scoped(.sqlite); 25const logger = std.log.scoped(.sqlite);
@@ -3302,50 +3303,6 @@ test "sqlite: two nested savepoints with outer failure" {
3302 try testing.expectEqual(@as(usize, 0), rows.len); 3303 try testing.expectEqual(@as(usize, 0), rows.len);
3303} 3304}
3304 3305
3305fn getTestDb() !Db {
3306 var buf: [1024]u8 = undefined;
3307 var fba = std.heap.FixedBufferAllocator.init(&buf);
3308
3309 var mode = dbMode(fba.allocator());
3310
3311 return try Db.init(.{
3312 .open_flags = .{
3313 .write = true,
3314 .create = true,
3315 },
3316 .mode = mode,
3317 });
3318}
3319
3320fn tmpDbPath(allocator: mem.Allocator) ![:0]const u8 {
3321 const tmp_dir = testing.tmpDir(.{});
3322
3323 const path = try std.fs.path.join(allocator, &[_][]const u8{
3324 "zig-cache",
3325 "tmp",
3326 &tmp_dir.sub_path,
3327 "zig-sqlite.db",
3328 });
3329 defer allocator.free(path);
3330
3331 return allocator.dupeZ(u8, path);
3332}
3333
3334fn dbMode(allocator: mem.Allocator) Db.Mode {
3335 return if (build_options.in_memory) blk: {
3336 break :blk .{ .Memory = {} };
3337 } else blk: {
3338 if (build_options.dbfile) |dbfile| {
3339 return .{ .File = allocator.dupeZ(u8, dbfile) catch unreachable };
3340 }
3341
3342 const path = tmpDbPath(allocator) catch unreachable;
3343
3344 std.fs.cwd().deleteFile(path) catch {};
3345 break :blk .{ .File = path };
3346 };
3347}
3348
3349const MyData = struct { 3306const MyData = struct {
3350 data: [16]u8, 3307 data: [16]u8,
3351 3308