Executing Statements
A query tab can hold one statement or a whole script. Two actions run them:
- "Execute" runs one statement: the selection when there is one, and otherwise the statement the cursor is in.
- "Execute All" runs every statement in the tab, one after another, in the order they appear.
A selection is run exactly as selected, also when it holds several statements. "Select Current Statement" in the "Selection" menu shows which statement "Execute" would take.
On Microsoft Windows and Linux the key F9 runs "Execute" and F5 runs "Execute All", next to Ctrl+Enter. On MacOS the operating system takes the function keys, so the shortcuts of the menu are the only ones.
Licence
Running every statement in a tab is licensed apart from running one statement. From release 27.0 onwards "Execute All" needs a licence which covers the function itgen_querytool_execute_script. "Execute" needs no function of its own.
Without the function the button stays in the ribbon. The run is then refused before the first statement starts. The message names the function to acquire and appears in the messages pane as well.
On a connection to an Invantive repository the function must be granted to the user too, as every function of such a repository is. On a connection without such a repository the licence is the only gate. See License Registration.
A licence which covers the function covers it in Invantive Query Tool for Microsoft Windows as well, where "Execute All" needs the same function from release 27.0 onwards.
Where a Statement Ends
Statements are separated by a line which holds nothing, or which holds only go, or which holds only /. A semicolon does not separate statements; a semicolon at the end of the last line of a statement is removed before the statement is sent, unless that line ends in end;, which belongs to Procedural SQL.
A line may hold go or / in any case, with white space around it. A line which only starts with go, such as gone, belongs to the statement.
So the following text holds two statements:
select code
, description
from ItemsIncremental
select count(*)
from ItemsIncremental
whereas the same text without the empty line in the middle is one statement and will not run.
Bind Variables
A statement can hold bind variables: names behind the parameter prefix of the connection, which is usually a colon, such as :name. Before such a statement runs, a window "Variables" asks for each of them. A variable is selected in the list at the left. "Data Type" offers varchar2, number, int64, boolean, date, datetime and guid, and "Value" takes the text which is converted to that type; an empty value is null. The statement is shown below for reference. "OK" runs the statement with the values and "Cancel" does not run it. A value which does not fit the type, such as a word for an int64, is refused with the message of the conversion and the statement does not run.
A name which occurs more than once is asked for once, in any case. What only looks like a variable is none: a name between single or double quotes, a time such as 12:30 in a literal, and a name directly behind a letter, a digit or an underscore. A name in a comment is asked for as well. Any value lets the statement run.
What was typed for a name is offered again at the next execution for as long as the product is open. "Execute All" asks before each statement which holds a variable.
The statement
select '12:30' as moment
, :top_n as top_n
from dual
asks for one variable, top_n, and with the type int64 and the value 7 returns one row holding 12:30 and 7. The time in the literal is not a variable.
Results of a Statement
The rows of a select statement appear in the grid of the "Results" pane; see Results. The grid shows the first rows of a statement which is run with "Execute" as soon as they are read, and reads the next rows while the reader scrolls. It holds at most 1,000,000 rows, and says so when it cuts the result off. The statements of a script which is run with "Execute All" are not cut off. See Large Results.
Sorting, filtering and grouping in the grid do not run the statement again. When the grid has not read all rows yet, it reads the remaining rows first; see Large Results. The formats of the export which write the complete result do run it again, which is why they are unavailable after "Execute All"; see Exporting Results.
Client-side Statements
Statements of Invantive Script which run on the device itself, such as local export results, are recognised as such and handled by the product instead of being sent to the platform. They are reported in the messages as a local statement with the time they took. local exit closes the window.
While a Statement Runs
The bar above the editor reports what the engine is doing and how long the statement has been running, refreshed twice a second. The row count and the duration are reported on the status bar and in the messages as soon as the statement is finished. "Execute All" reports every statement separately, with the line it starts on, and the total afterwards, and stops at the first statement that fails. The cursor is then placed at the start of that statement and the editor scrolls to it.
The button "Cancel" in that bar stops the statement. The cancellation is handed to the engine, which ends the statement at the next point where it looks for one, and the bar reads "Cancelling..." until it has. The messages then report "Cancelled after" and the time in milliseconds. A statement which does not react to "Cancel" within ten seconds is let go of: the tab becomes available again, the messages say so, and whatever the statement still returns is discarded. The platform may go on with such a statement. With "Execute All" the statements that have not started yet are dropped.
Cancelling a statement in one query tab leaves the statements in the other query tabs running.
A statement that fails writes the full error in the messages and opens a window with the message, the message code and the topics about that code on the product forums.