求助将循环简化为无限循环
sql="Select trim(dwmc) as dwmc,trim(dwcd) as dwcd from 单位名称 where parent is null or trim(parent)='' order by dwcd"cur.execute(sql)
tr0=cur.fetchall()
for s0 in tr0:
root= QTreeWidgetItem(self.tree)
root.setText(0,s0[0])
root.setText(1,s0[1])
dwh=s0[1]
sql="Select trim(dwmc) as dwmc,trim(dwcd) as dwcd from 单位名称 where trim(parent)='"+dwh+"' order by dwcd"
cur.execute(sql)
tr1=cur.fetchall()
if bool(tr1):
for s1 in tr1:
child = QTreeWidgetItem(root)
child.setText(0, s1[0])
child.setText(1, s1[1])
dwh = s1[1]
sql="Select trim(dwmc) as dwmc,trim(dwcd) as dwcd from 单位名称 where trim(parent)='"+dwh+"' order by dwcd"
cur.execute(sql)
tr2=cur.fetchall()
if bool(tr2):
for s2 in tr2:
child2 = QTreeWidgetItem(child)
child2.setText(0, s2[0])
child2.setText(1, s2[1])
dwh= s2[1]
sql="Select trim(dwmc) as dwmc,trim(dwcd) as dwcd from 单位名称 where trim(parent)='"+dwh+"' order by dwcd"
cur.execute(sql)
tr3=cur.fetchall()
if bool(tr3):
for s3 in tr3:
child3 = QTreeWidgetItem(child2)
child3.setText(0, s3[0])
child3.setText(1, s3[1])
dwh= s3[1]
sql="Select trim(dwmc) as dwmc,trim(dwcd) as dwcd from 单位名称 where trim(parent)='"+dwh+"' order by dwcd"
cur.execute(sql)
tr4=cur.fetchall()
if bool(tr4):
for s4 in tr4:
child4 = QTreeWidgetItem(child3)
child4.setText(0, s4[0])
child4.setText(1, s4[1])
dwh= s4[1]
sql="Select trim(dwmc) as dwmc,trim(dwcd) as dwcd from 单位名称 where trim(parent)='"+dwh+"' order by dwcd"
cur.execute(sql)
tr5=cur.fetchall()
if bool(tr5):
for s5 in tr5:
child5 = QTreeWidgetItem(child4)
child5.setText(0, s5[0])
child5.setText(1, s5[1])
dwh= s5[1]
sql="Select trim(dwmc) as dwmc,trim(dwcd) as dwcd from 单位名称 where trim(parent)='"+dwh+"' order by dwcd"
cur.execute(sql)
tr6=cur.fetchall()
if bool(tr6):
for s6 in tr6:
child6 = QTreeWidgetItem(child5)
child6.setText(0, s6[0])
child6.setText(1, s6[1])