Skip to content

Commit 5f66554

Browse files
committed
Fallback to RRN if no uniques available
Signed-off-by: worksofliam <[email protected]>
1 parent 244b453 commit 5f66554

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-db2i",
33
"displayName": "Db2 for IBM i",
44
"description": "Db2 for IBM i tools in VS Code",
5-
"version": "1.6.3",
5+
"version": "1.6.3-scott2",
66
"engines": {
77
"vscode": "^1.95.0"
88
},

src/views/results/html.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ export function generateScroller(basicSelect: string, isCL: boolean, withCancel?
119119
120120
if (trWithColumn && trWithColumn.column) {
121121
const chosenColumn = trWithColumn.column;
122+
if (chosenColumn === 'RRN') return;
123+
122124
const chosenColumnDetail = updateTable.columns.find(col => col.name === chosenColumn);
123125
if (!chosenColumnDetail) return;
124126
@@ -158,8 +160,10 @@ export function generateScroller(basicSelect: string, isCL: boolean, withCancel?
158160
159161
if (newValue === chosenValue) return;
160162
163+
const useRrn = updateKeyColumns.length === 1 && updateKeyColumns.some(col => col.name === 'RRN');
164+
161165
let bindings = [];
162-
let updateStatement = 'UPDATE ' + updateTable.table + ' SET ' + chosenColumn + ' = ';
166+
let updateStatement = 'UPDATE ' + updateTable.table + ' t SET t.' + chosenColumn + ' = ';
163167
164168
if (newValue === 'null') {
165169
updateStatement += 'NULL';
@@ -187,7 +191,13 @@ export function generateScroller(basicSelect: string, isCL: boolean, withCancel?
187191
188192
for (let i = 0; i < updateKeyColumns.length; i++) {
189193
if (idValues[i] === 'null') continue;
190-
updateStatement += updateKeyColumns[i].name + ' = ?';
194+
195+
if (useRrn && updateKeyColumns[i].name === 'RRN') {
196+
updateStatement += 'RRN(t) = ?';
197+
} else {
198+
updateStatement += updateKeyColumns[i].name + ' = ?';
199+
}
200+
191201
switch (updateKeyColumns[i].jsType) {
192202
case 'number':
193203
bindings.push(Number(idValues[i]));

src/views/results/resultSetPanelProvider.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export class ResultSetPanelProvider implements WebviewViewProvider {
167167
}
168168
}
169169

170-
async setScrolling(basicSelect, isCL = false, queryId: string = ``, withCancel = false, ref?: ObjectRef) {
170+
async setScrolling(basicSelect: string, isCL = false, queryId: string = ``, withCancel = false, ref?: ObjectRef) {
171171
this.loadingState = false;
172172
await this.focus();
173173

@@ -182,13 +182,21 @@ export class ResultSetPanelProvider implements WebviewViewProvider {
182182
);
183183

184184
if (tableInfo.length > 0) {
185-
var currentColumns: html.BasicColumn[]|undefined;
185+
let currentColumns: html.BasicColumn[]|undefined;
186186

187187
currentColumns = tableInfo.map((column) => ({name: column.COLUMN_NAME, jsType: column.NUMERIC_PRECISION ? `number` : `asString`, useInWhere: column.IS_IDENTITY === `YES` || column.CONSTRAINT_NAME !== null}));
188188

189189
if (!currentColumns.some(c => c.useInWhere)) {
190-
// Let's fallback and use all the columns in the where!
191-
currentColumns = tableInfo.map((column) => ({name: column.COLUMN_NAME, jsType: column.NUMERIC_PRECISION ? `number` : `asString`, useInWhere: true}))
190+
// We need to override the input statement if they want to do updatable
191+
const whereClauseStart = basicSelect.toLowerCase().indexOf(`where`);
192+
let fromWhereClause: string|undefined;
193+
194+
if (whereClauseStart > 0) {
195+
fromWhereClause = basicSelect.substring(whereClauseStart);
196+
}
197+
198+
basicSelect = `select rrn(t) as RRN, t.* from ${schema}.${ref.object.name} as t ${fromWhereClause || ``}`;
199+
currentColumns = [{name: `RRN`, jsType: `number`, useInWhere: true}, ...currentColumns];
192200
}
193201

194202
updatable = {

0 commit comments

Comments
 (0)