Xh Lin
Xh Lin

Reputation: 776

ORMLite - How to return all rows where a column contains some String?

I have an android application that is currently using the ORMLite library. Currently, I have a database table let's say X, which contains a column for the Id and another column, say Column Y. Column Y is intended to store strings like "AppleBananaCinnamon" (imagine like a very long string of keywords). My goal is to retrieve all the ID's that contain a specific query which could be something like "bana" which would return all the rows where "bana" appears in Column Y. How could I do this?

Upvotes: 2

Views: 1306

Answers (1)

ADimaano
ADimaano

Reputation: 426

You can use ORMLite's Querybuilder and its where and like functionalities.

E.g.

PreparedQuery preparedQuery = databaseContext.<DAO Name>().queryBuilder()
                    .where().like(<column name>, "bana").prepare();

List<tableName> objName = databaseContext.<DAO Name>().query(preparedQuery);

Database context code snippet:

private Context _context; 
public DatabaseContext(Context context) 
{ 
    _context = context;
} 

public SQLiteDatabase open() throws SQLException 
{ 
    ...
}

and so on.

Upvotes: 2

Related Questions