diff options
| author | 2025-08-09 18:57:19 +0800 | |
|---|---|---|
| committer | 2025-08-09 18:57:19 +0800 | |
| commit | e011e342420fe1f1f5d2fee932447b194f989032 (patch) | |
| tree | 01c19ac7f5b7ce540cc3fd98581e29d8f7b782bd /vtab.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 '')
| -rw-r--r-- | vtab.zig | 38 |
1 files changed, 19 insertions, 19 deletions
| @@ -50,7 +50,7 @@ pub const VTabDiagnostics = struct { | |||
| 50 | error_message: []const u8 = "unknown error", | 50 | error_message: []const u8 = "unknown error", |
| 51 | 51 | ||
| 52 | pub fn setErrorMessage(self: *Self, comptime format_string: []const u8, values: anytype) void { | 52 | pub fn setErrorMessage(self: *Self, comptime format_string: []const u8, values: anytype) void { |
| 53 | self.error_message = fmt.allocPrint(self.allocator, format_string, values) catch |err| switch (err) { | 53 | self.error_message = fmt.allocPrintSentinel(self.allocator, format_string, values, 0) catch |err| switch (err) { |
| 54 | error.OutOfMemory => "can't set diagnostic message, out of memory", | 54 | error.OutOfMemory => "can't set diagnostic message, out of memory", |
| 55 | }; | 55 | }; |
| 56 | } | 56 | } |
| @@ -717,7 +717,7 @@ pub fn VirtualTable( | |||
| 717 | return try State.init(module_context, table); | 717 | return try State.init(module_context, table); |
| 718 | } | 718 | } |
| 719 | 719 | ||
| 720 | fn xCreate(db: ?*c.sqlite3, module_context_ptr: ?*anyopaque, argc: c_int, argv: [*c]const [*c]const u8, vtab: [*c][*c]c.sqlite3_vtab, err_str: [*c][*c]const u8) callconv(.C) c_int { | 720 | fn xCreate(db: ?*c.sqlite3, module_context_ptr: ?*anyopaque, argc: c_int, argv: [*c]const [*c]const u8, vtab: [*c][*c]c.sqlite3_vtab, err_str: [*c][*c]const u8) callconv(.c) c_int { |
| 721 | _ = db; | 721 | _ = db; |
| 722 | _ = module_context_ptr; | 722 | _ = module_context_ptr; |
| 723 | _ = argc; | 723 | _ = argc; |
| @@ -730,7 +730,7 @@ pub fn VirtualTable( | |||
| 730 | return c.SQLITE_ERROR; | 730 | return c.SQLITE_ERROR; |
| 731 | } | 731 | } |
| 732 | 732 | ||
| 733 | fn xConnect(db: ?*c.sqlite3, module_context_ptr: ?*anyopaque, argc: c_int, argv: [*c]const [*c]const u8, vtab: [*c][*c]c.sqlite3_vtab, err_str: [*c][*c]u8) callconv(.C) c_int { | 733 | fn xConnect(db: ?*c.sqlite3, module_context_ptr: ?*anyopaque, argc: c_int, argv: [*c]const [*c]const u8, vtab: [*c][*c]c.sqlite3_vtab, err_str: [*c][*c]u8) callconv(.c) c_int { |
| 734 | const module_context = getModuleContext(module_context_ptr); | 734 | const module_context = getModuleContext(module_context_ptr); |
| 735 | 735 | ||
| 736 | var arena = heap.ArenaAllocator.init(module_context.allocator); | 736 | var arena = heap.ArenaAllocator.init(module_context.allocator); |
| @@ -761,7 +761,7 @@ pub fn VirtualTable( | |||
| 761 | return c.SQLITE_OK; | 761 | return c.SQLITE_OK; |
| 762 | } | 762 | } |
| 763 | 763 | ||
| 764 | fn xBestIndex(vtab: [*c]c.sqlite3_vtab, index_info_ptr: [*c]c.sqlite3_index_info) callconv(.C) c_int { | 764 | fn xBestIndex(vtab: [*c]c.sqlite3_vtab, index_info_ptr: [*c]c.sqlite3_index_info) callconv(.c) c_int { |
| 765 | const index_info: *c.sqlite3_index_info = index_info_ptr orelse unreachable; | 765 | const index_info: *c.sqlite3_index_info = index_info_ptr orelse unreachable; |
| 766 | 766 | ||
| 767 | // | 767 | // |
| @@ -775,20 +775,20 @@ pub fn VirtualTable( | |||
| 775 | // Create an index builder and let the user build the index. | 775 | // Create an index builder and let the user build the index. |
| 776 | 776 | ||
| 777 | var builder = BestIndexBuilder.init(arena.allocator(), index_info) catch |err| { | 777 | var builder = BestIndexBuilder.init(arena.allocator(), index_info) catch |err| { |
| 778 | logger.err("unable to create best index builder, err: {!}", .{err}); | 778 | logger.err("unable to create best index builder, err: {}", .{err}); |
| 779 | return c.SQLITE_ERROR; | 779 | return c.SQLITE_ERROR; |
| 780 | }; | 780 | }; |
| 781 | 781 | ||
| 782 | var diags = VTabDiagnostics{ .allocator = arena.allocator() }; | 782 | var diags = VTabDiagnostics{ .allocator = arena.allocator() }; |
| 783 | state.table.buildBestIndex(&diags, &builder) catch |err| { | 783 | state.table.buildBestIndex(&diags, &builder) catch |err| { |
| 784 | logger.err("unable to build best index, err: {!}", .{err}); | 784 | logger.err("unable to build best index, err: {}", .{err}); |
| 785 | return c.SQLITE_ERROR; | 785 | return c.SQLITE_ERROR; |
| 786 | }; | 786 | }; |
| 787 | 787 | ||
| 788 | return c.SQLITE_OK; | 788 | return c.SQLITE_OK; |
| 789 | } | 789 | } |
| 790 | 790 | ||
| 791 | fn xDisconnect(vtab: [*c]c.sqlite3_vtab) callconv(.C) c_int { | 791 | fn xDisconnect(vtab: [*c]c.sqlite3_vtab) callconv(.c) c_int { |
| 792 | const nullable_state: ?*State = @fieldParentPtr("vtab", vtab); | 792 | const nullable_state: ?*State = @fieldParentPtr("vtab", vtab); |
| 793 | const state = nullable_state orelse unreachable; | 793 | const state = nullable_state orelse unreachable; |
| 794 | 794 | ||
| @@ -797,7 +797,7 @@ pub fn VirtualTable( | |||
| 797 | return c.SQLITE_OK; | 797 | return c.SQLITE_OK; |
| 798 | } | 798 | } |
| 799 | 799 | ||
| 800 | fn xDestroy(vtab: [*c]c.sqlite3_vtab) callconv(.C) c_int { | 800 | fn xDestroy(vtab: [*c]c.sqlite3_vtab) callconv(.c) c_int { |
| 801 | _ = vtab; | 801 | _ = vtab; |
| 802 | 802 | ||
| 803 | debug.print("xDestroy\n", .{}); | 803 | debug.print("xDestroy\n", .{}); |
| @@ -805,12 +805,12 @@ pub fn VirtualTable( | |||
| 805 | return c.SQLITE_ERROR; | 805 | return c.SQLITE_ERROR; |
| 806 | } | 806 | } |
| 807 | 807 | ||
| 808 | fn xOpen(vtab: [*c]c.sqlite3_vtab, vtab_cursor: [*c][*c]c.sqlite3_vtab_cursor) callconv(.C) c_int { | 808 | fn xOpen(vtab: [*c]c.sqlite3_vtab, vtab_cursor: [*c][*c]c.sqlite3_vtab_cursor) callconv(.c) c_int { |
| 809 | const nullable_state: ?*State = @fieldParentPtr("vtab", vtab); | 809 | const nullable_state: ?*State = @fieldParentPtr("vtab", vtab); |
| 810 | const state = nullable_state orelse unreachable; | 810 | const state = nullable_state orelse unreachable; |
| 811 | 811 | ||
| 812 | const cursor_state = CursorState.init(state.module_context, state.table) catch |err| { | 812 | const cursor_state = CursorState.init(state.module_context, state.table) catch |err| { |
| 813 | logger.err("unable to create cursor state, err: {!}", .{err}); | 813 | logger.err("unable to create cursor state, err: {}", .{err}); |
| 814 | return c.SQLITE_ERROR; | 814 | return c.SQLITE_ERROR; |
| 815 | }; | 815 | }; |
| 816 | vtab_cursor.* = @ptrCast(cursor_state); | 816 | vtab_cursor.* = @ptrCast(cursor_state); |
| @@ -818,7 +818,7 @@ pub fn VirtualTable( | |||
| 818 | return c.SQLITE_OK; | 818 | return c.SQLITE_OK; |
| 819 | } | 819 | } |
| 820 | 820 | ||
| 821 | fn xClose(vtab_cursor: [*c]c.sqlite3_vtab_cursor) callconv(.C) c_int { | 821 | fn xClose(vtab_cursor: [*c]c.sqlite3_vtab_cursor) callconv(.c) c_int { |
| 822 | const nullable_cursor_state: ?*CursorState = @fieldParentPtr("vtab_cursor", vtab_cursor); | 822 | const nullable_cursor_state: ?*CursorState = @fieldParentPtr("vtab_cursor", vtab_cursor); |
| 823 | const cursor_state = nullable_cursor_state orelse unreachable; | 823 | const cursor_state = nullable_cursor_state orelse unreachable; |
| 824 | 824 | ||
| @@ -827,7 +827,7 @@ pub fn VirtualTable( | |||
| 827 | return c.SQLITE_OK; | 827 | return c.SQLITE_OK; |
| 828 | } | 828 | } |
| 829 | 829 | ||
| 830 | fn xEof(vtab_cursor: [*c]c.sqlite3_vtab_cursor) callconv(.C) c_int { | 830 | fn xEof(vtab_cursor: [*c]c.sqlite3_vtab_cursor) callconv(.c) c_int { |
| 831 | const nullable_cursor_state: ?*CursorState = @fieldParentPtr("vtab_cursor", vtab_cursor); | 831 | const nullable_cursor_state: ?*CursorState = @fieldParentPtr("vtab_cursor", vtab_cursor); |
| 832 | const cursor_state = nullable_cursor_state orelse unreachable; | 832 | const cursor_state = nullable_cursor_state orelse unreachable; |
| 833 | const cursor = cursor_state.cursor; | 833 | const cursor = cursor_state.cursor; |
| @@ -865,7 +865,7 @@ pub fn VirtualTable( | |||
| 865 | return res; | 865 | return res; |
| 866 | } | 866 | } |
| 867 | 867 | ||
| 868 | fn xFilter(vtab_cursor: [*c]c.sqlite3_vtab_cursor, idx_num: c_int, idx_str: [*c]const u8, argc: c_int, argv: [*c]?*c.sqlite3_value) callconv(.C) c_int { | 868 | fn xFilter(vtab_cursor: [*c]c.sqlite3_vtab_cursor, idx_num: c_int, idx_str: [*c]const u8, argc: c_int, argv: [*c]?*c.sqlite3_value) callconv(.c) c_int { |
| 869 | const nullable_cursor_state: ?*CursorState = @fieldParentPtr("vtab_cursor", vtab_cursor); | 869 | const nullable_cursor_state: ?*CursorState = @fieldParentPtr("vtab_cursor", vtab_cursor); |
| 870 | const cursor_state = nullable_cursor_state orelse unreachable; | 870 | const cursor_state = nullable_cursor_state orelse unreachable; |
| 871 | const cursor = cursor_state.cursor; | 871 | const cursor = cursor_state.cursor; |
| @@ -878,7 +878,7 @@ pub fn VirtualTable( | |||
| 878 | const id = IndexIdentifier.fromC(idx_num, idx_str); | 878 | const id = IndexIdentifier.fromC(idx_num, idx_str); |
| 879 | 879 | ||
| 880 | const args = filterArgsFromCPointer(arena.allocator(), argc, argv) catch |err| { | 880 | const args = filterArgsFromCPointer(arena.allocator(), argc, argv) catch |err| { |
| 881 | logger.err("unable to create filter args, err: {!}", .{err}); | 881 | logger.err("unable to create filter args, err: {}", .{err}); |
| 882 | return c.SQLITE_ERROR; | 882 | return c.SQLITE_ERROR; |
| 883 | }; | 883 | }; |
| 884 | 884 | ||
| @@ -891,7 +891,7 @@ pub fn VirtualTable( | |||
| 891 | return c.SQLITE_OK; | 891 | return c.SQLITE_OK; |
| 892 | } | 892 | } |
| 893 | 893 | ||
| 894 | fn xNext(vtab_cursor: [*c]c.sqlite3_vtab_cursor) callconv(.C) c_int { | 894 | fn xNext(vtab_cursor: [*c]c.sqlite3_vtab_cursor) callconv(.c) c_int { |
| 895 | const nullable_cursor_state: ?*CursorState = @fieldParentPtr("vtab_cursor", vtab_cursor); | 895 | const nullable_cursor_state: ?*CursorState = @fieldParentPtr("vtab_cursor", vtab_cursor); |
| 896 | const cursor_state = nullable_cursor_state orelse unreachable; | 896 | const cursor_state = nullable_cursor_state orelse unreachable; |
| 897 | const cursor = cursor_state.cursor; | 897 | const cursor = cursor_state.cursor; |
| @@ -910,7 +910,7 @@ pub fn VirtualTable( | |||
| 910 | return c.SQLITE_OK; | 910 | return c.SQLITE_OK; |
| 911 | } | 911 | } |
| 912 | 912 | ||
| 913 | fn xColumn(vtab_cursor: [*c]c.sqlite3_vtab_cursor, ctx: ?*c.sqlite3_context, n: c_int) callconv(.C) c_int { | 913 | fn xColumn(vtab_cursor: [*c]c.sqlite3_vtab_cursor, ctx: ?*c.sqlite3_context, n: c_int) callconv(.c) c_int { |
| 914 | const nullable_cursor_state: ?*CursorState = @fieldParentPtr("vtab_cursor", vtab_cursor); | 914 | const nullable_cursor_state: ?*CursorState = @fieldParentPtr("vtab_cursor", vtab_cursor); |
| 915 | const cursor_state = nullable_cursor_state orelse unreachable; | 915 | const cursor_state = nullable_cursor_state orelse unreachable; |
| 916 | const cursor = cursor_state.cursor; | 916 | const cursor = cursor_state.cursor; |
| @@ -954,7 +954,7 @@ pub fn VirtualTable( | |||
| 954 | return c.SQLITE_OK; | 954 | return c.SQLITE_OK; |
| 955 | } | 955 | } |
| 956 | 956 | ||
| 957 | fn xRowid(vtab_cursor: [*c]c.sqlite3_vtab_cursor, row_id_ptr: [*c]c.sqlite3_int64) callconv(.C) c_int { | 957 | fn xRowid(vtab_cursor: [*c]c.sqlite3_vtab_cursor, row_id_ptr: [*c]c.sqlite3_int64) callconv(.c) c_int { |
| 958 | const nullable_cursor_state: ?*CursorState = @fieldParentPtr("vtab_cursor", vtab_cursor); | 958 | const nullable_cursor_state: ?*CursorState = @fieldParentPtr("vtab_cursor", vtab_cursor); |
| 959 | const cursor_state = nullable_cursor_state orelse unreachable; | 959 | const cursor_state = nullable_cursor_state orelse unreachable; |
| 960 | const cursor = cursor_state.cursor; | 960 | const cursor = cursor_state.cursor; |
| @@ -1011,7 +1011,7 @@ const TestVirtualTable = struct { | |||
| 1011 | n = fmt.parseInt(usize, kv.value, 10) catch |err| { | 1011 | n = fmt.parseInt(usize, kv.value, 10) catch |err| { |
| 1012 | switch (err) { | 1012 | switch (err) { |
| 1013 | error.InvalidCharacter => diags.setErrorMessage("not a number: {s}", .{kv.value}), | 1013 | error.InvalidCharacter => diags.setErrorMessage("not a number: {s}", .{kv.value}), |
| 1014 | else => diags.setErrorMessage("got error while parsing value {s}: {!}", .{ kv.value, err }), | 1014 | else => diags.setErrorMessage("got error while parsing value {s}: {}", .{ kv.value, err }), |
| 1015 | } | 1015 | } |
| 1016 | return err; | 1016 | return err; |
| 1017 | }; | 1017 | }; |
| @@ -1297,7 +1297,7 @@ test "parse module arguments" { | |||
| 1297 | 1297 | ||
| 1298 | const args = try allocator.alloc([*c]const u8, 20); | 1298 | const args = try allocator.alloc([*c]const u8, 20); |
| 1299 | for (args, 0..) |*arg, i| { | 1299 | for (args, 0..) |*arg, i| { |
| 1300 | const tmp = try fmt.allocPrintZ(allocator, "arg={d}", .{i}); | 1300 | const tmp = try fmt.allocPrintSentinel(allocator, "arg={d}", .{i}, 0); |
| 1301 | arg.* = @ptrCast(tmp); | 1301 | arg.* = @ptrCast(tmp); |
| 1302 | } | 1302 | } |
| 1303 | 1303 | ||