From 228d595f7d10994f34e948888093c2cd290267c4 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Thu, 24 Jan 2019 19:01:10 -0800 Subject: [PATCH] Allow column names to be reserved words --- sqlite_utils/db.py | 2 +- tests/test_create.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/sqlite_utils/db.py b/sqlite_utils/db.py index 5c147381c..41270579b 100644 --- a/sqlite_utils/db.py +++ b/sqlite_utils/db.py @@ -318,7 +318,7 @@ def insert_all( """.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}) diff --git a/tests/test_create.py b/tests/test_create.py index 67071ae27..82eb7edd1 100644 --- a/tests/test_create.py +++ b/tests/test_create.py @@ -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):