| Bug #30215 | Connector\J and MySQL command-line utility treat "---" (3-dashes) differently | ||
|---|---|---|---|
| Submitted: | 2 Aug 2007 22:45 | Modified: | 3 Oct 2007 16:56 |
| Reporter: | Christopher Schultz | Email Updates: | |
| Status: | Duplicate | Impact on me: | |
| Category: | Connector / J | Severity: | S3 (Non-critical) |
| Version: | 5.0.4 | OS: | Any |
| Assigned to: | CPU Architecture: | Any | |
[2 Aug 2007 22:47]
Christopher Schultz
Test file that demonstrates the behavior of the JDBC driver.
Attachment: CommentTest.java (application/octet-stream, text), 2.42 KiB.
[3 Aug 2007 9:04]
Tonci Grgin
Hi Christopher and thanks for another bug report. Verified as described with test case attached: - MySQL 5.0.48 on WinXP Pro SP2 - JDK 1.5.0_11 and latest c/J 5.0 sources Apparently, the value of column "num" is -1... .Loading JDBC driver 'com.mysql.jdbc.Driver' Done. Done. Connected to 5.0.48-pb1030-log F Time: 2,266 There was 1 failure: 1) testbug30215(testsuite.simple.TestBug30215)junit.framework.ComparisonFailure: expected:<-...> but was:<...>
[3 Aug 2007 9:06]
Tonci Grgin
Test case on latest c/J 5.0 sources
Attachment: TestBug30215.java (text/x-java), 1.15 KiB.
[3 Aug 2007 13:51]
Christopher Schultz
Thanks for the quick turnaround on this bug. I'm not entirely sure what the resolution should be. On the one hand, the MySQL command-line behavior is very nice in this particular case. On the other hand, the documentation makes a compelling case against treating all "--" as comment-until-newline indicators. Someone also pointed out to me that even treating "\n--" as a comment-until-newline indicator might not work inside of a literal string. I'm not sure how sensitive the query parser is to string literals, but as long as those could be ignored, then I would vote for treating all non-literal "\n--" strings as comment-until-newline indicators. Thanks!
[3 Oct 2007 16:56]
Mark Matthews
Duplicate of Bug#26215.

Description: Issue this multi-line query using the MySQL command-line utility and you will get: mysql> SELECT -> --- -> --- This is a comment -> --- -> 1 AS num -> ; +-----+ | num | +-----+ | 1 | +-----+ 1 row in set (0.01 sec) Issue the same multi-line query through Connector/J and the results will be different: Running query: SELECT --- --- This is a comment --- 1 AS num Results: num -1 (Please see the attached sample Java code to demonstrate). The MySQL documentation seems to indicate that "--"-style comments must be followed by whitespace or a control character to avoid unfortunate bugs (http://dev.mysql.com/doc/refman/5.0/en/comments.html and http://dev.mysql.com/doc/refman/5.0/en/ansi-diff-comments.html). One particular comment in the documentation is very relevant: "Another safe feature is that the mysql command-line client ignores lines that start with ‘--’." So, the documentation states that "--" followed by a non-whitespace character (as is the case for "---") is required for comments, but then the command-line utility allows /any/ line that begins with "--" to be treated as a comment. I believe this is a discrepancy that needs to be corrected. It is very confusing to have a query behave one way through the MySQL client, and another way through the JDBC driver. How to repeat: Run this query using both MySQL command-line utility and through the Conenctor/J JDBC driver: SELECT --- --- This is a comment --- 1 AS num