簡體   English   中英

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聲明記錄在文檔中 synchronous設置需要權衡速度與安全性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM