diff options
| author | 2021-01-01 17:47:38 +0100 | |
|---|---|---|
| committer | 2021-01-01 17:47:38 +0100 | |
| commit | 281549e4cab07deb7fdd8fff6cdd13f0b2e4051e (patch) | |
| tree | 0fb8fe8f83bd69ce81469ae6b2917058d6e55ba2 /README.md | |
| parent | build: set the target (diff) | |
| download | zig-sqlite-281549e4cab07deb7fdd8fff6cdd13f0b2e4051e.tar.gz zig-sqlite-281549e4cab07deb7fdd8fff6cdd13f0b2e4051e.tar.xz zig-sqlite-281549e4cab07deb7fdd8fff6cdd13f0b2e4051e.zip | |
readme: document statement reuse
Fixes #3
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 21 |
1 files changed, 21 insertions, 0 deletions
| @@ -102,6 +102,27 @@ try stmt.exec({ | |||
| 102 | 102 | ||
| 103 | See the section "Bind parameters and resultset rows" for more information on the types mapping rules. | 103 | See the section "Bind parameters and resultset rows" for more information on the types mapping rules. |
| 104 | 104 | ||
| 105 | ## Reuse a statement | ||
| 106 | |||
| 107 | You can reuse a statement by resetting it like this: | ||
| 108 | ```zig | ||
| 109 | const query = | ||
| 110 | \\UPDATE foo SET salary = ? WHERE id = ? | ||
| 111 | ; | ||
| 112 | |||
| 113 | var stmt = try db.prepare(query); | ||
| 114 | defer stmt.deinit(); | ||
| 115 | |||
| 116 | var id: usize = 0; | ||
| 117 | while (id < 20) : (id += 1) { | ||
| 118 | stmt.reset(); | ||
| 119 | try stmt.exec(.{ | ||
| 120 | .salary = 2000, | ||
| 121 | .id = id, | ||
| 122 | }); | ||
| 123 | } | ||
| 124 | ``` | ||
| 125 | |||
| 105 | ## Reading data | 126 | ## Reading data |
| 106 | 127 | ||
| 107 | For queries which return data you have multiple options: | 128 | For queries which return data you have multiple options: |