mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-08-01 15:04:11 +02:00
insert_all(..., alter=True) works for columns introduced after first 100 records
* Insert all columns for every chunk * Update unit test to reflect new behaviour * Test that exception is raised * Update documentation Closes #139. Thanks, Simon Wiles!
This commit is contained in:
parent
ea87c2b943
commit
947bb7626f
3 changed files with 23 additions and 4 deletions
|
|
@ -707,13 +707,24 @@ def test_insert_thousands_using_generator(fresh_db):
|
|||
assert 10000 == fresh_db["test"].count
|
||||
|
||||
|
||||
def test_insert_thousands_ignores_extra_columns_after_first_100(fresh_db):
|
||||
def test_insert_thousands_raises_exception_wtih_extra_columns_after_first_100(fresh_db):
|
||||
# https://github.com/simonw/sqlite-utils/issues/139
|
||||
with pytest.raises(Exception, match="table test has no column named extra"):
|
||||
fresh_db["test"].insert_all(
|
||||
[{"i": i, "word": "word_{}".format(i)} for i in range(100)]
|
||||
+ [{"i": 101, "extra": "This extra column should cause an exception"}],
|
||||
)
|
||||
|
||||
|
||||
def test_insert_thousands_adds_extra_columns_after_first_100_with_alter(fresh_db):
|
||||
# https://github.com/simonw/sqlite-utils/issues/139
|
||||
fresh_db["test"].insert_all(
|
||||
[{"i": i, "word": "word_{}".format(i)} for i in range(100)]
|
||||
+ [{"i": 101, "extra": "This extra column should cause an exception"}]
|
||||
+ [{"i": 101, "extra": "Should trigger ALTER"}],
|
||||
alter=True,
|
||||
)
|
||||
rows = fresh_db.execute_returning_dicts("select * from test where i = 101")
|
||||
assert [{"i": 101, "word": None}] == rows
|
||||
assert [{"i": 101, "word": None, "extra": "Should trigger ALTER"}] == rows
|
||||
|
||||
|
||||
def test_insert_ignore(fresh_db):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue