Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 升级到Peewee 2.6后的sqlite3接口错误_Python_Sqlite_Peewee - Fatal编程技术网

Python 升级到Peewee 2.6后的sqlite3接口错误

Python 升级到Peewee 2.6后的sqlite3接口错误,python,sqlite,peewee,Python,Sqlite,Peewee,从v2.4.7升级到Peewee 2.6.3后,在迭代select查询的结果时会弹出以下错误 编辑:这似乎是一个与使用create\u或\u get方法有关的错误 File "./script.py", line 137, in load_data for name,country in rows: File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/peewee.p

从v2.4.7升级到Peewee 2.6.3后,在迭代select查询的结果时会弹出以下错误

编辑:这似乎是一个与使用create\u或\u get方法有关的错误

 File "./script.py", line 137, in load_data
    for name,country in rows:
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/peewee.py", line 1957, in next
    obj = self.iterate()
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/peewee.py", line 1934, in iterate
    row = self.cursor.fetchone()
sqlite3.InterfaceError: Cursor needed to be reset because of commit/rollback and can no longer be fetched from. 
以下是违规代码:

for i in range(1, nb_rows // CHUNK_SIZE + 2):                                                                                                                                                                                                                                                                                                     
    rows = (Source.select(Source.name,Source.country)                                                                                                                       
           .where(Source.status == 'new').paginate(i, CHUNK_SIZE).tuples())                                                                                                     

    for name,country in rows:                                                                                                                                                                                                                                                                                                               
        person, created = Person.create_or_get(name = name, new = True)                                                                                                        

        if country:                                                                                                                                                                   
            country, created = Countries.create_or_get(name = country)                                                                                                                         
            Person_Country(person_id = person.id, country_id = country.id).save()   
你能帮我确定问题是什么以及如何解决吗


注意:使用Sqlite3 3.8.9时,外部
SELECT
语句的光标仍然处于打开状态,因此通过使用外部
SELECT
可以使代码正常工作:

for i in range(1, nb_rows // CHUNK_SIZE + 2):                                                                                                                                                                                                                                                                                                     
    rows = (Source.select(Source.name,Source.country)                                                                                                                       
           .where(Source.status == 'new').paginate(i, CHUNK_SIZE).tuples())                                                                                                     

    # CONSUME SELECT
    rows = list(rows)

    for name,country in rows:                                                                                                                                                                                                                                                                                                               
        person, created = Person.create_or_get(name = name, new = True)                                                                                                        

        if country:                                                                                                                                                                   
            country, created = Countries.create_or_get(name = country)                                                                                                                         
            Person_Country(person_id = person.id, country_id = country.id).save()   
create_或_get
将使用事务(如果您已经在事务中,则使用保存点)。提交或回滚时,
选择
的光标将无法再使用