Android 提高 SQLite 性能?
Android Improve SQLite Performance?
我可以比下面的代码更快地插入查询吗:
public void InsertFast2(List<Marketing_Points_B> values) {
String sql = "INSERT INTO " + tableName2 + " ( Count, Date, Time, Lat, Lng, UserCode, LatLng ) VALUES ( ?, ?, ?, ?, ?, ?, ? )";
SQLiteDatabase db = this.getWritableDatabase();
/*?*/db.execSQL("PRAGMA synchronous=OFF");
db.beginTransactionNonExclusive();
SQLiteStatement stmt = db.compileStatement(sql);
for (int i = 0; i < values.size(); i++) {
stmt.bindString(1, values.get(i).getCounts());
stmt.bindString(2, values.get(i).getDate());
stmt.bindString(3, values.get(i).getTime());
stmt.bindString(4, String.valueOf(values.get(i).getLat()));
stmt.bindString(5, String.valueOf(values.get(i).getLng()));
stmt.bindString(6, values.get(i).getUserCode());
stmt.bindString(7, String.valueOf(values.get(i).getmPosition()));
stmt.execute();
stmt.clearBindings();
}
db.setTransactionSuccessful();
db.endTransaction();
/*?*/db.execSQL("PRAGMA synchronous=NORMAL");
db.close();
}
什么是(我可以从中使用)?
db.execSQL("PRAGMA synchronous=OFF");
db.execSQL("PRAGMA synchronous=NORMAL");
你不能走得更快,除非运送一个完整的数据库,这样你根本不必做任何插入。
PRAGMA 语句记录在 documentation 中。 synchronous
设置在速度与安全之间进行权衡。
我可以比下面的代码更快地插入查询吗:
public void InsertFast2(List<Marketing_Points_B> values) {
String sql = "INSERT INTO " + tableName2 + " ( Count, Date, Time, Lat, Lng, UserCode, LatLng ) VALUES ( ?, ?, ?, ?, ?, ?, ? )";
SQLiteDatabase db = this.getWritableDatabase();
/*?*/db.execSQL("PRAGMA synchronous=OFF");
db.beginTransactionNonExclusive();
SQLiteStatement stmt = db.compileStatement(sql);
for (int i = 0; i < values.size(); i++) {
stmt.bindString(1, values.get(i).getCounts());
stmt.bindString(2, values.get(i).getDate());
stmt.bindString(3, values.get(i).getTime());
stmt.bindString(4, String.valueOf(values.get(i).getLat()));
stmt.bindString(5, String.valueOf(values.get(i).getLng()));
stmt.bindString(6, values.get(i).getUserCode());
stmt.bindString(7, String.valueOf(values.get(i).getmPosition()));
stmt.execute();
stmt.clearBindings();
}
db.setTransactionSuccessful();
db.endTransaction();
/*?*/db.execSQL("PRAGMA synchronous=NORMAL");
db.close();
}
什么是(我可以从中使用)?
db.execSQL("PRAGMA synchronous=OFF");
db.execSQL("PRAGMA synchronous=NORMAL");
你不能走得更快,除非运送一个完整的数据库,这样你根本不必做任何插入。
PRAGMA 语句记录在 documentation 中。 synchronous
设置在速度与安全之间进行权衡。