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

Adding KEY as a reserved word for QueryDSL 3.x #2183

Conversation

jerometerry
Copy link

@jerometerry jerometerry commented Aug 13, 2017

MS SQL Server rejects queries for columns named key without being escaped. MS SQL Reserved Keywords

Without KEY being part of the default reserved words, I need to override the MS SQL Templates and override requiresQuotes.

An alternative design would be to allow addition of keywords via configuration, but that is needless complexity IMHO. KEY is in the default list of keywords in QueryDSL 4.

@Shredder121
Copy link
Member

You can also put the list of keywords, specific to SQL Server in the SQLServerTemplates, and use that to call the super constructor.

@jerometerry
Copy link
Author

jerometerry commented Aug 13, 2017

I couldn't access a constructor to pass a list of keywords. Only solution I could come up with was this

public class SQLServerAdditionalKeywords
{
    private static final Set<String> additionalReservedKeywords = Sets.newHashSet("KEY");

    public static boolean isReservedWord(String identifier)
    {
        return additionalReservedKeywords.contains(identifier.toUpperCase());
    }
}

public class SS2012 extends SQLServer2012Templates
{
    @Override
    protected boolean requiresQuotes(final String identifier, final boolean precededByDot)
    {
        if (SQLServerAdditionalKeywords.isReservedWord(identifier))
        {
            return true;
        }
        else
        {
            return super.requiresQuotes(identifier, precededByDot);
        }
    }
}

I would rather not have to add this boilerplate to a production system.

@jerometerry
Copy link
Author

jerometerry commented Aug 13, 2017

@Shredder121 Are you recommending that I update this PR to add additional keywords required by SQL Server to SQLServerTemplates, instead of updating SQLTemplates? Like this?

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

Successfully merging this pull request may close these issues.

None yet

2 participants