Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 20, 2025

Add SQLite compatibility to wp db commands

This PR implements SQLite support for database commands when using the SQLite Database Integration plugin. Commands now detect SQLite via DB_ENGINE constant, SQLITE_DB_DROPIN_VERSION, or db.php drop-in inspection.

Changes

  • New DB_Command_SQLite trait - Isolated SQLite operations using PDO:

    • create/drop/reset - File-based database lifecycle with sqlite3 binary
    • query - Direct PDO execution with formatted output (now supports --skip-column-names)
    • export/import - SQL dump/restore with proper identifier escaping
    • size - File size calculation
    • Database path resolution supporting FQDB, FQDBDIR, DB_FILE constants
  • Modified DB_Command methods - Detect SQLite and route accordingly:

    • create, drop, reset, query, export, import - Full SQLite implementation
    • size - SQLite file size vs MySQL information_schema query
    • check, optimize, repair, cli - Warning messages (not applicable to SQLite)
    • tables, prefix, columns, search, clean - Unchanged (work via $wpdb)
  • Test scenarios - Updated to support SQLite for --skip-column-names flag

  • Documentation (README.md) - Supported commands, configuration, detection methods

Security Updates

  • Fixed command injection vulnerabilities: All sqlite3 CLI commands now use Utils\esc_cmd to properly escape arguments
  • Added sqlite3 binary check: Preflight validation with clear error messages if sqlite3 is not installed

Recent Updates

  • Added --skip-column-names support for SQLite: The sqlite_query() method now accepts $assoc_args and respects the --skip-column-names flag
  • Replaced custom display_table() with Formatter class: Using the standard WP-CLI Formatter class for consistency with other commands
  • Updated tests: Removed MySQL-only restriction from --skip-column-names test as SQLite now supports it

Example Usage

# Works automatically when SQLite is detected
wp db query "SELECT * FROM wp_posts"
wp db query "SELECT * FROM wp_posts" --skip-column-names
wp db export backup.sql
wp db size

Technical Notes

  • Requires sqlite3 CLI binary for create/drop/reset/export/import operations
  • PDO used for query execution, enabling functionality at after_wp_config_load stage
  • SQLite identifiers escaped with double-quotes, values via PDO::quote()
  • Default database path: wp-content/database/.ht.sqlite
  • Full backward compatibility - MySQL/MariaDB code paths unchanged
  • Uses WP-CLI Formatter class for query output formatting
  • All shell commands properly escaped using Utils\esc_cmd

Fixes #234


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 4 commits November 20, 2025 16:30
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Add SQLite compatibility to wp db commands Add SQLite compatibility to wp db commands Nov 20, 2025
Copilot AI requested a review from swissspidy November 20, 2025 16:41
@codecov
Copy link

codecov bot commented Nov 20, 2025

Codecov Report

❌ Patch coverage is 15.45741% with 268 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/DB_Command_SQLite.php 4.23% 226 Missing ⚠️
src/DB_Command.php 48.14% 42 Missing ⚠️

📢 Thoughts on this report? Let us know!

This comment was marked as resolved.

This comment was marked as resolved.

swissspidy and others added 5 commits February 11, 2026 12:32
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI and others added 2 commits February 11, 2026 11:44
- Use Utils\esc_cmd to properly escape database path arguments
- Add is_sqlite3_available() helper to check for sqlite3 binary
- Add preflight check with clear error message if sqlite3 not found
- Addresses security concerns about unescaped shell commands

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
@swissspidy

This comment was marked as resolved.

gemini-code-assist[bot]

This comment was marked as resolved.

@swissspidy swissspidy marked this pull request as ready for review February 11, 2026 13:00
@swissspidy swissspidy requested a review from a team as a code owner February 11, 2026 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add SQLite compatibility to wp db commands

2 participants