0

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...

1
  • I'm not a python guy but does executing a query against your results collection c cause that collection to be reset? Commented Apr 28, 2011 at 21:22

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

2 Comments

ah, OK - so I should copy c into another list[] and then iterate over that? with nearly 1 million rows that's going to hurt, but at least it will work...
@Toby: 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, 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.
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.