Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support case sensitive/case insensitive comparisons #5

Open
jewenx opened this issue Dec 16, 2014 · 3 comments
Open

Support case sensitive/case insensitive comparisons #5

jewenx opened this issue Dec 16, 2014 · 3 comments

Comments

@jewenx
Copy link

jewenx commented Dec 16, 2014

There is a similar ticket for django-mssql:
https://bitbucket.org/Manfre/django-mssql/issue/36/support-case-sensitive-comparisons

We get database collation by checking:
SELECT DATABASEPROPERTYEX('', 'Collation')

If the database collation is case sensitive (Latin1_General_BIN) and django tries to do case insensitive filtration such as icontains can we append the corresponding case insensitive collation (Latin1_General_CI_AS) just behind column name ?
The sql query will look like:
select * from where COLLATE Latin1_General_CI_AS like 'test%'
instead of
select * from where like 'test%'

@denisenkom
Copy link
Owner

That is not reliable, it is possible for a table or even a column to have a collation different from the database collation.

@jewenx
Copy link
Author

jewenx commented Feb 26, 2015

Can we check column collation ?

@denisenkom
Copy link
Owner

You can, but I think this would be a performance hit if you do it on every request.
One way you can do it is by adding an extension function here https://bitbucket.org/Manfre/django-mssql/src/1d8da0ee6dd4c1f1e32d29bf405dd8c7e682fba8/extras/sqlserver/regex_clr/REGEXP_LIKE.cs?at=master

You can call functions CS_LIKE and CI_LIKE for case sensitive and case insensitive kinds.

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

No branches or pull requests

2 participants