From dabbb107d719cb753673e394fbd4da090f74d458 Mon Sep 17 00:00:00 2001 From: Ekaitz Zarraga Date: Fri, 2 Aug 2024 13:23:21 +0200 Subject: WIP String queries and proper conversion: Still have to make the type checking better, not just an assert. Rethink. --- src/duckdb/db.zig | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/duckdb/db.zig') diff --git a/src/duckdb/db.zig b/src/duckdb/db.zig index 19feffe..f662ee0 100644 --- a/src/duckdb/db.zig +++ b/src/duckdb/db.zig @@ -109,3 +109,31 @@ test "Checks if all fields are captured" { try std.testing.expectError(error.QueryColumnCountCapture, connection.query("SELECT * FROM integers;", s)); } + +test "String queries" { + var database = try Database.init(":memory:"); + defer database.deinit(); + var connection = try database.connect(); + defer connection.deinit(); + + const s : type = comptime struct { + primer: []const u8 + }; + + var x = try connection.query("CREATE TABLE text (i VARCHAR NOT NULL );", void); + x.deinit(); + var y = try connection.query("INSERT INTO text VALUES ('Inlined');", void); + y.deinit(); + var z = try connection.query("INSERT INTO text VALUES ('A very long string that is not inlined');", void); + z.deinit(); + var result = try connection.query("SELECT * FROM text;", s); + defer result.deinit(); + + + try std.testing.expect(1 == result.getColumnCount()); + + var w = try result.next(); + try std.testing.expect(std.mem.eql(u8, w.primer, "Inlined")); + w = try result.next(); + try std.testing.expect(std.mem.eql(u8, w.primer, "A very long string that is not inlined")); +} -- cgit v1.2.3