Idea support for SQL and Datasources

I have this code in my project.


PreparedStatement query = participantsConnection.prepareStatement(
                    "SELECT id, surname, name, login, grade " +
                    "FROM " + prefix + "users " +
                    "JOIN " + prefix + "participants ON id=user_id " +
                    (byId ? "WHERE id=? AND trash=0" : "WHERE login=? AND pass_hash=? AND trash=0")
);


if (byId)
    query.setInt(1, id);
else {
    query.setString(1, login);
    query.setString(2, getPasswordHash(password));
}



I opened the project in Idea 122.746 and configured a datasource to make idea understand my request and to highlight it. But it absolutely failed to understand anything. For example, It can not find the users table because the prefix is not written precisely. And it thinks that the line query.setString(2, ... has an error in the argument 2 because there is only one ? in the request.

I need to make only a few requests in my code so I don't want to use any frameworks, the plain JDBC is just enough. How should one treat the situation?
* There is a bug in Idea, and developers should somehow make it work on this example
* Developers should not mark errors in this code, they should highlight them as warnings
* I should not check this code over a datasource and I should disable the feature
* This code is extremely bad written and I should write it in some other way. How?
4 comments
Comment actions Permalink

What SQL dialect is configured for the file?

Thanks,
Alexander.

0
Comment actions Permalink

Your code is OK.
Here's the ticket: http://youtrack.jetbrains.com/issue/IDEA-95635
Taking the first solution, thanks.

0
Comment actions Permalink

It is MySQL dialect

0
Comment actions Permalink

Thank you for the response. I thought that the first variant is the least probable.

0

Please sign in to leave a comment.