Advertisement
Guest User

Untitled

a guest
Dec 6th, 2012
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         new AsyncTask<Void, Void, Void>() {
  2.  
  3.             @Override
  4.             protected Void doInBackground(Void... params) {
  5.                 File name = getDatabasePath("test.db");
  6.                 name.mkdirs();
  7.                 try {
  8.                     name.createNewFile();
  9.                     name.delete();
  10.                 } catch (IOException e) {
  11.                     e.printStackTrace();
  12.                 }
  13.                 SQLiteDatabase db = SQLiteDatabase.openDatabase(name.getPath(),
  14.                         null, SQLiteDatabase.OPEN_READWRITE
  15.                                 | SQLiteDatabase.CREATE_IF_NECESSARY);
  16.                 db.execSQL("CREATE TABLE IF NOT EXISTS t(x INTEGER PRIMARY KEY ASC, y, z, a, b, c, d, e, f)");
  17.                 db.beginTransaction();
  18.                 final SQLiteStatement insert = db
  19.                         .compileStatement("INSERT INTO t (y, z, a, b, c, d, e, f) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
  20.                 try {
  21.                     for (int i = 0; i < 1000000; i++) {
  22.                         insert.clearBindings();
  23.                         insert.bindString(1, "value y " + i);
  24.                         insert.bindString(2, "value z " + i);
  25.                         insert.bindString(3, "value a " + i);
  26.                         insert.bindString(4, "value b " + i);
  27.                         insert.bindString(5, "value c " + i);
  28.                         insert.bindString(6, "value d " + i);
  29.                         insert.bindString(7, "value e " + i);
  30.                         insert.bindString(8, "value f " + i);
  31.                         insert.executeInsert();
  32.                     }
  33.                     db.setTransactionSuccessful();
  34.                 } catch (Exception e) {
  35.                     e.printStackTrace();
  36.                 } finally {
  37.                     db.endTransaction();
  38.                 }
  39.                 Cursor c = db.rawQuery("SELECT * FROM t", null);
  40.                 if (c.moveToFirst()) {
  41.                     db.delete("t", "y LIKE '%1%'", null);
  42.                     Log.d("Count: ", "" + c.getCount());
  43.  
  44.                     /*-
  45.                     final int indexx = c.getColumnIndex("x");
  46.                     final int indexy = c.getColumnIndex("y");
  47.                     final int indexz = c.getColumnIndex("z");*/
  48.                     int i = 0;
  49.                     do {
  50.                         /*- Log.d("Cur x, y, z:",
  51.                                 String.format("%s,  %s, %s",
  52.                                         c.getString(indexx),
  53.                                         c.getString(indexy),
  54.                                         c.getString(indexz)));*/
  55.                         i++;
  56.                     } while (c.moveToNext());
  57.                     Log.d("Count by iterate: ", "" + i);
  58.                      /**/
  59.                 }
  60.                 c.close();
  61.                 c = db.rawQuery("SELECT * FROM t", null);
  62.                 Log.d("Count: ", "" + c.getCount());
  63.                 c.close();
  64.                 db.close();
  65.                 return null;
  66.             }
  67.  
  68.         }.execute();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement