Skip to content

Commit

Permalink
accomodate Zig changes to std.builtin.Type
Browse files Browse the repository at this point in the history
  • Loading branch information
karlseguin committed Aug 29, 2024
1 parent 997d3ac commit f6dc335
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions zqlite.zig
Original file line number Diff line number Diff line change
Expand Up @@ -157,20 +157,20 @@ fn bindValue(comptime T: type, stmt: *c.sqlite3_stmt, value: anytype, bind_index
var rc: c_int = 0;

switch (@typeInfo(T)) {
.Null => rc = c.sqlite3_bind_null(stmt, bind_index),
.Int, .ComptimeInt => rc = c.sqlite3_bind_int64(stmt, bind_index, @intCast(value)),
.Float, .ComptimeFloat => rc = c.sqlite3_bind_double(stmt, bind_index, value),
.Bool => {
.null => rc = c.sqlite3_bind_null(stmt, bind_index),
.int, .comptime_int => rc = c.sqlite3_bind_int64(stmt, bind_index, @intCast(value)),
.float, .comptime_float => rc = c.sqlite3_bind_double(stmt, bind_index, value),
.bool => {
if (value) {
rc = c.sqlite3_bind_int64(stmt, bind_index, @intCast(1));
} else {
rc = c.sqlite3_bind_int64(stmt, bind_index, @intCast(0));
}
},
.Pointer => |ptr| {
.pointer => |ptr| {
switch (ptr.size) {
.One => switch (@typeInfo(ptr.child)) {
.Array => |arr| {
.array => |arr| {
if (arr.child == u8) {
rc = c.sqlite3_bind_text(stmt, bind_index, value.ptr, @intCast(value.len), c.SQLITE_STATIC);
} else {
Expand All @@ -186,15 +186,15 @@ fn bindValue(comptime T: type, stmt: *c.sqlite3_stmt, value: anytype, bind_index
else => bindError(T),
}
},
.Array => return bindValue(@TypeOf(&value), stmt, &value, bind_index),
.Optional => |opt| {
.array => return bindValue(@TypeOf(&value), stmt, &value, bind_index),
.optional => |opt| {
if (value) |v| {
return bindValue(opt.child, stmt, v, bind_index);
} else {
rc = c.sqlite3_bind_null(stmt, bind_index);
}
},
.Struct => {
.@"struct" => {
if (T == Blob) {
const inner = value.value;
rc = c.sqlite3_bind_blob(stmt, bind_index, @ptrCast(inner), @intCast(inner.len), c.SQLITE_STATIC);
Expand Down

0 comments on commit f6dc335

Please sign in to comment.