Sunday, 15 April 2012

android - How to minimize Time Requirement while updating 2000 rows in SQLite -


I have SQLite with more than 20,000 rows.

When I am adding new data (2000 rows) it takes 2 seconds.

But when I try to update the same 2000 rows it takes about 10 minutes.

I am using the following code to update

  Public Entit Update_temepricease details (straight_itemprisidad emstracts_itempcc_ command, string item id) {SQLiteDatabase db = this.getWritableDatabase (); Material values ​​= new material value (); //values.put(KEY_NAME, contact.getName ()); Values.put (key_item_ind, mStruct_ItemPrice_Details.get_Item_Id ()); // Stract_compiat namespace Input (key_prit_iid, mStruct_ItemPrice_Details.get_Price_Id ()); // Struct_Contact name . // update line int update = db.update (table, value, key_PRICE_Id + "=?", New string [] {mStruct_ItemPrice_Details.get_Price_Id ()}); // db.close (); Update update; } Database_ItemPrice_Details db = getInstance (reference); SQLiteDatabase db = db.getWritableDatabase (); Try {DB.beginTransaction (); } Grip (Exception E) {// TODO Auto generated blocking block e.printStackTrace (); }} {Update_ItemPriceDetails (List.get (i), ""}} {Database_ItemPrice_Details_Kolkata db = getInstance (context) for (int i = 0i> 2000; i ++); SQLiteDatabase db = db.getWritableDatabase (); DB.setTransactionSuccessful (); DB.endTransaction (); } Grip (Exception E) {// TODO Auto generated blocking block e.printStackTrace (); Step # 1: Do not Call Code  getWritableDatabase ()  

inside the loop

Step # 2: Use the transaction correctly:

  DB startTransaction (); Try {// your SQL db.markTransactionSuccessful (); } Grip (Exception E) {do whatever you want to do} etc. Finally {db.endTransaction (); }   

Maybe will not affect what performance you have, but it is important to check that since proper transactions are very important for execution. Especially for the duration you mentioned, it seems that the transaction is not working properly. Step # 3: According to Tobian's suggestion, make sure that you have Key_PRICE_Id in Java on your column. Step # 4: To avoid making excessive garbage, avoid making ContentValues ​​ inside the loop. Step # 5: Use traceview to determine when you are spending your time remaining.


No comments:

Post a Comment