Skip to content

Commit

Permalink
Revert "Only support ?-params in DB2i"
Browse files Browse the repository at this point in the history
Turns out that :name parameters are also supported in DB2i.

This reverts commit 4b2bc98.
  • Loading branch information
nene committed Nov 11, 2023
1 parent 434d2f8 commit 1d22019
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
3 changes: 2 additions & 1 deletion src/languages/db2i/db2i.formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ export const db2i: DialectOptions = {
],
identTypes: [`""-qq`],
identChars: { first: '@#$', rest: '@#$' },
paramTypes: { positional: true },
paramTypes: { positional: true, named: [':'] },
paramChars: { first: '@#$', rest: '@#$' },
operators: ['**', '¬=', '¬>', '¬<', '!>', '!<', '||'],
},
formatOptions: {
Expand Down
14 changes: 14 additions & 0 deletions test/behavesLikeDb2Formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import supportsConstraints from './features/constraints.js';
import supportsDeleteFrom from './features/deleteFrom.js';
import supportsCommentOn from './features/commentOn.js';
import supportsIdentifiers from './features/identifiers.js';
import supportsParams from './options/param.js';
import supportsSetOperations from './features/setOperations.js';
import supportsLimiting from './features/limiting.js';
import supportsInsertInto from './features/insertInto.js';
Expand Down Expand Up @@ -51,6 +52,7 @@ export default function behavesLikeDb2Formatter(format: FormatFn) {
'INTERSECT',
'INTERSECT ALL',
]);
supportsParams(format, { positional: true, named: [':'] });
supportsLimiting(format, { fetchFirst: true });
supportsArrayLiterals(format, { withArrayPrefix: true });
supportsArrayAndMapAccessors(format);
Expand Down Expand Up @@ -95,6 +97,18 @@ export default function behavesLikeDb2Formatter(format: FormatFn) {
`);
});

it('supports @, #, $ characters in named parameters', () => {
expect(format(`SELECT :foo@bar, :foo#bar, :foo$bar, :@zip, :#zap, :$zop`)).toBe(dedent`
SELECT
:foo@bar,
:foo#bar,
:foo$bar,
:@zip,
:#zap,
:$zop
`);
});

it('supports WITH isolation level modifiers for UPDATE statement', () => {
expect(format('UPDATE foo SET x = 10 WITH CS')).toBe(dedent`
UPDATE foo
Expand Down
16 changes: 0 additions & 16 deletions test/db2.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import dedent from 'dedent-js';

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

import supportsCreateTable from './features/createTable.js';
import supportsDropTable from './features/dropTable.js';
import supportsJoin from './features/join.js';
import supportsParams from './options/param.js';
import supportsStrings from './features/strings.js';
import supportsComments from './features/comments.js';
import supportsOperators from './features/operators.js';
Expand All @@ -21,7 +18,6 @@ describe('Db2Formatter', () => {
supportsCreateTable(format);
supportsDropTable(format);
supportsJoin(format, { without: ['NATURAL'] });
supportsParams(format, { positional: true, named: [':'] });
supportsOperators(format, [
'**',
'%',
Expand All @@ -43,16 +39,4 @@ describe('Db2Formatter', () => {
]);
// Additional U& string type in addition to others shared by all DB2 implementations
supportsStrings(format, ["U&''"]);

it('supports @, #, $ characters in named parameters', () => {
expect(format(`SELECT :foo@bar, :foo#bar, :foo$bar, :@zip, :#zap, :$zop`)).toBe(dedent`
SELECT
:foo@bar,
:foo#bar,
:foo$bar,
:@zip,
:#zap,
:$zop
`);
});
});
2 changes: 0 additions & 2 deletions test/db2i.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import supportsCreateTable from './features/createTable.js';
import supportsDropTable from './features/dropTable.js';
import supportsJoin from './features/join.js';
import supportsOperators from './features/operators.js';
import supportsParams from './options/param.js';

describe('Db2iFormatter', () => {
const language = 'db2i';
Expand All @@ -21,6 +20,5 @@ describe('Db2iFormatter', () => {
without: ['NATURAL'],
additionally: ['EXCEPTION JOIN', 'LEFT EXCEPTION JOIN', 'RIGHT EXCEPTION JOIN'],
});
supportsParams(format, { positional: true });
supportsOperators(format, ['**', '¬=', '¬>', '¬<', '!>', '!<', '||']);
});

0 comments on commit 1d22019

Please sign in to comment.