SQLite cursor in Python with statement -


i have following code:

def executeone(self, query, parameters):     self.connection cursor:                  cursor.execute(query, parameters)         return cursor.fetchone() 

when call method, throws me following error: attributeerror: 'sqlite3.connection' object has no attribute 'fetchone' doing wrong?

the reason receiving error because connection class not have method called fetchone. need add .cursor() create instance of cursor , wrap closing work in with statement.

from contextlib import closing closing(self.connectio.cursor()) cur: 

the easiest way deal remove with statement , manually close cursor.

cur = self.connection.cursor()  try:     cur.execute(query, parameters)      return cur.fetchone() finally:     cur.close()  

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -