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

Conversation

chrjorgensen
Copy link
Contributor

The Generate SQL output use the result set from the QSYS2.GENERATE_SQL procedure, but this is using a source member (in QTEMP) as intermediate storage and thus have a fixed length source line - 80 characters by default.

This is a problem, since identifiers can be split by a linebreak.

An example is the generated source for view QSYS2.OBJECT_LOCK_INFO where the lines containing the SELECT is broken in the middle of identifiers and functions:

billede

This can not be fixed by the SQL formatter, which will replace a linebreak in an identifier by a space:

billede

This PR will change the use of the QSYS2.GENERATE_SQL procedure to generate a streamfile instead of a source member and read this file. This will eliminate the problem with linebreaks in identifiers:

billede

After SQL formatting the source will look as expected:

billede

@chrjorgensen chrjorgensen self-assigned this Jan 31, 2025
@chrjorgensen chrjorgensen added the bug Something isn't working label Jan 31, 2025
].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.

@worksofliam worksofliam requested a review from julesyan January 31, 2025 14:43
@worksofliam worksofliam mentioned this pull request Jan 31, 2025
2 tasks
@worksofliam worksofliam merged commit eb9ea6e into codefori:main Feb 3, 2025
1 check failed
@chrjorgensen chrjorgensen deleted the fix/Generate_SQL branch February 5, 2025 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants