Skip to content

Commit 531eddb

Browse files
committed
Fix executing current SQL running incorrect line
Previously, it was running the query at the current cursor position, but that proved to be confusing. Now, it runs the SQL that contains the start of the current line. So having: SELECT * FROM table1; SELECT * FROM table2; and the cursor either before the first semicolon, either after it, the first SQL will be run, and not the second one as before.
1 parent f295616 commit 531eddb

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

src/MainWindow.cpp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -862,27 +862,16 @@ void MainWindow::executeQuery()
862862

863863
execution_start_line = cursor_line;
864864

865-
int position = editor->positionFromLineIndex(cursor_line, cursor_index);
865+
int lineStartCursorPosition = editor->positionFromLineIndex(cursor_line, 0);
866866

867867
QString entireSQL = editor->text();
868-
QString secondPartEntireSQL = entireSQL.right(entireSQL.length() - position);
868+
QString firstPartEntireSQL = entireSQL.left(lineStartCursorPosition);
869+
QString secondPartEntireSQL = entireSQL.right(entireSQL.length() - lineStartCursorPosition);
869870

870-
if (secondPartEntireSQL.trimmed().length() == 0) {
871-
position = entireSQL.lastIndexOf(";") - 1;
872-
}
873-
874-
if (position == -1) {
875-
query = entireSQL;
876-
} else {
877-
secondPartEntireSQL = entireSQL.right(entireSQL.length() - position);
871+
QString firstPartSQL = firstPartEntireSQL.split(";").last();
872+
QString lastPartSQL = secondPartEntireSQL.split(";").first();
878873

879-
QString firstPartEntireSQL = entireSQL.left(position);
880-
881-
QString firstPartSQL = firstPartEntireSQL.split(";").last();
882-
QString lastPartSQL = secondPartEntireSQL.split(";").first();
883-
884-
query = firstPartSQL + lastPartSQL;
885-
}
874+
query = firstPartSQL + lastPartSQL;
886875
} else {
887876
// if a part of the query is selected, we will only execute this part
888877
query = sqlWidget->getSelectedSql();

0 commit comments

Comments
 (0)