I am new to SQLite and when I run the application there is no .db file in
data/data/your.application.package/databases/
package com.navigationsystem;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase;
import android.hardware.SensorManager;
public class DatabaseHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME="navigationsystem.db";
public static final String NODE_ID="nodeID";
public static final String CHILD_ID="childID";
public static final String PARENT_ID="parentID";
private SQLiteDatabase db;
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE nodes( nodeID CHAR(1) PRIMARY KEY );");
db.execSQL("CREATE TABLE edges( childID CHAR(1) NOT NULL, parentID CHAR(1) NOT NULL,PRIMARY KEY(childID,parentID) );");
this.db = this.getWritableDatabase();
ContentValues cv=new ContentValues();
cv.put(NODE_ID, "A");
db.insert("nodes", NODE_ID, cv);
cv.put(NODE_ID, "B");
db.insert("nodes", NODE_ID, cv);
cv.put(NODE_ID, "C");
db.insert("nodes", NODE_ID, cv);
cv.put(NODE_ID, "D");
db.insert("nodes", NODE_ID, cv);
cv.put(NODE_ID, "E");
db.insert("nodes", NODE_ID, cv);
cv.put(NODE_ID, "E");
db.insert("nodes", NODE_ID, cv);
cv.put(CHILD_ID, "A");
cv.put(PARENT_ID, "C");
db.insert("edges", CHILD_ID, cv);
db.insert("edges", PARENT_ID,cv);
cv.put(CHILD_ID, "B");
cv.put(PARENT_ID, "E");
db.insert("edges", CHILD_ID, cv);
db.insert("edges", PARENT_ID,cv);
cv.put(CHILD_ID, "C");
cv.put(PARENT_ID, "D");
db.insert("edges", CHILD_ID, cv);
db.insert("edges", PARENT_ID,cv);
cv.put(CHILD_ID, "C");
cv.put(PARENT_ID, "F");
db.insert("edges", CHILD_ID, cv);
db.insert("edges", PARENT_ID,cv);
db.close();
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
android.util.Log.w("Constants", "Upgrading database, which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS constants");
onCreate(db);
}
}
What is wrong with my code? Is there any setting I have to do for this, or do I have to create another class for creation of a database file?
thanks.