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
This commit is contained in:
Iulian Onofrei
2016-09-30 20:39:01 +03:00
parent 8c510ff4e4
commit 45affc9bd5

View File

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