diff options
| author | 2024-04-14 19:26:44 +0200 | |
|---|---|---|
| committer | 2024-04-14 19:31:53 +0200 | |
| commit | a1c695f5be5178cefaa22aac22dff0480a29e61f (patch) | |
| tree | 275544d58a5b35ef99475032eefd210fd584839c | |
| parent | build: add the workaround C file (diff) | |
| download | zig-sqlite-a1c695f5be5178cefaa22aac22dff0480a29e61f.tar.gz zig-sqlite-a1c695f5be5178cefaa22aac22dff0480a29e61f.tar.xz zig-sqlite-a1c695f5be5178cefaa22aac22dff0480a29e61f.zip | |
all: use our workaround function for SQLITE_TRANSIENT
Diffstat (limited to '')
| -rw-r--r-- | helpers.zig | 8 | ||||
| -rw-r--r-- | sqlite.zig | 2 |
2 files changed, 5 insertions, 5 deletions
diff --git a/helpers.zig b/helpers.zig index 7bb695e..b9a6131 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(result.data.len), c.SQLITE_TRANSIENT), | 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.SQLITE_TRANSIENT), | 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); |
| @@ -26,12 +26,12 @@ pub fn setResult(ctx: ?*c.sqlite3_context, result: anytype) void { | |||
| 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.SQLITE_TRANSIENT), | 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.SQLITE_TRANSIENT), | 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)), |
| 36 | }, | 36 | }, |
| 37 | else => @compileError("cannot use a result of type " ++ @typeName(ResultType)), | 37 | else => @compileError("cannot use a result of type " ++ @typeName(ResultType)), |
| @@ -1676,7 +1676,7 @@ pub const DynamicStatement = struct { | |||
| 1676 | const data: []const u8 = field[0..field.len]; | 1676 | const data: []const u8 = field[0..field.len]; |
| 1677 | 1677 | ||
| 1678 | // NOTE(vincent): The array is temporary and must be copied, therefore we use SQLITE_TRANSIENT | 1678 | // NOTE(vincent): The array is temporary and must be copied, therefore we use SQLITE_TRANSIENT |
| 1679 | const result = c.sqlite3_bind_text(self.stmt, column, data.ptr, @intCast(data.len), c.SQLITE_TRANSIENT); | 1679 | const result = c.sqlite3_bind_text(self.stmt, column, data.ptr, @intCast(data.len), c.sqliteTransientAsDestructor()); |
| 1680 | return convertResultToError(result); | 1680 | return convertResultToError(result); |
| 1681 | }, | 1681 | }, |
| 1682 | else => @compileError("cannot bind field " ++ field_name ++ " of type array of " ++ @typeName(arr.child)), | 1682 | else => @compileError("cannot bind field " ++ field_name ++ " of type array of " ++ @typeName(arr.child)), |