Skip to content

Commit f89097c

Browse files
mgrojolucydodo
authored andcommitted
Execute SQL: avoid problems with selection when there are multibyte chars
QScintilla returns selection in bytes, so we have to take into account cases where the multibyte characters are inside the query, and also when they are before the query. We do that by trimming after the end byte position of the selection and replacing all the bytes previous to the selection with a space (single-byte character) See issue #3731.
1 parent 03bbbc6 commit f89097c

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

‎src/MainWindow.cpp‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,9 +1240,11 @@ void MainWindow::executeQuery()
12401240
// Get the statement(s) to execute. When in selection mode crop the query string at exactly the end of the selection to make sure SQLite has
12411241
// no chance to execute any further.
12421242
QString sql = sqlWidget->getSql();
1243-
if(mode == Selection)
1244-
sql = sql.toUtf8().left(execute_to_position); // We have to convert to a QByteArray here because QScintilla gives us the position in bytes, not in characters.
1245-
1243+
if(mode == Selection) {
1244+
// We have to convert to a QByteArray here because QScintilla gives us the position in bytes, not in characters.
1245+
// We also have to replace the characters before execute_from_position by spaces, so that they count as bytes and not multibyte characters.
1246+
sql = sql.toUtf8().replace(0, execute_from_position, QString(" ").repeated(execute_from_position).toUtf8()).left(execute_to_position);
1247+
}
12461248
// Prepare the SQL worker to run the query. We set the context of each signal-slot connection to the current SQL execution area.
12471249
// This means that if the tab is closed all these signals are automatically disconnected so the lambdas won't be called for a not
12481250
// existing execution area.

0 commit comments

Comments
 (0)