I have an SQLite database file, created using Sqliteman admin utility. I copied the database file that I created into my Eclipse project's "Assets" folder (should I have done export to a .sql file?).
So in the code I created my own class for opening and using databases from existing file paths. Here is the relevant code:
private static String DB_FULL_PATH_EXISTING = "/data/data/com.jds.databasetest/databases/Book1";
Where com.jds.databasetest is my package name, and Book1 is the name of the database file in the assets folder. Now in some activity:
SQSimple existingDB = new SQSimple(this, "Book1", DB_FULL_PATH_EXISTING);
existingDB.open();
SQSimple is my custom DB class. Here is the relevant constructor code:
public SQSimple(Context c, String DBname, String existingDBpath) {
this.mCtx = c;
this.DBname = DBname;
this.DBpath = existingDBpath;
this.fromExisting = true;
}
public SQSimple open() throws android.database.SQLException {
if (this.fromExisting == false) {
dbHelper = new DatabaseHelper(this);
db = dbHelper.getWritableDatabase();
return this;
} else { //opening from existing DB, i.e. this code gets run
db = SQLiteDatabase.openDatabase(this.DBpath, null, SQLiteDatabase.OPEN_READWRITE);
return this;
}
}
So just trying to open the database via existingDB.open() causes the app the crash. Logcat says the following:
E/Database(13144): sqlite3_open_v2("/data/data/com.jds.databasetest/databases/Book1", &handle, 2, NULL) failed
Hopefully what I'm doing is pretty well-defined and I'm missing something rather obvious here.
Thank you very much for any help.