summaryrefslogtreecommitdiff
path: root/sqlite.zig
diff options
context:
space:
mode:
authorGravatar Vincent Rischmann2022-05-03 00:30:49 +0200
committerGravatar Vincent Rischmann2022-05-03 00:53:53 +0200
commit7df239cbf107e0484f844767e3f46412ad6eabb9 (patch)
tree5867f44378cfd5a11f7741f7d9fc2538d708fa60 /sqlite.zig
parentallow parsing optional types in bind marker types (diff)
downloadzig-sqlite-7df239cbf107e0484f844767e3f46412ad6eabb9.tar.gz
zig-sqlite-7df239cbf107e0484f844767e3f46412ad6eabb9.tar.xz
zig-sqlite-7df239cbf107e0484f844767e3f46412ad6eabb9.zip
add a test for a bind marker with an optional type
Diffstat (limited to '')
-rw-r--r--sqlite.zig48
1 files changed, 34 insertions, 14 deletions
diff --git a/sqlite.zig b/sqlite.zig
index d9cff3b..619e0b8 100644
--- a/sqlite.zig
+++ b/sqlite.zig
@@ -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
2887test "sqlite: statement reset" { 2907test "sqlite: statement reset" {