@Test public void testColumnExists() { for (String table : TABLES) { mDb.execSQL(String.format(BASE_TABLE_CREATE, table)); } for (String table : TABLES) { assertTrue(mDbHelper.columnExists(mDb, table, "id")); assertFalse(mDbHelper.columnExists(mDb, table, "meow")); } }
@VisibleForTesting boolean columnExists(SQLiteDatabase db, String tableName, String columnName) { if (tableName == null || db == null || columnName == null) { return false; } Cursor cursor = db.rawQuery("PRAGMA table_info(" + tableName + ")", null); if (cursor.moveToFirst()) { do { int value = cursor.getColumnIndex("name"); if (value != -1 && cursor.getString(value).equals(columnName)) { cursor.close(); return true; } } while (cursor.moveToNext()); } cursor.close(); return false; }
Database extends SQLiteOpenHelper { @VisibleForTesting boolean columnExists(SQLiteDatabase db, String tableName, String columnName) { if (tableName == null || db == null || columnName == null) { return false; } Cursor cursor = db.rawQuery("PRAGMA table_info(" + tableName + ")", null); if (cursor.moveToFirst()) { do { int value = cursor.getColumnIndex("name"); if (value != -1 && cursor.getString(value).equals(columnName)) { cursor.close(); return true; } } while (cursor.moveToNext()); } cursor.close(); return false; } }
Database extends SQLiteOpenHelper { @VisibleForTesting boolean columnExists(SQLiteDatabase db, String tableName, String columnName) { if (tableName == null || db == null || columnName == null) { return false; } Cursor cursor = db.rawQuery("PRAGMA table_info(" + tableName + ")", null); if (cursor.moveToFirst()) { do { int value = cursor.getColumnIndex("name"); if (value != -1 && cursor.getString(value).equals(columnName)) { cursor.close(); return true; } } while (cursor.moveToNext()); } cursor.close(); return false; } protected  Database(Context context); }
Database extends SQLiteOpenHelper { @VisibleForTesting boolean columnExists(SQLiteDatabase db, String tableName, String columnName) { if (tableName == null || db == null || columnName == null) { return false; } Cursor cursor = db.rawQuery("PRAGMA table_info(" + tableName + ")", null); if (cursor.moveToFirst()) { do { int value = cursor.getColumnIndex("name"); if (value != -1 && cursor.getString(value).equals(columnName)) { cursor.close(); return true; } } while (cursor.moveToNext()); } 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 columnExists(SQLiteDatabase db, String tableName, String columnName) { if (tableName == null || db == null || columnName == null) { return false; } Cursor cursor = db.rawQuery("PRAGMA table_info(" + tableName + ")", null); if (cursor.moveToFirst()) { do { int value = cursor.getColumnIndex("name"); if (value != -1 && cursor.getString(value).equals(columnName)) { cursor.close(); return true; } } while (cursor.moveToNext()); } 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; }