Database 如何在Google App Engine中使用游标从数据库中批量获取记录?
我正在尝试批量从db数据库获取数据,并使用游标将其复制到ndb数据库。我的代码成功地完成了第一批处理,但没有获取任何进一步的记录。我没有找到太多关于游标的信息,请在这里帮助我Database 如何在Google App Engine中使用游标从数据库中批量获取记录?,database,google-app-engine,gql,cursors,Database,Google App Engine,Gql,Cursors,我正在尝试批量从db数据库获取数据,并使用游标将其复制到ndb数据库。我的代码成功地完成了第一批处理,但没有获取任何进一步的记录。我没有找到太多关于游标的信息,请在这里帮助我 以下是我的代码片段:def post(self): 基本上,我如何设置下一个要迭代的光标?def post(self): 你试过什么代码?具体来说,您使用的是哪个数据库?下面是我的代码片段:嗨!发布了一个代码片段,其中我的查询一次从db数据库中获取2条记录并写入ndb数据库。我如何处理所有记录? a = 0
以下是我的代码片段:def post(self): 基本上,我如何设置下一个要迭代的光标?def post(self):
你试过什么代码?具体来说,您使用的是哪个数据库?下面是我的代码片段:嗨!发布了一个代码片段,其中我的查询一次从db数据库中获取2条记录并写入ndb数据库。我如何处理所有记录?
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")
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)