sqlparse icon indicating copy to clipboard operation
sqlparse copied to clipboard

Add TruncateValueFilter to de-parameterize a sql text

Open sunjun-csu opened this issue 5 years ago • 1 comments

sqlparse formatter can replace string values in a sql text with specified character and length by using truncate_strings option. However, we want to get a sql text completely de-parameterized in some special situations, just like we use some placeholders to replace all values in a sql. Here I add a new filter named TruncateValueFilter to implement this function. F or example: sql = "select * from t1 where c1 = 123" plain_sql = sqlparse.format(sql, truncate_values=True) print (plain_sql)

We can get " select * from t1 where c1 = ?"

sunjun-csu avatar Mar 26 '21 09:03 sunjun-csu

Codecov Report

Merging #612 (3dacec7) into master (23d2993) will increase coverage by 0.03%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #612      +/-   ##
==========================================
+ Coverage   96.82%   96.86%   +0.03%     
==========================================
  Files          20       20              
  Lines        1514     1530      +16     
==========================================
+ Hits         1466     1482      +16     
  Misses         48       48              
Impacted Files Coverage Δ
sqlparse/filters/__init__.py 100.00% <100.00%> (ø)
sqlparse/filters/tokens.py 95.74% <100.00%> (+1.15%) :arrow_up:
sqlparse/formatter.py 95.31% <100.00%> (+0.19%) :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 23d2993...3dacec7. Read the comment docs.

codecov[bot] avatar Mar 26 '21 10:03 codecov[bot]

邮件已收到,谢谢~

sunjun-csu avatar Mar 16 '24 15:03 sunjun-csu