mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 01:14:31 +02:00
.add_missing_columns() is now case insensitive, closes #221
This commit is contained in:
parent
4cc82fd0bc
commit
b6840646ba
2 changed files with 12 additions and 2 deletions
|
|
@ -1973,9 +1973,9 @@ class Table(Queryable):
|
|||
|
||||
def add_missing_columns(self, records):
|
||||
needed_columns = suggest_column_types(records)
|
||||
current_columns = self.columns_dict
|
||||
current_columns = {c.lower() for c in self.columns_dict}
|
||||
for col_name, col_type in needed_columns.items():
|
||||
if col_name not in current_columns:
|
||||
if col_name.lower() not in current_columns:
|
||||
self.add_column(col_name, col_type)
|
||||
return self
|
||||
|
||||
|
|
|
|||
|
|
@ -503,6 +503,16 @@ def test_insert_row_alter_table_invalid_column_characters(fresh_db):
|
|||
table.insert({"foo": "baz", "new_col[abc]": 1.2}, alter=True)
|
||||
|
||||
|
||||
def test_add_missing_columns_case_insensitive(fresh_db):
|
||||
table = fresh_db["foo"]
|
||||
table.insert({"id": 1, "name": "Cleo"}, pk="id")
|
||||
table.add_missing_columns([{"Name": ".", "age": 4}])
|
||||
assert (
|
||||
table.schema
|
||||
== "CREATE TABLE [foo] (\n [id] INTEGER PRIMARY KEY,\n [name] TEXT\n, [age] INTEGER)"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("use_table_factory", [True, False])
|
||||
def test_insert_replace_rows_alter_table(fresh_db, use_table_factory):
|
||||
first_row = {"id": 1, "title": "Hedgehogs of the world", "author_id": 1}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue