db locking mitigation

This introduces a retry mechanism to the db cursor.

This should mitigate any problems due to database locking.