在下面的代码中,实际出现在数据库中的唯一提交是找到的最后一个“idn”。idn 只是一个标识号,用于计算每个客户有多少个机顶盒。因此,如果 idn 1,2 和 3 都存在,它只会在应该正确 1,2 和 3 时将 3 写入 DB。如果 idn 1 是唯一存在的,那么它会被写入。谢谢你的帮助!
if "STBSINFO||" in line:
head, sep, tail = line.partition('STBSINFO||')
idn = idn + 1
if "|" in tail:
head, sep, tail = tail.partition('|')
#Creates the mac address variable from the partition
mac = head
if "|" in tail:
head, sep, tail = tail.partition('|')
#Gathers the IP of the given set top box
stbip = head
if idn == 1:
cursor.execute("INSERT OR REPLACE INTO packages (cid, mstb1) VALUES (?,?)", (cid, stbip))
conn.commit()
elif idn == 2:
cursor.execute("INSERT OR REPLACE INTO packages (cid, mstb2) VALUES (?,?)", (cid, stbip))
conn.commit()
elif idn == 3:
cursor.execute("INSERT OR REPLACE INTO packages (cid, mstb3) VALUES (?,?)", (cid, stbip))
conn.commit()
elif idn == 4:
cursor.execute("INSERT OR REPLACE INTO packages (cid, mstb4) VALUES (?,?)", (cid, stbip))
conn.commit()