The SQL editor of DBNova is implemented based on Monaco editor and provides basic syntax highlighting and auto-completion features.
In addition, DBNova extends the editor with several custom functionalities.
Defining Parameters
Parameters can be defined in comments using the format:
@param name / type [/ key=val[; key=val ...] ]
In SQL statements, parameters are referenced using ${paramname}.
-- @param uid / uint / label=UserId; default=35; max=56
select * from `user` where id = ${uid};TIP
Auto-completion is triggered when typing @param in the editor, but not inside ordinary SQL comments.
For more parameter options, refer to Feats-Params.
Custom Column Rendering
Refer to Feats-ColRender.
Statement Splitting
DBNova implements a simple SQL statement splitting mechanism. It does not fully parse SQL grammar, but splits statements by ;, while accounting for parameters, comments, strings, and their escaping.
Parameters are referenced in the format
${paramname}.Single-line comments start with
--and end at the end of the line.Multi-line comments start with
/*and end with*/, and do not support nested comments.Strings can be enclosed in single quotes
'or double quotes", and escaping is supported. The implementation is designed to be flexible across different databases. however, actual databases handle strings inconsistently. Users need to use the correct quotes and escape characters according to the specific database (or avoid using complex string literals when possible).
WARNING
'hello world'、"hello world"、'hello\nworld'、"hello "" world", 'hello '' world' are all considered valid string literals by DBNova, although this may not be valid in every database.
See the test case below:
-- comment 1
SELECT '${mock_param}' AS "quoted;semicolon", -- comment 2
t.name
FROM users t
WHERE t.id = ${user_id} /* This is a multi-line comment
The order of param comment directives does not matter.
@param user_id / int / default=12
Semicolons ; included should not break the statement */
AND t.bio = 'I''m a 0.0\n-- "_" =_=!;';
-- Next statement
UPDATE settings SET val = 1;