django-sqlserver icon indicating copy to clipboard operation
django-sqlserver copied to clipboard

Support case sensitive/case insensitive comparisons

Open jewenx opened this issue 9 years ago • 3 comments

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%'

jewenx avatar Dec 16 '14 21:12 jewenx

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

denisenkom avatar Feb 24 '15 01:02 denisenkom

Can we check column collation ?

jewenx avatar Feb 26 '15 15:02 jewenx

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.

denisenkom avatar Mar 07 '15 15:03 denisenkom