Allow column names to be reserved words

This commit is contained in:
Simon Willison 2019-01-24 19:01:10 -08:00
commit 228d595f7d
2 changed files with 5 additions and 1 deletions

View file

@ -318,7 +318,7 @@ class Table:
""".format(
upsert="OR REPLACE" if upsert else "",
table=self.name,
columns=", ".join(all_columns),
columns=", ".join("[{}]".format(c) for c in all_columns),
rows=", ".join(
"""
({placeholders})

View file

@ -36,6 +36,10 @@ def test_create_table(fresh_db):
{"name": "Ravi", "age": 63},
[{"name": "name", "type": "TEXT"}, {"name": "age", "type": "INTEGER"}],
),
(
{"create": "Reserved word", "table": "Another"},
[{"name": "create", "type": "TEXT"}, {"name": "table", "type": "TEXT"}],
),
),
)
def test_create_table_from_example(fresh_db, example, expected_columns):