Add assert against mixing cursor and regular DB calls.

Only active in debug mode.
Merge pull request #1681 from kacfengine/assert_against_cursor_errors

Add assert against mixing cursor and regular DB calls.