Okay so I've followed a few tutorials and created a databaseHelper class after following a tutorial. However I don't fully understand or get how to actually create the database in the first place.
In my mainActivity I've added this to my onCreate but it doesn't create any database or at least nothing shows up in my Android Device Monitor.
Basically how do I actually get the database to be created?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
sharedPreferences = getSharedPreferences(PREFERENCES, Context.MODE_PRIVATE);
dbHelper = new databaseHelper(this);
}
Java
public class databaseHelper extends SQLiteOpenHelper {
static final String DATABASEHELPER = "DATABASE HELPER";
static final String dbName="chefs";
//User Table Fields
static final String userTable="user";
static final String userColID="userID";
static final String userColName="firstName";
static final String userColLast="lastName";
static final String userColDOB="DOB";
static final String userColGend="gender";
static final String userColAddr="address";
static final String userColPost="postcode";
static final String userColBio="bio";
static final String userColUser="username";
static final String userColEmail="email";
static final String userColPass="password";
static final String userColPic="picture";
static final String userColLastLog="lastlogin";
static final String userColLastLogIP="lastloginIP";
static final String userColRegisteredIP="registeredIP";
static final String userColCreatedOn="createdOn";
//Recipe Table Fields
static final String recipeTable="recipe";
static final String recipeColID="recipeID";
static final String recipeColName="name";
static final String recipeColCate="category";
static final String recipeColDesc="description";
static final String recipeColUserID="user_userID";
//Ingredient Table Fields
static final String ingredientTable="ingredient";
static final String ingredientColID="ingredientID";
static final String ingredientColRecipeID="recipe_recipeID";
static final String ingredientColName="name";
static final String ingredientColAmount="amount";
static final String ingredientColUnit="unit";
//Step Table Fields
static final String stepTable="step";
static final String stepColID="stepID";
static final String stepColRecipeID="recipe_recipeID";
static final String stepColNumber="stepNumber";
static final String stepColDesc="description";
public databaseHelper(Context context) {
super(context, dbName, null,1);
Log.d(DATABASEHELPER, "Database Created");
}
@Override
public void onCreate(SQLiteDatabase db) {
// Creating User Table
db.execSQL("CREATE TABLE "+userTable+" ("+userColID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+userColName+" TEXT, "+userColLast+" TEXT, "
+userColDOB+" NUMERIC, "+userColGend+" TEXT, "+userColAddr+" TEXT, "+userColPost+" TEXT, "+userColBio+" TEXT, "
+userColUser+" TEXT, "+userColEmail+" TEXT, "+userColPass+" TEXT, "+userColPic+" TEXT, "+userColLastLog+" NUMERIC, "
+userColLastLogIP+" TEXT, "+userColRegisteredIP+" TEXT, "+userColCreatedOn+" NUMERIC)");
// Creating Recipe Table
db.execSQL("CREATE TABLE "+recipeTable+" ("+recipeColID+" INTEGER AUTOINCREMENT, "+recipeColName+" INTEGER, "+recipeColCate+" TEXT, "
+recipeColDesc+" TEXT, "+recipeColUserID+" INTEGER");
// Creating Ingredient Table
db.execSQL("CREATE TABLE "+ingredientTable+" ("+ingredientColID+" INTEGER AUTOINCREMENT, "+ingredientColRecipeID+" TEXT ,"+ingredientColName+" TEXT, "
+ingredientColAmount+" INTEGER, "+ingredientColUnit+" TEXT");
db.execSQL("CREATE TABLE "+stepTable+" ("+stepColID+" INTEGER AUTOINCREMENT, "+stepColRecipeID+" INTEGER, "+stepColNumber+" INTEGER, "
+stepColDesc+" TEXT");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.d(DATABASEHELPER, "Upgrading Database");
}
}
Any help is appreciated.