diff options
| author | 2022-04-23 19:27:40 -0300 | |
|---|---|---|
| committer | 2022-04-24 11:22:42 +0200 | |
| commit | bb7dde4d25eaacd105f860af86a2c9cbca18387f (patch) | |
| tree | 5ceef042094692c36d151bf2324cb20b7edff771 /sqlite.zig | |
| parent | add test for runtime slices as DynamicStatement args (diff) | |
| download | zig-sqlite-bb7dde4d25eaacd105f860af86a2c9cbca18387f.tar.gz zig-sqlite-bb7dde4d25eaacd105f860af86a2c9cbca18387f.tar.xz zig-sqlite-bb7dde4d25eaacd105f860af86a2c9cbca18387f.zip | |
add compile error when passing non-struct to Statement.bind
Diffstat (limited to '')
| -rw-r--r-- | sqlite.zig | 5 |
1 files changed, 5 insertions, 0 deletions
| @@ -2024,6 +2024,10 @@ pub fn Statement(comptime opts: StatementOptions, comptime query: ParsedQuery) t | |||
| 2024 | /// The types are checked at comptime. | 2024 | /// The types are checked at comptime. |
| 2025 | fn bind(self: *Self, options: anytype, values: anytype) !void { | 2025 | fn bind(self: *Self, options: anytype, values: anytype) !void { |
| 2026 | const StructType = @TypeOf(values); | 2026 | const StructType = @TypeOf(values); |
| 2027 | if (!comptime std.meta.trait.is(.Struct)(@TypeOf(values))) { | ||
| 2028 | @compileError("options passed to Statement.bind must be a struct (DynamicStatement supports runtime slices)"); | ||
| 2029 | } | ||
| 2030 | |||
| 2027 | const StructTypeInfo = @typeInfo(StructType).Struct; | 2031 | const StructTypeInfo = @typeInfo(StructType).Struct; |
| 2028 | 2032 | ||
| 2029 | if (comptime query.nb_bind_markers != StructTypeInfo.fields.len) { | 2033 | if (comptime query.nb_bind_markers != StructTypeInfo.fields.len) { |
| @@ -3424,6 +3428,7 @@ test "sqlite: bind runtime slice" { | |||
| 3424 | try stmt.exec(.{}, args); | 3428 | try stmt.exec(.{}, args); |
| 3425 | } | 3429 | } |
| 3426 | } | 3430 | } |
| 3431 | |||
| 3427 | test "sqlite: prepareDynamic" { | 3432 | test "sqlite: prepareDynamic" { |
| 3428 | var arena = std.heap.ArenaAllocator.init(testing.allocator); | 3433 | var arena = std.heap.ArenaAllocator.init(testing.allocator); |
| 3429 | defer arena.deinit(); | 3434 | defer arena.deinit(); |