This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 134113

Summary: Code snippets for SQL
Product: db Reporter: John Baker <jbaker>
Component: CodeAssignee: Jiri Rechtacek <jrechtacek>
Status: RESOLVED FIXED    
Severity: blocker CC: hmichel, mschovanek, romanmostyka
Priority: P2 Keywords: PLAN
Version: 6.x   
Hardware: All   
OS: All   
URL: http://wiki.netbeans.org/DatabaseSQLSnippets
Issue Type: ENHANCEMENT Exception Reporter:

Description John Baker 2008-04-29 00:27:33 UTC
For 6.5 we want to make it easy to generate SQL statements using shortcuts within the SQL editor.
Once the SQL is generated, the SQL source can be saved in an SQL file, for later reuse (by reopening the file).

In 6.x, the SQL editor can save and open SQL files.

In 6.5, supporting SQL generation using shortcut keys, e.g. Ctrl-Alt-I, to generate an insert statement
Comment 1 David Vancouvering 2008-04-29 00:43:33 UTC
Another aspect of this feature is to make it easy to store and load snippets from within the SQL editor, e.g. a keyboard
shortcut brings up a drop-down list and you can type to filter out possible names and see the first <n> lines of the
snippet, then pick it and it pastes into your editor.

Better than having to go to the File menu, browse for the SQL file, poking around your directory tree trying to find it.

I'm thinking the code snippets are saved in your userdir, but the user can specify a different location if they want.
Comment 2 David Vancouvering 2008-04-29 00:45:37 UTC
Also, SQLYog and AquaStudio both have this feature that if you select a database object like a connection or table, if
you right click you have a sub-menu that lets you generate SELECT (basically View Data), INSERT, or UPDATE statements
against the current object.
Comment 3 John Baker 2008-06-15 12:06:38 UTC
I'll be on leave of absence during the M2 timeframe.Not staffed.  
Comment 4 Jiri Rechtacek 2009-10-16 14:05:24 UTC
Reassigned to new owner.
Comment 5 Jiri Rechtacek 2009-10-23 09:29:52 UTC
Like issue 152411 - Provide pre-defined SQL code templates in SQL editor
Comment 6 Jiri Rechtacek 2009-10-23 09:30:07 UTC
*** Issue 152411 has been marked as a duplicate of this issue. ***
Comment 7 matthias42 2012-04-17 18:40:44 UTC
*** Bug 65165 has been marked as a duplicate of this bug. ***
Comment 8 matthias42 2013-05-16 17:59:20 UTC
There is a working way in netbeans:

Go to: Tools -> Options -> Editor -> Code Templates

for example: 

1. Enter "Abbreviation": "s"
2. Set "Expanded Text": "SELECT ${columns} FROM ${from}"
3. Change "Expand Template on" to "Tab"

Acknowledge the dialog.

Now enter an SQL Editor, enter "s" and press "Tab"-Key. now the first part is directly selected and you can enter the columns you want to select, with TAB you can jump to the next variable and with Shift-Tab you can jump back.

I had to look for this, but the proposed solution in the wiki would just conflict with existing shortcuts.

I'll close this as FIXED.

What could be done is define a better editor for code templates, but for that bugs already exist.
Comment 9 davelhs03 2014-12-12 22:32:22 UTC
Geertjan Wielenga (Twitter: @GeertjanW) created this awesome plugin for Code Templates and includes some of the SQL code templates I provided him.  You can download the plugin here:
http://plugins.netbeans.org/plugin/49660/?show=true

List of SQL code templates I suggested he use:
https://gist.github.com/phpdave/4fff31d51dd34f6e8201

Vid tutorial on using his plugin:
https://www.youtube.com/watch?v=1SUHFMvM39Y