diff options
Diffstat (limited to '')
| -rw-r--r-- | helpers.zig | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/helpers.zig b/helpers.zig index b9a6131..dd7fd4f 100644 --- a/helpers.zig +++ b/helpers.zig | |||
| @@ -16,20 +16,20 @@ pub fn setResult(ctx: ?*c.sqlite3_context, result: anytype) void { | |||
| 16 | Text => c.sqlite3_result_text(ctx, result.data.ptr, @intCast(result.data.len), c.sqliteTransientAsDestructor()), | 16 | Text => c.sqlite3_result_text(ctx, result.data.ptr, @intCast(result.data.len), c.sqliteTransientAsDestructor()), |
| 17 | Blob => c.sqlite3_result_blob(ctx, result.data.ptr, @intCast(result.data.len), c.sqliteTransientAsDestructor()), | 17 | Blob => c.sqlite3_result_blob(ctx, result.data.ptr, @intCast(result.data.len), c.sqliteTransientAsDestructor()), |
| 18 | else => switch (@typeInfo(ResultType)) { | 18 | else => switch (@typeInfo(ResultType)) { |
| 19 | .Int => |info| if ((info.bits + if (info.signedness == .unsigned) 1 else 0) <= 32) { | 19 | .int => |info| if ((info.bits + if (info.signedness == .unsigned) 1 else 0) <= 32) { |
| 20 | c.sqlite3_result_int(ctx, result); | 20 | c.sqlite3_result_int(ctx, result); |
| 21 | } else if ((info.bits + if (info.signedness == .unsigned) 1 else 0) <= 64) { | 21 | } else if ((info.bits + if (info.signedness == .unsigned) 1 else 0) <= 64) { |
| 22 | c.sqlite3_result_int64(ctx, result); | 22 | c.sqlite3_result_int64(ctx, result); |
| 23 | } else { | 23 | } else { |
| 24 | @compileError("integer " ++ @typeName(ResultType) ++ " is not representable in sqlite"); | 24 | @compileError("integer " ++ @typeName(ResultType) ++ " is not representable in sqlite"); |
| 25 | }, | 25 | }, |
| 26 | .Float => c.sqlite3_result_double(ctx, result), | 26 | .float => c.sqlite3_result_double(ctx, result), |
| 27 | .Bool => c.sqlite3_result_int(ctx, if (result) 1 else 0), | 27 | .bool => c.sqlite3_result_int(ctx, if (result) 1 else 0), |
| 28 | .Array => |arr| switch (arr.child) { | 28 | .array => |arr| switch (arr.child) { |
| 29 | u8 => c.sqlite3_result_blob(ctx, &result, arr.len, c.sqliteTransientAsDestructor()), | 29 | u8 => c.sqlite3_result_blob(ctx, &result, arr.len, c.sqliteTransientAsDestructor()), |
| 30 | else => @compileError("cannot use a result of type " ++ @typeName(ResultType)), | 30 | else => @compileError("cannot use a result of type " ++ @typeName(ResultType)), |
| 31 | }, | 31 | }, |
| 32 | .Pointer => |ptr| switch (ptr.size) { | 32 | .pointer => |ptr| switch (ptr.size) { |
| 33 | .Slice => switch (ptr.child) { | 33 | .Slice => switch (ptr.child) { |
| 34 | u8 => c.sqlite3_result_text(ctx, result.ptr, @intCast(result.len), c.sqliteTransientAsDestructor()), | 34 | u8 => c.sqlite3_result_text(ctx, result.ptr, @intCast(result.len), c.sqliteTransientAsDestructor()), |
| 35 | else => @compileError("cannot use a result of type " ++ @typeName(ResultType)), | 35 | else => @compileError("cannot use a result of type " ++ @typeName(ResultType)), |
| @@ -49,7 +49,7 @@ pub fn setTypeFromValue(comptime ArgType: type, arg: *ArgType, sqlite_value: *c. | |||
| 49 | Text => arg.*.data = sliceFromValue(sqlite_value), | 49 | Text => arg.*.data = sliceFromValue(sqlite_value), |
| 50 | Blob => arg.*.data = sliceFromValue(sqlite_value), | 50 | Blob => arg.*.data = sliceFromValue(sqlite_value), |
| 51 | else => switch (@typeInfo(ArgType)) { | 51 | else => switch (@typeInfo(ArgType)) { |
| 52 | .Int => |info| if ((info.bits + if (info.signedness == .unsigned) 1 else 0) <= 32) { | 52 | .int => |info| if ((info.bits + if (info.signedness == .unsigned) 1 else 0) <= 32) { |
| 53 | const value = c.sqlite3_value_int(sqlite_value); | 53 | const value = c.sqlite3_value_int(sqlite_value); |
| 54 | arg.* = @intCast(value); | 54 | arg.* = @intCast(value); |
| 55 | } else if ((info.bits + if (info.signedness == .unsigned) 1 else 0) <= 64) { | 55 | } else if ((info.bits + if (info.signedness == .unsigned) 1 else 0) <= 64) { |
| @@ -58,15 +58,15 @@ pub fn setTypeFromValue(comptime ArgType: type, arg: *ArgType, sqlite_value: *c. | |||
| 58 | } else { | 58 | } else { |
| 59 | @compileError("integer " ++ @typeName(ArgType) ++ " is not representable in sqlite"); | 59 | @compileError("integer " ++ @typeName(ArgType) ++ " is not representable in sqlite"); |
| 60 | }, | 60 | }, |
| 61 | .Float => { | 61 | .float => { |
| 62 | const value = c.sqlite3_value_double(sqlite_value); | 62 | const value = c.sqlite3_value_double(sqlite_value); |
| 63 | arg.* = @floatCast(value); | 63 | arg.* = @floatCast(value); |
| 64 | }, | 64 | }, |
| 65 | .Bool => { | 65 | .bool => { |
| 66 | const value = c.sqlite3_value_int(sqlite_value); | 66 | const value = c.sqlite3_value_int(sqlite_value); |
| 67 | arg.* = value > 0; | 67 | arg.* = value > 0; |
| 68 | }, | 68 | }, |
| 69 | .Pointer => |ptr| switch (ptr.size) { | 69 | .pointer => |ptr| switch (ptr.size) { |
| 70 | .Slice => switch (ptr.child) { | 70 | .Slice => switch (ptr.child) { |
| 71 | u8 => arg.* = sliceFromValue(sqlite_value), | 71 | u8 => arg.* = sliceFromValue(sqlite_value), |
| 72 | else => @compileError("cannot use an argument of type " ++ @typeName(ArgType)), | 72 | else => @compileError("cannot use an argument of type " ++ @typeName(ArgType)), |
| @@ -98,7 +98,7 @@ pub fn hasFn(comptime T: type, comptime name: []const u8) bool { | |||
| 98 | const decl_type_info = @typeInfo(decl_type); | 98 | const decl_type_info = @typeInfo(decl_type); |
| 99 | 99 | ||
| 100 | return switch (decl_type_info) { | 100 | return switch (decl_type_info) { |
| 101 | .Fn => true, | 101 | .@"fn" => true, |
| 102 | else => false, | 102 | else => false, |
| 103 | }; | 103 | }; |
| 104 | } | 104 | } |