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

comment before special command causes command failure #1362

Closed
ERYoung11 opened this issue Aug 29, 2022 · 1 comment
Closed

comment before special command causes command failure #1362

ERYoung11 opened this issue Aug 29, 2022 · 1 comment

Comments

@ERYoung11
Copy link
Contributor

ERYoung11 commented Aug 29, 2022

I'm looking for guidance on how to move forward.

The former issue was closed by the user without comment so I'm copying my analysis into a new Issue as it still is a problem.

@j-bennet @amjith This is my analysis and 2 possible solutions: 1 easy change to pgcli and 1 more extensive change to pgspecial. Let me know if you want any more work on this as I'm not sure which way you want to go.


This issue was revealed by PR #1296 because it allowed comments to get to pgspecial.

It can be replicated with ANY special command preceded by a comment on the first line.

For instance:

-- blah
\h;

In pgcli:pgexecute it sorts out whether you have a special command or a normal SQL command. In this case it detects that it is "normal SQL" in the end of this block and fails because pgspecial:main isn't handling it well.

In the pgspecial:main:parse_special_command function it splits this text up in an unexpected way.

  • It receives sql as "'-- blah\n\h'"

and splits it up so that

  • command is '--'
  • args is 'blah\n\h'

Since pgcli:pgexecute doesn't recognize '--' as a special command, you eventually fall through to the CommandNotFound exception and then it tries to execute it as "normal SQL" and fails.


Possible Solution 1 - Set sql.parseformat to strip comments again. I have that change and an associated test available in a PR if you want to go this direction.

Possible Solution 2 - fix pgspecial:main:parse_special_command to more properly parse this line, by ignoring the comment. However, the change may be a bit more extensive depending on how attached you are to passing through that first comment. If you just drop it, then it won't go through. You may be able to adapt pgspecial to send it through by buffering the comment and sending it through without change but that will be a more extensive change to the way pgspecial works.

Originally posted by @ERYoung11 in #1336 (comment)

amjith added a commit that referenced this issue Sep 1, 2022
@ERYoung11
Copy link
Contributor Author

Closed due to merge of #1363

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant