Skip to content

Commit 45affc9

Browse files
committed
Fix executing current SQL line not working always
If the last character was a semicolon and the cursor was placed after it, the Execute current line action didn't execute anything. It now execute the last SQL found
1 parent 8c510ff commit 45affc9

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/MainWindow.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -865,13 +865,24 @@ void MainWindow::executeQuery()
865865
int position = editor->positionFromLineIndex(cursor_line, cursor_index);
866866

867867
QString entireSQL = editor->text();
868-
QString firstPartEntireSQL = entireSQL.left(position);
869868
QString secondPartEntireSQL = entireSQL.right(entireSQL.length() - position);
870869

871-
QString firstPartSQL = firstPartEntireSQL.split(";").last();
872-
QString lastPartSQL = secondPartEntireSQL.split(";").first();
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);
873878

874-
query = firstPartSQL + lastPartSQL;
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+
}
875886
} else {
876887
// if a part of the query is selected, we will only execute this part
877888
query = sqlWidget->getSelectedSql();

0 commit comments

Comments
 (0)