goldmansachs/reladomo

Problem with attribute quoting in ddl generation for h2.

Opened this issue · 2 comments

After upgrading to the latest version of Reladomo, I see the new attribute quoting behavior. I'm generating ddl files to disk using the postgres database type, and then I load them into h2 inside tests. I realize this might not be a valid thing to do, but it's always worked in the past and CoreMithraDbDefinitionGenerator#setDatabaseType doesn't have an option for h2. Should it?

The quoting is happening a little differently in ddl files, idx files, and fk files.

In ddl files, the quotes appear escaped with slashes. H2 doesn't seem to like this syntax.

drop table if exists MYTYPE;

create table MYTYPE
(
    \"name\" varchar(256) not null,
    data varchar(100000) not null,
);

In fk files, there's no quoting. H2 is fine with this, at least for the identifier "name".

references MYTYPE(
    name
);

In idx files, there's quoting with no slashes. H2 is fine with this too.

alter table MYTYPE add constraint MYTYPE_PK primary key ("name");

I stepped through AbstractGeneratorDatabaseType a bit and see the places where getColumnNameWithEscapedQuote() and getPlainColumnName() are called, and I'm happy to help with a fix, but I'm not confident I understand the issue.

Let's first start with adding an H2 database type for ddl generation.

We can then review the quoting and ddl generation for H2 and other dbs.

Thanks for the quick response! I think H2GeneratorDatabaseType is basically a copy of PostgresGeneratorDatabaseType but with the override:

    @Override
    protected void generateNullStatement(PrintWriter writer, Attribute[] attributes, String attributeSqlType, int i)
    {
        writer.println("    " + attributes[i].getColumnName() + " " + attributeSqlType +
                (attributes[i].isNullable() ? "" : " not null") + ((i < attributes.length - 1) ? "," : ""));
    }