The iCoder
The iCoder

Reputation: 1444

Database values are some times updated but sometimes not?

I have written a simple code for Database updatation, but it is sometime updating and sometimes not... i have written LOG for conformation but the log is giving correct output. Here is what i am trying :=

public void updateDownloadedAssetNumberOfStartingBytesEncrypted(int id, int startingBytesEncrypted)
   {
       SQLiteDatabase database = null;
       int numOfRowsUpdated = 0;

       try
       {
           database = getWritableDatabase();

           ContentValues values = new ContentValues();
           values.put("StartingBytesEncrypted", startingBytesEncrypted);

           if(database.isOpen())
           {
               Log.v("updating in db","doc id - "+id + " encrypted bytes - "+startingBytesEncrypted);
               numOfRowsUpdated = database.update("_assets", values, "Id = "+id, null);
           }
           else
           {
               Log.v("Database","the database is not open thus starting encrypted bytes were not updated");
           }
           Log.v("muber of rows updated - ",""+numOfRowsUpdated);
       }
       catch(Exception ex)
       {

       }
       finally
       {
           if(database != null)
           {
               database.close();
           }
       }
   }

What is the problem?? Any help would be Appreciable.

Upvotes: 0

Views: 135

Answers (2)

mAc
mAc

Reputation: 2514

Ya i got ur code...

Finally i resolved the issue.... actually it is beacuse of threading....

the thread creating the row was executed later and that updating the row was executed first i have resolved it.Have fun :)

Upvotes: 1

Jwalin Shah
Jwalin Shah

Reputation: 2521

This happened due to connection of database is not open. Pls keep ex.printstacktrace(); in catch statement.

Upvotes: 0

Related Questions