You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by "Knut Anders Hatlen (JIRA)" <ji...@apache.org> on 2007/12/02 00:33:43 UTC

[jira] Created: (DERBY-3242) ij doesn't understand bracketed comments

ij doesn't understand bracketed comments
----------------------------------------

                 Key: DERBY-3242
                 URL: https://issues.apache.org/jira/browse/DERBY-3242
             Project: Derby
          Issue Type: Bug
          Components: SQL, Tools
    Affects Versions: 10.4.0.0
            Reporter: Knut Anders Hatlen


When I execute this sql script in ij

------
create table t (x int);
/*
insert into t values 1, 2, 3;
insert into t values 4, 5, 6;
*/
------

the first INSERT statement in the comment is correctly ignored, but the second one is executed. So after running the script, table T contains these rows:

ij> select * from t;
X          
-----------
4          
5          
6          

3 rows selected

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (DERBY-3242) ij doesn't understand bracketed comments

Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-3242?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Knut Anders Hatlen updated DERBY-3242:
--------------------------------------

    Attachment: comment.sql

Attached is the script I used for testing. This is what ij prints when I run it:

ij> run '/tmp/comment.sql';
ij> create table t (x int);
0 rows inserted/updated/deleted
ij> /*
insert into t values 1, 2, 3;
ERROR 42X01: Syntax error: Encountered "<EOF>" at line 2, column 28.
ij> insert into t values 4, 5, 6;
3 rows inserted/updated/deleted
ij> */
;
ERROR 42X01: Syntax error: Encountered "*" at line 1, column 1.

> ij doesn't understand bracketed comments
> ----------------------------------------
>
>                 Key: DERBY-3242
>                 URL: https://issues.apache.org/jira/browse/DERBY-3242
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL, Tools
>    Affects Versions: 10.4.0.0
>            Reporter: Knut Anders Hatlen
>         Attachments: comment.sql
>
>
> When I execute this sql script in ij
> ------
> create table t (x int);
> /*
> insert into t values 1, 2, 3;
> insert into t values 4, 5, 6;
> */
> ------
> the first INSERT statement in the comment is correctly ignored, but the second one is executed. So after running the script, table T contains these rows:
> ij> select * from t;
> X          
> -----------
> 4          
> 5          
> 6          
> 3 rows selected

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (DERBY-3242) ij doesn't understand bracketed comments

Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-3242?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Knut Anders Hatlen updated DERBY-3242:
--------------------------------------

    Attachment: comment3.sql

Thanks again, James. I think the last patch is very close, but there seems to be a problem with nested comments. Please see the attached sql script.

$ java -jar derbyrun.jar ij comment3.sql
ij version 10.4
ij> /* let's start the file with a /* nested comment */ and see what happens */
connect 'jdbc:derby:d3242;create=true';
IJ ERROR: Unable to establish connection
ij> values 'hi!';
IJ ERROR: Unable to establish connection
ij>

This script works if the comment isn't nested. I don't know what's causing this, but I suspect that it's the rather cryptic regex you uncommented in ij.jj that doesn't handle nested comments. Nested comments in the middle of a statement do however work correctly.

> ij doesn't understand bracketed comments
> ----------------------------------------
>
>                 Key: DERBY-3242
>                 URL: https://issues.apache.org/jira/browse/DERBY-3242
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL, Tools
>    Affects Versions: 10.4.0.0
>            Reporter: Knut Anders Hatlen
>            Assignee: James F. Adams
>         Attachments: comment.sql, comment2.sql, comment3.sql, Derby-3241-v2.txt, Derby-3242.txt
>
>
> When I execute this sql script in ij
> ------
> create table t (x int);
> /*
> insert into t values 1, 2, 3;
> insert into t values 4, 5, 6;
> */
> ------
> the first INSERT statement in the comment is correctly ignored, but the second one is executed. So after running the script, table T contains these rows:
> ij> select * from t;
> X          
> -----------
> 4          
> 5          
> 6          
> 3 rows selected

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Assigned: (DERBY-3242) ij doesn't understand bracketed comments

Posted by "James F. Adams (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-3242?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

James F. Adams reassigned DERBY-3242:
-------------------------------------

    Assignee: James F. Adams

> ij doesn't understand bracketed comments
> ----------------------------------------
>
>                 Key: DERBY-3242
>                 URL: https://issues.apache.org/jira/browse/DERBY-3242
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL, Tools
>    Affects Versions: 10.4.0.0
>            Reporter: Knut Anders Hatlen
>            Assignee: James F. Adams
>         Attachments: comment.sql
>
>
> When I execute this sql script in ij
> ------
> create table t (x int);
> /*
> insert into t values 1, 2, 3;
> insert into t values 4, 5, 6;
> */
> ------
> the first INSERT statement in the comment is correctly ignored, but the second one is executed. So after running the script, table T contains these rows:
> ij> select * from t;
> X          
> -----------
> 4          
> 5          
> 6          
> 3 rows selected

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (DERBY-3242) ij doesn't understand bracketed comments

Posted by "James F. Adams (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-3242?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

James F. Adams updated DERBY-3242:
----------------------------------

    Derby Info: [Patch Available]

> ij doesn't understand bracketed comments
> ----------------------------------------
>
>                 Key: DERBY-3242
>                 URL: https://issues.apache.org/jira/browse/DERBY-3242
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL, Tools
>    Affects Versions: 10.4.0.0
>            Reporter: Knut Anders Hatlen
>            Assignee: James F. Adams
>         Attachments: comment.sql, Derby-3242.txt
>
>
> When I execute this sql script in ij
> ------
> create table t (x int);
> /*
> insert into t values 1, 2, 3;
> insert into t values 4, 5, 6;
> */
> ------
> the first INSERT statement in the comment is correctly ignored, but the second one is executed. So after running the script, table T contains these rows:
> ij> select * from t;
> X          
> -----------
> 4          
> 5          
> 6          
> 3 rows selected

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (DERBY-3242) ij doesn't understand bracketed comments

Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-3242?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Knut Anders Hatlen updated DERBY-3242:
--------------------------------------

    Attachment: comment2.sql

Thanks for the patch, James! Your approach looks fine, and it seems to work correctly in most cases. The one thing that didn't seem to work, was when a script ended with a comment. Apparently, ij then thinks we have started a new statement and emits a syntax error on EOF. I have attached a repro as comment2.sql.

By the way, the indentation in readBracketedComment() is a bit funny. Each line starts with a single tab character which is followed by a number of space characters. I think it would be better not to mix different indentation characters on the same line.

StatementFinder defines constants for some "special state-changing characters". Would the code be more consistent if readBracketedComment() used those? At least, it defines a slash constant, but it seems like we need to add a constant for asterisk ourselves.

I was also wondering if readBracketedComment() would be simpler if we used peekChar()/readChar() instead of maintaining the flags lookingForSlash and lookingForAsterisk. Something like:

char peek = peekChar();
if (nextChar == ASTERISK && peek == SLASH) {
    readChar();
    ...
} else if (nextChar == SLASH && peek == ASTERISK) {
    readChar();
    ....
} else {
    ....
}

What do you think?

> ij doesn't understand bracketed comments
> ----------------------------------------
>
>                 Key: DERBY-3242
>                 URL: https://issues.apache.org/jira/browse/DERBY-3242
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL, Tools
>    Affects Versions: 10.4.0.0
>            Reporter: Knut Anders Hatlen
>            Assignee: James F. Adams
>         Attachments: comment.sql, comment2.sql, Derby-3242.txt
>
>
> When I execute this sql script in ij
> ------
> create table t (x int);
> /*
> insert into t values 1, 2, 3;
> insert into t values 4, 5, 6;
> */
> ------
> the first INSERT statement in the comment is correctly ignored, but the second one is executed. So after running the script, table T contains these rows:
> ij> select * from t;
> X          
> -----------
> 4          
> 5          
> 6          
> 3 rows selected

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (DERBY-3242) ij doesn't understand bracketed comments

Posted by "James F. Adams (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-3242?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

James F. Adams updated DERBY-3242:
----------------------------------

    Attachment: Derby3242-v3.txt

Knut, thanks for reviewing the previous patch.  I have uploaded another, and hopefully final, patch proposal.  I modified ij.jj to recognize nested bracketed comments and added an additional test to IJRunScriptTest.java.

Ran derbyAll and suites.All and saw no errors I could attribute to this patch.

> ij doesn't understand bracketed comments
> ----------------------------------------
>
>                 Key: DERBY-3242
>                 URL: https://issues.apache.org/jira/browse/DERBY-3242
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL, Tools
>    Affects Versions: 10.4.0.0
>            Reporter: Knut Anders Hatlen
>            Assignee: James F. Adams
>         Attachments: comment.sql, comment2.sql, comment3.sql, Derby-3241-v2.txt, Derby-3242.txt, Derby3242-v3.txt
>
>
> When I execute this sql script in ij
> ------
> create table t (x int);
> /*
> insert into t values 1, 2, 3;
> insert into t values 4, 5, 6;
> */
> ------
> the first INSERT statement in the comment is correctly ignored, but the second one is executed. So after running the script, table T contains these rows:
> ij> select * from t;
> X          
> -----------
> 4          
> 5          
> 6          
> 3 rows selected

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (DERBY-3242) ij doesn't understand bracketed comments

Posted by "James F. Adams (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-3242?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

James F. Adams updated DERBY-3242:
----------------------------------

    Attachment: Derby-3242.txt

Attached a patch proposal that addresses this issue.  Modified StatementFinder.java to recognize nested brackted comments.  Added a test to IJRunScriptTest.java to verify bracketed comment support in ij.

Ran derbyAll and suites.All and saw no errors I could attribute to this patch.

> ij doesn't understand bracketed comments
> ----------------------------------------
>
>                 Key: DERBY-3242
>                 URL: https://issues.apache.org/jira/browse/DERBY-3242
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL, Tools
>    Affects Versions: 10.4.0.0
>            Reporter: Knut Anders Hatlen
>            Assignee: James F. Adams
>         Attachments: comment.sql, Derby-3242.txt
>
>
> When I execute this sql script in ij
> ------
> create table t (x int);
> /*
> insert into t values 1, 2, 3;
> insert into t values 4, 5, 6;
> */
> ------
> the first INSERT statement in the comment is correctly ignored, but the second one is executed. So after running the script, table T contains these rows:
> ij> select * from t;
> X          
> -----------
> 4          
> 5          
> 6          
> 3 rows selected

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (DERBY-3242) ij doesn't understand bracketed comments

Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-3242?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Knut Anders Hatlen closed DERBY-3242.
-------------------------------------

       Resolution: Fixed
    Fix Version/s: 10.4.0.0
       Derby Info:   (was: [Patch Available])

Great! Seems like everything is covered now. Committed revision 604871.
Thanks!

> ij doesn't understand bracketed comments
> ----------------------------------------
>
>                 Key: DERBY-3242
>                 URL: https://issues.apache.org/jira/browse/DERBY-3242
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL, Tools
>    Affects Versions: 10.4.0.0
>            Reporter: Knut Anders Hatlen
>            Assignee: James F. Adams
>             Fix For: 10.4.0.0
>
>         Attachments: comment.sql, comment2.sql, comment3.sql, Derby-3241-v2.txt, Derby-3242.txt, Derby3242-v3.txt
>
>
> When I execute this sql script in ij
> ------
> create table t (x int);
> /*
> insert into t values 1, 2, 3;
> insert into t values 4, 5, 6;
> */
> ------
> the first INSERT statement in the comment is correctly ignored, but the second one is executed. So after running the script, table T contains these rows:
> ij> select * from t;
> X          
> -----------
> 4          
> 5          
> 6          
> 3 rows selected

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (DERBY-3242) ij doesn't understand bracketed comments

Posted by "James F. Adams (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-3242?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

James F. Adams updated DERBY-3242:
----------------------------------

    Attachment: Derby-3241-v2.txt

Thanks Knut for spending the time to review my previous patch proposal.  I have prepared a new patch proposal (Derby-3241-v2.txt) that incorporates your suggestions.

In particular:

Scripts ending with bracketed comments are correctly handled.
I cleaned up the indentation to be in the style of the surrounding code.
Added the missing constants and removed the unnecessary state flags.

Ran derbyAll and suites.All and saw no errors I could attribute to this patch. 


> ij doesn't understand bracketed comments
> ----------------------------------------
>
>                 Key: DERBY-3242
>                 URL: https://issues.apache.org/jira/browse/DERBY-3242
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL, Tools
>    Affects Versions: 10.4.0.0
>            Reporter: Knut Anders Hatlen
>            Assignee: James F. Adams
>         Attachments: comment.sql, comment2.sql, Derby-3241-v2.txt, Derby-3242.txt
>
>
> When I execute this sql script in ij
> ------
> create table t (x int);
> /*
> insert into t values 1, 2, 3;
> insert into t values 4, 5, 6;
> */
> ------
> the first INSERT statement in the comment is correctly ignored, but the second one is executed. So after running the script, table T contains these rows:
> ij> select * from t;
> X          
> -----------
> 4          
> 5          
> 6          
> 3 rows selected

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.