SQL Highlighting

I declare my SQL at the top of my DAO's in private final static String variables. Sometimes IntelliJ applies syntax highlighting to them and sometimes not (mostly not). This occurs to SQL in the same file for lines right next to each other. For instance:

private final static String = "SELECT blah,moreblah FROM foo WHERE junk = ?";  <--Will have highlighting applied
private final static String = "SELECT morecrap FROM bar WHERE morejunk = ?"; <--Won't have highlighting applied

I can't find any rhyme nor reason to what has highlighting applied and what doesn't. These are statements in the same file on subsequent lines.

I have GenericSQL set as my dialect for the entire project.

Also, are we supposed to get auto-completion when writing SQL? Because that doesn't work for me either.

I have my datasources setup and the jdbc console works fine.

6 comments
Comment actions Permalink

Are you using your second query as an argument to any of the methods setup for SQL as defined in Settings -> Language Injection?  If you're passing it to a custom method you can add this to those same settings to get the highlighting.  If it's not being used then it won't get highlighted automatically.  There should be an intention that pops up that allows you to inject the language you want (but it places an annotation in your code).

I've also never had any luck with getting code completion to work even though I have my datasources setup properly.  I think this may only work for certain dialects (e.g MySQL) and not for GenericSQL.

0
Comment actions Permalink

I can't say why the highlighting is so inconsistent, but you can annotate the declaration to enforce highlighting:

@Language("SQL")
private final static String SQL = "SELECT morecrap FROM bar WHERE morejunk = ?";

There should be a quickfix on the un-imported @Language annotation to add IDEA's annotation.jar to the project.

Michael Parmeley wrote:

I declare my SQL at the top of my DAO's in private final static String variables. Sometimes IntelliJ applies syntax highlighting to them and sometimes not (mostly not). This occurs to SQL in the same file for lines right next to each other. For instance:

private final static String = "SELECT blah,moreblah FROM foo WHERE junk = ?"; <--Will have highlighting applied
private final static String = "SELECT morecrap FROM bar WHERE morejunk = ?"; <--Won't have highlighting applied

I can't find any rhyme nor reason to what has highlighting applied and what doesn't. These are statements in the same file on subsequent lines.

I have GenericSQL set as my dialect for the entire project.

Also, are we supposed to get auto-completion when writing SQL? Because that doesn't work for me either.

I have my datasources setup and the jdbc console works fine.

---
Original message URL: http://www.jetbrains.net/devnet/message/5243882#5243882

0
Comment actions Permalink

Hi.

SQL highlighting is propagated into String constant, if this constant is either used as an argument of a method with SQL injection (see Settings / Language injection), or explicitly annotated with @Language(...).

GenericSQL does not provide completion for table and column names. It's by design.

Alexander.

0
Comment actions Permalink

Thanks for the information (went on vacation so just now getting back to this thread).

The lines are highlighted if I use the annotation, but I don't really want to put an annonation before every line that has SQL on it (ruins readability). I don't understand why some constants have highlighting applied and others don't. (I took a look at Settings->Language Settings and don't really understand what is going on there).

What determines if the constant "used as an argument of a method with SQL injection". i.e. what determines if the method has SQL Injection?

Anyone know what SQL dialect works best for Informix?

0
Comment actions Permalink

I have my SQL dialect to SQL92 for the project and I still don't get any completions for my SQL statement (and
for most of my SQL statements I still don't get highlighting).

I am going to create a small test class and submit a bug report.

0
Comment actions Permalink

I have created the following bug report:

http://www.jetbrains.net/jira/browse/IDEA-24495

Let me know if more info is needed.

0

Please sign in to leave a comment.