Tuesday, May 17, 2011

Complete the select awith initialize

In this posting, we'll take the next step in having the initialize procedure load the word grouping table. What the previous load was doing was, depending on the test level, pulling up a separate file. Since they're all in the same database, we don't need to do that anymore.

What we do need to do, however, is read all the rows in the database for that level into a question object. Then we can continue with the logic as usual, loading the word table and the appState.questionHash.


if (question.kanji! = question.hiragana) {
Utils.storeWordBySuffix(appState, question);
} else {
Utils.storeKana(appState, question);
}


/* store question in the AppState question hash */
appState.questionHash.put(new Integer(question.number),
question);


To get to this we need a statement that is something like:

SELECT _id, level, number, kanji, hiragana, english, freq
FROM all_words
ORDER BY level, freq
WHERE level = appState.level;

The question is how to set this up in the database access. We already have a view by level called:

v_all_words_by_level_freq

Plus, there is already a method in DatabaseHelper called:

public ArrayList selectByLevelAndNumber(int levelIn, int numberIn) {

So, we can just change that around a little bit to access by level, and change the table name.

The first record with a kanji on level 5 is on row 6, and is the one for "人", which means person. So, let's change the test to look for that, and change the method to use the new select and and return the sixth element.

public static void initializeQuestionsSQL(JlptQuizStartActivity a,
AppState appState) {

ArrayList rows = null;

DataBaseHelper myDbHelper = Utils.createDB(a);

rows = myDbHelper.selectByLevel(appState.jlptLevel);

myDbHelper.close();

Question question = rows.get(5);

a.testAnswer = question.kanji;

}

Let's give it a try! Ok, perfect. All green bars.

In the next post, we'll incorporate the word hash.

No comments:

Post a Comment