Using DatabaseUtils.InsertHelper for faster insertions into SQLite database
http://www.outofwhatbox.com/blog/2010/12/android-using-databaseutils-inserthelper-for-faster-insertions-into-sqlite-database/
Thisisagoodarticle.
twowaystodobatchinsert:
try{
db.beginTransaction();
for each record in the list {
do_some_processing();
if (line represent a valid entry) {
db.insert(SOME_TABLE, null, SOME_VALUE);
}
some_other_processing();
}
db.setTransactionSuccessful();
} catch (SQLException e) {
} finally {
db.endTranscation();
}try {
mDb.beginTransaction();
InsertHelper ih = new InsertHelper(db, "columnTable");
for (Value value : values) {
ih.prepareForInsert();
ih.bind(colIdx, value.getSomeValue());
// ...
ih.execute();
}
mDb.setTransactionSuccessful();
} finally {
mDb.endTransaction();
}Thesecondoneisreallyhelpful,becauseiwanttoinserttherecordswiththefieldindexandwithoutknowingthefieldname.
相关推荐
寻常白昼 2020-08-15
HMHYY 2020-07-28
loviezhang 2020-06-16
lsfreeing 2020-06-11
sunlizhen 2020-06-01
Yasin 2020-05-14
czsay 2020-05-09
wqbala 2020-03-04
会哭的雨 2020-02-19
wordmhg 2020-02-13
awoyaoc 2020-02-02
czsay 2020-01-31
xiaoxiaoniaoer 2020-01-29
猛禽的编程艺术 2020-01-16
xinhao 2020-01-14
TinyDolphin 2020-01-14
Winterto0 2020-01-07
lustdevil 2019-12-31