Skip to content

Commit 1502e70

Browse files
committed
feat: support hex value
1 parent 4856547 commit 1502e70

5 files changed

Lines changed: 15 additions & 6 deletions

File tree

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
],
6767
"complexity": [
6868
"error",
69-
20
69+
25
7070
],
7171
"space-infix-ops": 2,
7272
"consistent-return": 0,

pegjs/bigquery.pegjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ literal_bool
11241124
literal_string
11251125
= r:'R'i? __ ca:("'" single_char* "'") {
11261126
return {
1127-
type: r ? 'regex_string' : 'string',
1127+
type: r ? 'regex_string' : 'single_quote_string',
11281128
value: ca[1].join('')
11291129
};
11301130
}

pegjs/mysql.pegjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,15 +1997,15 @@ literal_bool
19971997
}
19981998

19991999
literal_string
2000-
= ca:("'" single_char* "'") {
2000+
= r:'X'i? ca:("'" single_char* "'") {
20012001
return {
2002-
type: 'single_quote_string',
2002+
type: r ? 'hex_string' : 'single_quote_string',
20032003
value: ca[1].join('')
20042004
};
20052005
}
2006-
/ ca:("\"" single_quote_char* "\"") {
2006+
/ r:'X'i? ca:("\"" single_quote_char* "\"") {
20072007
return {
2008-
type: 'string',
2008+
type: r ? 'hex_string' : 'string',
20092009
value: ca[1].join('')
20102010
};
20112011
}

src/util.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ function literalToSQL(literal) {
188188
case 'regex_string':
189189
str = `r"${escape(value)}"`
190190
break
191+
case 'hex_string':
192+
str = `X'${escape(value)}'`
193+
break
191194
case 'double_quote_string':
192195
str = `"${escape(value)}"`
193196
break

test/insert.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ describe('insert', () => {
151151
expect(parser.sqlify(parser.astify(`INSERT INTO account (date, id) VALUES ("2019-12-23",123) RETURNING *`, opt), opt)).to.be.equal('INSERT INTO "account" ("date", "id") VALUES ("2019-12-23",123) RETURNING *')
152152
})
153153

154+
it('should support insert hex value', () => {
155+
expect(parser.sqlify(parser.astify(`INSERT INTO \`t\`
156+
(\`a\`) VALUES
157+
(X'ax')`))).to.be.equal("INSERT INTO `t` (`a`) VALUES (X'ax')")
158+
})
159+
154160
describe('support ascii pnCtrl single-char', () => {
155161
it('should support ascii pnCtrl', () => {
156162
// 0~31及127(共33个)是控制字符或通信专用字符 \0-\x1F和\x7f in ascii, ETX ascii code is 0x03

0 commit comments

Comments
 (0)