Skip to content

Comment in beggining of SQL statement returns empty recordSet. In clickhouse-client works OK. #233

@josepowera

Description

@josepowera

When we provide Sql statement with comment in clickhouse-client it works. - no matter if comment is at the begining or at the end of sql statement.

docker run --rm yandex/clickhouse-client -h ch8.local -q "select * from system.numbers limit 3 /*comment*/"
0
1
2
uporabnik@lju1135:~$ ^C
uporabnik@lju1135:~$ docker run --rm yandex/clickhouse-client -h ch8.local -q "/*comment*/select * from system.numbers limit 3"
0
1
2

When running clickhouse-jdbc and we use comment at the beggining it FAILS

  @Test
    public void clickhouseJdbcFailsBecauseOfCommentInStart() throws Exception {

        Connection connection = DriverManager.getConnection("jdbc:clickhouse://ch8:8123/test4ssp?dataTransferTimeout=600&connection_timeout=5000");
        String sqlStatement = "/*comment*/ select * from system.numbers limit 3";


        try (Statement statement2 = connection.createStatement()) {
            try (ResultSet resultSet2 = statement2.executeQuery(sqlStatement)) {
                if (resultSet2 == null) {
                    Assert.assertTrue(false);
                    throw new Exception("resultset was null");
                } else {
                    while (resultSet2.next()) {
                        System.out.println(resultSet2.getString(1));
                    }
                    Assert.assertTrue(true);
                }
            }
        }
    }

and if we supply comment at the end of statement if works

 @Test
    public void clickhouseJdbcPassOkBecauseOfNoCommentInStart() throws Exception {

        Connection connection = DriverManager.getConnection("jdbc:clickhouse://ch8/test4ssp?dataTransferTimeout=600&connection_timeout=5000");
        String sqlStatement = "select * from system.numbers limit 3 /*comment*/";

        try (Statement statement2 = connection.createStatement()) {
            try (ResultSet resultSet2 = statement2.executeQuery(sqlStatement)) {
                if (resultSet2 == null) {
                    Assert.assertTrue(false);
                    throw new Exception("resultset was null");
                } else {
                    while (resultSet2.next()) {
                        System.out.println(resultSet2.getString(1));
                    }
                    Assert.assertTrue(true);
                }
            }
        }
    }

Why is this a problem? We normally add some small comments above sql statements in order to describe statement.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions