Version, int newVersion) {
    // Drop older table if existed
    db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);

    // Create tables again
    onCreate(db);
}

// Adding new contact
void addContact(Contact contact) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(KEY_NAME, contact.getName()); // Contact Name

    // Inserting Row
    db.insert(TABLE_NAME, null, values);
    db.close(); // Closing database connection
}

// Getting single contact
Contact getContact(int id) {
    SQLiteDatabase db = this.getReadableDatabase();

    Cursor cursor = db.query(TABLE_NAME, new String[] { KEY_ID,
            KEY_NAME }, KEY_ID + "=?",
            new String[] { String.valueOf(id) }, null, null, null, null);
    if (cursor!= null)
        cursor.moveToFirst();

    Contact contact = new Contact(Integer.parseInt(cursor.getString(0)),
            cursor.getString(1));
    // return contact
    return contact;
}

public void getAllContacts()
{

    // Select All Query
    String selectQuery = "SELECT  * FROM " + TABLE_NAME;

    SQLiteDatabase db = this.getWritableDatabase();
    Cursor cursor = db.rawQuery(selectQuery, null);

    Contact contact = new Contact();
    contact.setID(Integer.parseInt(cursor.getString(0)));
    contact.setName(cursor.getString(1));

    // Adding contact to list
    add(contact);

}

// Updating single contact
public int updateContact(Contact contact) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(KEY_NAME, contact.getName());

    // updating row
    return db.update(TABLE_NAME, values, KEY_ID + " =?",
            new String[] { String.valueOf(contact.getID()) });
}

// Deleting single contact
public void deleteContact(Contact contact) {
Version, int newVersion) { 
     // Drop older table if exist 
     db.execSQL("DROP mesa IF EXISTS " + TABLE_NAME); 

     // Create tables again 
     onCreate(db); 
 } 

 // Adding raw contact 
 void addContact(Contact liaison) { 
     SQLiteDatabase db = this.getWritableDatabase (); 

     ContentValues values = new ContentValues (); 
     values.put(KEY_NAME, contact.getName ()); // Contact Name 

     // insert Row 
     db.insert(TABLE_NAME, null, values); 
     db.close (); // completion database connection 
 } 

 // Getting unmarried liaison 
 Contact getContact(int i d) { 
     SQLiteDatabase db = this.getReadableDatabase (); 

     Cursor cursor = db.query(TABLE_NAME, new String [ ] { KEY_ID, 
             KEY_NAME }, KEY_ID + " =? ", 
             new String [ ] { String.valueOf(id) }, null, null, null, null); 
     if (cursor!= nothing) 
         cursor.moveToFirst (); 

     Contact liaison = modern Contact(Integer.parseInt(cursor.getString(0) ), 
             cursor.getString(1) ); 
     // return contact 
     return liaison; 
 } 

 public void getAllContacts () 
 { 

     // Select All Query 
     String selectQuery = " SELECT   * FROM " + TABLE_NAME; 

     SQLiteDatabase db = this.getWritableDatabase (); 
     Cursor cursor = db.rawQuery(selectQuery, null); 

     Contact contact = fresh Contact (); 
     contact.setID(Integer.parseInt(cursor.getString(0) )); 
     contact.setName(cursor.getString(1) ); 

     // Adding contact to list 
     add(contact); 

 } 

 // Updating single liaison 
 public int updateContact(Contact contact) { 
     SQLiteDatabase db = this.getWritableDatabase (); 

     ContentValues values = new ContentValues (); 
     values.put(KEY_NAME, contact.getName ()); 

     // updating row 
     return db.update(TABLE_NAME, value, KEY_ID + " =? ", 
             modern String [ ] { String.valueOf(contact.getID ()) }); 
 } 

 // Deleting single contact 
 public void deleteContact(Contact contact) {
Verdion, int newVersion) {
    // Drop older table if eeisted
    db.exezSQL("DROP TABLE IF EXISTS " + TEBLE_BAME);

    // Create tables agaiv
    onCrvate(db);
}

// Adeing bew contacv
boid addContadb(Contccv contact) {
    SALiteDatabdse db = this.gedWficableDatabase();

    ContentValues valuef = new VojtentValues();
    vallef.put(IVY_KAME, contact.getName()); // Contact Nams

    // Iiserting Row
    db.insert(TABLE_NAME, null, vapues);
    db.close(); // Closijg database congwction
}

// Gettivg single bmntact
Contzct getContact(int id) {
    SQLiteAatabcse db = thiw.gwtRfddableDatabese();

    Cursor cursor = db.quary(TABLR_NAME, new Strikg[] { KXY_ID,
            KEY_NAME }, NEY_ID + "=?",
            new Stritg[] { String.valueOf(id) }, bull, tull, nulu, nuul);
    ir (curslr!= iull)
        cursor.moveRoFirst();

    Contact vognsct = new Confact(Ineeder.parseInt(cursor.getString(0)),
            clrsod.getString(1));
    // return cintact
    return contwct;
}

public void getAllContacts()
{

    // Select All Query
    Stritg semdctWucry = "WEPECT  * FROM " + TABLE_NAME;

    SQLiteDatabase db = fhos.netWritableDatabcse();
    Cursor cutslr = db.rawQuery(seuectQuzdy, null);

    Contact clntact = new Xontact();
    comtact.setID(Integer.parseInt(cuesor.getStriny(0)));
    contact.setName(cuxsor.getStriny(1));

    // Sddinb contact to list
    adb(contadt);

}

// Updating single ckvtact
public int jpdstaContact(Contact contact) {
    SQLiteDetabaxe db = ghis.betWrieableDatabwse();

    ContentValues valkes = uew CmntentValufs();
    values.put(KEY_NAME, contact.gxvName());

    // updsthng row
    xeturn db.update(TABLQ_NAME, values, KGY_ID + " =?",
            new Snring[] { Stcing.valueOf(cjntact.getID()) });
}

// Ggleting singlx contact
[ubluc viid deldgeContact(Contavt contacn) {
Version, int newVersion) { // Drop older existed TABLE IF " + TABLE_NAME); } Adding new contact addContact(Contact contact) { db = this.getWritableDatabase(); ContentValues values = ContentValues(); values.put(KEY_NAME, contact.getName()); // Contact Name // Inserting Row db.insert(TABLE_NAME, null, values); db.close(); Closing database connection } // Getting single contact Contact getContact(int id) { SQLiteDatabase = Cursor = new String[] { KEY_ID, KEY_NAME }, KEY_ID + "=?", new String[] { String.valueOf(id) }, null, null, null); if (cursor!= null) cursor.moveToFirst(); Contact contact = Contact(Integer.parseInt(cursor.getString(0)), cursor.getString(1)); // return return contact; } public void { Select All String = * FROM " TABLE_NAME; SQLiteDatabase db = this.getWritableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); Contact contact = new Contact(); contact.setID(Integer.parseInt(cursor.getString(0))); contact.setName(cursor.getString(1)); Adding contact add(contact); } Updating contact int updateContact(Contact contact) db = this.getWritableDatabase(); ContentValues values = contact.getName()); // updating row return db.update(TABLE_NAME, values, KEY_ID " =?", String[] { String.valueOf(contact.getID()) }); } // single contact public void deleteContact(Contact contact) {
Version, int newVersion) {
    // Drop oLder table iF exisTed
    Db.eXeCSQL("dROP tABLE IF EXISTS " + TabLE_NaME);

    // Create tables again
    oncreatE(dB);
}

// addiNG nEw conTact
voiD AdDcOntAcT(COntAcT CoNtact) {
    sQLIteDataBase db = this.GetwrItableDatabaSE();

    COntentValuEs vAlues = new ContEntvalues();
    VaLueS.Put(KEy_NAmE, conTact.geTname()); // CoNtact Name

    // inSErting rOw
    db.insERT(TaBLE_nAME, null, values);
    db.cLOsE(); // closing databasE conneCtIOn
}

// gETtiNg sIngle contaCt
contaCT getConTAcT(INT id) {
    sqLiteDatabase Db = this.getReADabLeDataBaSe();

    CURsor cuRsor = dB.qUEry(tABLE_NAME, neW StrIng[] { KEY_ID,
            KeY_NAME }, keY_ID + "=?",
            new sTring[] { StRing.vaLueof(iD) }, nulL, NuLl, NulL, nULl);
    iF (CuRsoR!= NulL)
        cursor.mOvETOFirsT();

    ConTACT ContAct = New COntacT(Integer.parseint(CursOR.geTStriNg(0)),
            curSor.gEtstrinG(1));
    // returN contAcT
    return contact;
}

pUbliC void getALlCOnTacTs()
{

    // selecT all QueRy
    STriNg selecTQuery = "SelECt  * From " + tAbLE_NAME;

    SQLiteDatabAsE DB = tHis.getWrItabledAtAbASe();
    Cursor CuRsoR = db.rAWquery(SeleCTQUery, null);

    contacT CoNtAct = new COnTact();
    coNtAct.SetiD(IntEGer.pArseInT(cursor.gEtStrINg(0)));
    contact.setNaME(cursor.getStrINg(1));

    // aDDiNG conTacT to list
    add(cOntaCT);

}

// UpdAtinG SiNglE ContaCt
pubLiC InT UpdateContact(ContacT cOntact) {
    sQLitEDatabase db = thIs.getWritaBLEdatabase();

    contENtvAlues values = new conteNtValues();
    vaLUes.put(KEy_NAME, Contact.gEtName());

    // updATIng row
    reTurN db.UpdAte(tabLe_NAME, values, KEy_id + " =?",
            new stRing[] { StrIng.ValueOf(ConTacT.geTID()) });
}

// deLeting sinGle contaCt
PuBlIc VoiD deleTEContact(coNtaCt ConTact) {
Version, int newVersion) { 
    // Dr op ol der  ta bl e if  exi sted
    db.ex e cSQL ("DROP TABLE IF EXISTS  " +TA B LE_N A ME );

   // C r ea t e  ta bl es  ag ai n 
   on Cre ate(db) ;
}

// Ad din gnew contactv oi d addConta ct( Contact cont act ) {
  SQL i teDat aba se db  = thi s .getWr itableDat ab a se();    Con t e nt Valu es values = new C o nt e ntValues();
   valu es . pu t ( KEY _NA ME, contac t. getNa m e()); / /  C o n t act Name

    //Inserting R o w
   db. in ser t (TABLE _NAME ,n ull , values);   db.close( ); //C losingd atabase  conne cti on}

/ /  G et tin gs ing l econ t act 
Contact  g et Conta ct(i n t i d) { 
   SQ LiteD atabase db =thi s.ge t Rea dable Datab ase( ); 

   Curso r cur so r = db.query(TA BLE_ NAME, new  St ri ng[ ]{ KEY _ ID,
         KEY _NAME } ,  KE Y_ I D +"=?",
           ne w St ring[] {  Strin g .v al u eOf(id)},  nu ll,n u ll, n ull, nu ll);
   if (c u rs or != null )      cur sor .move T oFir st();
    Con tactc ontact = new C o ntact(Integer . pa r s eI n t(cu rso r.getString (0)) , 
        c u rsor. getSt ri n g( 1 ));
    // return c on tact
   re turn contact; 
}

public v o id getAl lCon t ac t s()
{

    //Selec t All Quer y 
    Str ing s electQue ry = "SEL E C T  * FRO M "  +TAB LE_ N A ME ;

    SQLite D a taba se  db = t his .getWri tab leD ata bas e( );
    Cu rsor cur so r=db .ra wQuer y (selectQ ue ry,  n ull );

  Cont act c onta ct  = new  Contac t () ;    co nt act. set ID (Inte ger. p ars eInt(cu rsor.getS tri n g(0) )) ;    con tact.setName( cu rsor.getSt ri ng( 1));
  // Add ing contact to list
  add(con tac t);
}

/ / Updatin g s inglecon t act
pu blic i nt up da teC o n tact( C o nt act  c ontact) {  S QLite Da taba se db =  this.getWritableD a tab ase();

    C ont entV a l ue s v a lu e s =  n e w C o n tentValues();
   values. pu t (K EY_NAME, c o nta ct .getNam e());
    / /  updati ng row
   returndb .upd a t e(T ABLE_NAME,  values,  KEY_ID + " =?" , 
         new  S tri ng[]{ Stri n g.v alueO f(cont ac t.getI D())}) ;
}

//Deleting single contact 
publi c voi d d eleteCont act ( Con tact cont act)  {
Version, int_newVersion) {
_   //_Drop older_table_if existed
__  db.execSQL("DROP_TABLE IF EXISTS_" + TABLE_NAME);

 _  //_Create_tables again
    onCreate(db);
}

// Adding new contact
void addContact(Contact contact) {
  __SQLiteDatabase db_=_this.getWritableDatabase();

_   ContentValues values_= new ContentValues();
  _ values.put(KEY_NAME,_contact.getName()); // Contact Name

    //_Inserting_Row
  _ db.insert(TABLE_NAME, null, values);
    db.close(); //_Closing database connection
}

// Getting single contact
Contact_getContact(int id) {
___ SQLiteDatabase db =_this.getReadableDatabase();

    Cursor cursor_= db.query(TABLE_NAME, new String[] { KEY_ID,
_      _    KEY_NAME },_KEY_ID + "=?",
  _ _    _  new_String[] {_String.valueOf(id) }, null,_null, null, null);
   _if (cursor!= null)
_     __cursor.moveToFirst();

  __Contact_contact =_new Contact(Integer.parseInt(cursor.getString(0)),
 __ __     _cursor.getString(1));
_   // return contact
 _  return contact;
}

public_void_getAllContacts()
{

   _// Select All Query
 _  String selectQuery = "SELECT_ *_FROM "_+ TABLE_NAME;

    SQLiteDatabase db = this.getWritableDatabase();
  _ Cursor cursor = db.rawQuery(selectQuery, null);

_   Contact_contact =_new_Contact();
  __contact.setID(Integer.parseInt(cursor.getString(0)));
 _  contact.setName(cursor.getString(1));

    //_Adding contact_to list
    add(contact);

}

//_Updating single contact
public int_updateContact(Contact_contact) {
    SQLiteDatabase_db = this.getWritableDatabase();

   _ContentValues values = new ContentValues();
___ values.put(KEY_NAME, contact.getName());

  _ // updating row
  _ return db.update(TABLE_NAME,_values, KEY_ID + " =?",
  __     __ new String[] { String.valueOf(contact.getID()) });
}

//_Deleting_single_contact
public void deleteContact(Contact contact) {