CompileStatement or db.insert in android

I want to insert records into the table several times, I have the choice to either use compileStatement or use db.insert, as shown below.

String TABLENAME = "table"; //fields in table: id, name
SQLiteStatement statement = db.compileStatement("INSERT INTO "+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 one should be optimal?

EDIT: - The application that I run is single-threaded.

+4
source share
2 answers

insert()compiles SQL for each call, while the approach compileStatement()compiles SQL only once. When the same SQL with different binding arguments is used multiple times, the approach compileStatement()does less work and is faster.

, , -.

+1

, , Android , , . ( , .)

0

Source: https://habr.com/ru/post/1530396/


All Articles