Skip to content

Commit

Permalink
Fix a bug where bad data would crash the app because the database cur…
Browse files Browse the repository at this point in the history
…sor would throw an error on read
  • Loading branch information
hispeedimagins committed Aug 2, 2018
1 parent c11ba22 commit 4a39b13
Showing 1 changed file with 13 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,19 @@ class RequestsDatabase (context : Context) : SQLiteOpenHelper(context, Database
}
cursor.moveToFirst()
while (!cursor.isAfterLast) {
var addit = createRequestDataClass(cursor)
if(addit != null) questionsLites.add(addit)

if(!cursor.moveToNext()) break
}

return questionsLites
}

/*val q = Request(
//made the creation of the class to a common function as it was needed in another place
fun createRequestDataClass(cursor:Cursor):Request?{
try{
return Request(

json = cursor.getString(cursor.getColumnIndex(DatabaseColoumnJson)),
dateLong = cursor.getString(cursor.getColumnIndex(DatabaseColoumnDate)).toLong(),
Expand All @@ -155,28 +164,11 @@ class RequestsDatabase (context : Context) : SQLiteOpenHelper(context, Database
typeOfRequest = cursor.getString(cursor.getColumnIndex(DatabaseColoumnTypeOfRequest))


)*/
)
} catch (ex:Exception){

questionsLites.add(createRequestDataClass(cursor))
cursor.moveToNext()
}

return questionsLites
}

//made the creation of the class to a common function as it was needed in another place
fun createRequestDataClass(cursor:Cursor):Request{
return Request(

json = cursor.getString(cursor.getColumnIndex(DatabaseColoumnJson)),
dateLong = cursor.getString(cursor.getColumnIndex(DatabaseColoumnDate)).toLong(),
reqnumber = cursor.getInt(cursor.getColumnIndex(DatabaseColoumnReqId)),
dbId = cursor.getInt(cursor.getColumnIndex(DatabaseColoumnId)).toLong(),
otherInfo = cursor.getString(cursor.getColumnIndex(DatabaseColoumnOtherInfo)),
typeOfRequest = cursor.getString(cursor.getColumnIndex(DatabaseColoumnTypeOfRequest))


)
return null

}

Expand Down

0 comments on commit 4a39b13

Please sign in to comment.