diff options
| author | 2021-07-18 16:03:28 +0200 | |
|---|---|---|
| committer | 2021-07-18 16:03:28 +0200 | |
| commit | 507cf8090fe2e08b6b298551a8eb8e4f9104357d (patch) | |
| tree | d8983dee126fd883c2ba5e7fc57571c514fe4c95 | |
| parent | Merge branch 'add-gitattributes' (diff) | |
| download | zig-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.md | 24 |
1 files changed, 23 insertions, 1 deletions
| @@ -242,7 +242,29 @@ if (row) |row| { | |||
| 242 | ``` | 242 | ``` |
| 243 | 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. | 243 | 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. |
| 244 | 244 | ||
| 245 | The sentinel is mandatory: without one there would be no way to know where the data ends in the array. | 245 | 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. |
| 246 | |||
| 247 | However if the length is fixed, you can read into a non 0-terminated array, for example: | ||
| 248 | |||
| 249 | ```zig | ||
| 250 | const query = | ||
| 251 | \\SELECT id FROM employees WHERE name = ? | ||
| 252 | ; | ||
| 253 | |||
| 254 | var stmt = try db.prepare(query); | ||
| 255 | defer stmt.deinit(); | ||
| 256 | |||
| 257 | const row = try stmt.one( | ||
| 258 | [16]u8, | ||
| 259 | .{}, | ||
| 260 | .{ .name = "Vincent" }, | ||
| 261 | ); | ||
| 262 | if (row) |id| { | ||
| 263 | std.log.debug("id: {s}", .{std.fmt.fmtSliceHexLower(&id)}); | ||
| 264 | } | ||
| 265 | ``` | ||
| 266 | |||
| 267 | If the column data doesn't have the correct length a `error.ArraySizeMismatch` will be returned. | ||
| 246 | 268 | ||
| 247 | The convenience function `sqlite.Db.one` works exactly the same way: | 269 | The convenience function `sqlite.Db.one` works exactly the same way: |
| 248 | 270 | ||