You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
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:
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.
and splits it up so that
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)
The text was updated successfully, but these errors were encountered: