user2876485 user2876485 - 28 days ago 9
Android Question

Android UpDate Sqlite

With this code I update the value in the table. That value is stored in two tables. How can I do the update at the same time in the other table? Would also update the value in the other table just for that added in the last year .... is it possible?

This is my code for update table:

ContentValues values=new ContentValues();
ContentValues values1=new ContentValues();

values.put(CategorieTable.NOME_CATEGORIA,fname );
values1.put(GiornateTable.CATEGORIA,fname );////////////////


System.out.println("");
if(isUpdate)
{
//update database with new data
dataBase.update(CategorieTable.TABLE_NAME, values, CategorieTable._ID+"="+id, null);
dataBase.update(GiornateTable.TABLE_NAME, values1, GiornateTable._ID+"="+id, null);
}
else
{
//insert data into database
dataBase.insert(CategorieTable.NOME_CATEGORIA, null, values);
dataBase.insert(GiornateTable.CATEGORIA, null, values1);
}
//close database
dataBase.close();
finish();

Answer
if(isUpdate)
{    
    //update database with new data 
    dataBase.update(CategorieTable.TABLE_NAME, values, CategorieTable._ID+"="+id, null);

    Calendar calendar = Calendar.getInstance();

    int thisYear = calendar.get(Calendar.YEAR);

    if( yourDate == thisYear -1)
    dataBase.update(CategorieTable.OTHER_TABLE, values, CategorieTable._ID+"="+id, null);
}

just call the 2nd table. But it's too easy to be your answer