diff options
Diffstat (limited to 'sqlite.zig')
| -rw-r--r-- | sqlite.zig | 32 |
1 files changed, 16 insertions, 16 deletions
| @@ -202,15 +202,15 @@ pub fn Iterator(comptime Type: type) type { | |||
| 202 | switch (Type) { | 202 | switch (Type) { |
| 203 | []const u8, []u8 => { | 203 | []const u8, []u8 => { |
| 204 | debug.assert(columns == 1); | 204 | debug.assert(columns == 1); |
| 205 | return try self.readBytes(Type, 0, .Text, options); | 205 | return try self.readBytes(Type, options.allocator, 0, .Text); |
| 206 | }, | 206 | }, |
| 207 | Blob => { | 207 | Blob => { |
| 208 | debug.assert(columns == 1); | 208 | debug.assert(columns == 1); |
| 209 | return try self.readBytes(Blob, 0, .Blob, options); | 209 | return try self.readBytes(Blob, options.allocator, 0, .Blob); |
| 210 | }, | 210 | }, |
| 211 | Text => { | 211 | Text => { |
| 212 | debug.assert(columns == 1); | 212 | debug.assert(columns == 1); |
| 213 | return try self.readBytes(Text, 0, .Text, options); | 213 | return try self.readBytes(Text, options.allocator, 0, .Text); |
| 214 | }, | 214 | }, |
| 215 | else => {}, | 215 | else => {}, |
| 216 | } | 216 | } |
| @@ -336,13 +336,13 @@ pub fn Iterator(comptime Type: type) type { | |||
| 336 | // When using .Text you can only read into either []const u8, []u8 or Text. | 336 | // When using .Text you can only read into either []const u8, []u8 or Text. |
| 337 | // | 337 | // |
| 338 | // The options must contain an `allocator` field which will be used to create a copy of the data. | 338 | // The options must contain an `allocator` field which will be used to create a copy of the data. |
| 339 | fn readBytes(self: *Self, comptime BytesType: type, _i: usize, comptime mode: ReadBytesMode, options: anytype) !BytesType { | 339 | fn readBytes(self: *Self, comptime BytesType: type, allocator: *mem.Allocator, _i: usize, comptime mode: ReadBytesMode) !BytesType { |
| 340 | const i = @intCast(c_int, _i); | 340 | const i = @intCast(c_int, _i); |
| 341 | const type_info = @typeInfo(BytesType); | 341 | const type_info = @typeInfo(BytesType); |
| 342 | 342 | ||
| 343 | var ret: BytesType = switch (BytesType) { | 343 | var ret: BytesType = switch (BytesType) { |
| 344 | Text, Blob => .{ .data = "" }, | 344 | Text, Blob => .{ .data = "" }, |
| 345 | else => try dupeWithSentinel(BytesType, options.allocator, ""), | 345 | else => try dupeWithSentinel(BytesType, allocator, ""), |
| 346 | }; | 346 | }; |
| 347 | 347 | ||
| 348 | switch (mode) { | 348 | switch (mode) { |
| @@ -350,8 +350,8 @@ pub fn Iterator(comptime Type: type) type { | |||
| 350 | const data = c.sqlite3_column_blob(self.stmt, i); | 350 | const data = c.sqlite3_column_blob(self.stmt, i); |
| 351 | if (data == null) { | 351 | if (data == null) { |
| 352 | return switch (BytesType) { | 352 | return switch (BytesType) { |
| 353 | Text, Blob => .{ .data = try options.allocator.dupe(u8, "") }, | 353 | Text, Blob => .{ .data = try allocator.dupe(u8, "") }, |
| 354 | else => try dupeWithSentinel(BytesType, options.allocator, ""), | 354 | else => try dupeWithSentinel(BytesType, allocator, ""), |
| 355 | }; | 355 | }; |
| 356 | } | 356 | } |
| 357 | 357 | ||
| @@ -359,16 +359,16 @@ pub fn Iterator(comptime Type: type) type { | |||
| 359 | const ptr = @ptrCast([*c]const u8, data)[0..size]; | 359 | const ptr = @ptrCast([*c]const u8, data)[0..size]; |
| 360 | 360 | ||
| 361 | if (BytesType == Blob) { | 361 | if (BytesType == Blob) { |
| 362 | return Blob{ .data = try options.allocator.dupe(u8, ptr) }; | 362 | return Blob{ .data = try allocator.dupe(u8, ptr) }; |
| 363 | } | 363 | } |
| 364 | return try dupeWithSentinel(BytesType, options.allocator, ptr); | 364 | return try dupeWithSentinel(BytesType, allocator, ptr); |
| 365 | }, | 365 | }, |
| 366 | .Text => { | 366 | .Text => { |
| 367 | const data = c.sqlite3_column_text(self.stmt, i); | 367 | const data = c.sqlite3_column_text(self.stmt, i); |
| 368 | if (data == null) { | 368 | if (data == null) { |
| 369 | return switch (BytesType) { | 369 | return switch (BytesType) { |
| 370 | Text, Blob => .{ .data = try options.allocator.dupe(u8, "") }, | 370 | Text, Blob => .{ .data = try allocator.dupe(u8, "") }, |
| 371 | else => try dupeWithSentinel(BytesType, options.allocator, ""), | 371 | else => try dupeWithSentinel(BytesType, allocator, ""), |
| 372 | }; | 372 | }; |
| 373 | } | 373 | } |
| 374 | 374 | ||
| @@ -376,9 +376,9 @@ pub fn Iterator(comptime Type: type) type { | |||
| 376 | const ptr = @ptrCast([*c]const u8, data)[0..size]; | 376 | const ptr = @ptrCast([*c]const u8, data)[0..size]; |
| 377 | 377 | ||
| 378 | if (BytesType == Text) { | 378 | if (BytesType == Text) { |
| 379 | return Text{ .data = try options.allocator.dupe(u8, ptr) }; | 379 | return Text{ .data = try allocator.dupe(u8, ptr) }; |
| 380 | } | 380 | } |
| 381 | return try dupeWithSentinel(BytesType, options.allocator, ptr); | 381 | return try dupeWithSentinel(BytesType, allocator, ptr); |
| 382 | }, | 382 | }, |
| 383 | } | 383 | } |
| 384 | } | 384 | } |
| @@ -392,7 +392,7 @@ pub fn Iterator(comptime Type: type) type { | |||
| 392 | switch (ptr.size) { | 392 | switch (ptr.size) { |
| 393 | .One => unreachable, | 393 | .One => unreachable, |
| 394 | .Slice => switch (ptr.child) { | 394 | .Slice => switch (ptr.child) { |
| 395 | u8 => ret = try self.readBytes(PointerType, i, .Text, options), | 395 | u8 => ret = try self.readBytes(PointerType, options.allocator, i, .Text), |
| 396 | else => @compileError("cannot read pointer of type " ++ @typeName(PointerType)), | 396 | else => @compileError("cannot read pointer of type " ++ @typeName(PointerType)), |
| 397 | }, | 397 | }, |
| 398 | else => @compileError("cannot read pointer of type " ++ @typeName(PointerType)), | 398 | else => @compileError("cannot read pointer of type " ++ @typeName(PointerType)), |
| @@ -433,8 +433,8 @@ pub fn Iterator(comptime Type: type) type { | |||
| 433 | const field_type_info = @typeInfo(field.field_type); | 433 | const field_type_info = @typeInfo(field.field_type); |
| 434 | 434 | ||
| 435 | const ret = switch (field.field_type) { | 435 | const ret = switch (field.field_type) { |
| 436 | Blob => try self.readBytes(Blob, i, .Blob, options), | 436 | Blob => try self.readBytes(Blob, options.allocator, i, .Blob), |
| 437 | Text => try self.readBytes(Text, i, .Text, options), | 437 | Text => try self.readBytes(Text, options.allocator, i, .Text), |
| 438 | else => switch (field_type_info) { | 438 | else => switch (field_type_info) { |
| 439 | .Int => try self.readInt(field.field_type, i), | 439 | .Int => try self.readInt(field.field_type, i), |
| 440 | .Float => try self.readFloat(field.field_type, i), | 440 | .Float => try self.readFloat(field.field_type, i), |