summaryrefslogtreecommitdiff
path: root/vtab.zig
diff options
context:
space:
mode:
Diffstat (limited to 'vtab.zig')
-rw-r--r--vtab.zig82
1 files changed, 41 insertions, 41 deletions
diff --git a/vtab.zig b/vtab.zig
index 2c3e329..a7645c3 100644
--- a/vtab.zig
+++ b/vtab.zig
@@ -207,7 +207,7 @@ pub const BestIndexBuilder = struct {
207 .id = .{}, 207 .id = .{},
208 }; 208 };
209 209
210 for (res.constraints) |*constraint, i| { 210 for (res.constraints, 0..) |*constraint, i| {
211 const raw_constraint = index_info.aConstraint[i]; 211 const raw_constraint = index_info.aConstraint[i];
212 212
213 constraint.column = @intCast(isize, raw_constraint.iColumn); 213 constraint.column = @intCast(isize, raw_constraint.iColumn);
@@ -233,7 +233,7 @@ pub const BestIndexBuilder = struct {
233 233
234 // Populate the constraint usage 234 // Populate the constraint usage
235 var constraint_usage: []c.sqlite3_index_constraint_usage = index_info.aConstraintUsage[0..self.constraints.len]; 235 var constraint_usage: []c.sqlite3_index_constraint_usage = index_info.aConstraintUsage[0..self.constraints.len];
236 for (self.constraints) |constraint, i| { 236 for (self.constraints, 0..) |constraint, i| {
237 constraint_usage[i].argvIndex = constraint.usage.argv_index; 237 constraint_usage[i].argvIndex = constraint.usage.argv_index;
238 constraint_usage[i].omit = if (constraint.usage.omit) 1 else 0; 238 constraint_usage[i].omit = if (constraint.usage.omit) 1 else 0;
239 } 239 }
@@ -315,9 +315,9 @@ fn validateCursorType(comptime Table: type) void {
315 315
316 const info = @typeInfo(@TypeOf(Cursor.init)).Fn; 316 const info = @typeInfo(@TypeOf(Cursor.init)).Fn;
317 317
318 if (info.args.len != 2) @compileError(error_message); 318 if (info.params.len != 2) @compileError(error_message);
319 if (info.args[0].arg_type.? != mem.Allocator) @compileError(error_message); 319 if (info.params[0].type.? != mem.Allocator) @compileError(error_message);
320 if (info.args[1].arg_type.? != *Table) @compileError(error_message); 320 if (info.params[1].type.? != *Table) @compileError(error_message);
321 if (info.return_type.? != Cursor.InitError!*Cursor) @compileError(error_message); 321 if (info.return_type.? != Cursor.InitError!*Cursor) @compileError(error_message);
322 } 322 }
323 323
@@ -333,8 +333,8 @@ fn validateCursorType(comptime Table: type) void {
333 333
334 const info = @typeInfo(@TypeOf(Cursor.deinit)).Fn; 334 const info = @typeInfo(@TypeOf(Cursor.deinit)).Fn;
335 335
336 if (info.args.len != 1) @compileError(error_message); 336 if (info.params.len != 1) @compileError(error_message);
337 if (info.args[0].arg_type.? != *Cursor) @compileError(error_message); 337 if (info.params[0].type.? != *Cursor) @compileError(error_message);
338 if (info.return_type.? != void) @compileError(error_message); 338 if (info.return_type.? != void) @compileError(error_message);
339 } 339 }
340 340
@@ -354,9 +354,9 @@ fn validateCursorType(comptime Table: type) void {
354 354
355 const info = @typeInfo(@TypeOf(Cursor.next)).Fn; 355 const info = @typeInfo(@TypeOf(Cursor.next)).Fn;
356 356
357 if (info.args.len != 2) @compileError(error_message); 357 if (info.params.len != 2) @compileError(error_message);
358 if (info.args[0].arg_type.? != *Cursor) @compileError(error_message); 358 if (info.params[0].type.? != *Cursor) @compileError(error_message);
359 if (info.args[1].arg_type.? != *VTabDiagnostics) @compileError(error_message); 359 if (info.params[1].type.? != *VTabDiagnostics) @compileError(error_message);
360 if (info.return_type.? != Cursor.NextError!void) @compileError(error_message); 360 if (info.return_type.? != Cursor.NextError!void) @compileError(error_message);
361 } 361 }
362 362
@@ -376,9 +376,9 @@ fn validateCursorType(comptime Table: type) void {
376 376
377 const info = @typeInfo(@TypeOf(Cursor.hasNext)).Fn; 377 const info = @typeInfo(@TypeOf(Cursor.hasNext)).Fn;
378 378
379 if (info.args.len != 2) @compileError(error_message); 379 if (info.params.len != 2) @compileError(error_message);
380 if (info.args[0].arg_type.? != *Cursor) @compileError(error_message); 380 if (info.params[0].type.? != *Cursor) @compileError(error_message);
381 if (info.args[1].arg_type.? != *VTabDiagnostics) @compileError(error_message); 381 if (info.params[1].type.? != *VTabDiagnostics) @compileError(error_message);
382 if (info.return_type.? != Cursor.HasNextError!bool) @compileError(error_message); 382 if (info.return_type.? != Cursor.HasNextError!bool) @compileError(error_message);
383 } 383 }
384 384
@@ -398,11 +398,11 @@ fn validateCursorType(comptime Table: type) void {
398 398
399 const info = @typeInfo(@TypeOf(Cursor.filter)).Fn; 399 const info = @typeInfo(@TypeOf(Cursor.filter)).Fn;
400 400
401 if (info.args.len != 4) @compileError(error_message); 401 if (info.params.len != 4) @compileError(error_message);
402 if (info.args[0].arg_type.? != *Cursor) @compileError(error_message); 402 if (info.params[0].type.? != *Cursor) @compileError(error_message);
403 if (info.args[1].arg_type.? != *VTabDiagnostics) @compileError(error_message); 403 if (info.params[1].type.? != *VTabDiagnostics) @compileError(error_message);
404 if (info.args[2].arg_type.? != IndexIdentifier) @compileError(error_message); 404 if (info.params[2].type.? != IndexIdentifier) @compileError(error_message);
405 if (info.args[3].arg_type.? != []FilterArg) @compileError(error_message); 405 if (info.params[3].type.? != []FilterArg) @compileError(error_message);
406 if (info.return_type.? != Cursor.FilterError!void) @compileError(error_message); 406 if (info.return_type.? != Cursor.FilterError!void) @compileError(error_message);
407 } 407 }
408 408
@@ -425,10 +425,10 @@ fn validateCursorType(comptime Table: type) void {
425 425
426 const info = @typeInfo(@TypeOf(Cursor.column)).Fn; 426 const info = @typeInfo(@TypeOf(Cursor.column)).Fn;
427 427
428 if (info.args.len != 3) @compileError(error_message); 428 if (info.params.len != 3) @compileError(error_message);
429 if (info.args[0].arg_type.? != *Cursor) @compileError(error_message); 429 if (info.params[0].type.? != *Cursor) @compileError(error_message);
430 if (info.args[1].arg_type.? != *VTabDiagnostics) @compileError(error_message); 430 if (info.params[1].type.? != *VTabDiagnostics) @compileError(error_message);
431 if (info.args[2].arg_type.? != i32) @compileError(error_message); 431 if (info.params[2].type.? != i32) @compileError(error_message);
432 if (info.return_type.? != Cursor.ColumnError!Cursor.Column) @compileError(error_message); 432 if (info.return_type.? != Cursor.ColumnError!Cursor.Column) @compileError(error_message);
433 } 433 }
434 434
@@ -448,9 +448,9 @@ fn validateCursorType(comptime Table: type) void {
448 448
449 const info = @typeInfo(@TypeOf(Cursor.rowId)).Fn; 449 const info = @typeInfo(@TypeOf(Cursor.rowId)).Fn;
450 450
451 if (info.args.len != 2) @compileError(error_message); 451 if (info.params.len != 2) @compileError(error_message);
452 if (info.args[0].arg_type.? != *Cursor) @compileError(error_message); 452 if (info.params[0].type.? != *Cursor) @compileError(error_message);
453 if (info.args[1].arg_type.? != *VTabDiagnostics) @compileError(error_message); 453 if (info.params[1].type.? != *VTabDiagnostics) @compileError(error_message);
454 if (info.return_type.? != Cursor.RowIDError!i64) @compileError(error_message); 454 if (info.return_type.? != Cursor.RowIDError!i64) @compileError(error_message);
455 } 455 }
456} 456}
@@ -473,11 +473,11 @@ fn validateTableType(comptime Table: type) void {
473 473
474 const info = @typeInfo(@TypeOf(Table.init)).Fn; 474 const info = @typeInfo(@TypeOf(Table.init)).Fn;
475 475
476 if (info.args.len != 3) @compileError(error_message); 476 if (info.params.len != 3) @compileError(error_message);
477 if (info.args[0].arg_type.? != mem.Allocator) @compileError(error_message); 477 if (info.params[0].type.? != mem.Allocator) @compileError(error_message);
478 if (info.args[1].arg_type.? != *VTabDiagnostics) @compileError(error_message); 478 if (info.params[1].type.? != *VTabDiagnostics) @compileError(error_message);
479 // TODO(vincent): maybe allow a signature without the args since a table can do withoout them 479 // TODO(vincent): maybe allow a signature without the params since a table can do withoout them
480 if (info.args[2].arg_type.? != []const ModuleArgument) @compileError(error_message); 480 if (info.params[2].type.? != []const ModuleArgument) @compileError(error_message);
481 if (info.return_type.? != Table.InitError!*Table) @compileError(error_message); 481 if (info.return_type.? != Table.InitError!*Table) @compileError(error_message);
482 } 482 }
483 483
@@ -493,9 +493,9 @@ fn validateTableType(comptime Table: type) void {
493 493
494 const info = @typeInfo(@TypeOf(Table.deinit)).Fn; 494 const info = @typeInfo(@TypeOf(Table.deinit)).Fn;
495 495
496 if (info.args.len != 2) @compileError(error_message); 496 if (info.params.len != 2) @compileError(error_message);
497 if (info.args[0].arg_type.? != *Table) @compileError(error_message); 497 if (info.params[0].type.? != *Table) @compileError(error_message);
498 if (info.args[1].arg_type.? != mem.Allocator) @compileError(error_message); 498 if (info.params[1].type.? != mem.Allocator) @compileError(error_message);
499 if (info.return_type.? != void) @compileError(error_message); 499 if (info.return_type.? != void) @compileError(error_message);
500 } 500 }
501 501
@@ -515,10 +515,10 @@ fn validateTableType(comptime Table: type) void {
515 515
516 const info = @typeInfo(@TypeOf(Table.buildBestIndex)).Fn; 516 const info = @typeInfo(@TypeOf(Table.buildBestIndex)).Fn;
517 517
518 if (info.args.len != 3) @compileError(error_message); 518 if (info.params.len != 3) @compileError(error_message);
519 if (info.args[0].arg_type.? != *Table) @compileError(error_message); 519 if (info.params[0].type.? != *Table) @compileError(error_message);
520 if (info.args[1].arg_type.? != *VTabDiagnostics) @compileError(error_message); 520 if (info.params[1].type.? != *VTabDiagnostics) @compileError(error_message);
521 if (info.args[2].arg_type.? != *BestIndexBuilder) @compileError(error_message); 521 if (info.params[2].type.? != *BestIndexBuilder) @compileError(error_message);
522 if (info.return_type.? != Table.BuildBestIndexError!void) @compileError(error_message); 522 if (info.return_type.? != Table.BuildBestIndexError!void) @compileError(error_message);
523 } 523 }
524 524
@@ -541,7 +541,7 @@ fn parseModuleArguments(allocator: mem.Allocator, argc: c_int, argv: [*c]const [
541 var res = try allocator.alloc(ModuleArgument, @intCast(usize, argc)); 541 var res = try allocator.alloc(ModuleArgument, @intCast(usize, argc));
542 errdefer allocator.free(res); 542 errdefer allocator.free(res);
543 543
544 for (res) |*marg, i| { 544 for (res, 0..) |*marg, i| {
545 // The documentation of sqlite says each string in argv is null-terminated 545 // The documentation of sqlite says each string in argv is null-terminated
546 const arg = mem.sliceTo(argv[i], 0); 546 const arg = mem.sliceTo(argv[i], 0);
547 547
@@ -840,7 +840,7 @@ pub fn VirtualTable(
840 const size = @intCast(usize, argc); 840 const size = @intCast(usize, argc);
841 841
842 var res = try allocator.alloc(FilterArg, size); 842 var res = try allocator.alloc(FilterArg, size);
843 for (res) |*item, i| { 843 for (res, 0..) |*item, i| {
844 item.* = .{ 844 item.* = .{
845 .value = argv[i], 845 .value = argv[i],
846 }; 846 };
@@ -1276,7 +1276,7 @@ test "parse module arguments" {
1276 const allocator = arena.allocator(); 1276 const allocator = arena.allocator();
1277 1277
1278 var args = try allocator.alloc([*c]const u8, 20); 1278 var args = try allocator.alloc([*c]const u8, 20);
1279 for (args) |*arg, i| { 1279 for (args, 0..) |*arg, i| {
1280 const tmp = try fmt.allocPrintZ(allocator, "arg={d}", .{i}); 1280 const tmp = try fmt.allocPrintZ(allocator, "arg={d}", .{i});
1281 arg.* = @ptrCast([*c]const u8, tmp); 1281 arg.* = @ptrCast([*c]const u8, tmp);
1282 } 1282 }
@@ -1288,7 +1288,7 @@ test "parse module arguments" {
1288 ); 1288 );
1289 try testing.expectEqual(@as(usize, 20), res.len); 1289 try testing.expectEqual(@as(usize, 20), res.len);
1290 1290
1291 for (res) |arg, i| { 1291 for (res, 0..) |arg, i| {
1292 try testing.expectEqualStrings("arg", arg.kv.key); 1292 try testing.expectEqualStrings("arg", arg.kv.key);
1293 try testing.expectEqual(i, try fmt.parseInt(usize, arg.kv.value, 10)); 1293 try testing.expectEqual(i, try fmt.parseInt(usize, arg.kv.value, 10));
1294 } 1294 }