Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions pegjs/sqlite.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -2655,26 +2655,11 @@ single_quote_char
/ escape_char

single_char
= [^'\\] // remove \0-\x1F\x7f pnCtrl char [^'\\\0-\x1F\x7f]
= [^'] // remove \0-\x1F\x7f pnCtrl char [^'\\\0-\x1F\x7f]
/ escape_char

escape_char
= "\\'" { return "\\'"; }
/ '\\"' { return '\\"'; }
/ "\\\\" { return "\\\\"; }
/ "\\/" { return "\\/"; }
/ "\\b" { return "\b"; }
/ "\\f" { return "\f"; }
/ "\\n" { return "\n"; }
/ "\\r" { return "\r"; }
/ "\\t" { return "\t"; }
/ "\\u" h1:hexDigit h2:hexDigit h3:hexDigit h4:hexDigit {
return String.fromCharCode(parseInt("0x" + h1 + h2 + h3 + h4));
}
/ "\\" { return "\\"; }
/ "''" { return "''" }
/ '""' { return '""' }
/ '``' { return '``' }
= "''"

line_terminator
= [\n\r]
Expand Down
8 changes: 6 additions & 2 deletions test/sqlite.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,12 @@ describe('sqlite', () => {
})
})
it('should support LIKE with ESCAPE', () => {
const sql = `SELECT * FROM table_name WHERE column_name LIKE '%pattern%' ESCAPE '\'`
expect(getParsedSql(sql)).to.be.equal(`SELECT * FROM "table_name" WHERE "column_name" LIKE '%pattern%' ESCAPE '\'`)
const sql = `SELECT * FROM table_name WHERE column_name LIKE '%pattern%' ESCAPE 'x'`
expect(getParsedSql(sql)).to.be.equal(`SELECT * FROM "table_name" WHERE "column_name" LIKE '%pattern%' ESCAPE 'x'`)
})
it('should allow single backslash without escaping', () => {
const sql = `SELECT * FROM table_name WHERE column_name LIKE '\\_%' ESCAPE '\\'`
expect(getParsedSql(sql)).to.be.equal(`SELECT * FROM "table_name" WHERE "column_name" LIKE '\\_%' ESCAPE '\\'`)
})
it('should support string concatenation in LIKE opts', () => {
const sql = `SELECT * FROM file WHERE path LIKE 'C:' || CHAR(92) || 'Users' || CHAR(92) || 'example.txt'`
Expand Down