Python: Number of rows affected by cursor.execute("SELECT …)

前端 未结 6 1384
迷失自我
迷失自我 2020-12-13 08:36

How can I access the number of rows affected by:

cursor.execute(\"SELECT COUNT(*) from result where server_state=\'2\' AND name LIKE \'\"+digest+\"_\"+charse         


        
6条回答
  •  天命终不由人
    2020-12-13 08:53

    In my opinion, the simplest way to get the amount of selected rows is the following:

    The cursor object returns a list with the results when using the fetch commands (fetchall(), fetchone(), fetchmany()). To get the selected rows just print the length of this list. But it just makes sense for fetchall(). ;-)

    Example:

    print len(cursor.fetchall) 
    

提交回复
热议问题