Skip to content

Commit

Permalink
Additional non-standard SELECT clauses for DB2
Browse files Browse the repository at this point in the history
  • Loading branch information
nene committed Nov 13, 2023
1 parent f6cbe27 commit ee7c3a5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/languages/db2/db2.formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ const reservedClauses = expandPhrases([
'ORDER BY [INPUT SEQUENCE]',
'OFFSET',
'FETCH NEXT',
'FOR UPDATE [OF]',
'FOR {READ | FETCH} ONLY',
'FOR {RR | CS | UR | RS} [USE AND KEEP {SHARE | UPDATE | EXCLUSIVE} LOCKS]',
'WAIT FOR OUTCOME',
'SKIP LOCKED DATA',
// Data modification
// - insert:
'INSERT INTO',
Expand Down
15 changes: 15 additions & 0 deletions test/db2.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import dedent from 'dedent-js';

import { format as originalFormat, FormatFn } from '../src/sqlFormatter.js';
import behavesLikeDb2Formatter from './behavesLikeDb2Formatter.js';

Expand Down Expand Up @@ -47,4 +49,17 @@ describe('Db2Formatter', () => {
]);
// Additional U& string type in addition to others shared by all DB2 implementations
supportsStrings(format, ["U&''"]);

it('supports non-standard FOR clause', () => {
expect(format('SELECT * FROM tbl FOR UPDATE OF other_tbl FOR RS USE AND KEEP EXCLUSIVE LOCKS'))
.toBe(dedent`
SELECT
*
FROM
tbl
FOR UPDATE OF
other_tbl
FOR RS USE AND KEEP EXCLUSIVE LOCKS
`);
});
});

0 comments on commit ee7c3a5

Please sign in to comment.