Create cursor object inside the with statement.
Merge pull request #767 from sophron/create-cursor-object-inside-the-with-statement

Create cursor object inside the with statement