简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM