1. Get pet attributes from user input fields
2. Insert new pet with those attributes into the database
SELECT name, breed FROM pets;
SELECT * FROM pets;
SELECT * FROM pets WHERE _id = 1;
String selection = PetEntry._ID = "=?";
String[] selectionArgs = {"1"};
In Java;
String[] projection = { PetEntry.COLUMN_PET_BREED,
PetEntry.COLUMN_PET_WEIGHT };
String selection = PetEntry.COLUMN_PET_GENDER + "=?";
String selectionArgs = new String[] { PetEntry.GENDER_FEMALE };
Cursor c = db.query(PetEntry.TABLE_NAME, projection,
selection, selectionArgs,
null, null, null);
SELECT breed, weight FROM pets WHERE gender = 1
Handling a cursor object
-moveToFirst: moves the cursor to the first row that’s in the result set
-moveToLast: moves the cursor to the last row that’s in the result set
-moveToPosition(int position): moves the cursor to a specific position; for example, saying “moveToPosition(3)” would move it to the fourth row.
abstract float, abstract int, abstract long, abstract short, abstract String, abstract int
cusor.moveToPosition(3); int nameColumnIndex = cusor.getColumnIndex(PetEntry.COLUMN_PET_NAME); String name = cursor.getString(nameColumnIndex);
cusor.moveToFirst(); cusor.moveToNext(); cusor.moveToNext(); int nameColumnIndex = cusor.getColumnIndex(PetEntry.COLUMN_PET_NAME); int weightColumnIndex = cursor.getColumnIndex(PetEntry.COLUMN_PET_WEIGHT); int result = cursor.getInt(weightColumnIndex);