Skip to content

Add shared SQL classification module#99

Merged
ldayton merged 8 commits intomainfrom
add-sql-classification-module
Jan 24, 2026
Merged

Add shared SQL classification module#99
ldayton merged 8 commits intomainfrom
add-sql-classification-module

Conversation

@ldayton
Copy link
Owner

@ldayton ldayton commented Jan 24, 2026

Summary

  • Extract SQL read-only detection from aws.py into shared module dippy/core/sql.py
  • New implementation properly handles string literals, quoted identifiers, and comments
  • Detects multiple statements, CTEs, SELECT INTO, and UPSERT variants
  • Supports dialect-specific keywords via extra_readonly/extra_write parameters
  • Add verify-counts skill and update release skill to use it

Changes

File Description
src/dippy/core/sql.py New shared SQL classification module
tests/core/test_sql.py 113 comprehensive tests
src/dippy/cli/aws.py Use shared module with Athena-specific keywords
.claude/skills/verify-counts/ New skill for verifying numerical claims
.claude/skills/release/SKILL.md Update to run verify-counts

Extract SQL read-only detection from aws.py into a shared module at
dippy/core/sql.py. The new implementation handles:

- String literals (single/double quoted with escapes)
- Quoted identifiers (backticks, brackets, double quotes)
- Comments (single-line and block)
- Multiple statement detection
- CTEs (WITH clauses)
- SELECT INTO as a write operation
- UPSERT variants (REPLACE, ON CONFLICT, ON DUPLICATE KEY)
- Dialect-specific keywords via extra_readonly/extra_write parameters

Also adds verify-counts skill and updates release skill to use it.
Uses the shared SQL classification module to analyze queries.
Allows read-only queries, asks for write operations.

Special handling:
- -readonly and -safe flags always allowed
- SQLite-specific write keywords: PRAGMA, ATTACH, DETACH, VACUUM, REINDEX, ANALYZE
- Interactive mode (no SQL) requires confirmation
- -init script files require confirmation
Analyzes SQL passed via -e/--execute option.
Allows read-only queries, asks for write operations.

MySQL-specific write keyword: LOAD (for LOAD DATA)
Interactive mode (no -e) requires confirmation.
Analyzes SQL passed via -c/--command options.
Supports multiple -c options (all must be read-only).
Allows --list/-l for listing databases.

PostgreSQL-specific write keywords: COPY, VACUUM, CLUSTER, REINDEX, ANALYZE
Interactive mode and file input (-f) require confirmation.
Similar to sqlite3 - supports -readonly and -safe flags.
Analyzes SQL from positional args, -c, -s, and -cmd options.

DuckDB-specific write keywords: PRAGMA, ATTACH, DETACH, VACUUM, COPY, EXPORT, IMPORT
Supports the modern go-sqlcmd CLI for SQL Server.
Analyzes SQL in 'query' subcommand.

Safe: config, open, help, completion, read-only queries
Unsafe: create, install, delete, start, stop, write queries
- sqlite3: -lookaside takes TWO arguments (SIZE N), not one
- duckdb: -newline and -nullvalue take arguments, not no-arg flags

Added regression tests for these cases.
@ldayton ldayton merged commit 14e78ce into main Jan 24, 2026
1 check passed
@ldayton ldayton deleted the add-sql-classification-module branch January 24, 2026 15:41
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.

1 participant