diff options
| -rw-r--r-- | sqlite.zig | 20 |
1 files changed, 12 insertions, 8 deletions
| @@ -276,7 +276,7 @@ fn getDetailedErrorFromResultCode(code: c_int) DetailedError { | |||
| 276 | .code = @intCast(usize, code), | 276 | .code = @intCast(usize, code), |
| 277 | .message = blk: { | 277 | .message = blk: { |
| 278 | const msg = c.sqlite3_errstr(code); | 278 | const msg = c.sqlite3_errstr(code); |
| 279 | break :blk mem.spanZ(msg); | 279 | break :blk mem.sliceTo(msg, 0); |
| 280 | }, | 280 | }, |
| 281 | }; | 281 | }; |
| 282 | } | 282 | } |
| @@ -286,7 +286,7 @@ fn getLastDetailedErrorFromDb(db: *c.sqlite3) DetailedError { | |||
| 286 | .code = @intCast(usize, c.sqlite3_extended_errcode(db)), | 286 | .code = @intCast(usize, c.sqlite3_extended_errcode(db)), |
| 287 | .message = blk: { | 287 | .message = blk: { |
| 288 | const msg = c.sqlite3_errmsg(db); | 288 | const msg = c.sqlite3_errmsg(db); |
| 289 | break :blk mem.spanZ(msg); | 289 | break :blk mem.sliceTo(msg, 0); |
| 290 | }, | 290 | }, |
| 291 | }; | 291 | }; |
| 292 | } | 292 | } |
| @@ -1948,7 +1948,7 @@ test "sqlite: db pragma" { | |||
| 1948 | { | 1948 | { |
| 1949 | const journal_mode = try db.pragma([128:0]u8, .{}, "journal_mode", "wal"); | 1949 | const journal_mode = try db.pragma([128:0]u8, .{}, "journal_mode", "wal"); |
| 1950 | try testing.expect(journal_mode != null); | 1950 | try testing.expect(journal_mode != null); |
| 1951 | try testing.expectEqualStrings("memory", mem.spanZ(&journal_mode.?)); | 1951 | try testing.expectEqualStrings("memory", mem.sliceTo(&journal_mode.?, 0)); |
| 1952 | } | 1952 | } |
| 1953 | 1953 | ||
| 1954 | { | 1954 | { |
| @@ -1960,7 +1960,7 @@ test "sqlite: db pragma" { | |||
| 1960 | { | 1960 | { |
| 1961 | const journal_mode = try db.pragma([128:0]u8, .{}, "journal_mode", "wal"); | 1961 | const journal_mode = try db.pragma([128:0]u8, .{}, "journal_mode", "wal"); |
| 1962 | try testing.expect(journal_mode != null); | 1962 | try testing.expect(journal_mode != null); |
| 1963 | try testing.expectEqualStrings("wal", mem.spanZ(&journal_mode.?)); | 1963 | try testing.expectEqualStrings("wal", mem.sliceTo(&journal_mode.?, 0)); |
| 1964 | } | 1964 | } |
| 1965 | 1965 | ||
| 1966 | { | 1966 | { |
| @@ -2069,7 +2069,7 @@ test "sqlite: read a single user into a struct" { | |||
| 2069 | 2069 | ||
| 2070 | const exp = test_users[0]; | 2070 | const exp = test_users[0]; |
| 2071 | try testing.expectEqual(exp.id, row.?.id); | 2071 | try testing.expectEqual(exp.id, row.?.id); |
| 2072 | try testing.expectEqualStrings(exp.name, mem.spanZ(&row.?.name)); | 2072 | try testing.expectEqualStrings(exp.name, mem.sliceTo(&row.?.name, 0)); |
| 2073 | try testing.expectEqual(exp.age, row.?.age); | 2073 | try testing.expectEqual(exp.age, row.?.age); |
| 2074 | } | 2074 | } |
| 2075 | 2075 | ||
| @@ -2146,7 +2146,7 @@ test "sqlite: read in an anonymous struct" { | |||
| 2146 | const exp = test_users[0]; | 2146 | const exp = test_users[0]; |
| 2147 | try testing.expectEqual(exp.id, row.?.id); | 2147 | try testing.expectEqual(exp.id, row.?.id); |
| 2148 | try testing.expectEqualStrings(exp.name, row.?.name); | 2148 | try testing.expectEqualStrings(exp.name, row.?.name); |
| 2149 | try testing.expectEqualStrings(exp.name, mem.spanZ(&row.?.name_2)); | 2149 | try testing.expectEqualStrings(exp.name, mem.sliceTo(&row.?.name_2, 0xAD)); |
| 2150 | try testing.expectEqual(exp.age, row.?.age); | 2150 | try testing.expectEqual(exp.age, row.?.age); |
| 2151 | try testing.expect(row.?.is_id); | 2151 | try testing.expect(row.?.is_id); |
| 2152 | try testing.expectEqual(exp.weight, @floatCast(f32, row.?.weight)); | 2152 | try testing.expectEqual(exp.weight, @floatCast(f32, row.?.weight)); |
| @@ -2200,6 +2200,7 @@ test "sqlite: read a single text value" { | |||
| 2200 | // Array | 2200 | // Array |
| 2201 | [8:0]u8, | 2201 | [8:0]u8, |
| 2202 | [8:0xAD]u8, | 2202 | [8:0xAD]u8, |
| 2203 | [7]u8, | ||
| 2203 | // Specific text or blob | 2204 | // Specific text or blob |
| 2204 | Text, | 2205 | Text, |
| 2205 | Blob, | 2206 | Blob, |
| @@ -2224,7 +2225,10 @@ test "sqlite: read a single text value" { | |||
| 2224 | const type_info = @typeInfo(typ); | 2225 | const type_info = @typeInfo(typ); |
| 2225 | break :blk switch (type_info) { | 2226 | break :blk switch (type_info) { |
| 2226 | .Pointer => name.?, | 2227 | .Pointer => name.?, |
| 2227 | .Array => mem.spanZ(&(name.?)), | 2228 | .Array => |arr| if (arr.sentinel) |s| |
| 2229 | mem.sliceTo(&name.?, s) | ||
| 2230 | else | ||
| 2231 | mem.span(&name.?), | ||
| 2228 | else => @compileError("invalid type " ++ @typeName(typ)), | 2232 | else => @compileError("invalid type " ++ @typeName(typ)), |
| 2229 | }; | 2233 | }; |
| 2230 | }; | 2234 | }; |
| @@ -2570,7 +2574,7 @@ test "sqlite: statement iterator" { | |||
| 2570 | 2574 | ||
| 2571 | for (rows.items) |row, j| { | 2575 | for (rows.items) |row, j| { |
| 2572 | const exp_row = expected_rows.items[j]; | 2576 | const exp_row = expected_rows.items[j]; |
| 2573 | try testing.expectEqualStrings(exp_row.name, mem.spanZ(&row.name)); | 2577 | try testing.expectEqualStrings(exp_row.name, mem.sliceTo(&row.name, 0)); |
| 2574 | try testing.expectEqual(exp_row.age, row.age); | 2578 | try testing.expectEqual(exp_row.age, row.age); |
| 2575 | } | 2579 | } |
| 2576 | } | 2580 | } |