In my app i store my rss news in a database.When the user get into my news activity with internet i call createEnty(); method
HotOrNot entry = new HotOrNot(agones.this);
entry.open();
entry.createEntry(msg.getTitle(), msg.getagonistiki(), msg
.getskor(), msg.getgipedo(), msg.getDate(),msg.getgoal1(),msg.getgoal2(),msg.getDescription());
// entry.update(msg.getTitle(),msg.getagonistiki(),msg.getskor(),msg.getgipedo(),msg.getDate());
entry.close();
(in HotOrNot)
public void createEntry(String title, String getagonistiki, String getskor,
String getgipedo, String date, String getgoal1, String getgoal2, String teliko_skor) {
// TODO Auto-generated method stub
ContentValues cv=new ContentValues();
cv.put(DBHelper.TITLE, title);
cv.put(DBHelper.AGONISTIKI, getagonistiki);
cv.put(DBHelper.SKOR, getskor);
cv.put(DBHelper.GIPEDO, getgipedo);
cv.put(DBHelper.DATE, date);
cv.put(DBHelper.GOALA, getgoal1);
cv.put(DBHelper.GOALB, getgoal2);
cv.put(DBHelper.DESCRIPTION, teliko_skor);
try
{
ourDatabase.insert("osfpDB",null,cv);
} //ourDatabase.update("osfpDB",cv,DBHelper.ROWID,null);
catch(Exception e)
{
Log.e("DB ERROR ON .INSERT", e.toString()); // prints the error message to the log
e.printStackTrace(); // prints the stack trace to the log
}
}
Then,when the user gets into news activity without internet i m calling getData();
public Cursor getData()
{
String[] columns =new String[]{DBHelper.ROWID, DBHelper.TITLE , DBHelper.AGONISTIKI, DBHelper.SKOR, DBHelper.GIPEDO, DBHelper.DATE, DBHelper.GOALA, DBHelper.GOALB, DBHelper.DESCRIPTION };
Cursor c=ourDatabase.query(DBHelper.DATABASE_TABLE, columns, null, null, null, null, null);
return c;
}
My problem is that every time the user get into news activity with internet connection,the database writes all the data again from the beginning.I mean that if the first time there are 12 news,they are writing to the database.If the second time there are 12 news again,the same 12 news,the app rewrites them and i have 24 entries in my database and not 12 that i would like to have.So i m looking for a way to delete my database every time that the user has internet and recreate it,or rewrite the database every time….PLease help,i have been stacked here for days…:)
@Guillaume i m trying this but i m getting an empty database
HotOrNot entry = new HotOrNot(agones.this);
agones.this.deleteDatabase(DBHelper.DATABASE_NAME);
entry.open();
entry.createEntry(msg.getTitle(), msg.getagonistiki(), msg
.getskor(), msg.getgipedo(), msg.getDate(),msg.getgoal1(),msg.getgoal2(),msg.getDescription());
// entry.update(msg.getTitle(),msg.getagonistiki(),msg.getskor(),msg.getgipedo(),msg.getDate());
entry.close();
I think you can write delete * from scripts on on internet connection action.
Delete * clears entries in database, it doesn’t remove tables. So, on next action you can insert what ever you want.