Skip to content

Commit 766c923

Browse files
author
Paul Roskell
committed
Allow alphanumeric characters in SQLLite style parameters.
1 parent 199715a commit 766c923

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

src/lib.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,21 @@ mod tests {
10671067
assert_eq!(format(input, &QueryParams::None, options), expected);
10681068
}
10691069

1070+
#[test]
1071+
fn it_recognizes_dollar_sign_alphanumeric_placeholders() {
1072+
let input = "SELECT $hash, $foo, $bar;";
1073+
let options = FormatOptions::default();
1074+
let expected = indoc!(
1075+
"
1076+
SELECT
1077+
$hash,
1078+
$foo,
1079+
$bar;"
1080+
);
1081+
1082+
assert_eq!(format(input, &QueryParams::None, options), expected);
1083+
}
1084+
10701085
#[test]
10711086
fn it_recognizes_dollar_sign_numbered_placeholders_with_param_values() {
10721087
let input = "SELECT $2, $3, $1;";
@@ -1090,6 +1105,28 @@ mod tests {
10901105
);
10911106
}
10921107

1108+
#[test]
1109+
fn it_recognizes_dollar_sign_alphanumeric_placeholders_with_param_values() {
1110+
let input =
1111+
"SELECT $hash, $salt;";
1112+
let params = vec![
1113+
("hash".to_string(), "hash value".to_string()),
1114+
("salt".to_string(), "salt value".to_string()),
1115+
];
1116+
let options = FormatOptions::default();
1117+
let expected = indoc!(
1118+
"
1119+
SELECT
1120+
hash value,
1121+
salt value;"
1122+
);
1123+
1124+
assert_eq!(
1125+
format(input, &QueryParams::Named(params), options),
1126+
expected
1127+
);
1128+
}
1129+
10931130
#[test]
10941131
fn it_formats_query_with_go_batch_separator() {
10951132
let input = "SELECT 1 GO SELECT 2";

src/tokenizer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,9 @@ fn get_close_paren_token(input: &str) -> IResult<&str, Token<'_>> {
290290

291291
fn get_placeholder_token(input: &str) -> IResult<&str, Token<'_>> {
292292
alt((
293-
get_ident_named_placeholder_token,
294-
get_string_named_placeholder_token,
295293
get_indexed_placeholder_token,
294+
get_ident_named_placeholder_token,
295+
get_string_named_placeholder_token
296296
))(input)
297297
}
298298

@@ -327,7 +327,7 @@ fn get_indexed_placeholder_token(input: &str) -> IResult<&str, Token<'_>> {
327327

328328
fn get_ident_named_placeholder_token(input: &str) -> IResult<&str, Token<'_>> {
329329
recognize(tuple((
330-
alt((char('@'), char(':'))),
330+
alt((char('@'), char(':'), char('$'))),
331331
take_while1(|item: char| {
332332
item.is_alphanumeric() || item == '.' || item == '_' || item == '$'
333333
}),

0 commit comments

Comments
 (0)