Skip to content

Commit 3c99562

Browse files
committed
Fix issue with column data being undefined (#397)
Signed-off-by: worksofliam <[email protected]>
1 parent ef97dd7 commit 3c99562

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/notebooks/Controller.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,30 +86,27 @@ export class IBMiController {
8686
const results = await query.execute(1000);
8787

8888
const table = results.data;
89+
const columnNames = results.metadata.columns.map(c => c.name);
90+
8991
if (table === undefined && results.success && !results.has_results) {
9092
items.push(vscode.NotebookCellOutputItem.text(`Statement executed successfully. ${results.update_count ? `${results.update_count} rows affected.` : ``}`, `text/markdown`));
9193
break;
9294
}
9395

9496
if (table.length > 0) {
95-
96-
const keys = Object.keys(table[0]);
97-
9897
// Add `-` for blanks.
9998
table.forEach(row => {
100-
keys.forEach(key => {
99+
columnNames.forEach(key => {
101100
//@ts-ignore
102101
if (!row[key]) { row[key] = `-`; }
103102
});
104103
});
105104

106-
const columns = results.metadata.columns.map(c => c.label);
107-
108105
let fallbackToTable = true;
109106

110107
if (chartDetail.type) {
111108
if (chartJsTypes.includes(chartDetail.type as ChartJsType)) {
112-
const possibleChart = generateChart(execution.executionOrder, chartDetail, columns, table, generateChartHTMLCell);
109+
const possibleChart = generateChart(execution.executionOrder, chartDetail, columnNames, table, generateChartHTMLCell);
113110
if (possibleChart) {
114111
items.push(vscode.NotebookCellOutputItem.text(possibleChart, `text/html`));
115112
fallbackToTable = false;
@@ -118,7 +115,7 @@ export class IBMiController {
118115
}
119116

120117
if (fallbackToTable) {
121-
items.push(vscode.NotebookCellOutputItem.text(mdTable(table, columns), `text/markdown`));
118+
items.push(vscode.NotebookCellOutputItem.text(mdTable(table, columnNames), `text/markdown`));
122119
}
123120
} else {
124121
items.push(vscode.NotebookCellOutputItem.stderr(`No rows returned from statement.`));

0 commit comments

Comments
 (0)