Search code examples
sqlmysqlcase-sensitivecase-insensitiveopenbase

Openbase SQL case-sensitivity oddities ('=' vs. LIKE) - porting to MySQL


We are porting an app which formerly used Openbase 7 to now use MySQL 5.0.

OB 7 did have quite badly defined (i.e. undocumented) behavior regarding case-sensitivity. We only found this out now when trying the same queries with MySQL.

It appears that OB 7 treats lookups using "=" differently from those using "LIKE": If you have two values "a" and "A", and make a query with WHERE f="a", then it finds only the "a" field, not the "A" field. However, if you use LIKE instead of "=", then it finds both.

Our tests with MySQL showed that if we're using a non-binary collation (e.g. latin1), then both "=" and "LIKE" compare case-insensitively. However, to simulate OB's behavior, we need to get only "=" to be case-sensitive.

We're now trying to figure out how to deal with this in MySQL without having to add a lot of LOWER() function calls to all our queries (there are a lot!).

We have full control over the MySQL DB, meaning we can choose its collation mode as we like (our table names and unique indexes are not affected by the case sensitivity issues, fortunately).

Any suggestions how to simulate the OpenBase behaviour on MySQL with the least amount of code changes?

(I realize that a few smart regex replacements in our source code to add the LOWER calls might do the trick, but we'd rather find a different way)


Solution

  • Another idea .. does MySQL offer something like User Defined Functions? You could then write a UDF-version of like that is case insesitive (ci_like or so) and change all like's to ci_like. Probably easier to do than regexing a call to lower in ..