I have tried to create a temporary table (sqlite) in Android
Here is the code snippet:
// No error - But cannot create TEMP table
database.rawQuery("CREATE TEMP TABLE IF NOT EXISTS tt1 (unread_message int, target varchar)", null);
// Error - android.database.sqlite.SQLiteException: no such table: tt1: , while compiling: INSERT INTO tt1 SELECT count(*), target FROM messages where read_status=0 and direction=1 GROUP BY target
database.rawQuery("INSERT INTO tt1 SELECT count(*), target FROM messages where read_status=0 and direction=1 GROUP BY target", null);
There is no error for the create TEMP TABLE query, but it complains tt1 is not existed in the second query. Am I create TEMP table in a wrong way?
Typically you shouldn’t be using
rawQueryfor creating tables and doing inserts – try usingSQLiteDatabase#execSQL.This example works at least: