android - update sqlite table through attach db very slow -
I have a main SQLite-database (many data) and updated socket-database on an Android device. Want to update). I would like to update the table in the main DB with the table data (the same structure) in the update-db with my Android app - it means to destroy all the rows in the main in the update. - Mainly incorporate everyone with updates.
My approach is to: Delete and Insert are very slow (in my opinion) Is there a way to do it fast? Use batch insert to insert large amounts of data Here is the code: In your database: In your activity: Actually your execution can vary for databaseHelper. But it shows how to insert a large number of data into batches. attach 'to update' path updatetable to remove from mytable where id (Choose ID from updateb). Mytable) Insert in mytable * Select * from mytable
Public Zero Batch Industrial (String SQL, Arreelist & lt; String [] & gt; Value) {SQLiteDatabase db = getWritableDatabase ( ); Db.beginTransaction (); SQLiteStatement stmt = db.compile Statement (SQL); For (int i = 0; i & lt; values.size (); i ++) {string [] record = values.get (i); For (int ii = 0; ii & lt; record.length; ii ++) {stmt.bindString (ii + 1, record [ii]); } Stmt.execute (); Stmt.clearBindings (); } Db.setTransactionSuccessful (); Db.endTransaction (); Db.close (); }
Arreelist & lt; String []> Databatch = new arreelist & lt; String []> (); Int x = 0; For (data data: data list) {string [] data more = {data.getData1 (), data .getData2 (), data .getData2 ()}; DataBatch.add (questionsArray); } String sql = "include in data"; Sql + = "(Data1, Data2, Data3)"; Sql + = "value (?,?,?)"; DatabaseHelper dbhelper = New Database Helper (reference); Dbhelper.batchInsert (SQL, Databatch);
Comments
Post a Comment