ArockiaRaj
ArockiaRaj

Reputation: 608

Row count always prints as -1 while select values from the database using python script

I need to print the row count of the cursor while using select query using python. But it always returns -1 even the select query returns some values.

Code I've tried:

    cursor = conn.cursor()
    cursor.execute(query)
    print(cursor.rowcount)

How to print the rowcount of the cursor?

Upvotes: 1

Views: 389

Answers (2)

Bob.B
Bob.B

Reputation: 718

len( cursor.fetchall()) 

this should do

Upvotes: 0

ArockiaRaj
ArockiaRaj

Reputation: 608

The below code returns the lenth of the row.

  rows = cursor.fetchall()
  len(rows)

Upvotes: 1

Related Questions