10.2 SQLite Database
10.2 SQLite Database
Storing Data
Lesson 10
// Column names...
public static final String KEY_ID = "_id";
public static final String KEY_WORD = "word";
@Override
public void onCreate(SQLiteDatabase db) { // Creates new database
// Create the tables
db.execSQL(WORD_LIST_TABLE_CREATE);
// Add initial data
...
}
● SQLiteDatabase.query()
Use for all other queries
This work is licensed under a Creative
Android Developer SQLite Database Commons Attribution-NonCommercial 31
Fundamentals 4.0 International License
SQLiteDatabase.rawQuery() format
newId = mWritableDB.insert(
WORD_LIST_TABLE,
null,
values);
deleted = mWritableDB.delete(
WORD_LIST_TABLE,
KEY_ID + " =? ",
new String[]{String.valueOf(id)});
mNumberOfRowsUpdated = mWritableDB.update(
WORD_LIST_TABLE,
values, // new values to insert
KEY_ID + " = ?",
new String[]{String.valueOf(id)});
● In MainActivity onCreate()
db.beginTransaction();
try {
...
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}