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

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -