5

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!

2 Answers2

18

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.

Gray
  • 115,027
  • 24
  • 293
  • 354
  • Of course, using Like instead of equal *may* prevent the indexes to be used. If performance issues arise, check your query plan. – Name is carl Jul 12 '13 at 17:11
1

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?

Community
  • 1
  • 1
Gray
  • 115,027
  • 24
  • 293
  • 354