Passing dbConnection vs passing cursor
Deon Bredenhann <deon-jSf9LyimO26lz6pUZyCq0hBnub05S5/[email protected]>
| Newsgroups | gmane.comp.python.db.psycopg.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi all
Don't know where to send this question to, so if it is the wrong list,
forgive and forget. :)
I've been searching for an answer on this and went throught the list
archives with no luck.
OK. On to the question
In Listing1 vs Listing2. What is the preferred method for send a task to
a module for the db. Is there a lot of processing overhead in creating a
cursor for every module call? Is there any problems in reusing the same
cursor over and over again? How about memory usage between the two?
Thanx a mil
Listing 1
---------
def DoSomething(whatever, dbConnection):
cursor = dbConnection.cursor()
cursor.execute("""update whatever""")
cursor.close()
dbConnection = Connect to db()
for task in task list:
DoSomething(task, dbConnection)
dbConnection.commit
dbConnection.close()
------------------------------------------------
Listing 2
---------
def DoSomething(whatever, cursor):
cursor.execute("""update whatever""")
dbConnection = Connect to db()
cursor = dbConnection.cursor()
for task in task list:
DoSomething(task, cursor)
cursor.close()
dbConnection.commit
dbConnection.close()
------------------------------------------------