summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vincent Rischmann2022-05-02 19:21:22 +0200
committerGravatar Vincent Rischmann2022-05-02 19:21:22 +0200
commitd4bc0c0ee29e5c8b253d80c0fa5f2bbecbaeda39 (patch)
tree890e7957ceef912f0569f178b3b953d817b4a9c3
parentput the TODO comment at the end of the line instead (diff)
downloadzig-sqlite-d4bc0c0ee29e5c8b253d80c0fa5f2bbecbaeda39.tar.gz
zig-sqlite-d4bc0c0ee29e5c8b253d80c0fa5f2bbecbaeda39.tar.xz
zig-sqlite-d4bc0c0ee29e5c8b253d80c0fa5f2bbecbaeda39.zip
the '_' character is valid in a named bind parameter
-rw-r--r--query.zig7
-rw-r--r--sqlite.zig4
2 files changed, 8 insertions, 3 deletions
diff --git a/query.zig b/query.zig
index bc1bbc1..45577a1 100644
--- a/query.zig
+++ b/query.zig
@@ -16,7 +16,7 @@ const BindMarker = struct {
16}; 16};
17 17
18fn isNamedIdentifierChar(c: u8) bool { 18fn 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
22pub const ParsedQuery = struct { 22pub 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| {
diff --git a/sqlite.zig b/sqlite.zig
index 5299e7f..d9cff3b 100644
--- a/sqlite.zig
+++ b/sqlite.zig
@@ -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.?);