Android - Database

Objective #1: Use the AABDatabaseManager class

AABDatabaseManager

properties

Context                                context
SQLiteDatabase                db
String                                    DB_NAME = "contacts"  [must be edited for your app]
String                                    DB_VERSION
String                                    TABLE_NAME= "names" [must be edited for your app]
String                                    TABLE_ROW_ID = "id"
String                                    TABLE_ROW_ONE = "first_name" [must be edited for your app]
String                                    TABLE_ROW_TWO = "last_name" [must be edited for your app]
may need to add more field names for your app

methods

AABDatabaseManager                  constructor, creates instance of private helper class, initializes database
addRow                                               inserts a new record to the table by calling db.insert
deleteRow                                         deletes a single record from the table by calling db.delete
updateRow(rowID, String, String, ….)     updates a single record in the tab le by calling db.update [must be edited w/ additional fields]
getRowAsArray                (rowID)                                gets a whole record from the table by calling db.query [must be edited w/ additional fields]
getAllRowsAsArrays                       returns the whole database table (as type-checked  array rather than a Cursor)  [must be w/ add'l fields]

//////////////////////////////////////////////////////////////////////////////////////////

private, inner CustomSQLiteOpenHelper class (which extends SQLiteOpenHelper )

methods

CustomSQLiteOpenHelper          constructor that matches context with the database helper

onCreate(db)                                    creates a table with desired fields in the specified database. [must be edited for your app]

onUpgrade(db, int, int)                 hopefully will never need to be used since old database is deleted when it is upgraded from one version to another