Fixed cursor out of bounds exception while using database.