diff options
| author | 2022-05-03 00:24:40 +0200 | |
|---|---|---|
| committer | 2022-05-03 00:53:53 +0200 | |
| commit | 58c92dce9e4e81373ec0d8c0668b09697338e653 (patch) | |
| tree | 6abcdf01b3e01873e9d2da29afe2ef3bd2ada498 | |
| parent | Merge branch 'fix-bind-identifier-parsing' (diff) | |
| download | zig-sqlite-58c92dce9e4e81373ec0d8c0668b09697338e653.tar.gz zig-sqlite-58c92dce9e4e81373ec0d8c0668b09697338e653.tar.xz zig-sqlite-58c92dce9e4e81373ec0d8c0668b09697338e653.zip | |
allow parsing optional types in bind marker types
Diffstat (limited to '')
| -rw-r--r-- | query.zig | 17 |
1 files changed, 16 insertions, 1 deletions
| @@ -112,7 +112,18 @@ pub const ParsedQuery = struct { | |||
| 112 | '}' => { | 112 | '}' => { |
| 113 | state = .start; | 113 | state = .start; |
| 114 | 114 | ||
| 115 | const typ = parseType(current_bind_marker_type[0..current_bind_marker_type_pos]); | 115 | const type_info_string = current_bind_marker_type[0..current_bind_marker_type_pos]; |
| 116 | // Handles optional types | ||
| 117 | const typ = if (type_info_string[0] == '?') blk: { | ||
| 118 | const child_type = parseType(type_info_string[1..]); | ||
| 119 | break :blk @Type(std.builtin.TypeInfo{ | ||
| 120 | .Optional = .{ | ||
| 121 | .child = child_type, | ||
| 122 | }, | ||
| 123 | }); | ||
| 124 | } else blk: { | ||
| 125 | break :blk parseType(type_info_string); | ||
| 126 | }; | ||
| 116 | 127 | ||
| 117 | parsed_query.bind_markers[parsed_query.nb_bind_markers].typed = typ; | 128 | parsed_query.bind_markers[parsed_query.nb_bind_markers].typed = typ; |
| 118 | parsed_query.nb_bind_markers += 1; | 129 | parsed_query.nb_bind_markers += 1; |
| @@ -252,6 +263,10 @@ test "parsed query: bind markers types" { | |||
| 252 | .query = "foobar " ++ prefix, | 263 | .query = "foobar " ++ prefix, |
| 253 | .expected_marker = .{ .typed = null }, | 264 | .expected_marker = .{ .typed = null }, |
| 254 | }, | 265 | }, |
| 266 | .{ | ||
| 267 | .query = "foobar " ++ prefix ++ "{?[]const u8}", | ||
| 268 | .expected_marker = .{ .typed = ?[]const u8 }, | ||
| 269 | }, | ||
| 255 | }; | 270 | }; |
| 256 | 271 | ||
| 257 | inline for (testCases) |tc| { | 272 | inline for (testCases) |tc| { |