Describe the bug
When a user manually runs a SQL query via the SQL Editor (pressing F5 or "Execute"), the application executes the entire contents of the editor (_sqlController.text), completely ignoring any active text selection.
This leads to critical failures because the underlying database drivers (PostgreSQL via Extended Query Protocol, SQLite via sqflite, and MySQL) do not support passing multiple statements separated by semicolons in a single execute call. If a user has SELECT 1; SELECT 2; in their editor, the drivers will throw a syntax error or a "cannot insert multiple commands" error.
Additionally, in sqlite_connection.dart, there is a bug where the code checks if a statement returns data by doing sql.trim().toLowerCase().startsWith('select'). If the user writes a comment before the query (e.g., -- my query \n SELECT *), the check fails and the app returns 0 rows.
To Reproduce
- Open the SQL editor for PostgreSQL, MySQL, or SQLite.
- Write multiple queries:
SELECT * FROM table1;
SELECT * FROM table2;
- Highlight only the first query and press Execute.
- See error (e.g.
cannot insert multiple commands into a prepared statement in PostgreSQL).
Expected behavior
If there is an active text selection, the editor should only execute the highlighted text.
Proposed Fix
- In
postgres_sql_workspace.dart, mysql_sql_workspace.dart, and sqlite_sql_workspace.dart, change the extraction logic in _execute():
final selection = _sqlController.selection;
String userSql;
if (selection.isValid && !selection.isCollapsed) {
userSql = selection.textInside(_sqlController.text).trim();
} else {
// optionally, add logic to extract statement under cursor
userSql = _sqlController.text.trim();
}
- In
sqlite_connection.dart, fix the isQuery validation. Strip out leading SQL comments (e.g. -- ... or /* ... */) before checking .startsWith('select'), or use a Regex.
Describe the bug
When a user manually runs a SQL query via the SQL Editor (pressing F5 or "Execute"), the application executes the entire contents of the editor (
_sqlController.text), completely ignoring any active text selection.This leads to critical failures because the underlying database drivers (PostgreSQL via Extended Query Protocol, SQLite via sqflite, and MySQL) do not support passing multiple statements separated by semicolons in a single
executecall. If a user hasSELECT 1; SELECT 2;in their editor, the drivers will throw a syntax error or a "cannot insert multiple commands" error.Additionally, in
sqlite_connection.dart, there is a bug where the code checks if a statement returns data by doingsql.trim().toLowerCase().startsWith('select'). If the user writes a comment before the query (e.g.,-- my query \n SELECT *), the check fails and the app returns 0 rows.To Reproduce
cannot insert multiple commands into a prepared statementin PostgreSQL).Expected behavior
If there is an active text selection, the editor should only execute the highlighted text.
Proposed Fix
postgres_sql_workspace.dart,mysql_sql_workspace.dart, andsqlite_sql_workspace.dart, change the extraction logic in_execute():sqlite_connection.dart, fix theisQueryvalidation. Strip out leading SQL comments (e.g.-- ...or/* ... */) before checking.startsWith('select'), or use a Regex.