diff options
| author | 2024-10-23 02:50:55 +0600 | |
|---|---|---|
| committer | 2024-10-23 02:50:55 +0600 | |
| commit | e964c6eb2b95f692875ae344374bc99c99013120 (patch) | |
| tree | 593b8d5869f99a9971ba5fa400e2a7b475ef76e1 /query.zig | |
| parent | Merge pull request #166 from vrischmann/update-sqlite (diff) | |
| download | zig-sqlite-e964c6eb2b95f692875ae344374bc99c99013120.tar.gz zig-sqlite-e964c6eb2b95f692875ae344374bc99c99013120.tar.xz zig-sqlite-e964c6eb2b95f692875ae344374bc99c99013120.zip | |
Reuse field for binding
Diffstat (limited to '')
| -rw-r--r-- | query.zig | 17 |
1 files changed, 11 insertions, 6 deletions
| @@ -125,11 +125,11 @@ pub fn ParsedQuery(comptime tmp_query: []const u8) type { | |||
| 125 | if (!isNamedIdentifierChar(c)) { | 125 | if (!isNamedIdentifierChar(c)) { |
| 126 | // This marks the end of the named bind marker. | 126 | // This marks the end of the named bind marker. |
| 127 | state = .start; | 127 | state = .start; |
| 128 | const name = buf[hold_pos .. pos - 1]; | 128 | const name = buf[hold_pos - 1 .. pos]; |
| 129 | // TODO(vincent): name retains a pointer to a comptime var, FIX ! | 129 | // TODO(vincent): name retains a pointer to a comptime var, FIX ! |
| 130 | if (bindMarkerForName(tmp_bind_markers[0..nb_tmp_bind_markers], name) == null) { | 130 | if (bindMarkerForName(tmp_bind_markers[0..nb_tmp_bind_markers], name) == null) { |
| 131 | const new_buf = buf; | 131 | const new_buf = buf; |
| 132 | tmp_bind_markers[nb_tmp_bind_markers].name = new_buf[hold_pos .. pos - 1]; | 132 | tmp_bind_markers[nb_tmp_bind_markers].name = new_buf[hold_pos - 1 .. pos]; |
| 133 | nb_tmp_bind_markers += 1; | 133 | nb_tmp_bind_markers += 1; |
| 134 | } | 134 | } |
| 135 | } | 135 | } |
| @@ -175,6 +175,8 @@ pub fn ParsedQuery(comptime tmp_query: []const u8) type { | |||
| 175 | nb_tmp_bind_markers += 1; | 175 | nb_tmp_bind_markers += 1; |
| 176 | }, | 176 | }, |
| 177 | .bind_marker_identifier => { | 177 | .bind_marker_identifier => { |
| 178 | const new_buf = buf; | ||
| 179 | tmp_bind_markers[nb_tmp_bind_markers].name = @as([]const u8, new_buf[hold_pos - 1 .. pos]); | ||
| 178 | nb_tmp_bind_markers += 1; | 180 | nb_tmp_bind_markers += 1; |
| 179 | }, | 181 | }, |
| 180 | .start => {}, | 182 | .start => {}, |
| @@ -339,15 +341,15 @@ test "parsed query: bind markers identifier" { | |||
| 339 | }, | 341 | }, |
| 340 | .{ | 342 | .{ |
| 341 | .query = "foobar ?123", | 343 | .query = "foobar ?123", |
| 342 | .expected_marker = .{}, | 344 | .expected_marker = .{ .typed = null, .name = "123" }, |
| 343 | }, | 345 | }, |
| 344 | .{ | 346 | .{ |
| 345 | .query = "foobar :hola", | 347 | .query = "foobar :hola", |
| 346 | .expected_marker = .{}, | 348 | .expected_marker = .{ .typed = null, .name = "hola" }, |
| 347 | }, | 349 | }, |
| 348 | .{ | 350 | .{ |
| 349 | .query = "foobar @foo", | 351 | .query = "foobar @foo", |
| 350 | .expected_marker = .{}, | 352 | .expected_marker = .{ .typed = null, .name = "foo" }, |
| 351 | }, | 353 | }, |
| 352 | }; | 354 | }; |
| 353 | 355 | ||
| @@ -357,7 +359,10 @@ test "parsed query: bind markers identifier" { | |||
| 357 | try testing.expectEqual(@as(usize, 1), parsed_query.bind_markers.len); | 359 | try testing.expectEqual(@as(usize, 1), parsed_query.bind_markers.len); |
| 358 | 360 | ||
| 359 | const bind_marker = parsed_query.bind_markers[0]; | 361 | const bind_marker = parsed_query.bind_markers[0]; |
| 360 | try testing.expectEqual(tc.expected_marker, bind_marker); | 362 | if (bind_marker.name) |name| { |
| 363 | try testing.expectEqualStrings(tc.expected_marker.name.?, name); | ||
| 364 | } | ||
| 365 | try testing.expectEqual(tc.expected_marker.typed, bind_marker.typed); | ||
| 361 | } | 366 | } |
| 362 | } | 367 | } |
| 363 | 368 | ||