Skip to content

Add simple try catch to updatable check #350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 59 additions & 55 deletions src/views/results/resultSetPanelProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,71 +193,75 @@ export class ResultSetPanelProvider implements WebviewViewProvider {
const goodSchema = Statement.delimName(schema, true);
const goodName = Statement.delimName(ref.object.name, true);

const isPartitioned = await Table.isPartitioned(goodSchema, goodName);
if (!isPartitioned) {
let tableInfo: TableColumn[] = [];

if ([`SESSION`, `QTEMP`].includes(goodSchema)) {
tableInfo = await Table.getSessionItems(goodName);
} else {
tableInfo = await Table.getItems(
goodSchema,
goodName
);
}

const uneditableTypes = [`VARBIN`, `BINARY`, `ROWID`, `DATALINK`, `DBCLOB`, `BLOB`, `GRAPHIC`]

if (tableInfo.length > 0) {
let currentColumns: html.BasicColumn[] | undefined;

currentColumns = tableInfo
.filter((column) => !uneditableTypes.includes(column.DATA_TYPE))
.map((column) => ({
name: column.COLUMN_NAME,
jsType: column.NUMERIC_PRECISION ? `number` : `asString`,
useInWhere: column.IS_IDENTITY === `YES`,
maxInputLength: column.CHARACTER_MAXIMUM_LENGTH
}));

if (!currentColumns.some(c => c.useInWhere)) {
const cName = ref.alias || `t`;
try {
const isPartitioned = await Table.isPartitioned(goodSchema, goodName);
if (!isPartitioned) {
let tableInfo: TableColumn[] = [];

if ([`SESSION`, `QTEMP`].includes(goodSchema)) {
tableInfo = await Table.getSessionItems(goodName);
} else {
tableInfo = await Table.getItems(
goodSchema,
goodName
);
}

// Support for using a custom column list
const selectClauseStart = basicSelect.toLowerCase().indexOf(`select `);
const fromClauseStart = basicSelect.toLowerCase().indexOf(`from`);
let possibleColumnList: string | undefined;
const uneditableTypes = [`VARBIN`, `BINARY`, `ROWID`, `DATALINK`, `DBCLOB`, `BLOB`, `GRAPHIC`]

if (tableInfo.length > 0) {
let currentColumns: html.BasicColumn[] | undefined;

currentColumns = tableInfo
.filter((column) => !uneditableTypes.includes(column.DATA_TYPE))
.map((column) => ({
name: column.COLUMN_NAME,
jsType: column.NUMERIC_PRECISION ? `number` : `asString`,
useInWhere: column.IS_IDENTITY === `YES`,
maxInputLength: column.CHARACTER_MAXIMUM_LENGTH
}));

if (!currentColumns.some(c => c.useInWhere)) {
const cName = ref.alias || `t`;

// Support for using a custom column list
const selectClauseStart = basicSelect.toLowerCase().indexOf(`select `);
const fromClauseStart = basicSelect.toLowerCase().indexOf(`from`);
let possibleColumnList: string | undefined;

possibleColumnList = `${cName}.*`;
if (fromClauseStart > 0) {
possibleColumnList = basicSelect.substring(0, fromClauseStart);
if (selectClauseStart >= 0) {
possibleColumnList = possibleColumnList.substring(selectClauseStart + 7);

if (possibleColumnList.trim() === `*`) {
possibleColumnList = `${cName}.*`;
}
}
}

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

if (possibleColumnList.trim() === `*`) {
possibleColumnList = `${cName}.*`;
}
if (whereClauseStart > 0) {
fromWhereClause = basicSelect.substring(whereClauseStart);
}
}

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

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


basicSelect = `select rrn(${cName}) as RRN, ${possibleColumnList} from ${schema}.${ref.object.name} as ${cName} ${fromWhereClause || ``}`;
currentColumns = [{ name: `RRN`, jsType: `number`, useInWhere: true }, ...currentColumns];
updatable = {
table: schema + `.` + ref.object.name,
columns: currentColumns
};
}

updatable = {
table: schema + `.` + ref.object.name,
columns: currentColumns
};
}
} catch (e) {
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}`);
}
}
}
Expand Down
Loading