Skip to content

Replace non-alphanumeric with underscore - #4166

Merged
mgrojo merged 3 commits into
sqlitebrowser:masterfrom
kor44:master
Jul 31, 2026
Merged

Replace non-alphanumeric with underscore#4166
mgrojo merged 3 commits into
sqlitebrowser:masterfrom
kor44:master

Conversation

@kor44

@kor44 kor44 commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Added option to replace non-alphanumeric characters in column name with underscore. SQL editor does not complete correctly column names containing space, column and etc. This is example CSV

Option location
570958797-e709b36c-1a21-40ff-8575-dbcf01d3f3c1

Michail Koreshkov and others added 2 commits March 29, 2026 12:00
Added option to replace non-alphanumeric characters in column name with
underscore. SQL editor does not complete correctly column names
containing space, column and etc.
Comment thread src/ImportCsvDialog.cpp Outdated
// Take field name from CSV
fieldname = std::string(rowData.fields[i].data, rowData.fields[i].data_length);

// Replace any non-nlphanumeric characters with an underscore

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Replace any non-nlphanumeric characters with an underscore
// Replace any non-alphanumeric character with an underscore

Comment thread src/ImportCsvDialog.cpp Outdated
// Replace any non-nlphanumeric characters with an underscore
if(ui->checkReplaceNonAlnum->isChecked())
{
std::regex pattern("[^a-zA-Z0-9_]");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will treat international letters as non-valid. Is that what we want?

This alternative will support Unicode letters:

for (QChar &c : fieldname)
    if (!c.isLetterOrNumber() && c != '_')
        c = '_';

What I saw is that the special characters don't trigger the completion list (if present in the first characters), but can be completed if the first 3 characters are ASCII. Not sure what we should do; maybe your simple approach is the best option.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will treat international letters as non-valid. Is that what we want?

This alternative will support Unicode letters:

for (QChar &c : fieldname)
    if (!c.isLetterOrNumber() && c != '_')
        c = '_';

What I saw is that the special characters don't trigger the completion list (if present in the first characters), but can be completed if the first 3 characters are ASCII. Not sure what we should do; maybe your simple approach is the best option.

As fieldname is std::string I used conversion to/from QString.

What I saw is that the special characters don't trigger the completion list (if present in the first characters), but can be completed if the first 3 characters are ASCII. Not sure what we should do; maybe your simple approach is the best option.

The problem with QScintilla which inserts text up to first space. I have tried to change behavior, but it was complex and came to this idea (replace non_alnum by _)

@mgrojo
mgrojo merged commit d38a6c7 into sqlitebrowser:master Jul 31, 2026
21 of 23 checks passed
@mgrojo

mgrojo commented Jul 31, 2026

Copy link
Copy Markdown
Member

Perfect, @kor44, thanks for the contribution.

@lucydodo

Copy link
Copy Markdown
Member

@mgrojo There is currently an issue with the CI workflow, and I will fix it by this morning. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants