Oleksandr Ivanchenko Oleksandr Ivanchenko - 11 days ago 5
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();
cal.set(Calendar.MONTH,Calendar.JANUARY);
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("'%").
append(queryMonth).append("%'").toString();
double x = i;
double y = (double) ExerciseData.findWithQuery(ExerciseData.class,
"SELECT * FROM EXERCISE_DATA WHERE DATE_INSERT LIKE",completeArgs).size();
DataPoint v = new DataPoint(x, y);
values[i] = v;
cal.add(Calendar.MONTH, 1);
}
return values;
}

CL. CL.
Answer

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 ?.

Comments