@Test public void testTableExists() { for (String table : TABLES) { mDb.execSQL(String.format(BASE_TABLE_CREATE, table)); } for (String table : TABLES) { assertTrue(mDbHelper.tableExists(mDb, table)); } assertFalse(mDbHelper.tableExists(mDb, "meow")); }
@VisibleForTesting boolean tableExists(SQLiteDatabase db, String tableName) { if (tableName == null || db == null || !db.isOpen()) { return false; } Cursor cursor = db.rawQuery("SELECT 1 FROM sqlite_master WHERE type = ? AND name = ?", new String[] {"table", tableName}); if (cursor.moveToFirst()) { cursor.close(); return true; } else { cursor.close(); return false; } }
Database extends SQLiteOpenHelper { @VisibleForTesting boolean tableExists(SQLiteDatabase db, String tableName) { if (tableName == null || db == null || !db.isOpen()) { return false; } Cursor cursor = db.rawQuery("SELECT 1 FROM sqlite_master WHERE type = ? AND name = ?", new String[] {"table", tableName}); if (cursor.moveToFirst()) { cursor.close(); return true; } else { cursor.close(); return false; } } }
Database extends SQLiteOpenHelper { @VisibleForTesting boolean tableExists(SQLiteDatabase db, String tableName) { if (tableName == null || db == null || !db.isOpen()) { return false; } Cursor cursor = db.rawQuery("SELECT 1 FROM sqlite_master WHERE type = ? AND name = ?", new String[] {"table", tableName}); if (cursor.moveToFirst()) { cursor.close(); return true; } else { cursor.close(); return false; } } protected  Database(Context context); }
Database extends SQLiteOpenHelper { @VisibleForTesting boolean tableExists(SQLiteDatabase db, String tableName) { if (tableName == null || db == null || !db.isOpen()) { return false; } Cursor cursor = db.rawQuery("SELECT 1 FROM sqlite_master WHERE type = ? AND name = ?", new String[] {"table", tableName}); if (cursor.moveToFirst()) { cursor.close(); return true; } else { cursor.close(); return false; } } protected  Database(Context context); static synchronized Database getInstance(Context context); TeamsTable getTeamsTable(); EventsTable getEventsTable(); EventDetailsTable getEventDetailsTable(); AwardsTable getAwardsTable(); MatchesTable getMatchesTable(); MediasTable getMediasTable(); EventTeamsTable getEventTeamsTable(); DistrictsTable getDistrictsTable(); DistrictTeamsTable getDistrictTeamsTable(); FavoritesTable getFavoritesTable(); SubscriptionsTable getSubscriptionsTable(); NotificationsTable getNotificationsTable(); @WorkerThread void beginTransaction(); @WorkerThread static void beginTransaction(SQLiteDatabase db); void setTransactionSuccessful(); void endTransaction(); SQLiteDatabase getDb(); @Override void onCreate(SQLiteDatabase db); @Override void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion); Cursor getMatchesForTeamQuery(String query); Cursor getMatchesForEventQuery(String query); }
Database extends SQLiteOpenHelper { @VisibleForTesting boolean tableExists(SQLiteDatabase db, String tableName) { if (tableName == null || db == null || !db.isOpen()) { return false; } Cursor cursor = db.rawQuery("SELECT 1 FROM sqlite_master WHERE type = ? AND name = ?", new String[] {"table", tableName}); if (cursor.moveToFirst()) { cursor.close(); return true; } else { cursor.close(); return false; } } protected  Database(Context context); static synchronized Database getInstance(Context context); TeamsTable getTeamsTable(); EventsTable getEventsTable(); EventDetailsTable getEventDetailsTable(); AwardsTable getAwardsTable(); MatchesTable getMatchesTable(); MediasTable getMediasTable(); EventTeamsTable getEventTeamsTable(); DistrictsTable getDistrictsTable(); DistrictTeamsTable getDistrictTeamsTable(); FavoritesTable getFavoritesTable(); SubscriptionsTable getSubscriptionsTable(); NotificationsTable getNotificationsTable(); @WorkerThread void beginTransaction(); @WorkerThread static void beginTransaction(SQLiteDatabase db); void setTransactionSuccessful(); void endTransaction(); SQLiteDatabase getDb(); @Override void onCreate(SQLiteDatabase db); @Override void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion); Cursor getMatchesForTeamQuery(String query); Cursor getMatchesForEventQuery(String query); static final String ALL_TEAMS_LOADED_TO_DATABASE_FOR_PAGE; static final String ALL_EVENTS_LOADED_TO_DATABASE_FOR_YEAR; static final String ALL_DISTRICTS_LOADED_TO_DATABASE_FOR_YEAR; static final String TABLE_TEAMS; static final String CREATE_TEAMS; static final String CREATE_EVENTS; static final String CREATE_AWARDS; static final String CREATE_MATCHES; static final String CREATE_MEDIAS; static final String CREATE_EVENTTEAMS; static final String CREATE_DISTRICTS; static final String CREATE_DISTRICTTEAMS; static final String CREATE_EVENTDETAILS; static final String CREATE_FAVORITES; static final String CREATE_SUBSCRIPTIONS; static final String CREATE_SEARCH_TEAMS; static final String CREATE_SEARCH_EVENTS; static final String CREATE_NOTIFICATIONS; }