Skip to content

Commit c636652

Browse files
committed
feat: support with up in db2
1 parent 63a9c2a commit c636652

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

pegjs/db2.pegjs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,8 @@ select_stmt_nake
10461046
g:group_by_clause? __
10471047
h:having_clause? __
10481048
o:order_by_clause? __
1049-
l:limit_clause? {
1049+
l:limit_clause?
1050+
iso:isolation_clause? __ {
10501051
if(f) f.forEach(info => info.table && tableList.add(`select::${info.db}::${info.table}`));
10511052
return {
10521053
with: cte,
@@ -1059,7 +1060,8 @@ select_stmt_nake
10591060
groupby: g,
10601061
having: h,
10611062
orderby: o,
1062-
limit: l
1063+
limit: l,
1064+
isolation: iso,
10631065
};
10641066
}
10651067

@@ -1341,6 +1343,14 @@ limit_clause
13411343
}
13421344
}
13431345

1346+
isolation_clause
1347+
= KW_WITH __ is:('CS'i / 'UR'i / 'RS'i / 'RR'i) {
1348+
return {
1349+
type: 'isolation',
1350+
keyword: 'with',
1351+
expr: { type: 'origin', value: is },
1352+
}
1353+
}
13441354
update_stmt
13451355
= KW_UPDATE __
13461356
t:table_ref_list __

src/select.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { columnsToSQL } from './column'
33
import { limitToSQL } from './limit'
44
import { withToSQL } from './with'
55
import { tablesToSQL } from './tables'
6-
import { hasVal, commonOptionConnector, connector, identifierToSql, topToSQL, toUpper } from './util'
6+
import { hasVal, commonOptionConnector, connector, identifierToSql, topToSQL, toUpper, literalToSQL } from './util'
77
import { collateToSQL } from './collate'
88

99
function distinctToSQL(distinct) {
@@ -67,6 +67,7 @@ function selectToSQL(stmt) {
6767
groupby,
6868
having,
6969
into = {},
70+
isolation,
7071
limit,
7172
options,
7273
orderby,
@@ -100,6 +101,7 @@ function selectToSQL(stmt) {
100101
clauses.push(orderOrPartitionByToSQL(orderby, 'order by'))
101102
clauses.push(collateToSQL(collate))
102103
clauses.push(limitToSQL(limit))
104+
if (isolation) clauses.push(commonOptionConnector(isolation.keyword, literalToSQL, isolation.expr))
103105
clauses.push(toUpper(lockingRead))
104106
if (position === 'end') clauses.push(intoSQL)
105107
clauses.push(forXmlToSQL(forXml))

test/db2.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ describe('db2', () => {
2727
'SELECT CUSTOMER_NUMBER FROM ORG.CUSTOMER_INFO_1 EXCEPT SELECT CUSTOMER_NUMBER FROM ORG.CUSTOMER_BACKUP'
2828
]
2929
},
30+
{
31+
title: 'isolation clause',
32+
sql: [
33+
'SELECT * FROM STAFF WITH UR',
34+
'SELECT * FROM STAFF WITH UR'
35+
]
36+
},
3037
]
3138
SQL_LIST.forEach(sqlInfo => {
3239
const { title, sql } = sqlInfo

0 commit comments

Comments
 (0)