diff options
| -rw-r--r-- | query.zig | 7 | ||||
| -rw-r--r-- | sqlite.zig | 4 |
2 files changed, 8 insertions, 3 deletions
| @@ -16,7 +16,7 @@ const BindMarker = struct { | |||
| 16 | }; | 16 | }; |
| 17 | 17 | ||
| 18 | fn isNamedIdentifierChar(c: u8) bool { | 18 | fn isNamedIdentifierChar(c: u8) bool { |
| 19 | return std.ascii.isAlpha(c) or std.ascii.isDigit(c); | 19 | return std.ascii.isAlpha(c) or std.ascii.isDigit(c) or c == '_'; |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | pub const ParsedQuery = struct { | 22 | pub const ParsedQuery = struct { |
| @@ -341,6 +341,11 @@ test "parsed query: query bind identifier" { | |||
| 341 | .expected_query = "SELECT id, name, age FROM user WHER age > :ageGT AND age < $ageLT", | 341 | .expected_query = "SELECT id, name, age FROM user WHER age > :ageGT AND age < $ageLT", |
| 342 | .expected_nb_bind_markers = 2, | 342 | .expected_nb_bind_markers = 2, |
| 343 | }, | 343 | }, |
| 344 | .{ | ||
| 345 | .query = "SELECT id, name, age FROM user WHER age > $my_age{i32} AND age < :your_age{i32}", | ||
| 346 | .expected_query = "SELECT id, name, age FROM user WHER age > $my_age AND age < :your_age", | ||
| 347 | .expected_nb_bind_markers = 2, | ||
| 348 | }, | ||
| 344 | }; | 349 | }; |
| 345 | 350 | ||
| 346 | inline for (testCases) |tc| { | 351 | inline for (testCases) |tc| { |
| @@ -3534,9 +3534,9 @@ test "sqlite: one with all named parameters" { | |||
| 3534 | 3534 | ||
| 3535 | const id = try db.one( | 3535 | const id = try db.one( |
| 3536 | usize, | 3536 | usize, |
| 3537 | "SELECT id FROM user WHERE age = $age AND weight < :weight and id < @id", | 3537 | "SELECT id FROM user WHERE age = $age AND weight < :weight and id < @my_id", |
| 3538 | .{ .diags = &diags }, | 3538 | .{ .diags = &diags }, |
| 3539 | .{ .id = 400, .age = 33, .weight = 200 }, | 3539 | .{ .my_id = 400, .age = 33, .weight = 200 }, |
| 3540 | ); | 3540 | ); |
| 3541 | try testing.expect(id != null); | 3541 | try testing.expect(id != null); |
| 3542 | try testing.expectEqual(@as(usize, 20), id.?); | 3542 | try testing.expectEqual(@as(usize, 20), id.?); |