Question

I have problems in upgrading ormlite for android from version 4.47 to version 4.48

Everything works fine in 4.47 but in 4.48 launching application I'm having this exception:

java.lang.RuntimeException: Unable to resume activity:
    java.lang.IllegalStateException: The SQL statement has not been finished
    since there are previous operations still waiting for clauses.

The problem is in this line of code:

final PreparedQuery<Intervento> preparedQuery = queryBuilder.prepare();

Here is the source code of my method:

final Where<Intervento, Integer> where = queryBuilder.where();
where.eq(Intervento.ESEGUITO_FIELD_NAME, false).and();
where.eq(Intervento.ENABLED_FIELD_NAME, true).and();
if (whereFields!=null){
    for (String key : whereFields.keySet()){
        if (whereFields.get(key)!=null){                
            SelectArg selectArg = new SelectArg();
            selectArg.setValue(whereFields.get(key).getClass().cast(whereFields.get(key)));
            where.like(key,selectArg).and();
        }   
    }
}

final PreparedQuery<Intervento> preparedQuery = queryBuilder.prepare();
final AndroidCompiledStatement compiledStatement = (AndroidCompiledStatement)preparedQuery.compile(DatabaseHelper.getInstance(mContext).getConnectionSource().getReadOnlyConnection(),StatementType.SELECT);
return compiledStatement.getCursor();

Edit:

I think it is possibly due to the last .and() added in for cycle... But it has stop working in this latest version upgrade.

Was it helpful?

Solution

I think it is possibly due to the last .and() added in for cycle... But it has stop working in this latest version upgrade.

I'm not 100% sure why it was working at all under 4.47 but 4.48 added some features in the .and() chaining department so maybe now it is better checking for this error. Right now you have dangling .and() statements.

Instead of putting the .and() at the end of your lines, you should move them to the start of the lines. Right now, if whereFields is null then you would build a query with the following:

where.eq(Intervento.ESEGUITO_FIELD_NAME, false).and();
where.eq(Intervento.ENABLED_FIELD_NAME, true).and();

If ORMLite actually generated the SQL this would be something like:

WHERE eseguito = false AND enabled = true AND

Notice the dangling AND at the end of the query which is invalid. If you put the .and() when before you add another SQL clause, then this would not be an issue.

where.eq(Intervento.ESEGUITO_FIELD_NAME, false); // no .and() here
// .and() at the start of a new clause
where.and().eq(Intervento.ENABLED_FIELD_NAME, true);

Then inside the whereFields != null and the loop you would do something like:

where.and().like(key,selectArg);

So you would add the AND key like ? each time there is another key.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top