1

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?

xralf
  • 3,312
  • 45
  • 129
  • 200
  • Does this answer your question? [Python how to know if a record inserted successfully or not](https://stackoverflow.com/questions/19046202/python-how-to-know-if-a-record-inserted-successfully-or-not) – mkrieger1 May 24 '23 at 18:19

1 Answers1

2

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).

Sathyajith Bhat
  • 21,321
  • 22
  • 95
  • 134