[Tutor] The case of the missing close

Kent Johnson kent37 at tds.net
Wed Dec 1 13:53:17 CET 2004


Kent Johnson wrote:
> Here is a sketch to get you started. I'm not sure how cursors work so I 
> may be off the mark! You may want to keep the cursor as an attribute of 
> db so you can reuse it?
> 
> class db:
>   def __init__(self, db, uname, passwd)
>     self.connection = cx_Oracle.connect(dsn=db,user=uname,password=passwd)
> 
>   def execute(self, sql):
>     cursor = connection.cursor()

should be
     cursor = self.connection.cursor()

>     cursor.execute(sql)
>     return cursor
> 
>   def close(self):
>     self.connection.close()
>     self.connection = None # Prevent reusing a closed connection


More information about the Tutor mailing list