Android ORMlite SelectArg
I have read a few things about how to use SelectArg in stackoverflow and ORMLite documentation and I cannot see what I am doing wrong.
I am looking for an occupation table where the assignment field = "Athletes Business Manager". As you can see, it contains one quote that I am trying to escape with SelectArg.
SelectArg occupationArg = new SelectArg(txtOccupation.getText().toString().trim());
Occupations occupation = CommonUtilities.getHelper(getApplicationContext()).getOccupationsDao().queryBuilder().where().eq(
Occupations.JOB_FIELD, occupationArg).queryForFirst();
The above code is giving me the following error:
Unable to load driver information: SQL ex: Problems executing Android query: SELECT * FROM occupations
WHERE job
= 'Athletes Business Manager'
source to share
I struggled with a similar problem for a while and finally found the correct implementation:
Dao<Book, Integer> bookDao = getDatabaseHelper(ctx).getBookDao();
UpdateBuilder<Book, Integer> builder = bookDao.updateBuilder();
builder.updateColumnValue("title", book.getTitle());
SelectArg titleArg = new SelectArg();
titleArg.setValue(book.getTitle());
builder.updateColumnValue("title", titleArg);
...
PreparedUpdate<Book> prepare = (PreparedUpdate<Book>) builder.where().idEq(book.getIdField()).prepare();
bookDao.update(prepare);
So, in your case, pass the value using the setValue method instead of the constructor:
SelectArg occupationArg = new SelectArg(txtOccupation.getText().toString().trim());
source to share