|
1 | 1 | import { CommandResult } from "@halcyontech/vscode-ibmi-types";
|
2 | 2 | import { getInstance } from "../base";
|
3 | 3 | import { ServerComponent } from "./serverComponent";
|
4 |
| -import { JDBCOptions, ConnectionResult, Rows, QueryResult, JobLogEntry, CLCommandResult, VersionCheckResult } from "./types"; |
| 4 | +import { JDBCOptions, ConnectionResult, Rows, QueryResult, JobLogEntry, CLCommandResult, VersionCheckResult, GetTraceDataResult, ServerTraceDest, ServerTraceLevel, SetConfigResult, QueryOptions } from "./types"; |
| 5 | +import { Query } from "./query"; |
5 | 6 |
|
6 | 7 | export enum JobStatus {
|
7 | 8 | NotStarted = "notStarted",
|
@@ -29,7 +30,7 @@ export class SQLJob {
|
29 | 30 | })
|
30 | 31 | }
|
31 | 32 |
|
32 |
| - private async send(content: string): Promise<string> { |
| 33 | + async send(content: string): Promise<string> { |
33 | 34 | if (this.status === JobStatus.Ready) {
|
34 | 35 | this.status = JobStatus.Busy;
|
35 | 36 | ServerComponent.writeOutput(content);
|
@@ -101,92 +102,62 @@ export class SQLJob {
|
101 | 102 |
|
102 | 103 | return connectResult;
|
103 | 104 | }
|
| 105 | + query<T>(sql: string, opts?: QueryOptions): Query<T> { |
| 106 | + return new Query(this, sql, opts); |
| 107 | + } |
104 | 108 |
|
105 |
| - async query<T>(sql: string, parameters?: (number | string)[]): Promise<T[]> { |
106 |
| - const hasParms = (parameters && parameters.length > 0); |
107 |
| - |
108 |
| - const queryObject = { |
| 109 | + async getVersion(): Promise<VersionCheckResult> { |
| 110 | + const verObj = { |
109 | 111 | id: `boop`,
|
110 |
| - type: hasParms ? `prepare_sql_execute` : `sql`, |
111 |
| - sql, |
112 |
| - parameters: hasParms ? parameters : undefined |
| 112 | + type: `getversion` |
113 | 113 | };
|
114 | 114 |
|
115 |
| - const result = await this.send(JSON.stringify(queryObject)); |
| 115 | + const result = await this.send(JSON.stringify(verObj)); |
116 | 116 |
|
117 |
| - const queryResult: QueryResult = JSON.parse(result); |
| 117 | + const version: VersionCheckResult = JSON.parse(result); |
118 | 118 |
|
119 |
| - if (queryResult.success !== true) { |
120 |
| - throw new Error(queryResult.error || `Failed to run query (unknown error)`); |
| 119 | + if (version.success !== true) { |
| 120 | + throw new Error(version.error || `Failed to get version from backend`); |
121 | 121 | }
|
122 | 122 |
|
123 |
| - return queryResult.data; |
124 |
| - } |
125 |
| - |
126 |
| - |
127 |
| - async pagingQuery(correlation_id: string, sql: string, rowsToFetch: number = 1000): Promise<QueryResult> { |
128 |
| - |
129 |
| - const queryObject = { |
130 |
| - id: correlation_id, |
131 |
| - type: `sql`, |
132 |
| - sql, |
133 |
| - rows: rowsToFetch |
134 |
| - }; |
135 |
| - |
136 |
| - const result = await this.send(JSON.stringify(queryObject)); |
137 |
| - |
138 |
| - const queryResult: QueryResult = JSON.parse(result); |
139 |
| - |
140 |
| - if (queryResult.success !== true) { |
141 |
| - throw new Error(queryResult.error || `Failed to run query (unknown error)`); |
142 |
| - } |
143 |
| - return queryResult; |
| 123 | + return version; |
144 | 124 | }
|
145 |
| - async pagingQueryMoreData(correlation_id: string, rowsToFetch: number = 1000): Promise<QueryResult> { |
146 |
| - |
147 |
| - const queryObject = { |
| 125 | + async getTraceData(): Promise<GetTraceDataResult> { |
| 126 | + const tracedataReqObj = { |
148 | 127 | id: `boop`,
|
149 |
| - cont_id: correlation_id, |
150 |
| - type: `sqlmore`, |
151 |
| - rows: rowsToFetch |
| 128 | + type: `gettracedata` |
152 | 129 | };
|
153 | 130 |
|
154 |
| - const result = await this.send(JSON.stringify(queryObject)); |
| 131 | + const result = await this.send(JSON.stringify(tracedataReqObj)); |
155 | 132 |
|
156 |
| - const queryResult: QueryResult = JSON.parse(result); |
| 133 | + const rpy: GetTraceDataResult = JSON.parse(result); |
157 | 134 |
|
158 |
| - if (queryResult.success !== true) { |
159 |
| - throw new Error(queryResult.error || `Failed to run query (unknown error)`); |
| 135 | + if (rpy.success !== true) { |
| 136 | + throw new Error(rpy.error || `Failed to get trace data from backend`); |
160 | 137 | }
|
161 |
| - return queryResult; |
| 138 | + return rpy; |
162 | 139 | }
|
163 |
| - |
164 |
| - async getVersion(): Promise<VersionCheckResult> { |
165 |
| - const verObj = { |
| 140 | + //TODO: add/modify this API to allow manipulation of JTOpen tracing, and add tests |
| 141 | + async setTraceConfig(dest: ServerTraceDest, level: ServerTraceLevel): Promise<SetConfigResult> { |
| 142 | + const reqObj = { |
166 | 143 | id: `boop`,
|
167 |
| - type: `getversion` |
| 144 | + type: `setconfig`, |
| 145 | + tracedest: dest, |
| 146 | + tracelevel: level |
168 | 147 | };
|
169 | 148 |
|
170 |
| - const result = await this.send(JSON.stringify(verObj)); |
| 149 | + const result = await this.send(JSON.stringify(reqObj)); |
171 | 150 |
|
172 |
| - const version: VersionCheckResult = JSON.parse(result); |
| 151 | + const rpy: SetConfigResult = JSON.parse(result); |
173 | 152 |
|
174 |
| - if (version.success !== true) { |
175 |
| - throw new Error(version.error || `Failed to get version from backend`); |
| 153 | + if (rpy.success !== true) { |
| 154 | + throw new Error(rpy.error || `Failed to set trace options on backend`); |
176 | 155 | }
|
177 |
| - |
178 |
| - return version; |
| 156 | + return rpy; |
179 | 157 | }
|
180 |
| - async clcommand(cmd: string): Promise<CLCommandResult> { |
181 |
| - const cmdObj = { |
182 |
| - id: `boop`, |
183 |
| - type: `cl`, |
184 |
| - cmd: cmd |
185 |
| - }; |
186 |
| - const result = await this.send(JSON.stringify(cmdObj)); |
187 | 158 |
|
188 |
| - const commandResult: CLCommandResult = JSON.parse(result); |
189 |
| - return commandResult; |
| 159 | + clcommand(cmd: string): Query<any> { |
| 160 | + return new Query(this, cmd, {isClCommand: true}) |
190 | 161 | }
|
191 | 162 |
|
192 | 163 | async close() {
|
|
0 commit comments