yingnan liu
yingnan liu

Reputation: 509

Python printing out SQL statement results

I have this following python code with pymysql

    cursor=conn.cursor()
    cursor.execute("""select count(distinct `session_id`) from innodb.fh where `cs-uri-stem` like "/detail%"   """)
    cursor.fetchone()

which is working fine. But i just wonder how to print out the result for my sql statement. it should print out 1204. I tried the following but it is not working:

       results = cursor.execute("""select count(distinct `session_id`) from innodb.fh where `cs-uri-stem` like "/detail%"   """)
       print (results)

thx!

Upvotes: 3

Views: 1013

Answers (1)

Akshat Mahajan
Akshat Mahajan

Reputation: 9846

The PyMySQL cursor defines an attribute called rowcount, as can be seen in the source code.

Immediately after cursor.execute(), you can call cursor.rowcount to get the number of rows affected by the SQL statement.

Upvotes: 1

Related Questions