Why doesn't this work??
db.execSQL("INSERT INTO PARTIES (PARTY_NAME, PARTY_COUNT) SELECT DISTINCT(PARTY), COUNT(PARTY) FROM ? WHERE (Year=?) GROUP BY PARTY ORDER BY PARTY ASC", new Object[] { "Election", "2004" });
It works perfectly in rawQuery!!
Why doesn't this work??
db.execSQL("INSERT INTO PARTIES (PARTY_NAME, PARTY_COUNT) SELECT DISTINCT(PARTY), COUNT(PARTY) FROM ? WHERE (Year=?) GROUP BY PARTY ORDER BY PARTY ASC", new Object[] { "Election", "2004" });
It works perfectly in rawQuery!!
I don't know what "rawQuery" you're referring to (URL please). I don't know of any SQL engine which allows parameter substitution for metadata such as names of tables and columns -- only values, nor names, are allowed in parameter substitution. SQLite is no exception.
rawQuery() method on the SQLiteDatabase object: developer.android.com/reference/android/database/sqlite/…May be it should not?
copypaste from doc:
public void execSQL (String sql, Object[] bindArgs)
Execute a single SQL statement that is NOT a SELECT/INSERT/UPDATE/DELETE.
For INSERT statements, use any of the following instead.
insert(String, String, ContentValues) insertOrThrow(String, String, ContentValues) insertWithOnConflict(String, String, ContentValues,int)http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html