Skip to content

Commit 026a5c3

Browse files
authored
Merge pull request #350 from codefori/fix/handle_updatable_crash
Add simple try catch to updatable check
2 parents 4b9d3ea + 295cd1e commit 026a5c3

File tree

1 file changed

+59
-55
lines changed

1 file changed

+59
-55
lines changed

src/views/results/resultSetPanelProvider.ts

Lines changed: 59 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -193,71 +193,75 @@ export class ResultSetPanelProvider implements WebviewViewProvider {
193193
const goodSchema = Statement.delimName(schema, true);
194194
const goodName = Statement.delimName(ref.object.name, true);
195195

196-
const isPartitioned = await Table.isPartitioned(goodSchema, goodName);
197-
if (!isPartitioned) {
198-
let tableInfo: TableColumn[] = [];
199-
200-
if ([`SESSION`, `QTEMP`].includes(goodSchema)) {
201-
tableInfo = await Table.getSessionItems(goodName);
202-
} else {
203-
tableInfo = await Table.getItems(
204-
goodSchema,
205-
goodName
206-
);
207-
}
208-
209-
const uneditableTypes = [`VARBIN`, `BINARY`, `ROWID`, `DATALINK`, `DBCLOB`, `BLOB`, `GRAPHIC`]
210-
211-
if (tableInfo.length > 0) {
212-
let currentColumns: html.BasicColumn[] | undefined;
213-
214-
currentColumns = tableInfo
215-
.filter((column) => !uneditableTypes.includes(column.DATA_TYPE))
216-
.map((column) => ({
217-
name: column.COLUMN_NAME,
218-
jsType: column.NUMERIC_PRECISION ? `number` : `asString`,
219-
useInWhere: column.IS_IDENTITY === `YES`,
220-
maxInputLength: column.CHARACTER_MAXIMUM_LENGTH
221-
}));
222-
223-
if (!currentColumns.some(c => c.useInWhere)) {
224-
const cName = ref.alias || `t`;
196+
try {
197+
const isPartitioned = await Table.isPartitioned(goodSchema, goodName);
198+
if (!isPartitioned) {
199+
let tableInfo: TableColumn[] = [];
200+
201+
if ([`SESSION`, `QTEMP`].includes(goodSchema)) {
202+
tableInfo = await Table.getSessionItems(goodName);
203+
} else {
204+
tableInfo = await Table.getItems(
205+
goodSchema,
206+
goodName
207+
);
208+
}
225209

226-
// Support for using a custom column list
227-
const selectClauseStart = basicSelect.toLowerCase().indexOf(`select `);
228-
const fromClauseStart = basicSelect.toLowerCase().indexOf(`from`);
229-
let possibleColumnList: string | undefined;
210+
const uneditableTypes = [`VARBIN`, `BINARY`, `ROWID`, `DATALINK`, `DBCLOB`, `BLOB`, `GRAPHIC`]
211+
212+
if (tableInfo.length > 0) {
213+
let currentColumns: html.BasicColumn[] | undefined;
214+
215+
currentColumns = tableInfo
216+
.filter((column) => !uneditableTypes.includes(column.DATA_TYPE))
217+
.map((column) => ({
218+
name: column.COLUMN_NAME,
219+
jsType: column.NUMERIC_PRECISION ? `number` : `asString`,
220+
useInWhere: column.IS_IDENTITY === `YES`,
221+
maxInputLength: column.CHARACTER_MAXIMUM_LENGTH
222+
}));
223+
224+
if (!currentColumns.some(c => c.useInWhere)) {
225+
const cName = ref.alias || `t`;
226+
227+
// Support for using a custom column list
228+
const selectClauseStart = basicSelect.toLowerCase().indexOf(`select `);
229+
const fromClauseStart = basicSelect.toLowerCase().indexOf(`from`);
230+
let possibleColumnList: string | undefined;
231+
232+
possibleColumnList = `${cName}.*`;
233+
if (fromClauseStart > 0) {
234+
possibleColumnList = basicSelect.substring(0, fromClauseStart);
235+
if (selectClauseStart >= 0) {
236+
possibleColumnList = possibleColumnList.substring(selectClauseStart + 7);
237+
238+
if (possibleColumnList.trim() === `*`) {
239+
possibleColumnList = `${cName}.*`;
240+
}
241+
}
242+
}
230243

231-
possibleColumnList = `${cName}.*`;
232-
if (fromClauseStart > 0) {
233-
possibleColumnList = basicSelect.substring(0, fromClauseStart);
234-
if (selectClauseStart >= 0) {
235-
possibleColumnList = possibleColumnList.substring(selectClauseStart + 7);
244+
// We need to override the input statement if they want to do updatable
245+
const whereClauseStart = basicSelect.toLowerCase().indexOf(`where`);
246+
let fromWhereClause: string | undefined;
236247

237-
if (possibleColumnList.trim() === `*`) {
238-
possibleColumnList = `${cName}.*`;
239-
}
248+
if (whereClauseStart > 0) {
249+
fromWhereClause = basicSelect.substring(whereClauseStart);
240250
}
241-
}
242251

243-
// We need to override the input statement if they want to do updatable
244-
const whereClauseStart = basicSelect.toLowerCase().indexOf(`where`);
245-
let fromWhereClause: string | undefined;
246252

247-
if (whereClauseStart > 0) {
248-
fromWhereClause = basicSelect.substring(whereClauseStart);
253+
basicSelect = `select rrn(${cName}) as RRN, ${possibleColumnList} from ${schema}.${ref.object.name} as ${cName} ${fromWhereClause || ``}`;
254+
currentColumns = [{ name: `RRN`, jsType: `number`, useInWhere: true }, ...currentColumns];
249255
}
250256

251-
252-
basicSelect = `select rrn(${cName}) as RRN, ${possibleColumnList} from ${schema}.${ref.object.name} as ${cName} ${fromWhereClause || ``}`;
253-
currentColumns = [{ name: `RRN`, jsType: `number`, useInWhere: true }, ...currentColumns];
257+
updatable = {
258+
table: schema + `.` + ref.object.name,
259+
columns: currentColumns
260+
};
254261
}
255-
256-
updatable = {
257-
table: schema + `.` + ref.object.name,
258-
columns: currentColumns
259-
};
260262
}
263+
} catch (e) {
264+
window.showErrorMessage(`Table may not be updatable. This sometimes happens if you're Db2 for i PTF levels are not up to date: ${e.message}`);
261265
}
262266
}
263267
}

0 commit comments

Comments
 (0)