I have the following code:
def executeOne(self, query, parameters):
with self.connection as cursor:
cursor.execute(query, parameters)
return cursor.fetchone()
When I call this method, it throws me the following error: AttributeError: 'sqlite3.Connection' object has no attribute 'fetchone'
What am I doing wrong?
self.connectionhas a connection object (self.connection = sqlite3.connection('file.db')). Where should I call thecursor()method? Doesn't the sqlite module associate the connection from thewithstatement with a cursor?cur.executeusing cur = self.connection.cursor().