Skip to content

Commit c5b7918

Browse files
authored
Merge pull request #130 from blackbeam/quoted-identifier
Respect quoted identifiers in `ParsedNamedParams::parse` (fix #129)
2 parents 037d4f5 + 234bf43 commit c5b7918

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/named_params.rs

+18
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ enum ParserState {
2626
MaybeInCComment2,
2727
InCComment,
2828
MaybeExitCComment,
29+
InQuotedIdentifier,
2930
}
3031

3132
use self::ParserState::*;
@@ -61,6 +62,7 @@ impl<'a> ParsedNamedParams<'a> {
6162
b'\'' => state = InStringLiteral(b'\'', b'\''),
6263
b'"' => state = InStringLiteral(b'"', b'"'),
6364
b'?' => have_positional = true,
65+
b'`' => state = InQuotedIdentifier,
6466
_ => (),
6567
},
6668
InStringLiteral(separator, prev_char) => match c {
@@ -119,6 +121,11 @@ impl<'a> ParsedNamedParams<'a> {
119121
b'/' => state = TopLevel,
120122
_ => state = InCComment,
121123
},
124+
InQuotedIdentifier => {
125+
if *c == b'`' {
126+
state = TopLevel
127+
}
128+
}
122129
}
123130
if rematch {
124131
match c {
@@ -253,6 +260,17 @@ mod test {
253260
);
254261
}
255262

263+
#[test]
264+
fn quoted_identifier() {
265+
let result = ParsedNamedParams::parse(b"INSERT INTO `my:table` VALUES (?)").unwrap();
266+
assert_eq!(result.query(), b"INSERT INTO `my:table` VALUES (?)");
267+
assert!(result.params().is_empty());
268+
269+
let result = ParsedNamedParams::parse(b"INSERT INTO `my:table` VALUES (:foo)").unwrap();
270+
assert_eq!(result.query(), b"INSERT INTO `my:table` VALUES (?)");
271+
assert_eq!(result.params(), cows!(b"foo"));
272+
}
273+
256274
#[cfg(feature = "nightly")]
257275
mod bench {
258276
use super::*;

0 commit comments

Comments
 (0)