Skip to content

SQL errors related to unquoted keywords after upgrading H2. #266

@motlin

Description

@motlin

I recently upgrade Reladomo from 18.0.0 to 18.1.0, and H2 from 1.4.200 to 2.2.224. I ran into issues with SQL syntax errors, related to unquoted keywords user, which I use as a table name, and key and value, which I use as column names. I was able to work around the problem. I'll share my workarounds here, in case they make sense to upstream. I'm also wondering if there's a better way to handle this. It seems like Reladomo is designed to handle this, since the file SqlKeywords.java includes all of these keywords. Is there a way to turn on identifier quoting for all sql?

First, I created a custom DatabaseType, to copy patterns I found in e5d754c. As far as I can tell, there's no equivalent of SET QUOTED_IDENTIFIER ON for H2. Instead I ran SET NON_KEYWORDS USER, KEY, VALUE. I did not need SET MODE LEGACY.

    @Override
    public void configureConnection(Connection connection)
            throws SQLException
    {
        // this.fullyExecute(connection, "SET QUOTED_IDENTIFIER ON");
        // this.fullyExecute(connection, "SET MODE LEGACY");
        this.fullyExecute(connection, "SET NON_KEYWORDS USER, KEY, VALUE");
    }

I found I was still getting sql syntax errors and after debugging, I found some connections used by Reladomo that had not been passed to configureConnection. So next, I changed my ConnectionManager.

    @Override
    public Connection getConnection()
    {
        try
        {
            Connection connection = this.dataSource.getConnection();
            this.databaseType.configureConnection(connection);
            return connection;
        }
        catch (SQLException e)
        {
            throw new RuntimeException(e);
        }
    }

Thoughts on these changes? Is there another way to get identifiers to be quoted instead?

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