summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorGravatar Vincent Rischmann2021-07-18 16:03:28 +0200
committerGravatar Vincent Rischmann2021-07-18 16:03:28 +0200
commit507cf8090fe2e08b6b298551a8eb8e4f9104357d (patch)
treed8983dee126fd883c2ba5e7fc57571c514fe4c95 /README.md
parentMerge branch 'add-gitattributes' (diff)
downloadzig-sqlite-507cf8090fe2e08b6b298551a8eb8e4f9104357d.tar.gz
zig-sqlite-507cf8090fe2e08b6b298551a8eb8e4f9104357d.tar.xz
zig-sqlite-507cf8090fe2e08b6b298551a8eb8e4f9104357d.zip
document that fixed-sized arrays are supported
Diffstat (limited to '')
-rw-r--r--README.md24
1 files changed, 23 insertions, 1 deletions
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| {
242``` 242```
243Notice 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. 243Notice 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.
244 244
245The sentinel is mandatory: without one there would be no way to know where the data ends in the array. 245If 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.
246
247However if the length is fixed, you can read into a non 0-terminated array, for example:
248
249```zig
250const query =
251 \\SELECT id FROM employees WHERE name = ?
252;
253
254var stmt = try db.prepare(query);
255defer stmt.deinit();
256
257const row = try stmt.one(
258 [16]u8,
259 .{},
260 .{ .name = "Vincent" },
261);
262if (row) |id| {
263 std.log.debug("id: {s}", .{std.fmt.fmtSliceHexLower(&id)});
264}
265```
266
267If the column data doesn't have the correct length a `error.ArraySizeMismatch` will be returned.
246 268
247The convenience function `sqlite.Db.one` works exactly the same way: 269The convenience function `sqlite.Db.one` works exactly the same way:
248 270