Copy SQL That Is Split Over Multiple Lines

I might have an SQL string split over multiple lines in my code
e.g.

        String sql = "SELECT column_name(s)" +             "FROM table1" +             "LEFT JOIN table2" +             "ON table1.column_name=table2.column_name";



This is fine to make my code a bit more readable, however, it makes it a pain to copy and test the SQL outside of IDEA as I have to strip out the the quotes and plus marks after I paste it.
I can get the full string by running in debug mode and copying the value but that is just as painful.

I eventually found this tiny plugin Java2SQL:
http://plugins.jetbrains.com/plugin/7019?pr=

Thumbs up to Andrey, this seems like something that should be included in IDEA by default.

5 comments
Comment actions Permalink

Please go to Settings/Intentions and enable Strings/"Copy String Concatenation to Clipboard" intention.

For currently unknown reason it is disabled by default.

0
Comment actions Permalink

OK thanks. It seems to be enabled now in the latest EAP (133.471)

To be honest, I was surprised to find a copy action in the intentions.
It appears at the the top of the intentions so I can do Alt-Enter, Enter, however, is there anyway to add it to the context menu or a different keyboard shortcut?

0
Comment actions Permalink

I think Intention in this case is better as we desperately running out of shortcuts (shortcuts mine depleted several years ago actually :) ).
Intention popup is a more scalable solution, it is a searchable/filtered list with unlimited capacity.

Intention actions can't be called via shortcut...currently,  you can always create a ticket for that and lets see what happens.

0
Comment actions Permalink

Hi opticyclic,

Thanks for thumbs up :)

Intentions really helps much and really can replace the plugin and I would retire it ... however if you have a lot of constats used in the SQL it will be still very painful to try to find their definition and copy one by one into you SQL Client.

Is there any plans to enhance this functionallity and replace constants with their values?

For example:

    final BigInteger ID = new BigInteger("12345");
    final String SQL = "select * from dual\n" +
            " where a = " + ID;

If I use the Intention functionality:

select * from dual
where a = ?

If I use the Java2SQL plugin:

select * from dual
where a = 1235 /*ID*/

Regards,
Andrey

0
Comment actions Permalink

One easy way I know is to use language injection and invoke injected fragment editor via "Edit <lang> fragment" intention.

0

Please sign in to leave a comment.