Skip to content

Commit 527ec2f

Browse files
committed
Use different API to download generated SQL
Signed-off-by: worksofliam <[email protected]>
1 parent b27ca01 commit 527ec2f

File tree

3 files changed

+33
-29
lines changed

3 files changed

+33
-29
lines changed

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@
970970
},
971971
{
972972
"command": "vscode-db2i.getObjectLocks",
973-
"when": "viewItem == table || viewItem == view || viewItem == alias || viewItem == constraint || viewItem == function || viewItem == variable || viewItem == index || viewItem == procedure || viewItem == sequence || viewItem == package || viewItem == trigger || viewItem == type",
973+
"when": "viewItem == table || viewItem == view || viewItem == alias || viewItem == function || viewItem == variable || viewItem == index || viewItem == procedure || viewItem == sequence || viewItem == package || viewItem == trigger || viewItem == type",
974974
"group": "db2workWith@5"
975975
},
976976
{
@@ -1322,7 +1322,7 @@
13221322
},
13231323
"devDependencies": {
13241324
"@continuedev/core": "^1.0.13",
1325-
"@halcyontech/vscode-ibmi-types": "^2.14.0",
1325+
"@halcyontech/vscode-ibmi-types": "^2.14.5",
13261326
"@types/glob": "^7.1.3",
13271327
"@types/node": "18.x",
13281328
"@types/vscode": "^1.95.0",

src/database/schemas.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2+
import path from "path";
23
import { getInstance } from "../base";
3-
44
import { JobManager } from "../config";
55

66
export type SQLType = "schemas" | "tables" | "views" | "aliases" | "constraints" | "functions" | "variables" | "indexes" | "procedures" | "sequences" | "packages" | "triggers" | "types" | "logicals";
@@ -220,23 +220,27 @@ export default class Schemas {
220220
* @param object Not user input
221221
*/
222222
static async generateSQL(schema: string, object: string, internalType: string): Promise<string> {
223-
await JobManager.runSQL<{ SRCDTA: string }>([
224-
`CALL QSYS2.GENERATE_SQL( DATABASE_OBJECT_NAME => ?, DATABASE_OBJECT_LIBRARY_NAME => ?, DATABASE_OBJECT_TYPE => ?
225-
, CREATE_OR_REPLACE_OPTION => '1', PRIVILEGES_OPTION => '0'
226-
, DATABASE_SOURCE_FILE_NAME => '*STMF'
227-
, STATEMENT_FORMATTING_OPTION => '0'
228-
, SOURCE_STREAM_FILE => '/tmp/Q_GENSQL_' concat current_user concat '.sql'
229-
, SOURCE_STREAM_FILE_END_OF_LINE => 'LF'
230-
, SOURCE_STREAM_FILE_CCSID => 1208 )`
231-
].join(` `), { parameters: [object, schema, internalType] });
232-
const lines = await JobManager.runSQL<{ LINE: string }>(
233-
`select LINE
234-
from table( QSYS2.IFS_READ( PATH_NAME => '/tmp/Q_GENSQL_' concat current_user concat '.sql' ) )`
235-
);
236-
237-
const generatedStatement = lines.map( elem => elem.LINE ).join(`\n`);
238-
239-
return generatedStatement;
223+
const instance = getInstance();
224+
const connection = instance.getConnection();
225+
226+
const result = await connection.withTempDirectory<string>(async (tempDir) => {
227+
const tempFilePath = path.posix.join(tempDir, `generatedSql.sql`);
228+
await JobManager.runSQL<{ SRCDTA: string }>([
229+
`CALL QSYS2.GENERATE_SQL( DATABASE_OBJECT_NAME => ?, DATABASE_OBJECT_LIBRARY_NAME => ?, DATABASE_OBJECT_TYPE => ?
230+
, CREATE_OR_REPLACE_OPTION => '1', PRIVILEGES_OPTION => '0'
231+
, DATABASE_SOURCE_FILE_NAME => '*STMF'
232+
, STATEMENT_FORMATTING_OPTION => '0'
233+
, SOURCE_STREAM_FILE => '${tempFilePath}'
234+
, SOURCE_STREAM_FILE_END_OF_LINE => 'LF'
235+
, SOURCE_STREAM_FILE_CCSID => 1208 )`
236+
].join(` `), { parameters: [object, schema, internalType] });
237+
238+
// TODO: eventually .content -> .getContent(), it's not available yet
239+
const contents = (await connection.content.downloadStreamfileRaw(tempFilePath)).toString();
240+
return contents;
241+
})
242+
243+
return result;
240244
}
241245

242246
static async deleteObject(schema: string, name: string, type: string): Promise<void> {

0 commit comments

Comments
 (0)