summaryrefslogtreecommitdiff
path: root/sqlite.zig
diff options
context:
space:
mode:
Diffstat (limited to 'sqlite.zig')
-rw-r--r--sqlite.zig54
1 files changed, 27 insertions, 27 deletions
diff --git a/sqlite.zig b/sqlite.zig
index d39f44b..77c30fc 100644
--- a/sqlite.zig
+++ b/sqlite.zig
@@ -640,19 +640,19 @@ pub const Db = struct {
640 .Fn => |fn_info| fn_info, 640 .Fn => |fn_info| fn_info,
641 else => @compileError("cannot use func, expecting a function"), 641 else => @compileError("cannot use func, expecting a function"),
642 }; 642 };
643 if (finalize_fn_info.args.len != 1) @compileError("finalize function must take exactly one argument"); 643 if (finalize_fn_info.params.len != 1) @compileError("finalize function must take exactly one argument");
644 if (finalize_fn_info.is_generic) @compileError("finalize function can't be generic"); 644 if (finalize_fn_info.is_generic) @compileError("finalize function can't be generic");
645 if (finalize_fn_info.is_var_args) @compileError("finalize function can't be variadic"); 645 if (finalize_fn_info.is_var_args) @compileError("finalize function can't be variadic");
646 646
647 if (step_fn_info.args[0].arg_type.? != finalize_fn_info.args[0].arg_type.?) { 647 if (step_fn_info.params[0].type.? != finalize_fn_info.params[0].type.?) {
648 @compileError("both step and finalize functions must have the same first argument and it must be a FunctionContext"); 648 @compileError("both step and finalize functions must have the same first argument and it must be a FunctionContext");
649 } 649 }
650 if (step_fn_info.args[0].arg_type.? != FunctionContext) { 650 if (step_fn_info.params[0].type.? != FunctionContext) {
651 @compileError("both step and finalize functions must have a first argument of type FunctionContext"); 651 @compileError("both step and finalize functions must have a first argument of type FunctionContext");
652 } 652 }
653 653
654 // subtract the context argument 654 // subtract the context argument
655 const real_args_len = step_fn_info.args.len - 1; 655 const real_args_len = step_fn_info.params.len - 1;
656 656
657 // 657 //
658 658
@@ -669,7 +669,7 @@ pub const Db = struct {
669 fn xStep(ctx: ?*c.sqlite3_context, argc: c_int, argv: [*c]?*c.sqlite3_value) callconv(.C) void { 669 fn xStep(ctx: ?*c.sqlite3_context, argc: c_int, argv: [*c]?*c.sqlite3_value) callconv(.C) void {
670 debug.assert(argc == real_args_len); 670 debug.assert(argc == real_args_len);
671 671
672 const sqlite_args = argv.?[0..real_args_len]; 672 const sqlite_args = argv[0..real_args_len];
673 673
674 var args: std.meta.ArgsTuple(@TypeOf(step_func)) = undefined; 674 var args: std.meta.ArgsTuple(@TypeOf(step_func)) = undefined;
675 675
@@ -679,14 +679,14 @@ pub const Db = struct {
679 comptime var i: usize = 0; 679 comptime var i: usize = 0;
680 inline while (i < real_args_len) : (i += 1) { 680 inline while (i < real_args_len) : (i += 1) {
681 // Remember the firt argument is always the function context 681 // Remember the firt argument is always the function context
682 const arg = step_fn_info.args[i + 1]; 682 const arg = step_fn_info.params[i + 1];
683 const arg_ptr = &args[i + 1]; 683 const arg_ptr = &args[i + 1];
684 684
685 const ArgType = arg.arg_type.?; 685 const ArgType = arg.type.?;
686 helpers.setTypeFromValue(ArgType, arg_ptr, sqlite_args[i].?); 686 helpers.setTypeFromValue(ArgType, arg_ptr, sqlite_args[i].?);
687 } 687 }
688 688
689 @call(.{}, step_func, args); 689 @call(.auto, step_func, args);
690 } 690 }
691 }.xStep, 691 }.xStep,
692 struct { 692 struct {
@@ -696,7 +696,7 @@ pub const Db = struct {
696 // Pass the function context 696 // Pass the function context
697 args[0] = FunctionContext{ .ctx = ctx }; 697 args[0] = FunctionContext{ .ctx = ctx };
698 698
699 const result = @call(.{}, finalize_func, args); 699 const result = @call(.auto, finalize_func, args);
700 700
701 helpers.setResult(ctx, result); 701 helpers.setResult(ctx, result);
702 } 702 }
@@ -738,22 +738,22 @@ pub const Db = struct {
738 const result = c.sqlite3_create_function_v2( 738 const result = c.sqlite3_create_function_v2(
739 self.db, 739 self.db,
740 func_name, 740 func_name,
741 fn_info.args.len, 741 fn_info.params.len,
742 flags, 742 flags,
743 null, 743 null,
744 struct { 744 struct {
745 fn xFunc(ctx: ?*c.sqlite3_context, argc: c_int, argv: [*c]?*c.sqlite3_value) callconv(.C) void { 745 fn xFunc(ctx: ?*c.sqlite3_context, argc: c_int, argv: [*c]?*c.sqlite3_value) callconv(.C) void {
746 debug.assert(argc == fn_info.args.len); 746 debug.assert(argc == fn_info.params.len);
747 747
748 const sqlite_args = argv.?[0..fn_info.args.len]; 748 const sqlite_args = argv[0..fn_info.params.len];
749 749
750 var fn_args: ArgTuple = undefined; 750 var fn_args: ArgTuple = undefined;
751 inline for (fn_info.args) |arg, i| { 751 inline for (fn_info.params, 0..) |arg, i| {
752 const ArgType = arg.arg_type.?; 752 const ArgType = arg.type.?;
753 helpers.setTypeFromValue(ArgType, &fn_args[i], sqlite_args[i].?); 753 helpers.setTypeFromValue(ArgType, &fn_args[i], sqlite_args[i].?);
754 } 754 }
755 755
756 const result = @call(.{}, func, fn_args); 756 const result = @call(.auto, func, fn_args);
757 757
758 helpers.setResult(ctx, result); 758 helpers.setResult(ctx, result);
759 } 759 }
@@ -1395,7 +1395,7 @@ pub fn Iterator(comptime Type: type) type {
1395 1395
1396 var value: Type = undefined; 1396 var value: Type = undefined;
1397 1397
1398 inline for (@typeInfo(Type).Struct.fields) |field, _i| { 1398 inline for (@typeInfo(Type).Struct.fields, 0..) |field, _i| {
1399 const i = @as(usize, _i); 1399 const i = @as(usize, _i);
1400 1400
1401 const ret = try self.readField(field.type, options, i); 1401 const ret = try self.readField(field.type, options, i);
@@ -1721,7 +1721,7 @@ pub const DynamicStatement = struct {
1721 1721
1722 switch (@typeInfo(Type)) { 1722 switch (@typeInfo(Type)) {
1723 .Struct => |StructTypeInfo| { 1723 .Struct => |StructTypeInfo| {
1724 inline for (StructTypeInfo.fields) |struct_field, struct_field_i| { 1724 inline for (StructTypeInfo.fields, 0..) |struct_field, struct_field_i| {
1725 const field_value = @field(values, struct_field.name); 1725 const field_value = @field(values, struct_field.name);
1726 1726
1727 const i = sqlite3BindParameterIndex(self.stmt, struct_field.name); 1727 const i = sqlite3BindParameterIndex(self.stmt, struct_field.name);
@@ -1735,7 +1735,7 @@ pub const DynamicStatement = struct {
1735 .Pointer => |PointerTypeInfo| { 1735 .Pointer => |PointerTypeInfo| {
1736 switch (PointerTypeInfo.size) { 1736 switch (PointerTypeInfo.size) {
1737 .Slice => { 1737 .Slice => {
1738 for (values) |value_to_bind, index| { 1738 for (values, 0..) |value_to_bind, index| {
1739 try self.bindField(PointerTypeInfo.child, options, "unknown", @intCast(c_int, index), value_to_bind); 1739 try self.bindField(PointerTypeInfo.child, options, "unknown", @intCast(c_int, index), value_to_bind);
1740 } 1740 }
1741 }, 1741 },
@@ -1743,7 +1743,7 @@ pub const DynamicStatement = struct {
1743 } 1743 }
1744 }, 1744 },
1745 .Array => |ArrayTypeInfo| { 1745 .Array => |ArrayTypeInfo| {
1746 for (values) |value_to_bind, index| { 1746 for (values, 0..) |value_to_bind, index| {
1747 try self.bindField(ArrayTypeInfo.child, options, "unknown", @intCast(c_int, index), value_to_bind); 1747 try self.bindField(ArrayTypeInfo.child, options, "unknown", @intCast(c_int, index), value_to_bind);
1748 } 1748 }
1749 }, 1749 },
@@ -2025,7 +2025,7 @@ pub fn Statement(comptime opts: StatementOptions, comptime query: anytype) type
2025 })); 2025 }));
2026 } 2026 }
2027 2027
2028 inline for (StructTypeInfo.fields) |struct_field, _i| { 2028 inline for (StructTypeInfo.fields, 0..) |struct_field, _i| {
2029 const bind_marker = query.bind_markers[_i]; 2029 const bind_marker = query.bind_markers[_i];
2030 if (bind_marker.typed) |typ| { 2030 if (bind_marker.typed) |typ| {
2031 const FieldTypeInfo = @typeInfo(struct_field.type); 2031 const FieldTypeInfo = @typeInfo(struct_field.type);
@@ -2497,7 +2497,7 @@ test "sqlite: read all users into a struct" {
2497 2497
2498 var rows = try stmt.all(TestUser, allocator, .{}, .{}); 2498 var rows = try stmt.all(TestUser, allocator, .{}, .{});
2499 try testing.expectEqual(@as(usize, 3), rows.len); 2499 try testing.expectEqual(@as(usize, 3), rows.len);
2500 for (rows) |row, i| { 2500 for (rows, 0..) |row, i| {
2501 const exp = test_users[i]; 2501 const exp = test_users[i];
2502 try testing.expectEqual(exp.id, row.id); 2502 try testing.expectEqual(exp.id, row.id);
2503 try testing.expectEqualStrings(exp.name, row.name); 2503 try testing.expectEqualStrings(exp.name, row.name);
@@ -2623,7 +2623,7 @@ test "sqlite: read a single text value" {
2623 const res = mem.sliceTo(&name.?, sentinel); 2623 const res = mem.sliceTo(&name.?, sentinel);
2624 try testing.expectEqualStrings("Vincent", res); 2624 try testing.expectEqualStrings("Vincent", res);
2625 } else { 2625 } else {
2626 const res = mem.span(&name.?); 2626 const res: []const u8 = &name.?;
2627 try testing.expectEqualStrings("Vincent", res); 2627 try testing.expectEqualStrings("Vincent", res);
2628 }, 2628 },
2629 else => @compileError("invalid type " ++ @typeName(typ)), 2629 else => @compileError("invalid type " ++ @typeName(typ)),
@@ -2828,7 +2828,7 @@ test "sqlite: bind pointer" {
2828 var stmt = try db.prepare(query); 2828 var stmt = try db.prepare(query);
2829 defer stmt.deinit(); 2829 defer stmt.deinit();
2830 2830
2831 for (test_users) |test_user, i| { 2831 for (test_users, 0..) |test_user, i| {
2832 stmt.reset(); 2832 stmt.reset();
2833 2833
2834 const name = try stmt.oneAlloc([]const u8, allocator, .{}, .{&test_user.id}); 2834 const name = try stmt.oneAlloc([]const u8, allocator, .{}, .{&test_user.id});
@@ -2864,7 +2864,7 @@ test "sqlite: read pointers" {
2864 ); 2864 );
2865 2865
2866 try testing.expectEqual(@as(usize, 3), rows.len); 2866 try testing.expectEqual(@as(usize, 3), rows.len);
2867 for (rows) |row, i| { 2867 for (rows, 0..) |row, i| {
2868 const exp = test_users[i]; 2868 const exp = test_users[i];
2869 try testing.expectEqual(exp.id, row.id.*); 2869 try testing.expectEqual(exp.id, row.id.*);
2870 try testing.expectEqualStrings(exp.name, row.name.*); 2870 try testing.expectEqualStrings(exp.name, row.name.*);
@@ -2998,7 +2998,7 @@ test "sqlite: statement iterator" {
2998 // Check the data 2998 // Check the data
2999 try testing.expectEqual(expected_rows.items.len, rows.items.len); 2999 try testing.expectEqual(expected_rows.items.len, rows.items.len);
3000 3000
3001 for (rows.items) |row, j| { 3001 for (rows.items, 0..) |row, j| {
3002 const exp_row = expected_rows.items[j]; 3002 const exp_row = expected_rows.items[j];
3003 try testing.expectEqualStrings(exp_row.name, mem.sliceTo(&row.name, 0)); 3003 try testing.expectEqualStrings(exp_row.name, mem.sliceTo(&row.name, 0));
3004 try testing.expectEqual(exp_row.age, row.age); 3004 try testing.expectEqual(exp_row.age, row.age);
@@ -3025,7 +3025,7 @@ test "sqlite: statement iterator" {
3025 // Check the data 3025 // Check the data
3026 try testing.expectEqual(expected_rows.items.len, rows.items.len); 3026 try testing.expectEqual(expected_rows.items.len, rows.items.len);
3027 3027
3028 for (rows.items) |row, j| { 3028 for (rows.items, 0..) |row, j| {
3029 const exp_row = expected_rows.items[j]; 3029 const exp_row = expected_rows.items[j];
3030 try testing.expectEqualStrings(exp_row.name, row.name.data); 3030 try testing.expectEqualStrings(exp_row.name, row.name.data);
3031 try testing.expectEqual(exp_row.age, row.age); 3031 try testing.expectEqual(exp_row.age, row.age);
@@ -3386,7 +3386,7 @@ test "sqlite: bind custom type" {
3386 const rows = try stmt.all(Article, arena.allocator(), .{}, .{}); 3386 const rows = try stmt.all(Article, arena.allocator(), .{}, .{});
3387 try testing.expectEqual(@as(usize, 20), rows.len); 3387 try testing.expectEqual(@as(usize, 20), rows.len);
3388 3388
3389 for (rows) |row, i| { 3389 for (rows, 0..) |row, i| {
3390 var exp_data: MyData = undefined; 3390 var exp_data: MyData = undefined;
3391 mem.set(u8, &exp_data.data, @intCast(u8, i)); 3391 mem.set(u8, &exp_data.data, @intCast(u8, i));
3392 3392