// COMPLETED (1) Create an inner class named WaitlistEntry class that implements the BaseColumns interface publicstaticfinalclassWaitlistEntryimplementsBaseColumns { // COMPLETED (2) Inside create a static final members for the table name and each of the db columns publicstaticfinalStringTABLE_NAME="waitlist"; publicstaticfinalStringCOLUMN_GUEST_NAME="guestName"; publicstaticfinalStringCOLUMN_PARTY_SIZE="partySize"; publicstaticfinalStringCOLUMN_TIMESTAMP="timestamp"; }
// COMPLETED (1) extend the SQLiteOpenHelper class publicclassWaitlistDbHelperextendsSQLiteOpenHelper {
// COMPLETED (2) Create a static final String called DATABASE_NAME and set it to "waitlist.db" // The database name privatestaticfinalStringDATABASE_NAME="waitlist.db";
// COMPLETED (3) Create a static final int called DATABASE_VERSION and set it to 1 // If you change the database schema, you must increment the database version privatestaticfinalintDATABASE_VERSION=1;
// COMPLETED (4) Create a Constructor that takes a context and calls the parent constructor // Constructor publicWaitlistDbHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); }
// COMPLETED (6) Inside, create an String query called SQL_CREATE_WAITLIST_TABLE that will create the table // Create a table to hold waitlist data finalStringSQL_CREATE_WAITLIST_TABLE="CREATE TABLE " + WaitlistEntry.TABLE_NAME + " (" + WaitlistEntry._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + WaitlistEntry.COLUMN_GUEST_NAME + " TEXT NOT NULL, " + WaitlistEntry.COLUMN_PARTY_SIZE + " INTEGER NOT NULL, " + WaitlistEntry.COLUMN_TIMESTAMP + " TIMESTAMP DEFAULT CURRENT_TIMESTAMP" + "); ";
// COMPLETED (7) Execute the query by calling execSQL on sqLiteDatabase and pass the string query SQL_CREATE_WAITLIST_TABLE sqLiteDatabase.execSQL(SQL_CREATE_WAITLIST_TABLE); }
// COMPLETED (8) Override the onUpgrade method @Override publicvoidonUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) { // For now simply drop the table and create a new one. This means if you change the // DATABASE_VERSION the table will be dropped. // In a production app, this method might be modified to ALTER the table // instead of dropping it, so that existing data is not deleted. // COMPLETED (9) Inside, execute a drop table query, and then call onCreate to re-create it sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + WaitlistEntry.TABLE_NAME); onCreate(sqLiteDatabase); } }