SQL Editor

The SQL Editor tab allows you to write and run SQL and PLSQL. The tab provides the ability to use one of more syntax highlighting editors with automatic case adjustment for keywords. Provided with each editor is a table for displaying SQL query results and a text output area to display output (such as Oracle DBMS_Output). Jobs can be run in the background allowing for the execution of multiple statements at any given time.

This section is broken down into four areas: Tool Bar, Editors, Query Result, Output.

Figure 1 - Databrid showing the SQL Editor tab.

Toolbar

The buttons in the tool bar from left to right are:

Figure 2 - SQL Editor Tool Bar
New EditorThis allows you to create new editor. Clicking the icon will set the new editors connection to be the same as the current editors connection. Clicking the down arrow beside the icon will allow you to select a connection to use.
Open EditorAllows you to open a file in a Procedure or Sql Editor.
Save EditorSave the current editor
Save All EditorsSave all of the editors
Copy TextCopy the selected text field text or table selection into the clipboard.
Cut TextCut the selected text field text into the clipboard.
Paste TextPaste the clipboard contents into the field.
Commit ChangesCommit all database changes.
Rollback ChangesRollback all database changes.
Execute StatementExecute the statement under the cursor.
Execute Editor as a StatementThis treats the entire contents of the editor as a statement and executes this statement.
Count RecordsCount the number of records returned by query.
DescribeShow information about the word containing the cursor in a schema browser view. For example if the cursor was in the word emp and emp is a table then information about the table emp would be displayed.
Sql HistoryShow a list of Sql statements that have previously been successfully run.
Cancel JobCancel the statement previously run in the background job from the Sql Editor.
ConnectionThis allows you to change the connection used when executing commands in the editor. Each editor has its own or shares a connection. Figure A shows a typical popup menu for an instance of Databrid that has connections for only one type of database. Figure B shows the popup menu if there are connections for both Oracle and MySql. Note that the current active connections are shown on this top level menu to make reuse easier. The Connection, Oracle, MySql sub-menus show a list of one or more connections not currently used (Figure C).
Figure AFigure BFigure C
The Offline connections in Figure A and B allow you to work without connecting to a database but still have the syntax highlighting for the appropriate database.
If you choose a connection from first menu (either Figure A or B) then you are sharing a connection. If you choose a connection from the sub menu (figure C) then a new connnection will be made to that database.
DatabaseAllows the user to select the database to be used for the connection (MySql only). This is the equivalent of using the USE command.
Close WindowCloses the Sql Editor that is currently showing.

Editors

Databrid supports multiple Sql editors which appear as a set of tabs, one for each editor (Figure 3).

Figure 3 - Editors shown as Tabs

Each editor has a connection associated with it. Connections can be just for the editor or shared. The current connection is shown in the toolbar (under the connection heading) and can be changed at any stage. Commands in the editor can executed as the statment under the cursor (separated from other connections by blank lines) or the entire editor.

Figure 4 Shows how three valid Sql statements. The statements are on lines 1-2, 4-8 and 10. Performing an execute on lines 1-3 will execute the first statement, lines 4-9 will execute the second statement and lines 10-11 will execute the third statement.

Figure 5 shows only three valid Sql statements. Databrid would treat this as four different statements (lines 1-2, 4-6, 8-9 and 11). Figure 6 shows how comments can be used to separate parts of a statement. The second statement in this figure is now on lines 4-9. Performing an execute on any lines from 4 to 10 will execute on this statement.

Figure 4 - Three Valid Sql Statements Figure 5 - Three Valid Sql Statements Figure 6 - Three Valid Sql Statements

The result of an execution of any Select statement is displayed in the Query Result tab (see the Query Result section below). If you execute any statement that does an Oracle DMBS_Output then the output of this is shown in the Output tab (see the Output section below).

Each SQL Editor has its own Query Result and Output areas.

Word Highlighting

If the cursor stops on a word for more than 1.5 seconds that word and all other instances of the word are highlighted. Highlight is just a visual tool to help you identify all instances of a particular word, it has no impact on execution of a statement. Figure 7 shows an example of word highlighting.

Figure 7 - Word Highlighting

Autocompletion

Autocompletion is a feature that helps you write sql statements. When you type a table or view name or an alias followed by a dot and pause for half a second a list of columns will appear (See figure 8). If you have not paused but still want autocompletion then the menu can be displayed by pressing ctrl-space.

Figure 8 - Autocompletion

In the autocompletion menu you can select a word by using the up and down arrow and/or the page up and page down button. Pressing enter will place the currently selected autocompletion word into the editor. Pressing space, escape or moving off of the word will cancel the autocompletion.

Another method of selecting an autocompletion word is to partially type the word. As you type the word in the autocomplete list closest to what you have typed will be selected. When you press enter the currently typed word will be replaced with the autocompletion word.

The information displayed in the autocompletion popup is cached within Databrid to speed up response times. Because of this it can get out of date with the database. To refresh the data displayed as part of autocompletion select the "Reload Cache" item in the Database menu.

Oracle also does autocompletion for package functions and procedures. Typing the packaging name and a dot will display a list of function and procedure names along with their parameter and/or return values.

Binding and Substitutions

It is possible to bind in values by specifying the bind as a : followed by a name, i.e. :name and :salary. When the statement is executed you will be prompted for values of the fields. If the same bind is used more than once in a Sql statement it will only be prompted for once but the prompted value will be used for each instance.

The example in figure 9 illustrates how to use bind variables.

Figure 9 - Variable Binding

When the example in is executed the dialog in Figure 10 is displayed (Note that salary appears twice in the Sql Statement but only once in the Bind Variable dialog). Each consecutive time the statement is executed the dialog will be displayed and any previous values entered will also appear. If you do not want to bind any values (Databrid has mistaken the: or & for a bind when it really isn't) then check the "Ignore Binds" checkbox. With this checked the binds will be ignored.

Figure 10 - Bind Variable Entry

An alternative to binding is substitution. Substitution is specified by using a & followed by a variable name, i.e. &name &salary. Figure 11 shows an example of variable substitution.

Figure 11 - Variable Substitution

When the Sql statement from Figure 11 is executed the same dialog will be displayed that was used for Bind Substitution (Figure 10). This is where the difference between binding and substitution can be best shown. When the statement is run the values from the Bind Dialog are used to replace the substitution variables.

So what would actually be run for the statement in Figure 11 is shown in Figure 12 (your statement is not updated, the changes are in the database only). As can be seen from the statement it won't actually work, line four would create an error since the string CLARK is not quoted. To get this statement to work you need to change the Bind Dialog variable name from CLARK to 'CLARK'.

Figure 12 - Statement after Substitution

If you want to provide values for assignment or conditions then bind variables are best suited. If you want to change the Sql statement itself then substitution is the best way. Figure 13 shows a statement where the "where" clauses condition is the substitution. If a > is entered in the Bind Dialog for the value of condition then it would be the equivalent of Figure 14 and a < would be the equivalent of Figure 15.

Figure 13 - Before Substitution Figure 14 - Using Substitution of a > Figure 15 - Using Substitution of a <

Editor Menu

Right clicking on the editor background will pop up the menu shown in figure 16 and the “Edit” sub menu shown in figure 17.

Figure 16 - Editor MenuFigure 17 - Editor Edit Sub Menu

The commands on the editor right click menu(Figure 16) are as follows:

Copy

Copy the selected text to the clipboard.

CutCut the selected text to the clipboard.
PastePaste the clipboard to the editor.
RedoRedo the changes undone using the undo command.
UndoUndoes the changes just made.
AutoCase Disable/EnableEnable or Disable the AutoCase functionality. AutoCase will automatically adjust the case of your statements depending on whether they are key words, functions or other text.
EditDisplays the sub menu of edit commands, see below.
Find TextOpens a find dialog to search for a given text string.
Find NextIf text is selected then this finds the next occurrence of the selected text otherwise it finds the next occurrence of the previously searched for text from either this command or the Find Text Command.
Find PreviousSame as the Find Next command but this searches in the opposite direction.
Replace TextOpens the replace text dialog where one string can be replaced with another.
Select AllSelects all of the text in the editor.
Commit ChangesCommit the changes made to the database.
DescribeShow information about the word containing the cursor in a schema browser view. For example if the cursor was in the word emp and emp is a table then information about the table emp would be displayed.
Execute Editor and SaveExecutes the entire contents of the editor and opens the save query result dialog.
Execute Editor as StatementExecutes the entire contents of the editor as a statement.
Execute Statement at CursorExecute the statement under the cursor as a statement. Statement can be separated by blank lines
Execute and Save StatementExecute the statement under the cursor and save the Query Result data.
Rollback ChangesRolls back changes made to the database.

The commands on the editor right click Edit sub menu (Figure 17) are as follows:

Lower Case Text

Changes the selected text to lower case.

Upper Case TextChanges the selected text to upper case.
Delete to End of Word BoundaryDeletes from the current cursor position to the end of the word that contains the cursor.
Delete to Start of Word BoundaryDeletes from the current cursor position to the start of the the word that contains the cursor.
Go to End of WordGoes to the end of the word that contains the cursor.
Go to Start of WordGoes to the start of the word that contains the cursor.
Select to End of WordSelects to the end of the word that contains the cursor.
Select to Start of WordSelects to the start of the word that contains the cursor.
Export TextExports the selected text to a file.
Import TextInserts text from a specified file into the editor.
Import Text to ClipboardInserts text from a specified file into the clipboard.
FormatFormats the Sql and/or PlSql. If text is selected then only the selected text will be formatted otherwise the entire contents of the editor will be formatted.

Query Result

The Query Result area contains a table for displaying the results of queries and explain plans. The table can easily be scrolled through to examine the data presented.

Right clicking on a table item presents the following menu.

Figure 18 - Right Click table Menu

The commands on the editor right click menu are as follows:

CopyCopy the selected text to the clipboard.
Copy Current Table CellCopies only the focus cell, not the entire row or selection.
CutCut the selected text to the clipboard. This is disabled for the table menu.
PastePaste the clipboard to the editor. This is disabled for the table menu.
Toggle Selection ModeToggles between row selection, multiple row selection and multcell selection modes.
Count RecordsCounts the number of records the queryreturned.
Save Statement ResultSave the result of the query as a CSV (comma delimited file) or insert statements to the clipboard or to a file.

Toolbar

The buttons in the tool bar from left to right are:

Figure 2 - SQL Editor Table Tool Bar
Change Selection ModeToggles between the select row, select multiple rows or select multiple cells mode.
Copy RowCopies the currently selected row into the clipboard.
Copy Current CellCopies the current cell.
Save Table ResultsSaves the results currently displayed in the Query Result.
Edit/View rowOpens the Edit/View row dialog.
Add New RowTakes you to the Edit row dialog to create a new row.
Delete Selected RowDelete the currently selected row.
Save Changes to DatabaseWrites the changes made to the database, a commit is not done.
Undo Unsaved ChangesUndo changes that have not been written to the database.

Output

The Output area captures output from the Oracle DBMS_Output command. Output is only captured if the "Enable DBMS_Output" check box is checked. This tab also has a clear button for clearing the contents of the Output. This area can also be used as a temporary storage area.