python sqlite3更新语句不起作用

时间:2012-05-07 06:11:18

标签: python sqlite

我失去了3个小时,我无法弄清楚我做错了什么。请帮忙。 我得出结论,它不会在更新语句中传递密钥,因为我没有收到任何错误,但我也没有更新数据库。

conn = sqlite3.connect('mov.db')
c = conn.cursor()
old_rows = c.execute('SELECT imdb FROM movies WHERE desc="" and imdb<>"" and year<"1997"')
result = c.fetchall()

for row in result:
    key = row[0] [2:]
    try:
    # Get a Movie object with the data about the movie identified by
    # the given movieID.
        movie = i.get_movie(key)
    except IMDbError, e:
        print "Probably you're not connected to Internet.  Complete error report:"
        print e
            continue

    print movie['title']
    if movie.has_key('plot outline'):
    m=movie['plot outline']
    print m
    print key
    c.execute('UPDATE movies SET desc=? WHERE imdb=?',(m,key))
    print c.rowcount

# Commit the changes and close everything.
conn.commit()
c.close()
conn.close()

2 个答案:

答案 0 :(得分:0)

continue似乎在每次迭代时都会发生,因此永远不会执行c.execute('UPDATE ...行。你确定你的代码缩进了吗?

答案 1 :(得分:0)

你在这里从键中剪切了两个字符,这就是为什么它不再匹配表中的键:

key = row[0] [2:]
相关问题