1

I have seen a lot of posts on optimizing SQLITE on android with bulk inserts Currently its taking 90 seconds to do 900 inserts/updates. I added the Begin/End Transaction around them but only saw minor improvements. So I want to add I believe SQLiteStatement

Here is my code currently

static ArrayList<ContentSystem> csList = new ArrayList<ContentSystem>();

..fill out csList..

_dh.BeginTransaction(Table);
for(int i = 0; i < csList.size(); ++i)
{
    addItem(ma, csList.get(i), dh, Table, Key);
}
_dh.setTransactionSuccessful();
_dh.EndTransaction(Table);

public static void addItem(final MainActivity ma, ContentSystem cs,
final DatabaseHandler dh, String Table, String Key) 
{
         worked = dh.UpdateItem(cs.cv, Table, Key, cs.UUID);
         if (worked == 0) 
         {
            worked = dh.AddData(Table, cs.cv);
            if (worked <= 0) 
            {
               ErrorLogger.AddError("Error") 
            }
         }
}

My problem is that if my csList contains ~1000 items and some are already in my list, some are not so I am currently doing a update if the update returns 0 then I do an add

How could I get something like this to work in a bulk statement?

A bit more info

dh.Update

int wok = db.update(table, values, Key + " = ?", new String[] { Item });

dh.Add

int work = (int) db.insert(table, null, values);

ContentSystem is a list of ContentValues

4

2 回答 2

1

尝试INSERT OR REPLACE,而不是仅仅更新或失败的更新后跟插入。

于 2013-10-10T20:17:25.950 回答
0

你确定你的 DatabaseHandler 类中实例化的 SQLiteDatabase 对象是一样的_dh吗?

您可能已经为 _dh 启动了事务,但这甚至可能不是实际执行任何工作的实例化对象。

于 2013-10-10T19:50:50.263 回答