diff options
| -rw-r--r-- | sqlite.zig | 33 | ||||
| -rw-r--r-- | vtab.zig | 6 |
2 files changed, 20 insertions, 19 deletions
| @@ -1967,7 +1967,7 @@ pub const DynamicStatement = struct { | |||
| 1967 | pub fn all(self: *Self, comptime Type: type, allocator: mem.Allocator, options: QueryOptions, values: anytype) ![]Type { | 1967 | pub fn all(self: *Self, comptime Type: type, allocator: mem.Allocator, options: QueryOptions, values: anytype) ![]Type { |
| 1968 | var iter = try self.iteratorAlloc(Type, allocator, values); | 1968 | var iter = try self.iteratorAlloc(Type, allocator, values); |
| 1969 | 1969 | ||
| 1970 | var rows = std.ArrayList(Type).init(allocator); | 1970 | var rows: std.ArrayList(Type) = .{}; |
| 1971 | while (try iter.nextAlloc(allocator, options)) |row| { | 1971 | while (try iter.nextAlloc(allocator, options)) |row| { |
| 1972 | try rows.append(row); | 1972 | try rows.append(row); |
| 1973 | } | 1973 | } |
| @@ -2257,12 +2257,12 @@ pub fn Statement(comptime opts: StatementOptions, comptime query: anytype) type | |||
| 2257 | pub fn all(self: *Self, comptime Type: type, allocator: mem.Allocator, options: QueryOptions, values: anytype) ![]Type { | 2257 | pub fn all(self: *Self, comptime Type: type, allocator: mem.Allocator, options: QueryOptions, values: anytype) ![]Type { |
| 2258 | var iter = try self.iteratorAlloc(Type, allocator, values); | 2258 | var iter = try self.iteratorAlloc(Type, allocator, values); |
| 2259 | 2259 | ||
| 2260 | var rows = std.ArrayList(Type).init(allocator); | 2260 | var rows: std.ArrayList(Type) = .{}; |
| 2261 | while (try iter.nextAlloc(allocator, options)) |row| { | 2261 | while (try iter.nextAlloc(allocator, options)) |row| { |
| 2262 | try rows.append(row); | 2262 | try rows.append(allocator, row); |
| 2263 | } | 2263 | } |
| 2264 | 2264 | ||
| 2265 | return rows.toOwnedSlice(); | 2265 | return rows.toOwnedSlice(allocator); |
| 2266 | } | 2266 | } |
| 2267 | }; | 2267 | }; |
| 2268 | } | 2268 | } |
| @@ -3020,13 +3020,13 @@ test "sqlite: statement iterator" { | |||
| 3020 | var stmt = try db.prepare("INSERT INTO user(name, id, age, weight, favorite_color) VALUES(?{[]const u8}, ?{usize}, ?{usize}, ?{f32}, ?{[]const u8})"); | 3020 | var stmt = try db.prepare("INSERT INTO user(name, id, age, weight, favorite_color) VALUES(?{[]const u8}, ?{usize}, ?{usize}, ?{f32}, ?{[]const u8})"); |
| 3021 | defer stmt.deinit(); | 3021 | defer stmt.deinit(); |
| 3022 | 3022 | ||
| 3023 | var expected_rows = std.ArrayList(TestUser).init(allocator); | 3023 | var expected_rows: std.ArrayList(TestUser) = .{}; |
| 3024 | var i: usize = 0; | 3024 | var i: usize = 0; |
| 3025 | while (i < 20) : (i += 1) { | 3025 | while (i < 20) : (i += 1) { |
| 3026 | const name = try std.fmt.allocPrint(allocator, "Vincent {d}", .{i}); | 3026 | const name = try std.fmt.allocPrint(allocator, "Vincent {d}", .{i}); |
| 3027 | const user = TestUser{ .id = i, .name = name, .age = i + 200, .weight = @floatFromInt(i + 200), .favorite_color = .indigo }; | 3027 | const user = TestUser{ .id = i, .name = name, .age = i + 200, .weight = @floatFromInt(i + 200), .favorite_color = .indigo }; |
| 3028 | 3028 | ||
| 3029 | try expected_rows.append(user); | 3029 | try expected_rows.append(allocator, user); |
| 3030 | 3030 | ||
| 3031 | stmt.reset(); | 3031 | stmt.reset(); |
| 3032 | try stmt.exec(.{}, user); | 3032 | try stmt.exec(.{}, user); |
| @@ -3047,9 +3047,9 @@ test "sqlite: statement iterator" { | |||
| 3047 | 3047 | ||
| 3048 | var iter = try stmt2.iterator(RowType, .{}); | 3048 | var iter = try stmt2.iterator(RowType, .{}); |
| 3049 | 3049 | ||
| 3050 | var rows = std.ArrayList(RowType).init(allocator); | 3050 | var rows: std.ArrayList(RowType) = .{}; |
| 3051 | while (try iter.next(.{})) |row| { | 3051 | while (try iter.next(.{})) |row| { |
| 3052 | try rows.append(row); | 3052 | try rows.append(allocator, row); |
| 3053 | } | 3053 | } |
| 3054 | 3054 | ||
| 3055 | // Check the data | 3055 | // Check the data |
| @@ -3074,9 +3074,9 @@ test "sqlite: statement iterator" { | |||
| 3074 | 3074 | ||
| 3075 | var iter = try stmt2.iterator(RowType, .{}); | 3075 | var iter = try stmt2.iterator(RowType, .{}); |
| 3076 | 3076 | ||
| 3077 | var rows = std.ArrayList(RowType).init(allocator); | 3077 | var rows: std.ArrayList(RowType) = .{}; |
| 3078 | while (try iter.nextAlloc(allocator, .{})) |row| { | 3078 | while (try iter.nextAlloc(allocator, .{})) |row| { |
| 3079 | try rows.append(row); | 3079 | try rows.append(allocator, row); |
| 3080 | } | 3080 | } |
| 3081 | 3081 | ||
| 3082 | // Check the data | 3082 | // Check the data |
| @@ -3459,10 +3459,10 @@ test "sqlite: bind runtime slice" { | |||
| 3459 | const allocator = arena.allocator(); | 3459 | const allocator = arena.allocator(); |
| 3460 | 3460 | ||
| 3461 | // creating array list on heap so that it's deemed runtime size | 3461 | // creating array list on heap so that it's deemed runtime size |
| 3462 | var list = std.ArrayList([]const u8).init(allocator); | 3462 | var list: std.ArrayList([]const u8) = .{}; |
| 3463 | defer list.deinit(); | 3463 | defer list.deinit(allocator); |
| 3464 | try list.append("this is some data"); | 3464 | try list.append(allocator, "this is some data"); |
| 3465 | const args = try list.toOwnedSlice(); | 3465 | const args = try list.toOwnedSlice(allocator); |
| 3466 | 3466 | ||
| 3467 | var db = try getTestDb(); | 3467 | var db = try getTestDb(); |
| 3468 | defer db.deinit(); | 3468 | defer db.deinit(); |
| @@ -3871,13 +3871,14 @@ test "sqlite: create aggregate function with an aggregate context" { | |||
| 3871 | test "sqlite: empty slice" { | 3871 | test "sqlite: empty slice" { |
| 3872 | var arena = std.heap.ArenaAllocator.init(testing.allocator); | 3872 | var arena = std.heap.ArenaAllocator.init(testing.allocator); |
| 3873 | defer arena.deinit(); | 3873 | defer arena.deinit(); |
| 3874 | const allocator = arena.allocator(); | ||
| 3874 | 3875 | ||
| 3875 | var db = try getTestDb(); | 3876 | var db = try getTestDb(); |
| 3876 | defer db.deinit(); | 3877 | defer db.deinit(); |
| 3877 | try addTestData(&db); | 3878 | try addTestData(&db); |
| 3878 | 3879 | ||
| 3879 | var list = std.ArrayList(u8).init(arena.allocator()); | 3880 | var list: std.ArrayList(u8) = .{}; |
| 3880 | const ptr = try list.toOwnedSlice(); | 3881 | const ptr = try list.toOwnedSlice(allocator); |
| 3881 | 3882 | ||
| 3882 | try db.exec("INSERT INTO article(author_id, data) VALUES(?, ?)", .{}, .{ 1, ptr }); | 3883 | try db.exec("INSERT INTO article(author_id, data) VALUES(?, ?)", .{}, .{ 1, ptr }); |
| 3883 | 3884 | ||
| @@ -210,7 +210,7 @@ pub const BestIndexBuilder = struct { | |||
| 210 | const res = Self{ | 210 | const res = Self{ |
| 211 | .allocator = allocator, | 211 | .allocator = allocator, |
| 212 | .index_info = index_info, | 212 | .index_info = index_info, |
| 213 | .id_str_buffer = std.ArrayList(u8).init(allocator), | 213 | .id_str_buffer = .empty, |
| 214 | .constraints = try allocator.alloc(Constraint, @intCast(index_info.nConstraint)), | 214 | .constraints = try allocator.alloc(Constraint, @intCast(index_info.nConstraint)), |
| 215 | .columns_used = @intCast(index_info.colUsed), | 215 | .columns_used = @intCast(index_info.colUsed), |
| 216 | .id = .{}, | 216 | .id = .{}, |
| @@ -1070,7 +1070,7 @@ const TestVirtualTable = struct { | |||
| 1070 | _ = self; | 1070 | _ = self; |
| 1071 | _ = diags; | 1071 | _ = diags; |
| 1072 | 1072 | ||
| 1073 | var id_str_writer = builder.id_str_buffer.writer(); | 1073 | var id_str_writer = builder.id_str_buffer.writer(builder.allocator); |
| 1074 | 1074 | ||
| 1075 | var argv_index: i32 = 0; | 1075 | var argv_index: i32 = 0; |
| 1076 | for (builder.constraints) |*constraint| { | 1076 | for (builder.constraints) |*constraint| { |
| @@ -1084,7 +1084,7 @@ const TestVirtualTable = struct { | |||
| 1084 | 1084 | ||
| 1085 | // | 1085 | // |
| 1086 | 1086 | ||
| 1087 | builder.id.str = try builder.id_str_buffer.toOwnedSlice(); | 1087 | builder.id.str = try builder.id_str_buffer.toOwnedSlice(builder.allocator); |
| 1088 | builder.estimated_cost = 200; | 1088 | builder.estimated_cost = 200; |
| 1089 | builder.estimated_rows = 200; | 1089 | builder.estimated_rows = 200; |
| 1090 | 1090 | ||