Skip to content

Commit d741729

Browse files
committed
Fix for delimited names
Signed-off-by: worksofliam <[email protected]>
1 parent df33661 commit d741729

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/database/schemas.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ export default class Schemas {
103103
* Resolves to the following SQL types: SCHEMA, TABLE, VIEW, ALIAS, INDEX, FUNCTION and PROCEDURE
104104
*/
105105
static async resolveObjects(
106-
sqlObjects: ObjectReference[]
106+
sqlObjects: ObjectReference[],
107+
ignoreSystemTypes: string[] = []
107108
): Promise<ResolvedSqlObject[]> {
108109
let statements: string[] = [];
109110
let parameters: BasicColumnType[] = [];
@@ -114,6 +115,13 @@ export default class Schemas {
114115

115116
// First, we use OBJECT_STATISTICS to resolve the object based on the library list.
116117
// But, if the object is qualified with a schema, we need to use that schema to get the correct object.
118+
119+
let ignoreClause = ``;
120+
if (ignoreSystemTypes.length > 0) {
121+
ignoreSystemTypes = ignoreSystemTypes.map(i => i.toUpperCase());
122+
ignoreClause = `where objtype not in (${ignoreSystemTypes.map((i) => `?`).join(`, `)})`;
123+
}
124+
117125
for (const obj of sqlObjects) {
118126
const cached = this.getCachedReference(obj);
119127
if (cached) {
@@ -123,14 +131,14 @@ export default class Schemas {
123131

124132
if (obj.schema) {
125133
statements.push(
126-
`${BASE_RESOLVE_SELECT} from table(qsys2.object_statistics(?, '*ALL', object_name => ?))`
134+
`${BASE_RESOLVE_SELECT} from table(qsys2.object_statistics(?, '*ALL', object_name => ?)) ${ignoreClause}`
127135
);
128-
parameters.push(obj.schema, obj.name);
136+
parameters.push(obj.schema, obj.name, ...ignoreSystemTypes);
129137
} else {
130138
statements.push(
131-
`${BASE_RESOLVE_SELECT} from table(qsys2.object_statistics('*LIBL', '*ALL', object_name => ?))`
139+
`${BASE_RESOLVE_SELECT} from table(qsys2.object_statistics('*LIBL', '*ALL', object_name => ?)) ${ignoreClause}`
132140
);
133-
parameters.push(obj.name);
141+
parameters.push(obj.name, ...ignoreSystemTypes);
134142
}
135143
}
136144

src/language/providers/peekProvider.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ export const peekProvider = languages.registerDefinitionProvider({ language: `sq
2929
const ref = refs.find(ref => ref.tokens[0].range.start && offset <= ref.tokens[ref.tokens.length - 1].range.end);
3030

3131
if (ref) {
32-
const name = Statement.noQuotes(Statement.delimName(ref.object.name, true));
32+
const name = Statement.delimName(ref.object.name, true);
3333

3434
// Schema is based on a few things:
3535
// If it's a fully qualified path, use the schema path
3636
// Otherwise:
3737
// - if SQL naming is in use, then use the default schema
3838
// - if system naming is in use, then don't pass a library and the library list will be used
39-
const schema = ref.object.schema ? Statement.noQuotes(Statement.delimName(ref.object.schema, true)) : naming === `sql` ? defaultSchema : undefined;
39+
const schema = ref.object.schema ? Statement.delimName(ref.object.schema, true) : naming === `sql` ? defaultSchema : undefined;
4040

41-
const possibleObjects = await Schemas.resolveObjects([{name, schema}]);
41+
const possibleObjects = await Schemas.resolveObjects([{name, schema}], [`*LIB`]);
4242

4343
if (possibleObjects.length === 1) {
4444
const obj = possibleObjects[0];

0 commit comments

Comments
 (0)