Make has_column case insensitive, refs #270.

This commit is contained in:
Friedrich Lindenberg 2020-01-11 14:31:51 +01:00
parent 9b1f8ea649
commit 39385b7e0a

View File

@ -58,7 +58,8 @@ class Table(object):
def has_column(self, column): def has_column(self, column):
"""Check if a column with the given name exists on this table.""" """Check if a column with the given name exists on this table."""
return normalize_column_name(column) in self.columns columns = [c.lower() for c in self.columns]
return normalize_column_name(column).lower() in columns
def insert(self, row, ensure=None, types=None): def insert(self, row, ensure=None, types=None):
"""Add a ``row`` dict by inserting it into the table. """Add a ``row`` dict by inserting it into the table.
@ -343,7 +344,7 @@ class Table(object):
this will remove any keys from the ``row`` for which there is no this will remove any keys from the ``row`` for which there is no
matching column. matching column.
""" """
columns = self.columns columns = [c.lower() for c in self.columns]
ensure = self._check_ensure(ensure) ensure = self._check_ensure(ensure)
types = types or {} types = types or {}
types = {normalize_column_name(k): v for (k, v) in types.items()} types = {normalize_column_name(k): v for (k, v) in types.items()}
@ -351,7 +352,7 @@ class Table(object):
sync_columns = [] sync_columns = []
for name, value in row.items(): for name, value in row.items():
name = normalize_column_name(name) name = normalize_column_name(name)
if ensure and name not in columns: if ensure and name.lower() not in columns:
_type = types.get(name) _type = types.get(name)
if _type is None: if _type is None:
_type = self.db.types.guess(value) _type = self.db.types.guess(value)