diff options
| author | 2025-08-20 01:16:42 +0200 | |
|---|---|---|
| committer | 2025-08-20 01:16:42 +0200 | |
| commit | 812e0b51a11812c8ed712462e13c3743fb85f7e9 (patch) | |
| tree | 48314aee4bb0f5bbcac5191a5b39707037d5c047 /sqlite.zig | |
| parent | Merge pull request #193 from mattnite/arraylist (diff) | |
| download | zig-sqlite-812e0b51a11812c8ed712462e13c3743fb85f7e9.tar.gz zig-sqlite-812e0b51a11812c8ed712462e13c3743fb85f7e9.tar.xz zig-sqlite-812e0b51a11812c8ed712462e13c3743fb85f7e9.zip | |
all: fix for latest zig
Diffstat (limited to 'sqlite.zig')
| -rw-r--r-- | sqlite.zig | 33 |
1 files changed, 17 insertions, 16 deletions
| @@ -1967,7 +1967,7 @@ pub const DynamicStatement = struct { | |||
| 1967 | pub fn all(self: *Self, comptime Type: type, allocator: mem.Allocator, options: QueryOptions, values: anytype) ![]Type { | 1967 | pub fn all(self: *Self, comptime Type: type, allocator: mem.Allocator, options: QueryOptions, values: anytype) ![]Type { |
| 1968 | var iter = try self.iteratorAlloc(Type, allocator, values); | 1968 | var iter = try self.iteratorAlloc(Type, allocator, values); |
| 1969 | 1969 | ||
| 1970 | var rows = std.ArrayList(Type).init(allocator); | 1970 | var rows: std.ArrayList(Type) = .{}; |
| 1971 | while (try iter.nextAlloc(allocator, options)) |row| { | 1971 | while (try iter.nextAlloc(allocator, options)) |row| { |
| 1972 | try rows.append(row); | 1972 | try rows.append(row); |
| 1973 | } | 1973 | } |
| @@ -2257,12 +2257,12 @@ pub fn Statement(comptime opts: StatementOptions, comptime query: anytype) type | |||
| 2257 | pub fn all(self: *Self, comptime Type: type, allocator: mem.Allocator, options: QueryOptions, values: anytype) ![]Type { | 2257 | pub fn all(self: *Self, comptime Type: type, allocator: mem.Allocator, options: QueryOptions, values: anytype) ![]Type { |
| 2258 | var iter = try self.iteratorAlloc(Type, allocator, values); | 2258 | var iter = try self.iteratorAlloc(Type, allocator, values); |
| 2259 | 2259 | ||
| 2260 | var rows = std.ArrayList(Type).init(allocator); | 2260 | var rows: std.ArrayList(Type) = .{}; |
| 2261 | while (try iter.nextAlloc(allocator, options)) |row| { | 2261 | while (try iter.nextAlloc(allocator, options)) |row| { |
| 2262 | try rows.append(row); | 2262 | try rows.append(allocator, row); |
| 2263 | } | 2263 | } |
| 2264 | 2264 | ||
| 2265 | return rows.toOwnedSlice(); | 2265 | return rows.toOwnedSlice(allocator); |
| 2266 | } | 2266 | } |
| 2267 | }; | 2267 | }; |
| 2268 | } | 2268 | } |
| @@ -3020,13 +3020,13 @@ test "sqlite: statement iterator" { | |||
| 3020 | var stmt = try db.prepare("INSERT INTO user(name, id, age, weight, favorite_color) VALUES(?{[]const u8}, ?{usize}, ?{usize}, ?{f32}, ?{[]const u8})"); | 3020 | var stmt = try db.prepare("INSERT INTO user(name, id, age, weight, favorite_color) VALUES(?{[]const u8}, ?{usize}, ?{usize}, ?{f32}, ?{[]const u8})"); |
| 3021 | defer stmt.deinit(); | 3021 | defer stmt.deinit(); |
| 3022 | 3022 | ||
| 3023 | var expected_rows = std.ArrayList(TestUser).init(allocator); | 3023 | var expected_rows: std.ArrayList(TestUser) = .{}; |
| 3024 | var i: usize = 0; | 3024 | var i: usize = 0; |
| 3025 | while (i < 20) : (i += 1) { | 3025 | while (i < 20) : (i += 1) { |
| 3026 | const name = try std.fmt.allocPrint(allocator, "Vincent {d}", .{i}); | 3026 | const name = try std.fmt.allocPrint(allocator, "Vincent {d}", .{i}); |
| 3027 | const user = TestUser{ .id = i, .name = name, .age = i + 200, .weight = @floatFromInt(i + 200), .favorite_color = .indigo }; | 3027 | const user = TestUser{ .id = i, .name = name, .age = i + 200, .weight = @floatFromInt(i + 200), .favorite_color = .indigo }; |
| 3028 | 3028 | ||
| 3029 | try expected_rows.append(user); | 3029 | try expected_rows.append(allocator, user); |
| 3030 | 3030 | ||
| 3031 | stmt.reset(); | 3031 | stmt.reset(); |
| 3032 | try stmt.exec(.{}, user); | 3032 | try stmt.exec(.{}, user); |
| @@ -3047,9 +3047,9 @@ test "sqlite: statement iterator" { | |||
| 3047 | 3047 | ||
| 3048 | var iter = try stmt2.iterator(RowType, .{}); | 3048 | var iter = try stmt2.iterator(RowType, .{}); |
| 3049 | 3049 | ||
| 3050 | var rows = std.ArrayList(RowType).init(allocator); | 3050 | var rows: std.ArrayList(RowType) = .{}; |
| 3051 | while (try iter.next(.{})) |row| { | 3051 | while (try iter.next(.{})) |row| { |
| 3052 | try rows.append(row); | 3052 | try rows.append(allocator, row); |
| 3053 | } | 3053 | } |
| 3054 | 3054 | ||
| 3055 | // Check the data | 3055 | // Check the data |
| @@ -3074,9 +3074,9 @@ test "sqlite: statement iterator" { | |||
| 3074 | 3074 | ||
| 3075 | var iter = try stmt2.iterator(RowType, .{}); | 3075 | var iter = try stmt2.iterator(RowType, .{}); |
| 3076 | 3076 | ||
| 3077 | var rows = std.ArrayList(RowType).init(allocator); | 3077 | var rows: std.ArrayList(RowType) = .{}; |
| 3078 | while (try iter.nextAlloc(allocator, .{})) |row| { | 3078 | while (try iter.nextAlloc(allocator, .{})) |row| { |
| 3079 | try rows.append(row); | 3079 | try rows.append(allocator, row); |
| 3080 | } | 3080 | } |
| 3081 | 3081 | ||
| 3082 | // Check the data | 3082 | // Check the data |
| @@ -3459,10 +3459,10 @@ test "sqlite: bind runtime slice" { | |||
| 3459 | const allocator = arena.allocator(); | 3459 | const allocator = arena.allocator(); |
| 3460 | 3460 | ||
| 3461 | // creating array list on heap so that it's deemed runtime size | 3461 | // creating array list on heap so that it's deemed runtime size |
| 3462 | var list = std.ArrayList([]const u8).init(allocator); | 3462 | var list: std.ArrayList([]const u8) = .{}; |
| 3463 | defer list.deinit(); | 3463 | defer list.deinit(allocator); |
| 3464 | try list.append("this is some data"); | 3464 | try list.append(allocator, "this is some data"); |
| 3465 | const args = try list.toOwnedSlice(); | 3465 | const args = try list.toOwnedSlice(allocator); |
| 3466 | 3466 | ||
| 3467 | var db = try getTestDb(); | 3467 | var db = try getTestDb(); |
| 3468 | defer db.deinit(); | 3468 | defer db.deinit(); |
| @@ -3871,13 +3871,14 @@ test "sqlite: create aggregate function with an aggregate context" { | |||
| 3871 | test "sqlite: empty slice" { | 3871 | test "sqlite: empty slice" { |
| 3872 | var arena = std.heap.ArenaAllocator.init(testing.allocator); | 3872 | var arena = std.heap.ArenaAllocator.init(testing.allocator); |
| 3873 | defer arena.deinit(); | 3873 | defer arena.deinit(); |
| 3874 | const allocator = arena.allocator(); | ||
| 3874 | 3875 | ||
| 3875 | var db = try getTestDb(); | 3876 | var db = try getTestDb(); |
| 3876 | defer db.deinit(); | 3877 | defer db.deinit(); |
| 3877 | try addTestData(&db); | 3878 | try addTestData(&db); |
| 3878 | 3879 | ||
| 3879 | var list = std.ArrayList(u8).init(arena.allocator()); | 3880 | var list: std.ArrayList(u8) = .{}; |
| 3880 | const ptr = try list.toOwnedSlice(); | 3881 | const ptr = try list.toOwnedSlice(allocator); |
| 3881 | 3882 | ||
| 3882 | try db.exec("INSERT INTO article(author_id, data) VALUES(?, ?)", .{}, .{ 1, ptr }); | 3883 | try db.exec("INSERT INTO article(author_id, data) VALUES(?, ?)", .{}, .{ 1, ptr }); |
| 3883 | 3884 | ||