Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with attribute quoting in ddl generation for h2. #254

Open
motlin opened this issue May 8, 2022 · 2 comments
Open

Problem with attribute quoting in ddl generation for h2. #254

motlin opened this issue May 8, 2022 · 2 comments

Comments

@motlin
Copy link
Collaborator

motlin commented May 8, 2022

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.

@mohrezaei
Copy link
Collaborator

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.

@motlin
Copy link
Collaborator Author

motlin commented May 8, 2022

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) ? "," : ""));
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants