Skip to content

Commit c6781be

Browse files
committed
fix: hex number in values in tsql
1 parent 5c8bbba commit c6781be

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

pegjs/transactsql.pegjs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2640,7 +2640,7 @@ literal_bool
26402640
}
26412641

26422642
literal_string
2643-
= r:'N'i? ca:("'" single_char* "'") {
2643+
= r:'N'i? ca:("'" single_char* "'") {
26442644
return {
26452645
type: r ? 'var_string' : 'single_quote_string',
26462646
value: ca[1].join(''),
@@ -2652,6 +2652,13 @@ literal_string
26522652
value: ca[1].join('')
26532653
};
26542654
}
2655+
/ b:('_binary'i / '_latin1'i)? __ r:'0x'i ca:([0-9A-Fa-f]*) {
2656+
return {
2657+
type: 'full_hex_string',
2658+
prefix: b,
2659+
value: ca.join('')
2660+
};
2661+
}
26552662

26562663
literal_datetime
26572664
= type:(KW_TIME / KW_DATE / KW_TIMESTAMP / KW_DATETIME) __ ca:("'" single_char* "'") {

test/transactsql.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,10 @@ describe('transactsql', () => {
279279
const sql = "INSERT [dbo].[testtable] ([NodeID], [Timestamp], [ResponseTime], [PercentLoss], [Availability], [Weight]) VALUES (2, CAST(N'2023-04-11T22:17:13.0864249' AS DateTime2), 0, 0, 100, 120)"
280280
expect(getParsedSql(sql)).to.be.equal("INSERT INTO [dbo].[testtable] (NodeID, Timestamp, ResponseTime, PercentLoss, Availability, Weight) VALUES (2,CAST(N'2023-04-11T22:17:13.0864249' AS DATETIME2),0,0,100,120)")
281281
})
282+
it('should support hex string', () => {
283+
const sql = 'INSERT INTO [dbo].[mytable]([value]) values( 0x11 );'
284+
expect(getParsedSql(sql)).to.be.equal('INSERT INTO [dbo].[mytable] (value) VALUES (0x11)')
285+
})
282286
it('should support for xml', () => {
283287
const base = `SELECT Cust.CustomerID,
284288
OrderHeader.CustomerID,

0 commit comments

Comments
 (0)