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

fixed #1403, improved comment handling #1404

Merged
merged 3 commits into from
Oct 13, 2023
Merged

fixed #1403, improved comment handling #1404

merged 3 commits into from
Oct 13, 2023

Conversation

ERYoung11
Copy link
Contributor

Description

Fixed #1403, improved comment handling when the comment is on the first line. Also added some more testing for this and simmilar issues as well as rearranged these tests some.

Checklist

  • I've added this contribution to the changelog.rst.
  • I've added my name to the AUTHORS file (or it's already there).
  • I installed pre-commit hooks (pip install pre-commit && pre-commit install), and ran black on my code.
  • Please squash merge this pull request (uncheck if you'd like us to merge as multiple commits)

@codecov-commenter
Copy link

codecov-commenter commented May 21, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (6332e18) 79.60% compared to head (74d07ea) 79.67%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1404      +/-   ##
==========================================
+ Coverage   79.60%   79.67%   +0.06%     
==========================================
  Files          25       25              
  Lines        3030     3035       +5     
==========================================
+ Hits         2412     2418       +6     
+ Misses        618      617       -1     
Files Coverage Δ
pgcli/pgexecute.py 83.63% <100.00%> (+0.25%) ⬆️

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


def remove_beginning_comments(command):
# Regular expression pattern to match comments
pattern = r"^(/\*.*?\*/|--.*?)(?:\n|$)"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that sqlparse.format(command, strip_comments=True) may do exactly what you want. I didn't try it myself, though, so take it with a grain of salt, but I suggest trying.

Copy link
Contributor Author

@ERYoung11 ERYoung11 May 22, 2023

Choose a reason for hiding this comment

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

@j-bennet Thank you for taking time to analyze this. If I remember correctly, we decided to not use the strip_comments flags in sqlparse because it truly throws away the comments and some user wanted comments to show up in postgres error/output logs. So this "dance" in the code is to save the beginning comments, remove them from the sql query, parse the sql query, then re-add the comments to the beginning of the query so that they show up in error/output logs.

Does that make sense or would you like to tackle this a different way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@j-bennet Here is the original discussion about not stripping comments #1286

@j-bennet j-bennet merged commit 13ca7d2 into dbcli:main Oct 13, 2023
7 checks passed
@j-bennet
Copy link
Contributor

Merged. Thank you @ERYoung11 .

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

Successfully merging this pull request may close these issues.

SQL error when there is a comment on the first line
3 participants