1

I've a problem on this query:

WITH RECURSIVE dates(d)
AS (VALUES('2014-03-01')
    UNION ALL
    SELECT date(d, '+1 day')
    FROM dates
    WHERE d < '2014-03-31')
SELECT d AS date

If I execute this query on dedicated SqLite's application for windows, the query works fine.

If I execute this query on my android app, I receive this message as log:

/com.robertot.timereport E/SQLiteLog﹕ (1) near "WITH": syntax error
/com.robertot.timereport W/System.err﹕ java.sql.SQLException: Could not perform raw query for WITH RECURSIVE dates(d) AS (VALUES('2014-04-28') UNION ALL SELECT date(d, '+1 day') FROM dates WHERE d < '2014-06-01') SELECT d AS date

I don't understand why...

Anyway, this is my java code:

GenericRawResults<String[]> rawResults;
List<String[]> results = null;
DbHelperJob findjob = new DbHelperJob(getActivity());

      try
        {
            rawResults = findjob.getJobDao().queryRaw("WITH RECURSIVE dates(d) " +
                                                        "AS (VALUES('" + firstWeek + "') " +
                                                        "UNION ALL " +
                                                        "SELECT date(d, '+1 day') " +
                                                        "FROM dates " +
                                                        "WHERE d < '" + lastWeek + "') " +
                                                        "SELECT d AS date"

            results = rawResults.getResults();
            findjob.close();
        }
        catch (SQLException e)
        {
            e.printStackTrace();
        }

Thanks!! :)

2
  • Recursive queries in SQLite are a relatively new feature; what version are you using? Commented May 9, 2014 at 0:30
  • I''m developing on Android Kitkat and, in according to previous answer in this post, sqlite doesn't support this function... Commented May 9, 2014 at 6:14

1 Answer 1

5

According to this, the syntax that you're looking for was added in SQLite 3.8.3 But according to this, KitKat uses 3.7.11

So, it's just not supported yet on Android.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! :) Anyway, bad news...Is there an alternative to retrieve some data from other query without compatibility issues? Thanks man!
If you are using SQLite just to get range of dates in Java, then you should just generate dates in Java (without SQLite), but if you really need dates in the SQLite query, then here's a solution: stackoverflow.com/questions/2157282/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.