SQL Editor

The SQL Editor is the place to create, test and examine your SQL statements. There are some additional features made for your easier life. Of course you can customize editor behavior in Preferences.

Important

Transactions in the SQL scripts (in this editor) are under user control. There is no autocommit and automatic transaction starting. You can use PRAGMAs on your own of course.

It's strongly recommended not to mix transactions started in the SQL Editor and in the Data Viewer. You can get some ugly collisions.


SQL editor


Several of the following actions act on the current SQL statement. If the cursor is at the start of the editing window, the current SQL statement is the first one in the window; otherwise if the character to the left of the cursor is whitespace outside of any SQL statement, the current SQL statement is the next one to the right of the cursor if there are any, or no statement at all if not; otherwise the current SQL statement is the one containing the character to the left of the cursor. Note that in the case of
statement1;statement2;
with the cursor, and no space, between the semicolon and statement2, statement1 is the current one. This may not be what you expected: this author did not write the parser and it is difficult to modify. If your scripts start each SQL statement on a new line, putting the cursor at the beginning of an SQL statement will make it the current one.
  Run Current Statement F9 Ctrl+Return

The current SQL statement is run.

  Explain Query Plan F6

The current SQL statement is run, preceded by EXPLAIN QUERY PLAN. This will show a table of the high level operations which would be run by sqlite to execute the statement.

  Explain F6

The current SQL statement is run, preceded by EXPLAIN. This will show a table of the low level operations which would be run by sqlite to execute the statement.

  Run Multiple Statements F6

Everything from the current SQL statement to the end of the whole script is run as a sequence of SQL statements.

This "Start from cursor" feature is useful when your script contains an error. You can continue after correction from the middle of the script.

  Create View

Create a view. The Create View Dialog will be shown with the Edit SQL tab chosen and the SQL panel filled with the selected text, or if there is no selected text the current SQL statement.

  New Document

Create a new empty document in the editor. If there are any unsaved changes you will be asked if you want to save them first.

  Open Document

Load an existing file into the editor. If there are any unsaved changes you will be asked if you want to save them first. Then the file selection dialog will be shown, and the selected file will be loaded into the SQL editor.

  Save Document

Save the current file. If the document was new and not loaded from a file, the Save As dialog is shown. If the document was loaded from a file, it is saved back into that file.

  Save Document As

The Save As dialog is shown to select the name of a file into which the document is then saved (unless you cancel the dialog).

  Search in the SQL file Ctrl + F

Open or close the Search panel in the bottom of the SQL Editor.

Show History

Open or close the History panel to the right of the SQL Editor. This shows a list of recently executed SQL statements. The intention is to allow selection of a statement to repeat, but this is not yet implemented.