Skip to content

Commit c3badb5

Browse files
committed
If table is partitioned, no updates available
Signed-off-by: worksofliam <[email protected]>
1 parent 14b0c6b commit c3badb5

File tree

3 files changed

+67
-49
lines changed

3 files changed

+67
-49
lines changed

src/database/table.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ export default class Table {
3737
return JobManager.runSQL(sql);
3838
}
3939

40+
static async isPartitioned(schema: string, name: string): Promise<boolean> {
41+
const sql = `select table_name, partitioned_table from qsys2.sysfiles where table_schema = ? and table_name = ? and partitioned_table is not null and partitioned_table = 'YES'`;
42+
const parameters = [schema, name];
43+
44+
const result = await JobManager.runSQL(sql, {parameters});
45+
return result.length > 0;
46+
}
47+
4048
static async clearFile(library: string, objectName: string): Promise<void> {
4149
const command = `CLRPFM ${library}/${objectName}`;
4250

src/views/results/html.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ export function generateScroller(basicSelect: string, isCL: boolean, withCancel?
511511
<tbody></tbody>
512512
<tfoot id="resultfooter"></tfoot>
513513
</table>
514-
<p id="messageSpan"></p>
514+
<p style="padding-left: 20px;" id="messageSpan"></p>
515515
<div id="spinnerContent" class="center-screen">
516516
<p id="loadingText">Running statement</p>
517517
<span class="loader"></span>

src/views/results/resultSetPanelProvider.ts

Lines changed: 58 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class ResultSetPanelProvider implements WebviewViewProvider {
6363
if (message.id && message.update && message.bindings) {
6464
console.log(message);
6565
try {
66-
const result = await JobManager.runSQL(message.update, {parameters: message.bindings});
66+
const result = await JobManager.runSQL(message.update, { parameters: message.bindings });
6767
postCellResponse(message.id, true);
6868
} catch (e) {
6969
// this.setError(e.message);
@@ -98,7 +98,7 @@ export class ResultSetPanelProvider implements WebviewViewProvider {
9898

9999
if (this.currentQuery.getState() !== "RUN_DONE") {
100100
setCancelButtonVisibility(true);
101-
101+
102102
let queryResults = this.currentQuery.getState() == "RUN_MORE_DATA_AVAILABLE" ? await this.currentQuery.fetchMore() : await this.currentQuery.execute();
103103

104104
const jobId = this.currentQuery.getHostJob().id;
@@ -184,63 +184,73 @@ export class ResultSetPanelProvider implements WebviewViewProvider {
184184
this.loadingState = false;
185185
await this.focus();
186186

187-
let updatable: html.UpdatableInfo|undefined;
187+
let updatable: html.UpdatableInfo | undefined;
188188

189189
if (ref) {
190190
const schema = ref.object.schema || ref.object.system;
191191
if (schema) {
192-
const tableInfo = await Table.getItems(
193-
Statement.delimName(schema, true),
194-
Statement.delimName(ref.object.name, true)
195-
);
196-
197-
if (tableInfo.length > 0) {
198-
let currentColumns: html.BasicColumn[]|undefined;
199-
200-
currentColumns = tableInfo.map((column) => ({
201-
name: column.COLUMN_NAME,
202-
jsType: column.NUMERIC_PRECISION ? `number` : `asString`,
203-
useInWhere: column.IS_IDENTITY === `YES`,
204-
maxInputLength: column.CHARACTER_MAXIMUM_LENGTH
205-
}));
206-
207-
if (!currentColumns.some(c => c.useInWhere)) {
208-
const cName = ref.alias || `t`;
209-
210-
// Support for using a custom column list
211-
const selectClauseStart = basicSelect.toLowerCase().indexOf(`select `);
212-
const fromClauseStart = basicSelect.toLowerCase().indexOf(`from`);
213-
let possibleColumnList: string|undefined;
214-
215-
possibleColumnList = `${cName}.*`;
216-
if (fromClauseStart > 0) {
217-
possibleColumnList = basicSelect.substring(0, fromClauseStart);
218-
if (selectClauseStart >= 0) {
219-
possibleColumnList = possibleColumnList.substring(selectClauseStart + 7);
220-
221-
if (possibleColumnList.trim() === `*`) {
222-
possibleColumnList = `${cName}.*`;
192+
const goodSchema = Statement.delimName(schema, true);
193+
const goodName = Statement.delimName(ref.object.name, true);
194+
195+
const isPartitioned = await Table.isPartitioned(goodSchema, goodName);
196+
if (!isPartitioned) {
197+
const tableInfo = await Table.getItems(
198+
goodSchema,
199+
goodName
200+
);
201+
202+
const uneditableTypes = [`VARBIN`, `BINARY`, `ROWID`, `DATALINK`, `DBCLOB`, `BLOB`, `GRAPHIC`]
203+
204+
if (tableInfo.length > 0) {
205+
let currentColumns: html.BasicColumn[] | undefined;
206+
207+
currentColumns = tableInfo
208+
.filter((column) => !uneditableTypes.includes(column.DATA_TYPE))
209+
.map((column) => ({
210+
name: column.COLUMN_NAME,
211+
jsType: column.NUMERIC_PRECISION ? `number` : `asString`,
212+
useInWhere: column.IS_IDENTITY === `YES`,
213+
maxInputLength: column.CHARACTER_MAXIMUM_LENGTH
214+
}));
215+
216+
if (!currentColumns.some(c => c.useInWhere)) {
217+
const cName = ref.alias || `t`;
218+
219+
// Support for using a custom column list
220+
const selectClauseStart = basicSelect.toLowerCase().indexOf(`select `);
221+
const fromClauseStart = basicSelect.toLowerCase().indexOf(`from`);
222+
let possibleColumnList: string | undefined;
223+
224+
possibleColumnList = `${cName}.*`;
225+
if (fromClauseStart > 0) {
226+
possibleColumnList = basicSelect.substring(0, fromClauseStart);
227+
if (selectClauseStart >= 0) {
228+
possibleColumnList = possibleColumnList.substring(selectClauseStart + 7);
229+
230+
if (possibleColumnList.trim() === `*`) {
231+
possibleColumnList = `${cName}.*`;
232+
}
223233
}
224234
}
225-
}
226235

227-
// We need to override the input statement if they want to do updatable
228-
const whereClauseStart = basicSelect.toLowerCase().indexOf(`where`);
229-
let fromWhereClause: string|undefined;
236+
// We need to override the input statement if they want to do updatable
237+
const whereClauseStart = basicSelect.toLowerCase().indexOf(`where`);
238+
let fromWhereClause: string | undefined;
230239

231-
if (whereClauseStart > 0) {
232-
fromWhereClause = basicSelect.substring(whereClauseStart);
233-
}
240+
if (whereClauseStart > 0) {
241+
fromWhereClause = basicSelect.substring(whereClauseStart);
242+
}
234243

235244

236-
basicSelect = `select rrn(${cName}) as RRN, ${possibleColumnList} from ${schema}.${ref.object.name} as ${cName} ${fromWhereClause || ``}`;
237-
currentColumns = [{name: `RRN`, jsType: `number`, useInWhere: true}, ...currentColumns];
238-
}
245+
basicSelect = `select rrn(${cName}) as RRN, ${possibleColumnList} from ${schema}.${ref.object.name} as ${cName} ${fromWhereClause || ``}`;
246+
currentColumns = [{ name: `RRN`, jsType: `number`, useInWhere: true }, ...currentColumns];
247+
}
239248

240-
updatable = {
241-
table: schema + `.` + ref.object.name,
242-
columns: currentColumns
243-
};
249+
updatable = {
250+
table: schema + `.` + ref.object.name,
251+
columns: currentColumns
252+
};
253+
}
244254
}
245255
}
246256
}

0 commit comments

Comments
 (0)