summaryrefslogtreecommitdiff
path: root/helpers.zig
diff options
context:
space:
mode:
authorGravatar Vincent Rischmann2023-07-02 15:28:30 +0200
committerGravatar Vincent Rischmann2023-07-02 15:28:37 +0200
commitce7a6a7b657e4c8f9514d4181230068bd45823e2 (patch)
treeba788b9916d5d879737959d4823af9fbd104b4df /helpers.zig
parentfuzz: fix for latest zig (diff)
downloadzig-sqlite-ce7a6a7b657e4c8f9514d4181230068bd45823e2.tar.gz
zig-sqlite-ce7a6a7b657e4c8f9514d4181230068bd45823e2.tar.xz
zig-sqlite-ce7a6a7b657e4c8f9514d4181230068bd45823e2.zip
update for latest zig
Diffstat (limited to 'helpers.zig')
-rw-r--r--helpers.zig14
1 files changed, 7 insertions, 7 deletions
diff --git a/helpers.zig b/helpers.zig
index 7bcbabe..1a56231 100644
--- a/helpers.zig
+++ b/helpers.zig
@@ -13,8 +13,8 @@ pub fn setResult(ctx: ?*c.sqlite3_context, result: anytype) void {
13 const ResultType = @TypeOf(result); 13 const ResultType = @TypeOf(result);
14 14
15 switch (ResultType) { 15 switch (ResultType) {
16 Text => c.sqlite3_result_text(ctx, result.data.ptr, @intCast(c_int, result.data.len), c.SQLITE_TRANSIENT), 16 Text => c.sqlite3_result_text(ctx, result.data.ptr, @intCast(result.data.len), c.SQLITE_TRANSIENT),
17 Blob => c.sqlite3_result_blob(ctx, result.data.ptr, @intCast(c_int, result.data.len), c.SQLITE_TRANSIENT), 17 Blob => c.sqlite3_result_blob(ctx, result.data.ptr, @intCast(result.data.len), c.SQLITE_TRANSIENT),
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);
@@ -31,7 +31,7 @@ pub fn setResult(ctx: ?*c.sqlite3_context, result: anytype) void {
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(c_int, result.len), c.SQLITE_TRANSIENT), 34 u8 => c.sqlite3_result_text(ctx, result.ptr, @intCast(result.len), c.SQLITE_TRANSIENT),
35 else => @compileError("cannot use a result of type " ++ @typeName(ResultType)), 35 else => @compileError("cannot use a result of type " ++ @typeName(ResultType)),
36 }, 36 },
37 else => @compileError("cannot use a result of type " ++ @typeName(ResultType)), 37 else => @compileError("cannot use a result of type " ++ @typeName(ResultType)),
@@ -51,16 +51,16 @@ pub fn setTypeFromValue(comptime ArgType: type, arg: *ArgType, sqlite_value: *c.
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(ArgType, 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) {
56 const value = c.sqlite3_value_int64(sqlite_value); 56 const value = c.sqlite3_value_int64(sqlite_value);
57 arg.* = @intCast(ArgType, value); 57 arg.* = @intCast(value);
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(ArgType, 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);
@@ -79,7 +79,7 @@ pub fn setTypeFromValue(comptime ArgType: type, arg: *ArgType, sqlite_value: *c.
79} 79}
80 80
81fn sliceFromValue(sqlite_value: *c.sqlite3_value) []const u8 { 81fn sliceFromValue(sqlite_value: *c.sqlite3_value) []const u8 {
82 const size = @intCast(usize, c.sqlite3_value_bytes(sqlite_value)); 82 const size: usize = @intCast(c.sqlite3_value_bytes(sqlite_value));
83 83
84 const value = c.sqlite3_value_text(sqlite_value); 84 const value = c.sqlite3_value_text(sqlite_value);
85 debug.assert(value != null); // TODO(vincent): how do we handle this properly ? 85 debug.assert(value != null); // TODO(vincent): how do we handle this properly ?