[Tutor] best approach to db-api imports and cursor calls
Alan Gauld
alan.gauld at btinternet.com
Thu Aug 13 10:11:33 CEST 2009
"Serdar Tumgoren" <zstumgoren at gmail.com> wrote
> Is there any reason why you can't reuse the same cursor object? I know
> when you're writing to a database, you have to be sure to commit your
> changes. But if I'm just issuing execute statements and then fetching
> data, is it okay to reuse the same cursor?
No, there is no reason. You can reuse a single cursor as often as
you like provided you are happy to take responsibility for keeping
the transactions clean - eg not trying to read data from one while
writing at the same time, or combining two different selects, and
committing between each change transaction.
But most folks find multiple cursors easier to manage in the same
way that they find multiple variables easier than reusing a minimal
number.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list