db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "A B (JIRA)" <derby-...@db.apache.org>
Subject [jira] Updated: (DERBY-522) ERROR X0Y79 raised when adding comments using "--" before sql queries with Network Client
Date Thu, 13 Oct 2005 16:20:11 GMT
     [ http://issues.apache.org/jira/browse/DERBY-522?page=all ]

A B updated DERBY-522:

    Attachment: d522_v2.patch

Attaching an second version of the patch that has the following changes (w.r.t the first version):

1) Logic in client/am/Statement.java has been re-written to account for some edge cases that
weren't covered in the initial patch.

2) Per Kathey Marsden's suggestion, the ij code has been changed so that it no longer strips
leading comments when passing statements to the Derby Client.  NOTE: to be safe, this particular
part of the patch probably should _not_ be ported to 10.1.

3) In working with this patch, I noticed that statements which _end_ in comments do not work
when passed through JDBC--rather, the result will be a syntax error in all modes (embedded,
Derby Client, and JCC); see below for more on that issue.  The new version of the patch fixes
that problem in addition to the other documented problems in this Jira issue.

4) Updated additional master files to reflect the new changes.


Regarding #3 above: it turns out that if one tries to execute a SQL statement that _ends_
with a comment via JDBC, the result will be a syntax error.  This occurs in embedded mode
as well as client/server mode.  Ex:

    ResultSet rs = st.execute("values 2, 3, 4\n-- trailing comment");

will result in the following error:

 ERROR 42X01: Syntax error: Encountered "-" at line 2, column 1.

Note, though, that if you add an end-of-line character to the exact same statement, it will

    ResultSet rs = st.execute("values 2, 3, 4\n-- trailing comment\n");

The reason is because the grammar in sqlgrammar.jj defines a comment as always ending with
either "\n", "\r", or "\r\n".  Thus, in the first example above, since the comment doesn't
end with any of these three characters, the result is a syntax error.

To fix this, I just made the final "\n", "\r", or "\r\n" optional--then in situations where
the comment is the last part of the statement and there's no trailing newline, it will still
be recognized as a comment and processed accordingly (i.e. ignored).

I ran derbyall after making this simple change and there were no failures, so I _think_ it's
safe.  However, I'm hoping to get a second opinion on this, just to be safe.

Note that this change WILL have one side effect: in the edge case where a user tries to execute
a statement that consists of ALL  comments, the error message will now be:

 ERROR 42X01: Syntax error: Encountered "<EOF>" at line 1, column 3.

instead of:

 ERROR 42X01: Syntax error: Encountered "-" at line 1, column 3.

To me, this seems like an acceptable change in behavior since the new behavior matches what
currently happens if the user passes in an empty string--and, if the entire statement is just
comments, that is in effect the what we're doing.  However, if anyone thinks this is unacceptable,
please let me know and I'll just file a separate JIRA entry for that issue, to be addressed

Finally, regarding Kathey's question of whether or not this fix will work if a comment precedes
a stored procedure call that returns result sets, the answer is "Yes."  I ran something like:

  ResultSet rs = st.executeQuery("-- leading comment\ncall proc1()");

and was able to process the results successfully.  Did you have a particular concern with
this Kathey?  I added this test case to the set of cases for DERBY-522 in jdbcapi/nullSQLText.java,
just to be certain.

I ran derbyall on Windows 2000 with Sun JDK 1.4.2 with this patch and saw no failures.

Many thanks to anyone who has additional comments/feedback on this patch.

> ERROR X0Y79 raised when adding comments using "--" before sql queries with Network Client
> -----------------------------------------------------------------------------------------
>          Key: DERBY-522
>          URL: http://issues.apache.org/jira/browse/DERBY-522
>      Project: Derby
>         Type: Bug
>   Components: Network Client
>     Versions:,,
>     Reporter: Kathey Marsden
>     Assignee: A B
>      Fix For:,
>  Attachments: CommentBeforeSelect.java, d522_v2.patch, d522_v2.stat
> Comments before a  select statement Throws exception with Network Client
> For Example a statement like the one below in the attached program with throw an exception.
> stmt.execute("-- This is a comment \n Select c11 from TAB1");
> org.apache.derby.client.am.SqlException: Statement.executeUpdate() cannot be called with
a statement that returns a ResultSet.
>         at org.apache.derby.client.am.Statement.completeSqlca(Statement.java:1354)
>         at org.apache.derby.client.am.Statement.completeExecuteImmediate(Statement.java:964)
>         at org.apache.derby.client.net.NetStatementReply.parseEXCSQLIMMreply(NetStatementReply.java:199)
>         at org.apache.derby.client.net.NetStatementReply.readExecuteImmediate(NetStatementReply.java:50)
>         at org.apache.derby.client.net.StatementReply.readExecuteImmediate(StatementReply.java:44)
>         at org.apache.derby.client.net.NetStatement.readExecuteImmediate_(NetStatement.java:123)
>         at org.apache.derby.client.am.Statement.readExecuteImmediate(Statement.java:960)
>         at org.apache.derby.client.am.Statement.flowExecute(Statement.java:1587)
>         at org.apache.derby.client.am.Statement.executeX(Statement.java:631)
>         at org.apache.derby.client.am.Statement.execute(Statement.java:622)
>         at CommentBeforeSelect.createAndPopulateTable(CommentBeforeSelect.java:70)
>         at CommentBeforeSelect.main(CommentBeforeSelect.java:35)
> $
> To reproduce run the attached program 
> java CommentBeforeSelect

This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators:
For more information on JIRA, see:

View raw message