sqlite3 - compileStatement or db.insert in android -
i want insert records table multiple number of times, have choice either use compilestatement or use db.insert shown below.
string tablename = "table"; //fields in table: id, name sqlitestatement statement = db.compilestatement("insert "+tablename+" values(?,?);"); statement.bindlong(1,666); statement.bindstring(2,"john"); statement.executeinsert();
or
string tablename = "table"; contentvalues values = new contentvalues(); values.put("id", 666); values.put("name", "john"); db.insert(tablename, null, values);
which 1 should optimal?
edit:- application running single threaded.
insert()
compiles sql on each invocation while compilestatement()
approach compiles sql once. when same sql different bind arguments used more once, compilestatement()
approach less work , faster.
in addition, consider wrapping inserts in transaction reduce time spent waiting on i/o.
Comments
Post a Comment