mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 01:14:31 +02:00
Unit tests for .update()
Also now set .last_pk to lastrowid for rowid tables.
This commit is contained in:
parent
15368c5f59
commit
455071f3c5
2 changed files with 25 additions and 1 deletions
|
|
@ -961,7 +961,7 @@ class Table:
|
|||
else:
|
||||
raise
|
||||
self.last_rowid = result.lastrowid
|
||||
self.last_pk = None
|
||||
self.last_pk = self.last_rowid
|
||||
# self.last_rowid will be 0 if a "INSERT OR IGNORE" happened
|
||||
if (hash_id or pk) and self.last_rowid:
|
||||
row = list(self.rows_where("rowid = ?", [self.last_rowid]))[0]
|
||||
|
|
|
|||
24
tests/test_update.py
Normal file
24
tests/test_update.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import pytest
|
||||
|
||||
|
||||
def test_update_rowid_table(fresh_db):
|
||||
table = fresh_db["table"]
|
||||
rowid = table.insert({"foo": "bar"}).last_pk
|
||||
table.update(rowid, {"foo": "baz"})
|
||||
assert [{"foo": "baz"}] == list(table.rows)
|
||||
|
||||
|
||||
def test_update_pk_table(fresh_db):
|
||||
table = fresh_db["table"]
|
||||
pk = table.insert({"foo": "bar", "id": 5}, pk="id").last_pk
|
||||
assert 5 == pk
|
||||
table.update(pk, {"foo": "baz"})
|
||||
assert [{"id": 5, "foo": "baz"}] == list(table.rows)
|
||||
|
||||
|
||||
def test_update_compound_pk_table(fresh_db):
|
||||
table = fresh_db["table"]
|
||||
pk = table.insert({"id1": 5, "id2": 3, "v": 1}, pk=("id1", "id2")).last_pk
|
||||
assert (5, 3) == pk
|
||||
table.update(pk, {"v": 2})
|
||||
assert [{"id1": 5, "id2": 3, "v": 2}] == list(table.rows)
|
||||
Loading…
Add table
Add a link
Reference in a new issue