public User getUser()

in PersistenceMigrationsSample/app/src/sqlite/java/com/example/android/persistence/migrations/LocalUserDataSource.java [50:78]


    public User getUser() {
        User user = null;

        SQLiteDatabase db = mDbHelper.getReadableDatabase();

        String[] projection = {
                COLUMN_NAME_ENTRY_ID,
                COLUMN_NAME_USERNAME
        };

        // Get the user from the table. Since, for simplicity we only have one user in the database,
        // this query gets all users from the table, but limits the result to just the 1st user
        Cursor c = db.query(TABLE_NAME, projection, null, null,
                null, null, null, "1");

        if (c != null && c.getCount() > 0) {
            if (c.moveToNext()) {
                int itemId = c.getInt(c.getColumnIndexOrThrow(COLUMN_NAME_ENTRY_ID));
                String title = c.getString(c.getColumnIndexOrThrow(COLUMN_NAME_USERNAME));
                user = new User(itemId, title);
            }
        }
        if (c != null) {
            c.close();
        }
        db.close();

        return user;
    }