I have a quiz app which populates a sqlite database with questions of around 20 different categories. I want to implement in app billing so that if someone purchases Category1 for example, then these questions are added to the database and no others. Some of my questions fall within two categories so let’s say Category1 and Category2.
try {
for (int n = 1; n < sqlString.length; n++) {
db.execSQL("INSERT INTO " + DATABASE_TABLE + " VALUES ("
+ sqlString[n] + ");");
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
This is my current set up in the SQLite class onCreate method. sqlString is a string array containing all my 500 questions so far.
I’m going to store whether a category has been bought in another table (but I am open to other suggestions on how to do this). I plan on creating a class which reads this database setting up boolean values of true or false whether each category has been bought. So
boolean cat1 = CheckIfCategoryHasBeenBought(category1)
etc. Then if it has been bought I will implement a method such as
boolean[] catChecker = {cat1, cat2, cat3, etc....}
SQLite info = new SQLite(this);
info.open();
info.addQs(catChecker)
//this will pass the true and false boolean values for each method then
//based on that I choose to implement or not
info.close();
However I don’t know if this is even a good way to do it. I’m not sure how to check if the value has already been added (as a result of it crossing over with another category that’s been bought). I was thinking a cursor would be best to check if the value is already added however how do I get the cursor to search?
The ways I’ve thought this could be achieved is
1) I create a string array only with the strings associated with bought questions.
2) I create an if statement within the for loop above which checks whether the string is from a bought category
3) I give the value “null” to all strings that haven’t been bought then add an if statement only executing the SQL if the sqlString[n] is not null.
Do you guys have any idea how it would be best to set this up?
Have you thought about starting with a full database – i.e. containing all questions that could be purchased by anyone – and then delete those that are no longer applicable?