Wednesday, October 12, 2011

Re: [android-developers] SQLite slow

If you aren't, try using transactions:

dbHandle.beginTransaction();
lReturn = dbHandle.insert( sTable, null, cvEntry ); // Update and delete here also
dbHandle.setTransactionSuccessful();
dbHandle.endTransaction();

If you do multiple inserts/updates/deletes where you target specific rows for a reason you can't include them all in one query, add more statements between the beginTransaction and the setTransactionSuccessful.

Steven
Studio LFP
http://www.studio-lfp.com


On Wednesday, October 12, 2011 3:29:49 PM UTC-5, John Goche wrote:

On Wed, Oct 12, 2011 at 5:38 PM, Christopher Van Kirk <christoph...@gmail.com> wrote:
You haven't provided enough information to help you.

The question you need to ask is why is it slow? Are you opening and closing the connection many time? Too many records? Complex joins? Inefficient query? Lack of indexing? Unintentionally cartesianing?

I don't have a lot of data. Just the following class accessed from every
activity in my application and the storeAndRetrieve method called (which
calls insert and delete sql statements on a handful of tables each having
around just 60 rows each at the moment).

class DB {
 
  private DB(Context ctx) {

    dbHelper = new DBHelper(ctx);
    database = dbHelper.getWritableDatabase();
 
  }
 
  public static DB db(Context ctx) {
    if (db == null)
      db = new DB(ctx);
    return db;
  }

  // store and retrieve data

  public Data storeAndRetrieve(Data data) {

    putData(data);

    Data retData = getData();
   
    return retData;

  }
 
 // ... data getters and setters

  private static DB db = null;
  private DBHelper dbHelper;
  private SQLiteDatabase database;

}

Yes when I run sqlite3 from adb shell it is fast, but for some
reason when an activity is pushed and reads the data once
opened it takes more than half a second which really slows
down the user experience.

Thanks for your help,

John Goche

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment