@@ -46,22 +46,58 @@ export class SQLJob {
46
46
47
47
id : string | undefined ;
48
48
49
-
50
49
public static getNewUniqueId ( prefix : string = `id` ) : string {
51
50
return prefix + ( ++ SQLJob . uniqueIdCounter ) ;
52
51
}
53
52
53
+ public static async useExec ( ) {
54
+ let useExec = false ;
55
+
56
+ const instance = getInstance ( ) ;
57
+ const connection = instance . getConnection ( ) ;
58
+
59
+ const bashPathAvailable = connection . remoteFeatures [ `bash` ] ;
60
+ if ( bashPathAvailable ) {
61
+ const commandShellResult = await connection . sendCommand ( {
62
+ command : `echo $SHELL`
63
+ } ) ;
64
+ if ( ! commandShellResult . stderr ) {
65
+ let userDefaultShell = commandShellResult . stdout . trim ( ) ;
66
+ if ( userDefaultShell === bashPathAvailable ) {
67
+ useExec = true ;
68
+ }
69
+ }
70
+ }
71
+
72
+ return useExec ;
73
+ }
74
+
54
75
constructor ( public options : JDBCOptions = { } ) { }
55
76
private async getChannel ( ) {
56
77
const instance = getInstance ( ) ;
57
78
const connection = instance . getConnection ( ) ;
79
+
80
+ let useExec = await SQLJob . useExec ( ) ;
81
+
58
82
return new Promise ( ( resolve , reject ) => {
59
83
// Setting QIBM_JAVA_STDIO_CONVERT and QIBM_PASE_DESCRIPTOR_STDIO to make sure all PASE and Java converters are off
60
- connection . client . connection . exec ( `QIBM_JAVA_STDIO_CONVERT=N QIBM_PASE_DESCRIPTOR_STDIO=B exec ` + ServerComponent . getInitCommand ( ) , { } , ( err : any , stream : any , options : { encoding : `binary`} ) => {
61
- if ( err )
84
+ const startingCommand = `QIBM_JAVA_STDIO_CONVERT=N QIBM_PASE_DESCRIPTOR_STDIO=B QIBM_USE_DESCRIPTOR_STDIO=Y QIBM_MULTI_THREADED=Y ${ useExec ? `exec ` : `` } ` + ServerComponent . getInitCommand ( ) ;
85
+
86
+ ServerComponent . writeOutput ( startingCommand ) ;
87
+
88
+ const a = connection . client . connection . exec ( startingCommand , ( err : any , stream : any , options : { encoding : `binary`} ) => {
89
+ if ( err ) {
62
90
reject ( err ) ;
91
+ ServerComponent . writeOutput ( err ) ;
92
+ }
93
+
63
94
let outString = `` ;
64
- stream . on ( `data` , ( data : Buffer ) => {
95
+
96
+ stream . stderr . on ( `data` , ( data : Buffer ) => {
97
+ ServerComponent . writeOutput ( data . toString ( ) ) ;
98
+ } )
99
+
100
+ stream . stdout . on ( `data` , ( data : Buffer ) => {
65
101
outString += String ( data ) ;
66
102
if ( outString . endsWith ( `\n` ) ) {
67
103
let thisMsg = outString ;
@@ -76,8 +112,11 @@ export class SQLJob {
76
112
}
77
113
}
78
114
} ) ;
115
+
79
116
resolve ( stream ) ;
80
- } )
117
+ } ) ;
118
+
119
+ console . log ( a ) ;
81
120
} )
82
121
}
83
122
@@ -101,7 +140,15 @@ export class SQLJob {
101
140
async connect ( ) : Promise < ConnectionResult > {
102
141
this . channel = await this . getChannel ( ) ;
103
142
104
- this . status = JobStatus . Ready ;
143
+ this . channel . on ( `error` , ( err ) => {
144
+ ServerComponent . writeOutput ( err ) ;
145
+ this . dispose ( ) ;
146
+ } )
147
+
148
+ this . channel . on ( `close` , ( code : number ) => {
149
+ ServerComponent . writeOutput ( `Exited with code ${ code } .` )
150
+ this . dispose ( ) ;
151
+ } )
105
152
106
153
const props = Object
107
154
. keys ( this . options )
@@ -132,13 +179,10 @@ export class SQLJob {
132
179
throw new Error ( connectResult . error || `Failed to connect to server.` ) ;
133
180
}
134
181
135
- this . channel . on ( `error` , ( ) => {
136
- this . dispose ( ) ;
137
- } )
182
+ if ( this . status === JobStatus . Ended ) {
183
+ throw new Error ( `Failed to connect properly.` ) ;
184
+ }
138
185
139
- this . channel . on ( `close` , ( ) => {
140
- this . dispose ( ) ;
141
- } )
142
186
this . id = connectResult . job ;
143
187
this . status = JobStatus . Ready ;
144
188
0 commit comments