3

I've read a few things on using the SelectArg on stackoverflow and the ORMLite documentation and i can't see what I'm doing wrong.

I'm searching the occupations table where the job field = "Athletes' Business Manager". As you can see it contains a single quote which I'm trying to escape using a 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 gives me the following error:

Unable to load driver details: SQL ex: Problems executing Android query: SELECT * FROM occupations WHERE job = 'Athletes' Business Manager'

1 Answer 1

0

I've been struggling for a while with similar problem and finally found 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 via setValue method, instead of constructor:

SelectArg occupationArg = new SelectArg(txtOccupation.getText().toString().trim());

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.