Skip to content

Commit 65db39a

Browse files
committed
refactor: move dialect-specific logic to dialects and replace mssql alias with sqlsrv
- Move monitoring methods (getActiveQueries, getActiveConnections, getSlowQueries) to DialectInterface - Move listTables method to DialectInterface - Move error handling methods (getRetryableErrorCodes, getErrorDescription) to DialectInterface - Move getInsertSelectColumns method to DialectInterface for MSSQL IDENTITY handling - Move config methods (buildConfigFromEnv, normalizeConfigParams) to DialectInterface - Add formatConcatExpression method to DialectInterface for dialect-specific concatenation - Refactor MonitorManager to use dialect methods instead of match/case - Refactor TableManager to use dialect->listTables() instead of if statements - Refactor ErrorUtilityTrait to use trait methods with dialect fallback - Refactor FileLoader to use dialect->quoteIdentifier() instead of match - Refactor DmlQueryBuilder to use dialect->getInsertSelectColumns() - Refactor DialectAbstract::concat() to use formatConcatExpression() - Refactor InitWizard and BaseCliCommand to use dialect->buildConfigFromEnv() - Remove mssql alias from DialectRegistry (use only sqlsrv) - Remove mssql->sqlsrv normalization from BaseCliCommand, InitWizard, ErrorUtilityTrait - Rename config.mssql.php to config.sqlsrv.php - Update all references to use sqlsrv driver name - Update examples and documentation to use sqlsrv instead of mssql This refactoring follows Open/Closed Principle - new dialects can be added without modifying common classes.
1 parent 7d9d0b2 commit 65db39a

29 files changed

+1348
-285
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ PDODB_DRIVER=mysql php 01-basic/02-simple-crud.php
300300
# PostgreSQL (update config.pgsql.php with your credentials)
301301
PDODB_DRIVER=pgsql php 01-basic/02-simple-crud.php
302302

303-
# Microsoft SQL Server (update config.mssql.php with your credentials)
303+
# Microsoft SQL Server (update config.sqlsrv.php with your credentials)
304304
PDODB_DRIVER=sqlsrv php 01-basic/02-simple-crud.php
305305

306306
# Test all examples on all available databases
@@ -312,7 +312,7 @@ PDODB_DRIVER=sqlsrv php 01-basic/02-simple-crud.php
312312
- `mysql` - uses `config.mysql.php`
313313
- `mariadb` - uses `config.mariadb.php`
314314
- `pgsql` - uses `config.pgsql.php`
315-
- `sqlsrv` - uses `config.mssql.php`
315+
- `sqlsrv` - uses `config.sqlsrv.php`
316316

317317
If config file is missing, falls back to SQLite.
318318

examples/01-basic/01-connection.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function tryConnect($driver, $configFile) {
8282

8383
// Example 4: Microsoft SQL Server Connection (if config exists)
8484
echo "4. Connecting to Microsoft SQL Server...\n";
85-
$mssqlConfig = __DIR__ . '/../config.mssql.php';
85+
$mssqlConfig = __DIR__ . '/../config.sqlsrv.php';
8686
$mssql = tryConnect('sqlsrv', $mssqlConfig);
8787

8888
if ($mssql instanceof PdoDb) {
@@ -91,10 +91,10 @@ function tryConnect($driver, $configFile) {
9191
echo " Server: {$config['host']}:{$config['port']}\n";
9292
echo " Database: {$config['dbname']}\n\n";
9393
} elseif ($mssql === false) {
94-
echo " (Check your MSSQL server and config.mssql.php settings)\n\n";
94+
echo " (Check your MSSQL server and config.sqlsrv.php settings)\n\n";
9595
} else {
9696
echo " ℹ️ Config not found: $mssqlConfig\n";
97-
echo " (This is OK - MSSQL is optional. Create config.mssql.php to test)\n\n";
97+
echo " (This is OK - MSSQL is optional. Create config.sqlsrv.php to test)\n\n";
9898
}
9999

100100
// Example 5: Connection pooling (without default connection)
@@ -119,4 +119,4 @@ function tryConnect($driver, $configFile) {
119119
echo "$result\n\n";
120120

121121
echo "All connection examples completed!\n";
122-
echo "\nℹ️ Tip: Create config.mysql.php, config.pgsql.php, and config.mssql.php to test all databases\n";
122+
echo "\nℹ️ Tip: Create config.mysql.php, config.pgsql.php, and config.sqlsrv.php to test all databases\n";

examples/01-basic/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ PDODB_DRIVER=pgsql php 01-connection.php
8080

8181
### MSSQL
8282
```bash
83-
PDODB_DRIVER=mssql php 01-connection.php
83+
PDODB_DRIVER=sqlsrv php 01-connection.php
8484
```
8585

8686
## Next Steps

examples/03-advanced/07-window-functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
$driverEnv = getenv('PDODB_DRIVER') ?: 'mysql';
1010
$config = getExampleConfig();
11-
$driver = $config['driver'] ?? $driverEnv; // Use driver from config (converts mssql to sqlsrv)
11+
$driver = $config['driver'] ?? $driverEnv;
1212

1313
echo "=== Window Functions Examples ===\n\n";
1414
echo "Database: $driver\n\n";

examples/03-advanced/08-basic-cte.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
$driverEnv = getenv('PDODB_DRIVER') ?: 'sqlite';
1212
$config = getExampleConfig();
13-
$driver = $config['driver'] ?? $driverEnv; // Use driver from config (converts mssql to sqlsrv)
13+
$driver = $config['driver'] ?? $driverEnv;
1414

1515
echo "=== Common Table Expressions (CTEs) Examples ===\n\n";
1616
echo "Database: $driver\n\n";

examples/03-advanced/09-recursive-cte.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
$driverEnv = getenv('PDODB_DRIVER') ?: 'sqlite';
1212
$config = getExampleConfig();
13-
$driver = $config['driver'] ?? $driverEnv; // Use driver from config (converts mssql to sqlsrv)
13+
$driver = $config['driver'] ?? $driverEnv;
1414

1515
echo "=== Recursive CTE Examples ===\n\n";
1616
echo "Database: $driver\n\n";

examples/08-architecture/01-read-write-splitting.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
$driverEnv = getenv('PDODB_DRIVER') ?: 'mysql';
1919
$config = getExampleConfig();
20-
// Use driver from config (converts mssql to sqlsrv)
2120
$driver = $config['driver'] ?? $driverEnv;
2221

2322
// For SQLite, use a temporary file instead of :memory: for read/write splitting

examples/08-architecture/04-sticky-writes.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
$driverEnv = getenv('PDODB_DRIVER') ?: 'mysql';
1919
$config = getExampleConfig();
20-
// Use driver from config (converts mssql to sqlsrv)
2120
$driver = $config['driver'] ?? $driverEnv;
2221

2322
// For SQLite, use a temporary file instead of :memory: for read/write splitting

examples/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ PDODB_DRIVER=pgsql php 01-basic/02-simple-crud.php
4242

4343
### Option 5: Microsoft SQL Server (MSSQL)
4444
```bash
45-
# Edit config.mssql.php with your credentials
45+
# Edit config.sqlsrv.php with your credentials
4646
# File already exists in examples/ directory
47-
nano config.mssql.php
47+
nano config.sqlsrv.php
4848

4949
# Run with MSSQL
50-
PDODB_DRIVER=mssql php 01-basic/02-simple-crud.php
50+
PDODB_DRIVER=sqlsrv php 01-basic/02-simple-crud.php
5151
```
5252

5353
### Test All Examples on All Databases
@@ -69,14 +69,14 @@ PDOdb examples use **separate config files per database**:
6969
| `config.mysql.php` | MySQL | ✅ Included, update credentials |
7070
| `config.mariadb.php` | MariaDB | ✅ Included, update credentials |
7171
| `config.pgsql.php` | PostgreSQL | ✅ Included, update credentials |
72-
| `config.mssql.php` | Microsoft SQL Server | ✅ Included, update credentials |
72+
| `config.sqlsrv.php` | Microsoft SQL Server | ✅ Included, update credentials |
7373

7474
**Environment variable `PDODB_DRIVER`** controls which config to use:
7575
- `sqlite` (default) - loads `config.sqlite.php`
7676
- `mysql` - loads `config.mysql.php`
7777
- `mariadb` - loads `config.mariadb.php`
7878
- `pgsql` - loads `config.pgsql.php`
79-
- `mssql` - loads `config.mssql.php`
79+
- `sqlsrv` - loads `config.sqlsrv.php`
8080

8181
**No environment variable?** Defaults to SQLite with `:memory:` database.
8282

0 commit comments

Comments
 (0)