Friday 22 November 2019

How to bulk insert or update in sqlite android?

Let me explain my problem precisely i just want to insert 1000's of records in a single shot but it taking some time having some performance issue, is there anyway to improve the performance while doing insert or update operation. Let me explain what i have tried so far :



     public void VisitStatusInsertorUpdate(VisitStatusModel modlobj) {
String query = " SELECT * FROM " + VisitStatusModel.table + " WHERE " + VisitStatusModel.statusid + " =" + modlobj.getStatusID() + "";
Cursor c = db.rawQuery(query, null);

if (c.moveToFirst()) {
VisitStatusUpdate(modlobj);
} else {
InsertVisit_Status(modlobj);
}
c.close();


}
private void VisitStatusUpdate(VisitStatusModel modlobj) {

ContentValues contentValues = new ContentValues();
String[] args = {String.valueOf(modlobj.getStatusID())};
contentValues.put(VisitStatusModel.status,modlobj.getStatus());
contentValues.put(VisitStatusModel.statusid,modlobj.getStatusID());
db.update(VisitStatusModel.table, contentValues, VisitStatusModel.statusid + "= ?", args);
}
private void InsertVisit_Status(VisitStatusModel visitStatusModel) {
ContentValues contentValues = new ContentValues();
contentValues.put(VisitStatusModel.status, visitStatusModel.getStatus());
contentValues.put(VisitStatusModel.statusid, visitStatusModel.getStatusID());

mcontext.getContentResolver().notifyChange(VisitDAO_URI, null);
db.insert(VisitStatusModel.table, null, contentValues);
}


Can someone help me out. Thanks in advance!!



by using the above method i'l do this operation, now how to speed up the process is it the efficient way to do this

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...