lewisjwilson / kmj

The all-in-one Japanese dictionary/flashcard app.
2 stars 0 forks source link

Limit Flashcard Reviews Per Session #42

Closed lewisjwilson closed 3 years ago

lewisjwilson commented 3 years ago

In DatabaseHelper.kt/dueFlashcards(), change:

val cur = readableDatabase.rawQuery("SELECT * FROM " + TABLE1_NAME +
        " WHERE " + COL8 + "<= date('now')", null) //next_review < date now

to

val reviewNo = 25
try {
        db?.beginTransaction()
        val sql = "SELECT * FROM ? WHERE ? <= date('now') LIMIT ?"
        val statement = db?.compileStatement(sql)
        statement?.bindString(1, TABLE1_NAME)
        statement?.bindString(2, COL8)
        statement?.bindString(3, reviewNo.toString())
        statement?.execute()
        db?.setTransactionSuccessful()
} catch (e: SQLException) {
        Log.w("Exception:", e)
} finally {
        db?.endTransaction()
}

This will limit the number of reviews in each session to reviewNo. Binding done to prevent injection.