diff options
Diffstat (limited to 'query.zig')
| -rw-r--r-- | query.zig | 41 |
1 files changed, 0 insertions, 41 deletions
| @@ -19,13 +19,6 @@ const BindMarker = struct { | |||
| 19 | 19 | ||
| 20 | /// Contains the bind parameter identifier string. | 20 | /// Contains the bind parameter identifier string. |
| 21 | identifier: ?[]const u8 = null, | 21 | identifier: ?[]const u8 = null, |
| 22 | /// Contains the type of the identifier which is either an integer or a string. | ||
| 23 | identifier_type: IdentifierType = .integer, | ||
| 24 | |||
| 25 | pub const IdentifierType = enum { | ||
| 26 | integer, | ||
| 27 | string, | ||
| 28 | }; | ||
| 29 | }; | 22 | }; |
| 30 | 23 | ||
| 31 | pub const ParsedQuery = struct { | 24 | pub const ParsedQuery = struct { |
| @@ -58,7 +51,6 @@ pub const ParsedQuery = struct { | |||
| 58 | parsed_query.bind_markers[parsed_query.nb_bind_markers] = BindMarker{}; | 51 | parsed_query.bind_markers[parsed_query.nb_bind_markers] = BindMarker{}; |
| 59 | current_bind_marker_type_pos = 0; | 52 | current_bind_marker_type_pos = 0; |
| 60 | current_bind_marker_id_pos = 0; | 53 | current_bind_marker_id_pos = 0; |
| 61 | parsed_query.bind_markers[parsed_query.nb_bind_markers].identifier_type = if (c == '?') .integer else .string; | ||
| 62 | state = .BindMarker; | 54 | state = .BindMarker; |
| 63 | buf[pos] = c; | 55 | buf[pos] = c; |
| 64 | pos += 1; | 56 | pos += 1; |
| @@ -349,39 +341,6 @@ test "parsed query: query bind identifier" { | |||
| 349 | } | 341 | } |
| 350 | } | 342 | } |
| 351 | 343 | ||
| 352 | test "parsed query: bind markers identifier type" { | ||
| 353 | const testCase = struct { | ||
| 354 | query: []const u8, | ||
| 355 | expected_marker: BindMarker, | ||
| 356 | }; | ||
| 357 | |||
| 358 | const testCases = &[_]testCase{ .{ | ||
| 359 | .query = "foobar @ABC{usize}", | ||
| 360 | .expected_marker = .{ .identifier_type = .string }, | ||
| 361 | }, .{ | ||
| 362 | .query = "foobar ?123{text}", | ||
| 363 | .expected_marker = .{ .identifier_type = .integer }, | ||
| 364 | }, .{ | ||
| 365 | .query = "foobar $abc{blob}", | ||
| 366 | .expected_marker = .{ .identifier_type = .string }, | ||
| 367 | }, .{ | ||
| 368 | .query = "foobar ?123", | ||
| 369 | .expected_marker = .{ .identifier_type = .integer }, | ||
| 370 | }, .{ | ||
| 371 | .query = "foobar :abc", | ||
| 372 | .expected_marker = .{ .identifier_type = .string }, | ||
| 373 | } }; | ||
| 374 | |||
| 375 | inline for (testCases) |tc| { | ||
| 376 | comptime var parsed_query = ParsedQuery.from(tc.query); | ||
| 377 | |||
| 378 | try testing.expectEqual(@as(usize, 1), parsed_query.nb_bind_markers); | ||
| 379 | |||
| 380 | const bind_marker = parsed_query.bind_markers[0]; | ||
| 381 | try testing.expectEqual(tc.expected_marker.identifier_type, bind_marker.identifier_type); | ||
| 382 | } | ||
| 383 | } | ||
| 384 | |||
| 385 | test "parsed query: bind marker character inside string" { | 344 | test "parsed query: bind marker character inside string" { |
| 386 | const testCase = struct { | 345 | const testCase = struct { |
| 387 | query: []const u8, | 346 | query: []const u8, |