How to bulk insert or update in sqlite android? -
this question has answer here:
let me explain problem precisely want insert 1000's of records in single shot taking time having performance issue, there anyway improve performance while doing insert or update operation. let me explain have tried far :
public void visitstatusinsertorupdate(visitstatusmodel modlobj) { string query = " select * " + visitstatusmodel.table + " " + 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 me out. in advance!!
by using above method i'l operation, how speed process efficient way
i want insert 1000's
i assume 1 time action, , if so, skip step , provide pre-filled database instead. there're libs can task of setting db assets https://github.com/jgilfelt/android-sqlite-asset-helper , others.
Comments
Post a Comment