[英]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.我有以下代码,在没有转义的 SQL 语句的情况下,它工作正常 - 它迭代了之前 SELECT 查询的完整返回集,打印 ID、检测到的语言(来自 bingtranslate)和文本。
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.当我取消 UPDATE 调用时,它会循环一次,然后停止。
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.我认为
execute
的调用会改变 c 的c
,以便在下一次迭代中循环结束。
I don't know Python, so I try to explain what I do in C#.我不知道Python,所以我试着解释一下我在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.您正在使用 DataReader 的相同 object (python 中的
c
)执行命令,因此您有一个重置等奇怪的行为。
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
.在我看来,您不需要在另一个 object 中复制行,而只需创建一个新的命令 object(空)并使用它来执行您的查询,从
c
获取参数。
Correct me if I'm wrong, please.如果我错了,请纠正我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.