Skip to content

Fix #17: quote SQL table/column/index identifiers#52

Merged
iskandr merged 1 commit into
masterfrom
fix-17-quote-sql-identifiers
Jun 18, 2026
Merged

Fix #17: quote SQL table/column/index identifiers#52
iskandr merged 1 commit into
masterfrom
fix-17-quote-sql-identifiers

Conversation

@iskandr

@iskandr iskandr commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Problem

Closes #17.

datacache interpolated table, column, and index names directly into SQL strings without quoting. That forces names to be sanitized to a restricted alphanumeric + underscore character set, and breaks outright for identifiers that are SQL keywords (order, group, ...) or contain spaces/punctuation.

Fix

Add a quote_identifier() helper in datacache/database.py that wraps an identifier in double quotes (the SQL standard) and escapes embedded double quotes by doubling them. Apply it to every identifier interpolated into SQL:

  • CREATE TABLE (table + column names)
  • INSERT INTO (table name)
  • DROP TABLE (table name)
  • CREATE INDEX (index name, table name, indexed columns)
  • metadata table CREATE/INSERT/SELECT

Values continue to be bound via ? placeholders. Quoting is transparent for ordinary names (SQLite stores the unquoted form in its catalog), so existing databases keep working.

Added a regression test that creates and queries a table whose name and columns contain spaces and reserved words — invalid SQL before this change.

https://claude.ai/code/session_011bzfZPTzWnhAMVD7msyMg1

@coveralls

coveralls commented Jun 18, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 27778225547

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage increased (+0.1%) to 73.451%

Details

  • Coverage increased (+0.1%) from the base build.
  • Patch coverage: 1 uncovered change across 1 file (5 of 6 lines covered, 83.33%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
datacache/database.py 6 5 83.33%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 452
Covered Lines: 332
Line Coverage: 73.45%
Coverage Strength: 0.73 hits per line

💛 - Coveralls

Wrap every table, column, and index name in double quotes when building
SQL in database.py, via a new quote_identifier() helper that also escapes
embedded double quotes. This means identifiers containing spaces or
punctuation, or which collide with SQL keywords (e.g. "order", "group"),
no longer have to be sanitized down to alphanumeric + underscore.

Adds a regression test that creates and queries a table whose name and
columns contain spaces and reserved words.

Claude-Session: https://claude.ai/code/session_011bzfZPTzWnhAMVD7msyMg1
@iskandr iskandr force-pushed the fix-17-quote-sql-identifiers branch from a98f640 to 24ced29 Compare June 18, 2026 17:42
@iskandr iskandr merged commit 10ea11c into master Jun 18, 2026
4 of 6 checks passed
@iskandr iskandr deleted the fix-17-quote-sql-identifiers branch June 18, 2026 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrap table names with brackets and colum names with quotes in SQL queries

2 participants