Reputation: 375
I'm trying to figure out how to use python's mysqldb. I can do my job with my current knownledge, but I want to use the best practices.
Should I close properly my cursor? Exiting the program isn't close it autmatically? (Shouldn't I expect the object destructor to do it anyway?)
Should I create new cursors for every query, or one cursor is enough for multiple different queries in the same DB?
Upvotes: 3
Views: 759
Reputation: 29707
Should I close properly my cursor?
Yes, you should. Explicit is better than implicit.
Should I create new cursors for every query, or one cursor is enough for multiple different queries in the same DB?
This depends on how you use this cursor. For simple tasks it is enough to use one cursor. For some complex application it is better to create separate cursor for each batch of SQL-queries.
Upvotes: 2