Converted to the top one is best since it covers compatible syntax for the 3 most used Rails database backends. PostgreSQL, MySQL, and SQLite support this syntax. This has a (minor) flaw that you have to make your search bar in your application or in the conditions bar to make it a little ugly, but I think the compatibility you are typing makes it worthy.
Both MySQL and SQLite3 have a case-insensitive LIKE statement. Only PostgreSQL has a case-sensitive LIKE operator and PostgreSQL-specific (for guidance) ILIKE case-insensitive search. You can specify ILIKE insead LIKE in your conditions in the Rails application, but keep in mind that the application will stop working under MySQL or SQLite.
A third option might be to check which database engine you are using and modify the search bar accordingly. This can be better done by breaking into / monkeypatching the ActiveRecord connection adapters and the PostgreSQL adapter to change the query string to replace โLIKEโ with โILIKEโ before executing the query. However, this solution is the most confusing, and in the light of simpler ways, such as the upper part of both terms, I think it does not bother the effort (although you would get a lot of brown dots to do it this way).
Roadmaster Mar 05 '09 at 18:19 2009-03-05 18:19
source share