Skip to content

Commit

Permalink
Only support ?-params in DB2i
Browse files Browse the repository at this point in the history
The DB2 supports both ? and :name parameters, but DB2i only ?.
  • Loading branch information
nene committed Nov 10, 2023
1 parent b7b1643 commit 4b2bc98
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
3 changes: 1 addition & 2 deletions src/languages/db2i/db2i.formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ export const db2i: DialectOptions = {
],
identTypes: [`""-qq`],
identChars: { first: '@#$' },
paramTypes: { positional: true, named: [':'] },
paramChars: { first: '@#$', rest: '@#$' },
paramTypes: { positional: true },
operators: ['**', '¬=', '¬>', '¬<', '!>', '!<', '||'],
},
formatOptions: {
Expand Down
14 changes: 0 additions & 14 deletions test/behavesLikeDb2Formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import supportsDeleteFrom from './features/deleteFrom.js';
import supportsComments from './features/comments.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 @@ -54,7 +53,6 @@ export default function behavesLikeDb2Formatter(format: FormatFn) {
'INTERSECT',
'INTERSECT ALL',
]);
supportsParams(format, { positional: true, named: [':'] });
supportsLimiting(format, { fetchFirst: true });

it('formats only -- as a line comment', () => {
Expand Down Expand Up @@ -94,18 +92,6 @@ 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: 16 additions & 0 deletions test/db2.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
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';

describe('Db2Formatter', () => {
const language = 'db2';
Expand All @@ -14,4 +17,17 @@ describe('Db2Formatter', () => {
supportsCreateTable(format);
supportsDropTable(format);
supportsJoin(format, { without: ['NATURAL'], supportsUsing: false });
supportsParams(format, { positional: true, named: [':'] });

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: 2 additions & 0 deletions test/db2i.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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';

describe('Db2iFormatter', () => {
const language = 'db2i';
Expand All @@ -14,4 +15,5 @@ describe('Db2iFormatter', () => {
supportsCreateTable(format, { orReplace: true });
supportsDropTable(format, { ifExists: true });
supportsJoin(format, { without: ['NATURAL'], supportsUsing: true });
supportsParams(format, { positional: true });
});

3 comments on commit 4b2bc98

@chrjorgensen
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nene I don't quite understand this change - DB2 for i do support named parameters in static SQL?

See one example here: https://www.ibm.com/docs/en/i/7.5?topic=variables-in-dynamic-sql

@nene
Copy link
Collaborator Author

@nene nene commented on 4b2bc98 Nov 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the link. I failed to find an example of :name syntax being used in my own searches into DB2i syntax.

@nene
Copy link
Collaborator Author

@nene nene commented on 4b2bc98 Nov 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted the change.

Please sign in to comment.