Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- new AsyncTask<Void, Void, Void>() {
- @Override
- protected Void doInBackground(Void... params) {
- File name = getDatabasePath("test.db");
- name.mkdirs();
- try {
- name.createNewFile();
- name.delete();
- } catch (IOException e) {
- e.printStackTrace();
- }
- SQLiteDatabase db = SQLiteDatabase.openDatabase(name.getPath(),
- null, SQLiteDatabase.OPEN_READWRITE
- | SQLiteDatabase.CREATE_IF_NECESSARY);
- db.execSQL("CREATE TABLE IF NOT EXISTS t(x INTEGER PRIMARY KEY ASC, y, z, a, b, c, d, e, f)");
- db.beginTransaction();
- final SQLiteStatement insert = db
- .compileStatement("INSERT INTO t (y, z, a, b, c, d, e, f) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
- try {
- for (int i = 0; i < 1000000; i++) {
- insert.clearBindings();
- insert.bindString(1, "value y " + i);
- insert.bindString(2, "value z " + i);
- insert.bindString(3, "value a " + i);
- insert.bindString(4, "value b " + i);
- insert.bindString(5, "value c " + i);
- insert.bindString(6, "value d " + i);
- insert.bindString(7, "value e " + i);
- insert.bindString(8, "value f " + i);
- insert.executeInsert();
- }
- db.setTransactionSuccessful();
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- db.endTransaction();
- }
- Cursor c = db.rawQuery("SELECT * FROM t", null);
- if (c.moveToFirst()) {
- db.delete("t", "y LIKE '%1%'", null);
- Log.d("Count: ", "" + c.getCount());
- /*-
- final int indexx = c.getColumnIndex("x");
- final int indexy = c.getColumnIndex("y");
- final int indexz = c.getColumnIndex("z");
- do {
- Log.d("Cur x, y, z:",
- String.format("%s, %s, %s",
- c.getString(indexx),
- c.getString(indexy),
- c.getString(indexz)));
- } while (c.moveToNext());
- */
- }
- c.close();
- c = db.rawQuery("SELECT * FROM t", null);
- Log.d("Count: ", "" + c.getCount());
- c.close();
- db.close();
- return null;
- }
- }.execute();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement