diff options
| author | 2024-12-14 01:33:00 +0100 | |
|---|---|---|
| committer | 2024-12-14 01:33:00 +0100 | |
| commit | 324872564c48417bee7117c51ba954667ee89441 (patch) | |
| tree | 20f674e1c35bbaad72c9a9e55c8542c414e5eabe | |
| parent | readme: fix example (diff) | |
| download | zig-sqlite-324872564c48417bee7117c51ba954667ee89441.tar.gz zig-sqlite-324872564c48417bee7117c51ba954667ee89441.tar.xz zig-sqlite-324872564c48417bee7117c51ba954667ee89441.zip | |
readme: fix examples
Diffstat (limited to '')
| -rw-r--r-- | README.md | 10 |
1 files changed, 7 insertions, 3 deletions
| @@ -469,7 +469,9 @@ Take the following code: | |||
| 469 | var stmt = try db.prepare("SELECT id FROM user WHERE age > ? AND age < ? AND weight > ?"); | 469 | var stmt = try db.prepare("SELECT id FROM user WHERE age > ? AND age < ? AND weight > ?"); |
| 470 | defer stmt.deinit(); | 470 | defer stmt.deinit(); |
| 471 | 471 | ||
| 472 | const rows = try stmt.all(usize, .{}, .{ | 472 | const allocator = std.heap.page_allocator; // Use a suitable allocator |
| 473 | |||
| 474 | const rows = try stmt.all(usize, allocator, .{}, .{ | ||
| 473 | .age_1 = 10, | 475 | .age_1 = 10, |
| 474 | .age_2 = 20, | 476 | .age_2 = 20, |
| 475 | }); | 477 | }); |
| @@ -504,7 +506,9 @@ For example, take the same code as above but now we also bind the last parameter | |||
| 504 | var stmt = try db.prepare("SELECT id FROM user WHERE age > ? AND age < ? AND weight > ?"); | 506 | var stmt = try db.prepare("SELECT id FROM user WHERE age > ? AND age < ? AND weight > ?"); |
| 505 | defer stmt.deinit(); | 507 | defer stmt.deinit(); |
| 506 | 508 | ||
| 507 | const rows = try stmt.all(usize, .{ .allocator = allocator }, .{ | 509 | const allocator = std.heap.page_allocator; // Use a suitable allocator |
| 510 | |||
| 511 | const rows = try stmt.all(usize, allocator, .{}, .{ | ||
| 508 | .age_1 = 10, | 512 | .age_1 = 10, |
| 509 | .age_2 = 20, | 513 | .age_2 = 20, |
| 510 | .weight = false, | 514 | .weight = false, |
| @@ -519,7 +523,7 @@ We can make sure the bind parameters have the right type if we rewrite the query | |||
| 519 | var stmt = try db.prepare("SELECT id FROM user WHERE age > ? AND age < ? AND weight > ?{usize}"); | 523 | var stmt = try db.prepare("SELECT id FROM user WHERE age > ? AND age < ? AND weight > ?{usize}"); |
| 520 | defer stmt.deinit(); | 524 | defer stmt.deinit(); |
| 521 | 525 | ||
| 522 | const rows = try stmt.all(usize, .{ .allocator = allocator }, .{ | 526 | const rows = try stmt.all(usize, allocator, .{}, .{ |
| 523 | .age_1 = 10, | 527 | .age_1 = 10, |
| 524 | .age_2 = 20, | 528 | .age_2 = 20, |
| 525 | .weight = false, | 529 | .weight = false, |