我有以下代码:
I have the following code:
def executeOne(self, query, parameters):
with self.connection as cursor:
cursor.execute(query, parameters)
return cursor.fetchone()
当我调用这个方法时,它抛出以下错误:AttributeError: 'sqlite3.Connection'对象没有'fetchone'属性
。我做错了什么?
self.connection
有一个连接对象 (self.connection = sqlite3.connection('file.db')
)。我应该在哪里调用cursor()
方法?sqlite 模块不会将with
语句中的连接与游标关联吗? - linkyndycur.execute
,使用cur = self.connection.cursor()
。 - eandersson