@@ -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