A comprehensive command-line interface for SQLite database interaction, designed for developers and data analysts who need robust, user-friendly database querying capabilities.
- Secure Database Connections: Connect to SQLite databases with error handling
- Interactive SQL Execution: Execute SELECT, INSERT, UPDATE, DELETE queries
- Multiple Output Formats: Save results as CSV, JSON, or plain text
- Query History: Track and review previously executed queries
- Result Pagination: Handle large result sets with configurable page sizes
- Table Management: List tables and describe table structures
- Intuitive Commands: Simple, memorable command syntax
- Rich Feedback: Clear success/error messages with emojis
- Professional Interface: Clean, organized output formatting
- Error Handling: Graceful handling of connection and query errors
- Ensure you have Python 3.6+ installed
- No additional dependencies required (uses built-in libraries)
- Download the CLI tool files
```bash python demo_setup.py ```
```bash python run_cli.py ```
``` sqlcli> connect sample_data.sqlite ```
``` sqlcli> query SELECT * FROM users WHERE age > 25 sqlcli> query INSERT INTO users (username, email, age) VALUES ('newuser', 'new@example.com', 30) ```
connect <database_path>- Connect to SQLite databasequery <SQL_STATEMENT>- Execute SQL querytables- Show all tables in databasedescribe <table_name>- Show table structure
save <filename> [format]- Save last results (csv/json/txt)pagesize <number>- Set result pagination sizehistory [limit]- Show query history
status- Show connection status and statisticsclear- Clear screenhelp- Show available commandsexit/quit- Exit the CLI
```sql -- Select data with filtering sqlcli> query SELECT username, email, age FROM users WHERE city = 'New York'
-- Join tables sqlcli> query SELECT u.username, COUNT(o.id) as order_count FROM users u LEFT JOIN orders o ON u.id = o.user_id GROUP BY u.id
-- Update records sqlcli> query UPDATE users SET age = 29 WHERE username = 'john_doe'
-- Insert new data sqlcli> query INSERT INTO products (name, category, price) VALUES ('New Product', 'Electronics', 99.99) ```
```bash
sqlcli> save user_report.csv
sqlcli> save data_export.json json
sqlcli> save results.txt txt ```
```bash
sqlcli> tables
sqlcli> describe users
sqlcli> status ```
- Standard comma-separated values
- Headers included
- UTF-8 encoding
- Pretty-printed JSON array
- Each row as an object
- Proper data type handling
- Formatted table layout
- Column alignment
- Human-readable structure
The CLI provides comprehensive error handling for:
- Connection Errors: Invalid database paths, permissions
- SQL Errors: Syntax errors, constraint violations
- File Errors: Save operation failures
- Input Errors: Invalid commands, missing parameters
- Automatic tracking of all executed queries
- Timestamp and execution time recording
- Row count/affected rows tracking
- Configurable history display limits
- Result Pagination: Handle large datasets efficiently
- Optimized Display: Smart column width calculation
- Memory Management: Efficient result storage
- Fast Execution: Direct SQLite integration
- Local Database Access: Only works with local SQLite files
- No Network Exposure: CLI runs locally only
- Safe SQL Execution: Uses parameterized queries where applicable
- Error Information: Detailed but safe error messages
-
Database Not Found ``` ❌ Database connection error: unable to open database file ```
- Check file path spelling
- Ensure directory exists
- Verify file permissions
-
SQL Syntax Error ``` ❌ SQL Error: near "SELCT": syntax error ```
- Review SQL syntax
- Check table/column names
- Use
describecommand to verify structure
-
Permission Denied ``` ❌ Error saving file: [Errno 13] Permission denied ```
- Check write permissions
- Ensure directory exists
- Try different output location
```sql -- Create and populate table in sequence sqlcli> query CREATE TABLE temp_data (id INTEGER, value TEXT) sqlcli> query INSERT INTO temp_data VALUES (1, 'test'), (2, 'data') sqlcli> query SELECT * FROM temp_data ```
```sql -- Analytical queries sqlcli> query SELECT category, AVG(price) as avg_price, COUNT(*) as product_count FROM products GROUP BY category ORDER BY avg_price DESC
-- Subqueries sqlcli> query SELECT * FROM users WHERE id IN (SELECT DISTINCT user_id FROM orders WHERE order_date > '2024-01-01') ```
This CLI tool is designed to be extensible. Key areas for enhancement:
- Additional output formats
- Query result caching
- Batch query execution
- Configuration file support
- Plugin system for custom commands
Open source - feel free to modify and distribute according to your needs.