1
我有一個列'id','title','name'的表,並且正試圖根據與美麗的湯分析的XML插入值。當用變量查詢時返回空值的UPDATE TABLE
def getmax(column):
query = 'select count(?) from table'
c.execute(query, [column])
result = c.fetchall()
for e, i in enumerate(result):
for y in enumerate(i):
if not y[1]:
return 0
else:
return y[1] # used because fetchall returns a tuple
這給了我最後一排,其中一個值插入爲每列:跟蹤每個數值超出函數定義。插入值函數看起來象:
for e in soup.findAll('title'):
e = str(e)
query = "insert into table (id, title) values (?, ?)"
c.execute(query, (getmax('title') + 1, e))
db.commit()
for e in soup.findAll('name'):
e = str(e)
query = "UPDATE table SET name = (?) WHERE id = (?);"
c.execute(query, (e, getmax('name') + 1))
db.commit()
這將返回:
id title name
1 title1
2 title2
3 title3
4 title4
5 title5
非常感謝您的幫助。