0

I am using sqlite3 in python 3 I want to get only the updated data from the database. what I mean by that can be explained as follows: the database already has 2 rows of data and I add 2 more rows of data. How can I read only the updated rows instead of total rows

Note: indexing may not help here because the no of rows updating will change.

def read_all():
        cur = con.cursor()
        cur.execute("SELECT * FROM CVT")
        rows = cur.fetchall()
        # print(rows[-1])
        assert cur.rowcount == len(rows)
        lastrowids = range(cur.lastrowid - cur.rowcount + 1, cur.lastrowid + 1)
        print(lastrowids)
rohith santosh
  • 28
  • 6
  • 23

1 Answers1

1

If you insert rows "one by one" like that

cursor.execute('INSERT INTO foo (xxxx) VALUES (xxxx)')

You then can retrieve the last inserted rows id :

last_inserted_id = cursor.lastrowid

BUT it will work ONLY if you insert a single row with execute. It will return None if you try to use it after a executemany.

If you are trying to get multiple ids of rows that were inserted at the same time see that answer that may help you.

Flo
  • 936
  • 1
  • 8
  • 19