Reputation: 31
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!!
Upvotes: 3
Views: 3045
Reputation: 121
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
Upvotes: 1
Reputation: 881635
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.
Upvotes: 2