Oleksandr Ivanchenko Oleksandr Ivanchenko - 1 year ago 105
Android Question

Error with query in SugarORM

I'm trying to get number of rows in my Sugar database for each month. My DATE_INSERT is String value like dd-MM-yyyy. I'm trying to set query, but getting error:

android.database.sqlite.SQLiteException: near "LIKE": syntax error (code 1): , while compiling: SELECT * FROM EXERCISE_DATA WHERE DATE_INSERT LIKE

Here's my method. I'm trying to get list size for each month and draw it via GraphView:

private DataPoint[] generateYearlyData() {
Calendar cal = Calendar.getInstance();
int monthIndex = 12;
DataPoint[] values = new DataPoint[monthIndex];
for (int i=0; i < monthIndex; i++) {
SimpleDateFormat sdf = new SimpleDateFormat("MM-yyyy");
String queryMonth = sdf.format(cal.getTime());
String completeArgs = new StringBuilder().append("'%").
double x = i;
double y = (double) ExerciseData.findWithQuery(ExerciseData.class,
DataPoint v = new DataPoint(x, y);
values[i] = v;
cal.add(Calendar.MONTH, 1);
return values;

Answer Source

The third parameter of findWithQuery is a parameter value, or a list of parameter values. These values are inserted into the query string at the places that are marked with a parameter marker.

Your query does not contain any parameter markers. You need to write ... LIKE ?.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download