我有以下python源文件从MySQL数据库中检索行。问题是在订户表中检索的行太多。如何限制小块行来检索和处理等等?
class subinfo(peewee.Model):
sub_id = peewee.IntegerField()
active = peewee.BooleanField()
sub_type = peewee.IntegerField()
sub_cat = peewee.TextField()
class Meta:
database = locdb
class subscriber(peewee.Model):
sub_id = peewee.IntegerField(unique=True, primary_key=True)
sub_start = peewee.DateTimeField()
sub_end = peewee.DateTimeField()
ref_id = peewee.BigIntegerField()
class Meta:
database = locdb
for row in subscriber.select():
if(row.sub_start >= peewee.datetime.datetime.now()):
sub1, created = subinfo.get_or_create(sub_id=row.sub_id, active=True)
if(created == False & sub1.active == False):
q = subinfo.update(active=True).where(sub_id=row.sub_id)
q.execute()
else:
subinfo.get_or_create(sub_id=row.sub_id, active=False)
答案 0 :(得分:4)
for row in subscriber.select()
前100行执行此操作:
for row in subscriber.select().limit(100)
接下来的100行:
for row in subscriber.select().limit(100).offset(100)
等