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

Paste SQL from Java (or other) code? #240

Closed
bjorntj opened this issue Feb 28, 2016 · 8 comments
Closed

Paste SQL from Java (or other) code? #240

bjorntj opened this issue Feb 28, 2016 · 8 comments
Assignees
Milestone

Comments

@bjorntj
Copy link

bjorntj commented Feb 28, 2016

When developing one often need to copy some sql statements from the code to run in the SQL editor. The problem is that these statements often includes characters like " and + that need to removed before one can run the statement.
Would be a nice feature..

@carlosspohr
Copy link

I believe the simplest way it will do the inverse of Eclispse's past literal:

screen169

So, when some sql command is pasted in editor, it can be normalized and applying a SQL Format on it (if necessary).

@codebling
Copy link
Contributor

Hm...Would be a great feature but this might be hard to implement. Any ideas on how?

@carlosjrcabello you're right, but it's harder going the reverse direction. Eclipse knows that you are in a string and doesn't care what's inside the data, simply splits it at 80 characters (or however many) and wraps it using Java's String concatenation operators. But going the other way is harder. Since DBeaver is also a standalone application, you could be pasting in SQL from another language, like PHP with its . concatenation operator.

Maybe we could have a "paste from special" operation with a different hotkey which would try a "best guess" for removing these with a regex. I wonder how effective a simple naive regex would be... something like /(["'])[ ]*[.+][ ]*\1//g and /^["']// and /["']$//

@carlosspohr
Copy link

@codebling, you're right.

I believe that using ER could be simpler than the instance that I was thought.

@serge-rider
Copy link
Member

I like this feature but yes, it is not so easy to do.
Potentially it could be done as as a Paste handler (automatically determine that string contains source code from some programming language). This is a preferred way. Or as a separate command (if auto will be too complicated).
Fortunately there are not too many different languages with different syntaxes (not counting exotic ones). So 2-3 different heuristics should work..

@stepjacky
Copy link

@serge-rider anything else, the code can be run as a syntax corrected java string

@serge-rider serge-rider added this to the 3.6.3 milestone Mar 20, 2016
serge-rider added a commit that referenced this issue Mar 20, 2016
@serge-rider
Copy link
Member

For now it'll work for Java, C, C++, C# and other languages with similar syntax.
sql-from-source-config

serge-rider added a commit that referenced this issue Mar 20, 2016
@serge-rider
Copy link
Member

For now algorithm is very simple. But works.
Further improvement should be tracked in different issues.

@gillesB
Copy link

gillesB commented Apr 19, 2023

Hint for people who come from search engines (like me) because the feature stopped working:

It seems that in the Update to 23.0.2 Extract SQL from source code moved to another preference page and must be activated again.

grafik

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

No branches or pull requests

6 participants