From bb7dde4d25eaacd105f860af86a2c9cbca18387f Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 23 Apr 2022 19:27:40 -0300 Subject: add compile error when passing non-struct to Statement.bind --- sqlite.zig | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'sqlite.zig') diff --git a/sqlite.zig b/sqlite.zig index b1d5c7b..fd52691 100644 --- a/sqlite.zig +++ b/sqlite.zig @@ -2024,6 +2024,10 @@ pub fn Statement(comptime opts: StatementOptions, comptime query: ParsedQuery) t /// The types are checked at comptime. fn bind(self: *Self, options: anytype, values: anytype) !void { const StructType = @TypeOf(values); + if (!comptime std.meta.trait.is(.Struct)(@TypeOf(values))) { + @compileError("options passed to Statement.bind must be a struct (DynamicStatement supports runtime slices)"); + } + const StructTypeInfo = @typeInfo(StructType).Struct; if (comptime query.nb_bind_markers != StructTypeInfo.fields.len) { @@ -3424,6 +3428,7 @@ test "sqlite: bind runtime slice" { try stmt.exec(.{}, args); } } + test "sqlite: prepareDynamic" { var arena = std.heap.ArenaAllocator.init(testing.allocator); defer arena.deinit(); -- cgit v1.2.3