diff options
| author | 2025-08-09 18:57:19 +0800 | |
|---|---|---|
| committer | 2025-08-09 18:57:19 +0800 | |
| commit | e011e342420fe1f1f5d2fee932447b194f989032 (patch) | |
| tree | 01c19ac7f5b7ce540cc3fd98581e29d8f7b782bd /sqlite.zig | |
| parent | Merge pull request #188 from gracen-writes-code/master (diff) | |
| download | zig-sqlite-e011e342420fe1f1f5d2fee932447b194f989032.tar.gz zig-sqlite-e011e342420fe1f1f5d2fee932447b194f989032.tar.xz zig-sqlite-e011e342420fe1f1f5d2fee932447b194f989032.zip | |
chore: update to zig 0.15
Everything other than loadextension works. zig 0.15 remove
usingnamespac, so tha whole mechanism has to be reworked, and idk how
Diffstat (limited to 'sqlite.zig')
| -rw-r--r-- | sqlite.zig | 37 |
1 files changed, 19 insertions, 18 deletions
| @@ -132,7 +132,7 @@ pub const Blob = struct { | |||
| 132 | } | 132 | } |
| 133 | } | 133 | } |
| 134 | 134 | ||
| 135 | pub const Reader = io.Reader(*Self, errors.Error, read); | 135 | pub const Reader = io.GenericReader(*Self, errors.Error, read); |
| 136 | 136 | ||
| 137 | /// reader returns a io.Reader. | 137 | /// reader returns a io.Reader. |
| 138 | pub fn reader(self: *Self) Reader { | 138 | pub fn reader(self: *Self) Reader { |
| @@ -164,7 +164,7 @@ pub const Blob = struct { | |||
| 164 | return tmp_buffer.len; | 164 | return tmp_buffer.len; |
| 165 | } | 165 | } |
| 166 | 166 | ||
| 167 | pub const Writer = io.Writer(*Self, Error, write); | 167 | pub const Writer = io.GenericWriter(*Self, Error, write); |
| 168 | 168 | ||
| 169 | /// writer returns a io.Writer. | 169 | /// writer returns a io.Writer. |
| 170 | pub fn writer(self: *Self) Writer { | 170 | pub fn writer(self: *Self) Writer { |
| @@ -261,14 +261,14 @@ pub const Diagnostics = struct { | |||
| 261 | message: []const u8 = "", | 261 | message: []const u8 = "", |
| 262 | err: ?DetailedError = null, | 262 | err: ?DetailedError = null, |
| 263 | 263 | ||
| 264 | pub fn format(self: @This(), comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void { | 264 | pub fn format(self: @This(), writer: anytype) !void { |
| 265 | if (self.err) |err| { | 265 | if (self.err) |err| { |
| 266 | if (self.message.len > 0) { | 266 | if (self.message.len > 0) { |
| 267 | _ = try writer.print("{{message: {s}, detailed error: {s}}}", .{ self.message, err }); | 267 | _ = try writer.print("{{message: {s}, detailed error: {f}}}", .{ self.message, err }); |
| 268 | return; | 268 | return; |
| 269 | } | 269 | } |
| 270 | 270 | ||
| 271 | _ = try err.format(fmt, options, writer); | 271 | _ = try err.format(writer); |
| 272 | return; | 272 | return; |
| 273 | } | 273 | } |
| 274 | 274 | ||
| @@ -704,7 +704,7 @@ pub const Db = struct { | |||
| 704 | user_ctx, | 704 | user_ctx, |
| 705 | null, // xFunc | 705 | null, // xFunc |
| 706 | struct { | 706 | struct { |
| 707 | fn xStep(ctx: ?*c.sqlite3_context, argc: c_int, argv: [*c]?*c.sqlite3_value) callconv(.C) void { | 707 | fn xStep(ctx: ?*c.sqlite3_context, argc: c_int, argv: [*c]?*c.sqlite3_value) callconv(.c) void { |
| 708 | debug.assert(argc == real_args_len); | 708 | debug.assert(argc == real_args_len); |
| 709 | 709 | ||
| 710 | const sqlite_args = argv[0..real_args_len]; | 710 | const sqlite_args = argv[0..real_args_len]; |
| @@ -728,7 +728,7 @@ pub const Db = struct { | |||
| 728 | } | 728 | } |
| 729 | }.xStep, | 729 | }.xStep, |
| 730 | struct { | 730 | struct { |
| 731 | fn xFinal(ctx: ?*c.sqlite3_context) callconv(.C) void { | 731 | fn xFinal(ctx: ?*c.sqlite3_context) callconv(.c) void { |
| 732 | var args: std.meta.ArgsTuple(@TypeOf(finalize_func)) = undefined; | 732 | var args: std.meta.ArgsTuple(@TypeOf(finalize_func)) = undefined; |
| 733 | 733 | ||
| 734 | // Pass the function context | 734 | // Pass the function context |
| @@ -780,7 +780,7 @@ pub const Db = struct { | |||
| 780 | flags, | 780 | flags, |
| 781 | null, | 781 | null, |
| 782 | struct { | 782 | struct { |
| 783 | fn xFunc(ctx: ?*c.sqlite3_context, argc: c_int, argv: [*c]?*c.sqlite3_value) callconv(.C) void { | 783 | fn xFunc(ctx: ?*c.sqlite3_context, argc: c_int, argv: [*c]?*c.sqlite3_value) callconv(.c) void { |
| 784 | debug.assert(argc == fn_info.params.len); | 784 | debug.assert(argc == fn_info.params.len); |
| 785 | 785 | ||
| 786 | const sqlite_args = argv[0..fn_info.params.len]; | 786 | const sqlite_args = argv[0..fn_info.params.len]; |
| @@ -955,7 +955,7 @@ pub const Savepoint = struct { | |||
| 955 | 955 | ||
| 956 | // From DynamiStatement | 956 | // From DynamiStatement |
| 957 | EmptyQuery, | 957 | EmptyQuery, |
| 958 | } || std.fmt.AllocPrintError || Error; | 958 | } || std.mem.Allocator.Error || Error; |
| 959 | 959 | ||
| 960 | fn init(db: *Db, name: []const u8) InitError!Self { | 960 | fn init(db: *Db, name: []const u8) InitError!Self { |
| 961 | if (name.len < 1) return error.SavepointNameTooShort; | 961 | if (name.len < 1) return error.SavepointNameTooShort; |
| @@ -993,7 +993,7 @@ pub const Savepoint = struct { | |||
| 993 | pub fn commit(self: *Self) void { | 993 | pub fn commit(self: *Self) void { |
| 994 | self.commit_stmt.exec(.{}, .{}) catch |err| { | 994 | self.commit_stmt.exec(.{}, .{}) catch |err| { |
| 995 | const detailed_error = self.db.getDetailedError(); | 995 | const detailed_error = self.db.getDetailedError(); |
| 996 | logger.err("unable to release savepoint, error: {}, message: {s}", .{ err, detailed_error }); | 996 | logger.err("unable to release savepoint, error: {}, message: {f}", .{ err, detailed_error }); |
| 997 | }; | 997 | }; |
| 998 | self.committed = true; | 998 | self.committed = true; |
| 999 | } | 999 | } |
| @@ -1008,7 +1008,7 @@ pub const Savepoint = struct { | |||
| 1008 | 1008 | ||
| 1009 | self.rollback_stmt.exec(.{}, .{}) catch |err| { | 1009 | self.rollback_stmt.exec(.{}, .{}) catch |err| { |
| 1010 | const detailed_error = self.db.getDetailedError(); | 1010 | const detailed_error = self.db.getDetailedError(); |
| 1011 | std.debug.panic("unable to rollback transaction, error: {}, message: {s}\n", .{ err, detailed_error }); | 1011 | std.debug.panic("unable to rollback transaction, error: {}, message: {f}\n", .{ err, detailed_error }); |
| 1012 | }; | 1012 | }; |
| 1013 | } | 1013 | } |
| 1014 | }; | 1014 | }; |
| @@ -1589,7 +1589,7 @@ pub const DynamicStatement = struct { | |||
| 1589 | const result = c.sqlite3_finalize(self.stmt); | 1589 | const result = c.sqlite3_finalize(self.stmt); |
| 1590 | if (result != c.SQLITE_OK) { | 1590 | if (result != c.SQLITE_OK) { |
| 1591 | const detailed_error = getLastDetailedErrorFromDb(self.db); | 1591 | const detailed_error = getLastDetailedErrorFromDb(self.db); |
| 1592 | logger.err("unable to finalize prepared statement, result: {}, detailed error: {}", .{ result, detailed_error }); | 1592 | logger.err("unable to finalize prepared statement, result: {}, detailed error: {f}", .{ result, detailed_error }); |
| 1593 | } | 1593 | } |
| 1594 | } | 1594 | } |
| 1595 | 1595 | ||
| @@ -1598,12 +1598,12 @@ pub const DynamicStatement = struct { | |||
| 1598 | const result = c.sqlite3_clear_bindings(self.stmt); | 1598 | const result = c.sqlite3_clear_bindings(self.stmt); |
| 1599 | if (result != c.SQLITE_OK) { | 1599 | if (result != c.SQLITE_OK) { |
| 1600 | const detailed_error = getLastDetailedErrorFromDb(self.db); | 1600 | const detailed_error = getLastDetailedErrorFromDb(self.db); |
| 1601 | logger.err("unable to clear prepared statement bindings, result: {}, detailed error: {}", .{ result, detailed_error }); | 1601 | logger.err("unable to clear prepared statement bindings, result: {}, detailed error: {f}", .{ result, detailed_error }); |
| 1602 | } | 1602 | } |
| 1603 | const result2 = c.sqlite3_reset(self.stmt); | 1603 | const result2 = c.sqlite3_reset(self.stmt); |
| 1604 | if (result2 != c.SQLITE_OK) { | 1604 | if (result2 != c.SQLITE_OK) { |
| 1605 | const detailed_error = getLastDetailedErrorFromDb(self.db); | 1605 | const detailed_error = getLastDetailedErrorFromDb(self.db); |
| 1606 | logger.err("unable to reset prepared statement, result: {}, detailed error: {}", .{ result2, detailed_error }); | 1606 | logger.err("unable to reset prepared statement, result: {}, detailed error: {f}", .{ result2, detailed_error }); |
| 1607 | } | 1607 | } |
| 1608 | } | 1608 | } |
| 1609 | 1609 | ||
| @@ -3223,7 +3223,7 @@ test "sqlite: diagnostics format" { | |||
| 3223 | 3223 | ||
| 3224 | inline for (testCases) |tc| { | 3224 | inline for (testCases) |tc| { |
| 3225 | var buf: [1024]u8 = undefined; | 3225 | var buf: [1024]u8 = undefined; |
| 3226 | const str = try std.fmt.bufPrint(&buf, "my diagnostics: {s}", .{tc.input}); | 3226 | const str = try std.fmt.bufPrint(&buf, "my diagnostics: {f}", .{tc.input}); |
| 3227 | 3227 | ||
| 3228 | try testing.expectEqualStrings(tc.exp, str); | 3228 | try testing.expectEqualStrings(tc.exp, str); |
| 3229 | } | 3229 | } |
| @@ -3390,7 +3390,8 @@ const MyData = struct { | |||
| 3390 | const BaseType = []const u8; | 3390 | const BaseType = []const u8; |
| 3391 | 3391 | ||
| 3392 | pub fn bindField(self: MyData, allocator: mem.Allocator) !BaseType { | 3392 | pub fn bindField(self: MyData, allocator: mem.Allocator) !BaseType { |
| 3393 | return try std.fmt.allocPrint(allocator, "{}", .{std.fmt.fmtSliceHexLower(&self.data)}); | 3393 | const num = std.mem.bytesAsValue(u128, &self.data); |
| 3394 | return try std.fmt.allocPrint(allocator, "{s}", .{std.fmt.hex(num.*)}); | ||
| 3394 | } | 3395 | } |
| 3395 | 3396 | ||
| 3396 | pub fn readField(alloc: mem.Allocator, value: BaseType) !MyData { | 3397 | pub fn readField(alloc: mem.Allocator, value: BaseType) !MyData { |
| @@ -3797,7 +3798,7 @@ test "sqlite: create aggregate function with no aggregate context" { | |||
| 3797 | .{ .diags = &diags }, | 3798 | .{ .diags = &diags }, |
| 3798 | .{}, | 3799 | .{}, |
| 3799 | ) catch |err| { | 3800 | ) catch |err| { |
| 3800 | debug.print("err: {}\n", .{diags}); | 3801 | debug.print("err: {f}\n", .{diags}); |
| 3801 | return err; | 3802 | return err; |
| 3802 | }; | 3803 | }; |
| 3803 | 3804 | ||
| @@ -3858,7 +3859,7 @@ test "sqlite: create aggregate function with an aggregate context" { | |||
| 3858 | .{ .diags = &diags }, | 3859 | .{ .diags = &diags }, |
| 3859 | .{}, | 3860 | .{}, |
| 3860 | ) catch |err| { | 3861 | ) catch |err| { |
| 3861 | debug.print("err: {}\n", .{diags}); | 3862 | debug.print("err: {f}\n", .{diags}); |
| 3862 | return err; | 3863 | return err; |
| 3863 | }; | 3864 | }; |
| 3864 | 3865 | ||