diff options
Diffstat (limited to '')
| -rw-r--r-- | sqlite.zig | 48 |
1 files changed, 34 insertions, 14 deletions
| @@ -2865,23 +2865,43 @@ test "sqlite: optional" { | |||
| 2865 | 2865 | ||
| 2866 | const published: ?bool = true; | 2866 | const published: ?bool = true; |
| 2867 | 2867 | ||
| 2868 | try db.exec("INSERT INTO article(author_id, data, is_published) VALUES(?, ?, ?)", .{}, .{ 1, null, published }); | 2868 | { |
| 2869 | try db.exec("INSERT INTO article(author_id, data, is_published) VALUES(?, ?, ?)", .{}, .{ 1, null, published }); | ||
| 2869 | 2870 | ||
| 2870 | var stmt = try db.prepare("SELECT data, is_published FROM article"); | 2871 | var stmt = try db.prepare("SELECT data, is_published FROM article"); |
| 2871 | defer stmt.deinit(); | 2872 | defer stmt.deinit(); |
| 2872 | 2873 | ||
| 2873 | const row = try stmt.one( | 2874 | const row = try stmt.one( |
| 2874 | struct { | 2875 | struct { |
| 2875 | data: ?[128:0]u8, | 2876 | data: ?[128:0]u8, |
| 2876 | is_published: ?bool, | 2877 | is_published: ?bool, |
| 2877 | }, | 2878 | }, |
| 2878 | .{}, | 2879 | .{}, |
| 2879 | .{}, | 2880 | .{}, |
| 2880 | ); | 2881 | ); |
| 2881 | 2882 | ||
| 2882 | try testing.expect(row != null); | 2883 | try testing.expect(row != null); |
| 2883 | try testing.expect(row.?.data == null); | 2884 | try testing.expect(row.?.data == null); |
| 2884 | try testing.expectEqual(true, row.?.is_published.?); | 2885 | try testing.expectEqual(true, row.?.is_published.?); |
| 2886 | } | ||
| 2887 | |||
| 2888 | { | ||
| 2889 | const data: ?[]const u8 = "hello"; | ||
| 2890 | try db.exec("INSERT INTO article(author_id, data) VALUES(?, :data{?[]const u8})", .{}, .{ | ||
| 2891 | .author_id = 20, | ||
| 2892 | .dhe = data, | ||
| 2893 | }); | ||
| 2894 | |||
| 2895 | const row = try db.oneAlloc( | ||
| 2896 | []const u8, | ||
| 2897 | arena.allocator(), | ||
| 2898 | "SELECT data FROM article WHERE author_id = ?", | ||
| 2899 | .{}, | ||
| 2900 | .{ .author_id = 20 }, | ||
| 2901 | ); | ||
| 2902 | try testing.expect(row != null); | ||
| 2903 | try testing.expectEqualStrings(data.?, row.?); | ||
| 2904 | } | ||
| 2885 | } | 2905 | } |
| 2886 | 2906 | ||
| 2887 | test "sqlite: statement reset" { | 2907 | test "sqlite: statement reset" { |