sqlparse icon indicating copy to clipboard operation
sqlparse copied to clipboard

Adding support for options when parsing

Open MrMeemus opened this issue 7 years ago • 4 comments

Addresses #384.

Options added:

  • sql_dialect This option allows the user to select which sql dialect to use when parsing. Prior to this support, all SQL dialects (PGSQL, MYSQL, TSQL, etc.) would share the same list of regex to tokens mapping. This will lead to mismatch token types for certain words.

    Example: TransactSQL statement "@@Version" Expected token type: Builtin '@@version' Actual token type: Operator '@@', Identifier 'Version'

    Currently supported values are 'TransactSQL'.

  • additional_keywords This option allows the user to supply a list of additional strings to map to Keyword token type when parsing. Currently the list of keywords are hard-coded in the source code. This can create issues for users if they want to use the library against the latest version of their SQL dialect of choice that sqlparse may not have been updated with those new keywords.

MrMeemus avatar Feb 13 '18 19:02 MrMeemus

Codecov Report

Merging #389 into master will increase coverage by 0.04%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #389      +/-   ##
=========================================
+ Coverage   97.25%   97.3%   +0.04%     
=========================================
  Files          21      21              
  Lines        1420    1445      +25     
=========================================
+ Hits         1381    1406      +25     
  Misses         39      39
Impacted Files Coverage Δ
sqlparse/lexer.py 97.82% <100%> (+0.68%) :arrow_up:
sqlparse/engine/filter_stack.py 100% <100%> (ø) :arrow_up:
sqlparse/__init__.py 100% <100%> (ø) :arrow_up:
sqlparse/keywords.py 100% <100%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 9cf45eb...cdc6691. Read the comment docs.

codecov-io avatar Feb 13 '18 19:02 codecov-io

@andialbrecht, what is the ETA for this PR? I'm working on updating mssql-cli which relies on this update to sqlparse. Please let me know if there is anything I can do to expedite the process. Thank you!

MrMeemus avatar Mar 14 '18 14:03 MrMeemus

@andialbrecht , thanks for the feedback! I will resume work on this PR in the coming weeks. I'm currently a bit back logged :)

MrMeemus avatar Apr 25 '18 16:04 MrMeemus

Hi @MrMeemus / @andialbrecht - is there any chance of this PR being progressed? I've been digging into https://github.com/dbcli/pgcli/issues/954 (no completion in pgcli given a table named events) and I've tracked the cause down to sqlparse considering events as a keyword. However, events is not a PostgreSQL keyword so it would be great if I could select a Postgres dialect to avoid the misclassification for pgcli's purposes.

Thanks!

owst avatar Apr 04 '20 11:04 owst