Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Ormlite, write case insensitive query

Tags:

ormlite

In Ormlite, is it possible to make case-insensitive query without writing the actual SQL?

For example, if I am looking for

column name - "AccountName" and query on the column, I would like to get results for all "Finance", "fInance", "FINANCE", etc. if I do search on "finance".

I was wondering if there's a functional support for this or if I need to write a SQL for it.

Thank you!

like image 205
the5threvolution Avatar asked May 10 '11 04:05

the5threvolution


2 Answers

I am answering my own question, but the following seems to work.

newDao.query(newDao.queryBuilder().where().like("nameColumn", "finance")
    .prepare())

Above seems to return all "finance", "Finance", "FINANCE" or any other variations of it.

like image 108
the5threvolution Avatar answered Jan 04 '23 00:01

the5threvolution


Right now (May 2011) there is no mechanism to do this with ORMLite except for writing the actual SQL and using the queryRaw() and other raw methods.

In many databases, MySQL for example, case insensitivity looks to be the default. But this is not the case with Postgresql nor Oracle.

A quick look around at the various database implementations shows that there is not a very easy and portable way to do this. Am I wrong?

like image 35
Gray Avatar answered Jan 03 '23 23:01

Gray