Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion sqlite.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1951,7 +1951,7 @@ pub const DynamicStatement = struct {
pub fn all(self: *Self, comptime Type: type, allocator: mem.Allocator, options: QueryOptions, values: anytype) ![]Type {
var iter = try self.iteratorAlloc(Type, allocator, values);

var rows: std.ArrayList(Type) = .{};
var rows: std.ArrayList(Type) = .empty;
while (try iter.nextAlloc(allocator, options)) |row| {
try rows.append(allocator, row);
}
Expand Down Expand Up @@ -3558,6 +3558,24 @@ test "sqlite: oneDynamic" {
}
}

test "sqlite: dynamic statement all" {
var arena = std.heap.ArenaAllocator.init(testing.allocator);
defer arena.deinit();
const allocator = arena.allocator();

var db = try getTestDb();
defer db.deinit();
try addTestData(&db);

var stmt = try db.prepareDynamic("SELECT id FROM user WHERE age = ?");
defer stmt.deinit();

const rows = try stmt.all(usize, allocator, .{}, .{ .age = 33 });
defer allocator.free(rows);
try testing.expectEqual(@as(usize, 1), rows.len);
try testing.expectEqual(@as(usize, 20), rows[0]);
}

test "sqlite: one with all named parameters" {
var db = try getTestDb();
defer db.deinit();
Expand Down