From 7208d3e9ebc05591059f8244dee88bd91a73dee3 Mon Sep 17 00:00:00 2001 From: Ekaitz Zarraga Date: Mon, 19 Aug 2024 00:47:34 +0200 Subject: PreparedStatement: work with strings --- src/duckdb/PreparedStatement.zig | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'src/duckdb/PreparedStatement.zig') diff --git a/src/duckdb/PreparedStatement.zig b/src/duckdb/PreparedStatement.zig index 5e3229e..237152c 100644 --- a/src/duckdb/PreparedStatement.zig +++ b/src/duckdb/PreparedStatement.zig @@ -73,12 +73,14 @@ pub fn bindString(self: *Self, param: []const u8) !void{ self._current_binding += 1; } + pub fn bind(self: *Self, param: anytype) !void { switch (@typeInfo(@TypeOf(param))) { .Null => return try self.bindNull(), .Bool => return try self.bindBool(param), .Int => return try self.bindInt(param), .Float => return try self.bindFloat(param), + .Vector, .Array => |arr| { if (arr.child == u8){ return try self.bindString(param); @@ -86,12 +88,22 @@ pub fn bind(self: *Self, param: anytype) !void { return error.UnbindableType; } }, - .Pointer => |ptr| { - if (ptr.size == .Slice and ptr.child == u8){ - return try self.bindString(param); - } else { - return error.UnbindableType; - } + .Pointer => |info| switch (info.size) { + .One, .Many, .C, .Slice => switch (@typeInfo(info.child)) { + .Vector => |arr| + if (arr.child == u8){ + return try self.bindString(param); + } else { + return error.UnbindableType; + }, + .Array => |arr| + if (arr.child == u8){ + return try self.bindString(param); + } else { + return error.UnbindableType; + }, + else => {}, + }, }, else => @compileError("Invalid type for binding: " ++ @typeName(@TypeOf(param))), -- cgit v1.2.3