Created
April 25, 2019 05:31
-
-
Save schmidt-sebastian/51e0ab4632069f2453f69a7038e2f3b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.database.Cursor; | |
import android.database.sqlite.SQLiteDatabase; | |
import android.database.sqlite.SQLiteOpenHelper; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
public class MainActivity extends AppCompatActivity { | |
private SQLiteDatabase db; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
SQLiteOpenHelper opener = | |
new SQLiteOpenHelper(this.getApplicationContext(), "foo", null, 1) { | |
@Override | |
public void onCreate(SQLiteDatabase db) { | |
} | |
@Override | |
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { | |
} | |
}; | |
db = opener.getWritableDatabase(); | |
db.execSQL("DROP TABLE IF EXISTS a"); | |
db.execSQL("DROP TABLE IF EXISTS b "); | |
db.execSQL("CREATE TABLE a (path TEXT PRIMARY KEY)"); | |
for (int i = 0; i < 100000; ++i) { | |
db.execSQL("INSERT INTO a (path) VALUES ('foo" + i + "')"); | |
} | |
db.execSQL("CREATE TABLE b (path TEXT PRIMARY KEY)"); | |
Cursor cursor = db.rawQuery("SELECT path FROM a WHERE NOT EXISTS (SELECT 1 FROM b WHERE path = a.path)", new String[]{}); | |
while (cursor.moveToNext()) { | |
db.execSQL("INSERT INTO b (path) VALUES ('" + cursor.getString(0) + "')"); | |
} | |
System.out.println("done"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment