From 507cf8090fe2e08b6b298551a8eb8e4f9104357d Mon Sep 17 00:00:00 2001 From: Vincent Rischmann Date: Sun, 18 Jul 2021 16:03:28 +0200 Subject: document that fixed-sized arrays are supported --- README.md | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'README.md') diff --git a/README.md b/README.md index e922f62..235cbc7 100644 --- a/README.md +++ b/README.md @@ -242,7 +242,29 @@ if (row) |row| { ``` Notice that to read text we need to use a 0-terminated array; if the `name` column is bigger than 127 bytes the call to `one` will fail. -The sentinel is mandatory: without one there would be no way to know where the data ends in the array. +If the length of the data is variable then the sentinel is mandatory: without one there would be no way to know where the data ends in the array. + +However if the length is fixed, you can read into a non 0-terminated array, for example: + +```zig +const query = + \\SELECT id FROM employees WHERE name = ? +; + +var stmt = try db.prepare(query); +defer stmt.deinit(); + +const row = try stmt.one( + [16]u8, + .{}, + .{ .name = "Vincent" }, +); +if (row) |id| { + std.log.debug("id: {s}", .{std.fmt.fmtSliceHexLower(&id)}); +} +``` + +If the column data doesn't have the correct length a `error.ArraySizeMismatch` will be returned. The convenience function `sqlite.Db.one` works exactly the same way: -- cgit v1.2.3