greenrobot / greenDAO

greenDAO is a light & fast ORM solution for Android that maps objects to SQLite databases.
http://greenrobot.org/greendao/
12.63k stars 2.89k forks source link

Exception on raw query #1070

Open mecoFarid opened 3 years ago

mecoFarid commented 3 years ago

I'm trying to fetch the parent hierarchy of a given Department with the query below. Probably this is something GreenRobot can't handle. Is there any alternatives to run a pure SQL query in this library?

mDaoSession.getPlaceDepartmentItemDao().queryRawCreate("" +
                ";WITH CTE AS " +
                "(" +
                    "SELECT a.PID, a.ID, a.LEVEL, a.NAME  " +
                    "FROM PLACE_DEPARTMENT_ITEM a " +
                    " WHERE ID = ?" +
                    "UNION ALL   " +
                    "SELECT a.PID, a.ID, a.LEVEL, a.NAME  " +
                    "FROM PLACE_DEPARTMENT_ITEM a " +
                    "JOIN cte c ON c.PID = a.ID" +
                ")" +
"SELECT *  FROM CTE ORDER BY CTE.LEVEL DESC", departmentId)
.list();

GreenDao throws the following exception:

java.lang.IllegalArgumentException: Cannot bind argument at index 1 because the index is out of range. The statement has 0 parameters.