From 876b389e160f694c7ee487f970de62097d97d57b Mon Sep 17 00:00:00 2001 From: Gracen Date: Sun, 8 Jun 2025 11:39:57 -0600 Subject: fix https://github.com/vrischmann/zig-sqlite/issues/187 --- query.zig | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'query.zig') diff --git a/query.zig b/query.zig index 31245f7..e1f3631 100644 --- a/query.zig +++ b/query.zig @@ -53,6 +53,11 @@ pub fn ParsedQuery(comptime tmp_query: []const u8) type { var pos = 0; var state = .start; + // This holds the starting character of the string while + // state is .inside_string so that we know which type of + // string we're exiting from + var string_starting_character = null; + var current_bind_marker_type: [256]u8 = undefined; var current_bind_marker_type_pos = 0; @@ -75,6 +80,7 @@ pub fn ParsedQuery(comptime tmp_query: []const u8) type { }, '\'', '"', '[', '`' => { state = .inside_string; + string_starting_character = c; buf[pos] = c; pos += 1; }, @@ -84,8 +90,23 @@ pub fn ParsedQuery(comptime tmp_query: []const u8) type { }, }, .inside_string => switch (c) { - '\'', '"', ']', '`' => { - state = .start; + '\'' => { + if (string_starting_character == '\'') state = .start; + buf[pos] = c; + pos += 1; + }, + '"' => { + if (string_starting_character == '"') state = .start; + buf[pos] = c; + pos += 1; + }, + ']' => { + if (string_starting_character == '[') state = .start; + buf[pos] = c; + pos += 1; + }, + '`' => { + if (string_starting_character == '`') state = .start; buf[pos] = c; pos += 1; }, -- cgit v1.2.3