1- import { CommandResult } from "@halcyontech/vscode-ibmi-types" ;
21import { getInstance } from "../base" ;
32import { ServerComponent } from "./serverComponent" ;
43import { JDBCOptions , ConnectionResult , Rows , QueryResult , JobLogEntry , CLCommandResult , VersionCheckResult , GetTraceDataResult , ServerTraceDest , ServerTraceLevel , SetConfigResult , QueryOptions , ExplainResults } from "./types" ;
@@ -8,7 +7,7 @@ import { EventEmitter } from "stream";
87export enum JobStatus {
98 NotStarted = "notStarted" ,
109 Ready = "ready" ,
11- Active = "active " ,
10+ Busy = "busy " ,
1211 Ended = "ended"
1312}
1413
@@ -36,7 +35,6 @@ const TransactionCountQuery = [
3635const DB2I_VERSION = ( process . env [ `DB2I_VERSION` ] || `<version unknown>` ) + ( ( process . env . DEV ) ? `` :`-dev` ) ;
3736
3837export class SQLJob {
39-
4038 private static uniqueIdCounter : number = 0 ;
4139 private channel : any ;
4240 private responseEmitter : EventEmitter = new EventEmitter ( ) ;
@@ -130,7 +128,6 @@ export class SQLJob {
130128
131129 let req : ReqRespFmt = JSON . parse ( content ) ;
132130 this . channel . stdin . write ( content + `\n` ) ;
133- this . status = JobStatus . Active ;
134131 return new Promise ( ( resolve , reject ) => {
135132 this . responseEmitter . on ( req . id , ( x : string ) => {
136133 this . responseEmitter . removeAllListeners ( req . id ) ;
@@ -140,7 +137,9 @@ export class SQLJob {
140137 }
141138
142139 getStatus ( ) {
143- return this . status ;
140+ const currentListenerCount = this . responseEmitter . eventNames ( ) . length ;
141+
142+ return currentListenerCount > 0 ? JobStatus . Busy : this . status ;
144143 }
145144
146145 async connect ( ) : Promise < ConnectionResult > {
@@ -204,6 +203,20 @@ export class SQLJob {
204203 return new Query ( this , sql , opts ) ;
205204 }
206205
206+ async requestCancel ( ) : Promise < boolean > {
207+ const instance = getInstance ( ) ;
208+ const content = instance . getContent ( ) ;
209+
210+ // Note that this statement is run via the base extension since it has to be done on a job other than the one whose SQL is getting canceled
211+ await content . runSQL ( `CALL QSYS2.CANCEL_SQL('${ this . id } ')` ) ;
212+
213+ const [ row ] = await content . runSQL ( `select V_SQL_STMT_STATUS as STATUS from table(qsys2.get_job_info('${ this . id } '))` ) as { STATUS : string | null } [ ] ;
214+
215+ if ( row && row . STATUS === `ACTIVE` ) return false ;
216+
217+ return true ;
218+ }
219+
207220 async getVersion ( ) : Promise < VersionCheckResult > {
208221 const verObj = {
209222 id : SQLJob . getNewUniqueId ( ) ,
@@ -303,7 +316,7 @@ export class SQLJob {
303316 }
304317
305318 underCommitControl ( ) {
306- return this . options [ "transaction isolation" ] !== `none` ;
319+ return this . options [ "transaction isolation" ] && this . options [ "transaction isolation" ] !== `none` ;
307320 }
308321
309322 async getPendingTransactions ( ) {
0 commit comments