@@ -452,20 +452,17 @@ export default class schemaBrowser {
452
452
}
453
453
454
454
let rows : any [ ] = [ ] ;
455
-
455
+ let hasHeaders = true ;
456
456
if ( ext === `csv` ) {
457
+ hasHeaders = ( await vscode . window . showQuickPick ( [ 'Yes' , 'No' ] , { placeHolder : 'Does the file have headers?' } ) ) === `Yes` ? true : false ;
457
458
rows = parse ( data , {
458
- columns : true ,
459
+ columns : hasHeaders ,
459
460
cast : true
460
461
} ) ;
461
462
if ( ! rows . length ) {
462
463
vscode . window . showWarningMessage ( 'No rows found.' ) ;
463
464
return ;
464
465
}
465
-
466
- // Get the headers and types
467
- // Using the first two rows, first row is header names, second row will tell us the type
468
-
469
466
} else if ( ext === `json` ) {
470
467
rows = JSON . parse ( data ) ;
471
468
if ( ! Array . isArray ( rows ) ) {
@@ -478,28 +475,47 @@ export default class schemaBrowser {
478
475
return ;
479
476
}
480
477
481
- // Get headers using the first row of data
482
- const colNames = Object . keys ( rows [ 0 ] ) ;
483
- const cols = colNames . join ( ', ' ) ;
484
-
485
- // Generate the INSERT statement
486
- let content : string = `INSERT INTO SYSIBM.SYSDUMMY1 (${ cols } ) \nVALUES\n` ;
487
- for ( let i = 0 ; i < rows . length ; i ++ ) {
488
- const row = rows [ i ] ;
489
- let allValues = [ ] ;
490
- for ( const col of colNames ) {
491
- const val = row [ col ] ;
492
- if ( typeof val === `string` ) {
493
- allValues . push ( `'${ val } '` ) ;
494
- } else
495
- allValues . push ( val ) ;
496
- }
497
- content += ` (${ allValues . join ( ', ' ) } )` ;
498
-
499
- // If not at last item yet, append a comma
500
- if ( i != rows . length - 1 ) {
501
- content += `,\n` ;
502
- }
478
+ let content : string = `` ;
479
+ if ( hasHeaders ) {
480
+ // Get headers using the first row of data
481
+ const colNames = Object . keys ( rows [ 0 ] ) ;
482
+ const cols = colNames . join ( ', ' ) ;
483
+
484
+ // Generate the INSERT statement
485
+ content = `INSERT INTO SYSIBM.SYSDUMMY1 (${ cols } ) \nVALUES\n` ;
486
+ const allRowValues = [ ] ;
487
+ for ( let i = 0 ; i < rows . length ; i ++ ) {
488
+ const row = rows [ i ] ;
489
+ let allValues = [ ] ;
490
+ for ( const col of colNames ) {
491
+ const val = row [ col ] ;
492
+ if ( typeof val === `string` ) {
493
+ allValues . push ( `'${ val } '` ) ;
494
+ } else {
495
+ allValues . push ( val ) ;
496
+ }
497
+ }
498
+ allRowValues . push ( ` (${ allValues . join ( ', ' ) } )` ) ;
499
+ }
500
+ content += allRowValues . join ( `,\n` ) ;
501
+ } else {
502
+ // Generate the INSERT statement
503
+ content = `INSERT INTO SYSIBM.SYSDUMMY1 \nVALUES\n` ;
504
+ const allRowValues = [ ] ;
505
+ for ( let i = 0 ; i < rows . length ; i ++ ) {
506
+ const row = rows [ i ] ;
507
+ let allValues = [ ] ;
508
+ for ( let j = 0 ; j < row . length ; j ++ ) {
509
+ const val = row [ j ] ;
510
+ if ( typeof val === `string` ) {
511
+ allValues . push ( `'${ val } '` ) ;
512
+ } else {
513
+ allValues . push ( val ) ;
514
+ }
515
+ }
516
+ allRowValues . push ( ` (${ allValues . join ( ', ' ) } )` ) ;
517
+ }
518
+ content += allRowValues . join ( `,\n` ) ;
503
519
}
504
520
505
521
content += `;` ;
0 commit comments