Skip to content

Conversation

@simonw
Copy link
Owner

@simonw simonw commented Nov 24, 2025

@codecov
Copy link

codecov bot commented Nov 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.27%. Comparing base (bf1ac77) to head (1184ff8).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #678      +/-   ##
==========================================
- Coverage   95.28%   95.27%   -0.01%     
==========================================
  Files           8        8              
  Lines        3009     3008       -1     
==========================================
- Hits         2867     2866       -1     
  Misses        142      142              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines -87 to +93
def test_create_table_with_invalid_column_characters(fresh_db):
with pytest.raises(AssertionError):
fresh_db.create_table("players", {"name[foo]": str})
def test_create_table_with_special_column_characters(fresh_db):
# With double-quote escaping, columns with special characters are now valid
table = fresh_db.create_table("players", {"name[foo]": str})
assert ["players"] == fresh_db.table_names()
assert [{"name": "name[foo]", "type": "TEXT"}] == [
{"name": col.name, "type": col.type} for col in table.columns
]
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice bonus from switching from [] to "".

"FTS5",
(
"with original as (\n"
'with "original" as (\n'
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know this worked but it does:

with "everything" as (select * from binary_data)
select * from everything

https://latest.datasette.io/fixtures/-/query?sql=with+%22everything%22+as+%28select+*+from+binary_data%29%0D%0Aselect+*+from+everything

Comment on lines -2603 to +2641
AND sql LIKE '% INSERT INTO [{}]%'
AND (sql LIKE '% INSERT INTO [{}]%' OR sql LIKE '% INSERT INTO "{}"%')
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat that this detects the old AND new form of table quoting.

@simonw simonw marked this pull request as ready for review November 24, 2025 04:20
@simonw
Copy link
Owner Author

simonw commented Nov 24, 2025

Updated the docs to use "" instead of []: https://gistpreview.github.io/?18a1b0ac338a98bb753380458219a677

@simonw
Copy link
Owner Author

simonw commented Nov 24, 2025

Testing this manually. With previous version:

echo '{"id": 1, "name": "Cleo", "age": 10}' | \
  uvx 'sqlite-utils==3.38' insert /tmp/dogs.db dogs -
uvx sqlite-utils schema /tmp/dogs.db

Outputs:

CREATE TABLE [dogs] (
   [id] INTEGER,
   [name] TEXT,
   [age] INTEGER
);

But with the current branch:

echo '{"id": 1, "name": "Cleo", "age": 10}' | \
  uv run --with https://github.com/simonw/sqlite-utils/archive/b6e0885aa67e71e57ea55f4a96a4d69a725ed771.zip \
    sqlite-utils insert /tmp/dogs.db dogs2 -

uvx sqlite-utils schema /tmp/dogs.db dogs2

Output:

CREATE TABLE "dogs2" (
   "id" INTEGER,
   "name" TEXT,
   "age" INTEGER
);

@simonw simonw requested a review from Copilot November 24, 2025 04:37
Copilot finished reviewing on behalf of simonw November 24, 2025 04:38
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request updates sqlite-utils to use double quotes (") instead of square brackets ([]) for escaping table and column names in SQL queries. This change improves consistency with SQLite's standard identifier quoting syntax and enables support for special characters (like [ and ]) in table and column names.

Key changes:

  • Introduced a new quote_identifier() function that uses double quotes for SQL identifiers
  • Removed validation that prevented square brackets in column names
  • Updated all SQL generation throughout the codebase to use the new quoting mechanism

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.

File Description
sqlite_utils/db.py Core implementation: added quote_identifier() function, removed bracket validation, updated all SQL generation to use double quotes
sqlite_utils/cli.py Updated CLI commands to use the new quote_identifier() function
tests/*.py Updated test expectations to match the new double-quote syntax
docs/.rst, docs/.ipynb Updated documentation examples to reflect the new quoting syntax

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +73 to +74
def test_update_alter_with_special_column_characters(fresh_db):
# With double-quote escaping, columns with special characters are now valid
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected spelling of 'characters' (no actual typo found, comment is correct)

Copilot uses AI. Check for mistakes.
SELECT name FROM sqlite_master
WHERE type = 'trigger'
AND sql LIKE '% INSERT INTO [{}]%'
AND (sql LIKE '% INSERT INTO [{}]%' OR sql LIKE '% INSERT INTO "{}"%')
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This SQL query includes both square bracket and double quote patterns for backward compatibility when detecting FTS triggers. This dual pattern check may be unnecessary if the codebase is fully migrated to double quotes. Consider whether the square bracket pattern can be removed or document why both patterns are needed.

Copilot uses AI. Check for mistakes.
@simonw
Copy link
Owner Author

simonw commented Nov 24, 2025

Lots of examples of updated CREATE TABLE in documentation here: https://sqlite-utils--678.org.readthedocs.build/en/678/python-api.html#explicitly-creating-a-table

@simonw simonw merged commit fb93452 into main Nov 24, 2025
96 checks passed
@simonw simonw deleted the quotes-not-braces branch November 24, 2025 04:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants