Skip to content

bpo-38185: Fixed case-insensitive string comparison in sqlite3.Row indexing.#16190

Merged
serhiy-storchaka merged 1 commit into
python:masterfrom
serhiy-storchaka:sqlite-row-index-case-insensitive
Sep 17, 2019
Merged

bpo-38185: Fixed case-insensitive string comparison in sqlite3.Row indexing.#16190
serhiy-storchaka merged 1 commit into
python:masterfrom
serhiy-storchaka:sqlite-row-index-case-insensitive

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Sep 16, 2019

Copy link
Copy Markdown
Member

@berkerpeksag berkerpeksag left a comment

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.

Nice find! The PR looks good to me. I probably wouldn't bother fixing it in 3.7, but it's ultimately up to you :)

Comment thread Modules/_sqlite/row.c
if (!PyUnicode_Check(left) || !PyUnicode_Check(right)) {
return 0;
}
if (!PyUnicode_IS_ASCII(left) || !PyUnicode_IS_ASCII(right)) {

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.

Hmm, looks like sqlite supports non-ascii characters as identifiers: https://github.com/mackyle/sqlite/blob/a419afd73a544e30df878db55f7faa17790c01bd/ext/misc/normalize.c#L174-L177

And as shown in your example on bpo, should we maybe just simplify this code and do a casefold comparison?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

My initial version used casefold. But then I made some experiments and found that Sqlite itself ignores case only for ASCII letters. It was just my guess, and thank you for confirming it with the reference to sources.

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.

Aah okay, I thought the case-insensitivity for the Row object was for the convenience of the Python API, not trying to mirror any particular part of sqlite itself. Which part of sqlite ignores case?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Which part of sqlite ignores case?

I guess any part which compare identifiers. For example, the following code passes:

create table test(a text)
select A from test

and the following fails:

create table test(a text, A text)

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.

Aah gotcha, thanks for taking the time to explain Serhiy.

@serhiy-storchaka serhiy-storchaka merged commit f669581 into python:master Sep 17, 2019
@serhiy-storchaka serhiy-storchaka deleted the sqlite-row-index-case-insensitive branch September 17, 2019 06:20
@miss-islington

Copy link
Copy Markdown
Contributor

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7, 3.8.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 17, 2019
…dexing. (pythonGH-16190)

(cherry picked from commit f669581)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@bedevere-bot

Copy link
Copy Markdown

GH-16216 is a backport of this pull request to the 3.8 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 17, 2019
…dexing. (pythonGH-16190)

(cherry picked from commit f669581)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@bedevere-bot

Copy link
Copy Markdown

GH-16217 is a backport of this pull request to the 3.7 branch.

@serhiy-storchaka

Copy link
Copy Markdown
Member Author

It could be fixed even in 2.7, but I don't bother. The bug is too tiny.

miss-islington added a commit that referenced this pull request Sep 17, 2019
…dexing. (GH-16190)

(cherry picked from commit f669581)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
miss-islington added a commit that referenced this pull request Sep 17, 2019
…dexing. (GH-16190)

(cherry picked from commit f669581)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-bug An unexpected behavior, bug, or error

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants