开发者

Why does adding my Sql UPDATE break my loop?

I have the following code which, without the escaped SQL statement, is working fine - it iterates over the full set of returns from a previous SELECT query printing the ID, detected language (from bingtranslate) and text.

for row in c:
  lang=bingtranslate(row[0])
  tweetid = row[1]
  print tweetid, lang, row[0]
  #c.execute('UPDATE tweet SET iso_language_code=? WHERE id=?',(lang, tweetid))

When开发者_运维知识库 I unescape the UPDATE call, it loops once, and then stops.

What gives? No error reported. I'm sure it's something simple but I just can't crack it...


I think the call to execute alters the state of c, so that on the next iteration the loop ends.


I don't know Python, so I try to explain what I do in C#.
You're executing a Command using same object of a DataReader (c in python), so you have a reset and so the strange behaviour.
In my opinion you don't need to copy rows in another object, but only create a new Command object (empty) and use that to execute your query taking params from c.
Correct me if I'm wrong, please.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜