Take into account Windows line separator in Execute SQL

QScintilla text(line) returns the string of the passed line including the
line terminator. Given the differences in platforms in that regard, we
only supported the case for a single character separator.

This should solve issue #2073 for Windows.

It also should solve #1768 and #1632, which were only reproduced in Windows
or editing files with lines ending in "\r\n" in general.
This commit is contained in:
mgrojo
2020-01-04 19:36:41 +01:00
parent ff86e525b3
commit d0e0ee3f64

View File

@@ -1058,7 +1058,7 @@ void MainWindow::executeQuery()
// Need to set the end position here before adjusting the start line
int execute_to_line = execute_from_line;
int execute_to_index = editor->text(execute_to_line).length() - 1; // The -1 compensates for the line break at the end of the line
int execute_to_index = editor->text(execute_to_line).remove('\n').remove('\r').length(); // This chops the line break at the end of the line
execute_to_position = editor->positionFromLineIndex(execute_to_line, execute_to_index);
QByteArray firstPartEntireSQL = sqlWidget->getSql().toUtf8().left(execute_from_position);
@@ -1084,8 +1084,9 @@ void MainWindow::executeQuery()
// Special case: if the start position is at the end of a line, then move to the beggining of next line.
// Otherwise for the typical case, the line reference is one less than expected.
// Note that execute_from_index uses character positions and not byte positions, so text().length() must be used.
if (editor->text(execute_from_line).length() == execute_from_index+1) {
// Note that execute_from_index uses character positions and not byte positions, so at() can be used.
QChar char_at_index = editor->text(execute_from_line).at(execute_from_index);
if (char_at_index == '\r' || char_at_index == '\n') {
execute_from_line++;
// The next lines could be empty, so skip all of them too.
while(editor->text(execute_from_line).trimmed().isEmpty())