SugarORM中的查询出错

时间:2016-11-22 08:58:28

标签: android sqlite sugarorm

我试图在每个月的Sugar数据库中获取行数。我的DATE_INSERT是字符串值,如dd-MM-yyyy。我试图设置查询,但收到错误:

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

这是我的方法。我试图获取每个月的列表大小并通过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;
    }

1 个答案:

答案 0 :(得分:0)

findWithQuery的第三个参数是参数值或参数值列表。这些值将插入到标有parameter marker的位置的查询字符串中。

您的查询不包含任何参数标记。你需要写... LIKE ?