xralf
xralf

Reputation: 3642

How many rows have been inserted to sqlite table?

I'm using this code in Python:

for ... :
  cursor.execute('INSERT OR IGNORE INTO foo (bar,baz) VALUES (?, ?)',(1,3))
con.commit()

Can I get the value of the number of rows that have been inserted without using if statement and testing if the value existed before insert?

Upvotes: 1

Views: 290

Answers (1)

Sathyajith Bhat
Sathyajith Bhat

Reputation: 21851

To get number of rows inserted, cursor.rowcount should return the number of rows affected by the last execute ( in this case, number of inserts).

Upvotes: 2

Related Questions