Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid sqlite - "No such table" while table exist
    text
    copied!<p>I wrote a SQL query to return items to show to the users.<br> However, there seems to be a weird problem with it.</p> <p>Here's the error:</p> <pre><code>11-17 13:44:08.644: E/AndroidRuntime(3229): Caused by: android.database.sqlite.SQLiteException: no such table: events (code 1): , while compiling: SELECT eventsmeta.*, events.* FROM eventsmeta JOIN (SELECT events.*, classes.* FROM events JOIN classes ON events.idfortype=classes._id) ON eventsmeta.eventid=events._id WHERE (eventsmeta.repeat_start = ?) OR (((? - eventsmeta.repeat_start) % (eventsmeta.repeat_day * 86400000)) = 0) OR (((? - eventsmeta.repeat_start) % (eventsmeta.repeat_week * 7 * 86400000)) = 0) OR ((((12 - eventsmeta.repeat_start_month + ?) % (eventsmeta.repeat_month)) = 0) AND (eventsmeta.repeat_start_year &lt;= ?)) ORDER BY events.startat ASC; </code></pre> <p>The thing is the table <code>events</code> does exist (I verified it with a database viewer). </p> <p>If so, I guess there is some syntax problem... but I can't find it. </p> <p><strong>Other questions about this problem</strong> suggested the code refers to a different database, or a not up-to-date one. I do not think that is the problem since I tried to delete and recreate the database from scratch. I've also used the same code pattern before without any problems...</p> <p><strong>If so, what else could cause this problem?</strong></p> <h2><code>CREATE TABLE</code> Code</h2> <pre><code>public static final String SQL_CREATE_EVENTS = "CREATE TABLE IF NOT EXISTS " + Events.TABLE_NAME + " (" + Events._ID + " INTEGER PRIMARY KEY," + Events.COLUMN_NAME_EVENT_PRIORITY + " INTEGER," + // Events.COLUMN_NAME_EVENT_TITLE + " Text," + Events.COLUMN_NAME_START_AT + " INTEGER," + Events.COLUMN_NAME_END_AT + " INTEGER," + Events.COLUMN_NAME_EVENT_NOTES + " Text," + Events.COLUMN_NAME_EVENT_TYPE + " Text," + Events.COLUMN_NAME_ID_FOR_TYPE + " INTEGER);"; </code></pre> <h2>Extra Code</h2> <pre><code>SQLiteDatabase db = SchooLauncherDbHelper.getInstance(getActivity()).getReadableDatabase(); String sql = SQL QUERY HERE; Cursor c = db.rawQuery(sql, new String[] {.............}); </code></pre> <h2>Edit</h2> <p>Apparently, <code>SELECT * FROM events</code> works perfectly...</p> <h2>Edit 2</h2> <p><code>SQLiteOpenHelper</code>: </p> <pre><code>public class SchooLauncherDbHelper extends SQLiteOpenHelper { static SchooLauncherDbHelper mInstance = null; static final int DATABASE_VERSION = 1; static final String DATABASE_NAME = "SchooLauncher.db"; String query; String[] iconFileNames = {}; public static SchooLauncherDbHelper getInstance(Context context) { if (mInstance == null) { mInstance = new SchooLauncherDbHelper( context.getApplicationContext()); } return mInstance; } private SchooLauncherDbHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } @Override public void onCreate(SQLiteDatabase db) { db.execSQL(SchooLauncherContract.SQL_CREATE_SEMESTERS); db.execSQL(SchooLauncherContract.SQL_CREATE_STUDENTS); db.execSQL(SchooLauncherContract.SQL_CREATE_SUBJECTS); db.execSQL(SchooLauncherContract.SQL_CREATE_STUDENTSTUBJECTJOIN); db.execSQL(SchooLauncherContract.SQL_CREATE_TEACHERS); db.execSQL(SchooLauncherContract.SQL_CREATE_TEACHERSUBJECTJOIN); db.execSQL(SchooLauncherContract.SQL_CREATE_CLASSES); db.execSQL(SchooLauncherContract.SQL_CREATE_TEACHERCLASSJOIN); db.execSQL(SchooLauncherContract.SQL_CREATE_ASSIGNMENTS); db.execSQL(SchooLauncherContract.SQL_CREATE_EXAMS); db.execSQL(SchooLauncherContract.SQL_CREATE_EVENTS); db.execSQL(SchooLauncherContract.SQL_CREATE_EVENTS_META); db.execSQL(SchooLauncherContract.SQL_CREATE_SETTINGS); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { Log.i("onUpgrade()", "Upgrading from " + oldVersion + " to " + newVersion); } @Override public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) { onUpgrade(db, oldVersion, newVersion); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload