Hi all,
It currently takes my onCreate method 147 seconds to create and populate my
database, if anyone with a better knowledge of SQLite could help me reduce
this it would be greatly appreciated.
I have want to create a database with three tables;
1. CREATE TABLE "nodeConfigurations" ("nodeId" INTEGER PRIMARY KEY
AUTOINCREMENT NOT NULL , "filterId" INTEGER NOT NULL , "left" INTEGER NOT
NULL , "right" INTEGER NOT NULL , "type" INTEGER NOT NULL , "parameters"
TEXT);
2. CREATE TABLE "data" ("dataId" INTEGER PRIMARY KEY AUTOINCREMENT NOT
NULL , "dataName" TEXT NOT NULL );
3. CREATE TABLE "nodes" ("nodeId" INTEGER PRIMARY KEY NOT NULL ,
"nodeType" TEXT NOT NULL );
These three lines are stored in a file under the raw directory, one command
on each line.
I have data to insert of the form;
1. 24 x INSERT INTO "nodes" VALUES(1,'type');
2. 1000 x INSERT INTO "data" VALUES(1,'name');
3. 13589 x INSERT INTO "nodeConfigurations" VALUES(1,1000,5,6,1,'[]');
These 14614 separate insertion commands are stored one on each line in
another file in the raw resource directory.
My database helper is defined thus;
public class DBHelper extends SQLiteOpenHelper {
....
public void onCreate(SQLiteDatabase db) {
this.db = db;
long start = System.currentTimeMillis();
try{
Scanner sql = new
Scanner(context.getResources().openRawResource(R.raw.database_schema));
db.beginTransaction();
while(sql.hasNextLine()){
String command = sql.nextLine();
db.execSQL(command);
}
db.endTransaction();
sql = new
Scanner(context.getResources().openRawResource(R.raw.database_data));
db.beginTransaction();
while(sql.hasNextLine()){
String command = sql.nextLine();
db.execSQL(command);
}
db.endTransaction();
}catch (Throwable t) {
Toast.makeText(context, "Exception: "+t.toString(),2000).show();
Log.w("FilterDB", "Database initialization failed");
t.printStackTrace();
}
Log.i("FilterDBHelper","Database created in " + (System.currentTimeMillis()
- start) + " Milliseconds");
}
....
}
Checking the log I can see that the creation and inserts took a
whopping 147seconds.... I must be doing something wrong.
02-20 15:42:37.703: INFO/FilterDBHelper(281): Database created in 147844
Milliseconds
Any advice would be greatly appreciated!
Kind regards,
Gavin
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---