Skip to content

Commit 4addd71

Browse files
Spxgshssoichiro
authored andcommitted
Add fmt for SQLite blob literal
1 parent 8097179 commit 4addd71

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,27 @@ mod tests {
109109
use indoc::indoc;
110110
use pretty_assertions::assert_eq;
111111

112+
#[test]
113+
fn test_sqlite_blob_literal_fmt() {
114+
let options = FormatOptions::default();
115+
116+
let input = "SELECT x'73716c69676874' AS BLOB_VAL;";
117+
let expected = indoc!(
118+
"
119+
SELECT
120+
x'73716c69676874' AS BLOB_VAL;"
121+
);
122+
assert_eq!(format(input, &QueryParams::None, &options), expected);
123+
124+
let input = "SELECT X'73716c69676874' AS BLOB_VAL;";
125+
let expected = indoc!(
126+
"
127+
SELECT
128+
X'73716c69676874' AS BLOB_VAL;"
129+
);
130+
assert_eq!(format(input, &QueryParams::None, &options), expected);
131+
}
132+
112133
#[test]
113134
fn it_uses_given_indent_config_for_indentation() {
114135
let input = "SELECT count(*),Column1 FROM Table1;";

src/tokenizer.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ pub fn take_till_escaping<'a>(
208208
// 3. double quoted string using "" or \" to escape
209209
// 4. single quoted string using '' or \' to escape
210210
// 5. national character quoted string using N'' or N\' to escape
211+
// 6. hex(blob literal) does not need to escape
211212
fn get_string_token<'i>(input: &mut &'i str) -> Result<Token<'i>> {
212213
dispatch! {any;
213214
'`' => (take_till_escaping('`', &['`']), any).void(),
@@ -216,6 +217,8 @@ fn get_string_token<'i>(input: &mut &'i str) -> Result<Token<'i>> {
216217
'\'' => (take_till_escaping('\'', &['\'', '\\']), any).void(),
217218
'N' => ('\'', take_till_escaping('\'', &['\'', '\\']), any).void(),
218219
'E' => ('\'', take_till_escaping('\'', &['\'', '\\']), any).void(),
220+
'x' => ('\'', take_till_escaping('\'', &[]), any).void(),
221+
'X' => ('\'', take_till_escaping('\'', &[]), any).void(),
219222
_ => fail,
220223
}
221224
.take()

0 commit comments

Comments
 (0)