Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix linebreaks in generated SQL #326

Merged
merged 3 commits into from
Feb 3, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/database/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,21 @@ export default class Schemas {
* @param object Not user input
*/
static async generateSQL(schema: string, object: string, internalType: string): Promise<string> {
const lines = await JobManager.runSQL<{ SRCDTA: string }>([
`CALL QSYS2.GENERATE_SQL(?, ?, ?, CREATE_OR_REPLACE_OPTION => '1', PRIVILEGES_OPTION => '0')`
await JobManager.runSQL<{ SRCDTA: string }>([
`CALL QSYS2.GENERATE_SQL( DATABASE_OBJECT_NAME => ?, DATABASE_OBJECT_LIBRARY_NAME => ?, DATABASE_OBJECT_TYPE => ?
, CREATE_OR_REPLACE_OPTION => '1', PRIVILEGES_OPTION => '0'
, DATABASE_SOURCE_FILE_NAME => '*STMF'
, STATEMENT_FORMATTING_OPTION => '0'
, SOURCE_STREAM_FILE => '/tmp/Q_GENSQL_' concat current_user concat '.sql'
, SOURCE_STREAM_FILE_END_OF_LINE => 'LF'
, SOURCE_STREAM_FILE_CCSID => 1208 )`
].join(` `), { parameters: [object, schema, internalType] });
const lines = await JobManager.runSQL<{ LINE: string }>(
`select LINE
from table( QSYS2.IFS_READ( PATH_NAME => '/tmp/Q_GENSQL_' concat current_user concat '.sql' ) )`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point, should we just use our own Code for IBM i API to get the contents of the file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could... and we could also use our own C4i API to run the SQL and get the result in one step instead of these multiple calls. And maybe use the temporary streamfile API?

I'm quite busy currently with bigger projects at work, so we either

  1. wait for me to get some spare time
  2. let you code it or
  3. put a TODO in the source.

Which do you prefer? 😉

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am happy to do it actually! I will have a go at it on Monday morning. Using the temp streamfile is also a good idea.

);

const generatedStatement = lines.map(line => line.SRCDTA).join(`\n`);
const generatedStatement = lines.map( elem => elem.LINE ).join(`\n`);

return generatedStatement;
}
Expand Down
Loading