public class CustomerDB extends SQLiteOpenHelper
{
// defines the database structure
public static final String DATABASE_NAME = "customerDB.db";
public static final String TABLE_NAME = "tbl_Customers";
// creates the database
public CustomerDB(Context context){ super(context, DATABASE_NAME, null, 1);}
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase)
{
sqLiteDatabase.execSQL("CREATE TABLE tbl_Customers " +
"(Customer_ID INTEGER PRIMARY KEY AUTOINCREMENT," +
"Customer_First_Name TEXT," +
"Customer_Surname TEXT, " +
"Customer_Address_Line_1 TEXT," +
"Customer_Address_Line_2 TEXT, " +
"Customer_Address_Line_3 TEXT," +
"Customer_Postcode TEXT, " +
"Customer_Phone_Number TEXT," +
"Customer_Email TEXT)");
}
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1)
{
sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(sqLiteDatabase);
}
public long addCustomer (String name, String surname, String address1, String address2, String address3, String postcode, String phoneNo, String email)
{
SQLiteDatabase Cdb = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put("Customer_First_Name", name);
contentValues.put("Customer_Surname", surname);
contentValues.put("Customer_Address_Line_1", address1);
contentValues.put("Customer_Address_Line_2", address2);
contentValues.put("Customer_Address_Line_3", address3);
contentValues.put("Customer_Postcode", postcode);
contentValues.put("Customer_Phone_Number", phoneNo);
contentValues.put("Customer_Email", email);
long result = Cdb.insert("tbl_Customers", null, contentValues);
Cdb.close();
return result;
}
public Cursor ViewData()
{
SQLiteDatabase sqLiteDatabase = this.getReadableDatabase();
Cursor cust = sqLiteDatabase.rawQuery("select * from " + TABLE_NAME, null);
return cust;
}
}