/*! MySQL-specific code */ is not a comment
Hi!
According to docs http://dev.mysql.com/doc/refman/5.7/en/comments.html for example /*!40101 SET NAMES utf8 */; or /*! SET NAMES utf8 */; are an conditional-executed pieces of code. I think this should not be truncated by sqlparse.format(sql, strip_comments=True).
What do You think?
They all seem to start with /*! correct? I made a similar note (in an upstream branch) with respect to Oracle's hint comments but didn't press the issue. I think they shouldn't be stripped out.
In mysql do they have a particular location they go? in oracle they usually are next to the select keyword.
@andialbrecht any concerns in keeping them? should it be a secondary flag to strip out "special" comments?
I'm not an expert, but it seem not to be resolved in strings when I perform sql INSERT... Some example cases are in documentation that I gave a link before.
not sure i understood what you meant. The example shows CREATE and SELECT examples.
The changes I have in mind would identify the token and categorize it as a comment.code type regarless of what type of statement its in, or if its a valid instruction as long as it starts and ends with /*! */
@vmuriart, Oracle's optimizer hints all look like /*+ … */. The gory details are here (Oracle 11g).
All the examples and docs I've seen match this regex exactly, including the spaces:
re.match(r'/\*\+ .+ \*/', token.value)
So I think your solution of adding a non-skipped, non-stripped Token.Comment.Code makes a lot of sense. :+1:
Agreed!. I placed the hint tokens in an earlier commit is I'm familiar with its existance. Turns out there is a more obscure hint type; --+ ... \n is valid hint syntax.
On a side note, ISO-SQL92 defines another way to embed code (from other languages) within SQL. I've yet to find query that use it or database that allows it.
Just remembered why I haven't closed issue. I have upstream work that changes the behavior of the comment filter and handles it much earlier in the parsing process to speed-up the parsing grouping process.
I was waiting for 0.2.0 release (hint: @andialbrecht :innocent: ) before considering merging that work in.
Hi all,
Just checking in on this...I am on sqlparse version 0.2.3 (python 3.5.3) and am having issues stripping comments from Vertica SQL containing hints in the format /*+
Actually upon further investigation, this may be a separate issue with parsing comments inside comments?
stmt = "/* insert /*+ direct */ into table1 select * from table2; /" sqlparse.format(stmt, strip_comments=True, strip_whitespace=True) 'into table1 select * from table2;/'
It looks like embedding /*
Thanks!
Any workaround for this issue?