Skip to content

Query editor

Query is a view of every table tab; New query in a database’s context menu opens a tab with only this view. The query tabs (Query 1, Query 2, …, + for a new one) and the history belong to the connection, so every table tab of that connection shows the same ones. They live only in the window’s memory (they may contain data) and are gone when the window reloads.

Query view with a result and the history of the connection

Control What it does
Run / Run selection (⌘↩) Sends the selected text, or the whole editor without a selection. Trailing ; and blanks are removed. At most 1 MiB of SQL.
Database Default database for the statement: (none) or one from the server’s list. KryoDesk checks the name in information_schema.SCHEMATA and sends USE `name` before the statement when it differs from the current one.
Run as change… Only in write mode: Edit data.
History (clock icon) The last 200 statements of the connection with time, rows, duration, database and error; a click puts the statement back into the editor.

The statement goes over the prepared statement protocol, so the server accepts exactly one statement: SELECT 1; SELECT 2 fails with a syntax error. A statement the server does not support in that protocol fails with error 1295, and KryoDesk adds: the query editor sends each statement over the prepared statement protocol, so that one run is exactly one statement. The statement is not cached on the server after it ran.

The result line shows the statement as sent, then:

  • n rows (with (first 5000 shown) when there are more) or OK, n affected;
  • the time, the current database (in shop), the number of warnings, n result sets (first shown) for procedures that return several, and the server’s info text;
  • for warnings, SHOW WARNINGS LIMIT 100 runs right after the statement and lists level, code and message;
  • a server error as server error <code> (SQLSTATE <state>): <message>.

Results are limited to 5000 rows and 32 MiB of text in the window; the rest is counted, not transferred to the UI. Cells are cut like in the Data view.

After each statement KryoDesk sends, in this order: ROLLBACK, UNLOCK TABLES, DO RELEASE_ALL_LOCKS(), then reads

SELECT @@session.transaction_read_only, @@session.character_set_client, @@session.character_set_connection, @@session.character_set_results, @@session.autocommit, DATABASE(), @@session.max_execution_time

(tx_read_only on servers without transaction_read_only, max_statement_time on MariaDB). Whatever the statement changed is set back (SET NAMES utf8mb4, SET autocommit = 1, SET SESSION TRANSACTION READ ONLY, the 60 s limit) and the result shows Session set back after the statement: …. So SET SESSION TRANSACTION READ WRITE or START TRANSACTION READ WRITE does not open writes for the next statement. If the session cannot be checked, the connection is closed (the session could not be checked after the statement, so the connection is closed (nothing may run outside READ ONLY); reconnect in its tab).

Behind ProxySQL the editor works only when ProxySQL kept the read-only flag at login, and after every statement the session is reset (COM_RESET_CONNECTION) and set up again with the SETs accepted at login.

One statement can open its own read-write transaction, which the check afterwards cannot undo. In read-only mode the editor therefore refuses a statement whose first keyword is:

  • CALL, BEGIN (also BEGIN NOT ATOMIC), XA, START TRANSACTION, SET STATEMENT;
  • a MariaDB compound statement outside a stored program: IF, CASE, LOOP, REPEAT, WHILE, FOR, DECLARE, a label (label:) or <<label>>.

Blanks (also VT and FF), comments (-- , #, /* */) and opening parentheses before the keyword are skipped. An executable comment (/*! … */, /*!50100 … */, /*M! … */) before the first keyword, or between START/SET and the next word, is refused as well: the server runs or skips it depending on its version, so the keyword cannot be known. The message:

CALL is refused in read-only mode before sending: such a statement can open its own read-write transaction (plan 088/001); run it in write mode

The refusal is also printed in the console as refused: <statement> (…). Everything else goes to the server, and writes end with error 1792.

Copy (result) and Copy (Data view page) offer CSV, TSV, Markdown and SQL INSERT. KryoDesk formats the cells the window holds:

Format Details
CSV Header row, , separator, CRLF line ends; fields with ,, ", line breaks or edge spaces quoted; NULL = empty field, empty string = ""
TSV MySQL LOAD DATA text: tab, newline, CR and backslash escaped, NULL = \N
Markdown Table with `
SQL INSERT INSERT INTO `table` (…) VALUES … in groups of 100 rows; the table of the Data view, or query_result for a query result; text as literals (hex when needed), binary as 0x…

A cut cell (long text or long binary value) stops the copy with an error naming the row and column (only the first characters of n are loaded; select a shorter expression (e.g. LEFT(col, 4096)) to copy it): the copy would not be the data. CSV opened in a spreadsheet may evaluate cells that start with =, +, - or @.

Scroll or pinch to zoom · drag to move · double-click to zoom · Esc or click outside to close