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.
This commit is contained in:
Iulian Onofrei
2016-10-01 21:43:22 +03:00
parent f2956164c3
commit 531eddbd6c

View File

@@ -862,27 +862,16 @@ void MainWindow::executeQuery()
execution_start_line = cursor_line;
int position = editor->positionFromLineIndex(cursor_line, cursor_index);
int lineStartCursorPosition = editor->positionFromLineIndex(cursor_line, 0);
QString entireSQL = editor->text();
QString secondPartEntireSQL = entireSQL.right(entireSQL.length() - position);
QString firstPartEntireSQL = entireSQL.left(lineStartCursorPosition);
QString secondPartEntireSQL = entireSQL.right(entireSQL.length() - lineStartCursorPosition);
if (secondPartEntireSQL.trimmed().length() == 0) {
position = entireSQL.lastIndexOf(";") - 1;
}
QString firstPartSQL = firstPartEntireSQL.split(";").last();
QString lastPartSQL = secondPartEntireSQL.split(";").first();
if (position == -1) {
query = entireSQL;
} else {
secondPartEntireSQL = entireSQL.right(entireSQL.length() - position);
QString firstPartEntireSQL = entireSQL.left(position);
QString firstPartSQL = firstPartEntireSQL.split(";").last();
QString lastPartSQL = secondPartEntireSQL.split(";").first();
query = firstPartSQL + lastPartSQL;
}
query = firstPartSQL + lastPartSQL;
} else {
// if a part of the query is selected, we will only execute this part
query = sqlWidget->getSelectedSql();