如何解决如何使用Google App Engine中的游标从批处理数据库中批量提取记录?
我试图批量从数据库数据库中获取数据,然后使用游标将其复制到ndb数据库中。我的代码在第一个批处理中成功完成了该操作,但未获取任何其他记录。我没有找到有关游标的太多信息,请在这里帮助我。
这是我的代码段:def post(self):
a = 0
chunk_size = 2
next_cursor = self.request.get("cursor")
query = db.GqlQuery("select * from BooksPost")
while a == 0:
if next_cursor:
query.with_cursor(start_cursor = next_cursor)
else:
a = 1
results = query.fetch(chunk_size)
for result in results:
nbook1 = result.bookname
nauthor1 = result.authorname
nbook1 = nBooksPost(nbookname = nbook1,nauthorname = nauthor1)
nbook1.put()
next_cursor = self.request.get("cursor")
基本上,如何设置下一个光标进行迭代?
解决方法
def帖子(自己):
chunk_size = 10
has_more_results = True
query = db.GqlQuery("select * from Post")
cursor = self.request.get('cursor',None)
#cursor = query.cursor()
if cursor:
query.with_cursor(cursor)
while has_more_results == True:
results = query.fetch(chunk_size)
new_cursor = query.cursor()
print("count: %d,results %d" % (query.count(),len(results)))
if query.count(1) == 1:
has_more_results = True
else:
has_more_results = False
for result in results:
#do this
query.with_cursor(new_cursor)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。