@@ -2276,46 +2276,38 @@ private function getRemoveColumnSQL(String $tableName, String $columnName): Stri
2276
2276
public function renameTable (String $ tableName , String $ newTableName )
2277
2277
{
2278
2278
$ sql = $ this ->getTableRenameSQL ($ tableName , $ newTableName );
2279
- $ stmt = $ this ->pdo ->prepare ($ sql );
2280
- return $ stmt ->execute ();
2279
+ return $ this ->query ($ sql );
2281
2280
}
2282
2281
2283
2282
public function renameColumn (String $ tableName , String $ columnName , ReflectedColumn $ newColumn )
2284
2283
{
2285
2284
$ sql = $ this ->getColumnRenameSQL ($ tableName , $ columnName , $ newColumn );
2286
- $ stmt = $ this ->pdo ->prepare ($ sql );
2287
- return $ stmt ->execute ();
2285
+ return $ this ->query ($ sql );
2288
2286
}
2289
2287
2290
2288
public function retypeColumn (String $ tableName , String $ columnName , ReflectedColumn $ newColumn )
2291
2289
{
2292
2290
$ sql = $ this ->getColumnRetypeSQL ($ tableName , $ columnName , $ newColumn );
2293
- $ stmt = $ this ->pdo ->prepare ($ sql );
2294
- return $ stmt ->execute ();
2291
+ return $ this ->query ($ sql );
2295
2292
}
2296
2293
2297
2294
public function setColumnNullable (String $ tableName , String $ columnName , ReflectedColumn $ newColumn )
2298
2295
{
2299
2296
$ sql = $ this ->getSetColumnNullableSQL ($ tableName , $ columnName , $ newColumn );
2300
- $ stmt = $ this ->pdo ->prepare ($ sql );
2301
- return $ stmt ->execute ();
2297
+ return $ this ->query ($ sql );
2302
2298
}
2303
2299
2304
2300
public function addColumnPrimaryKey (String $ tableName , String $ columnName , ReflectedColumn $ newColumn )
2305
2301
{
2306
2302
$ sql = $ this ->getSetColumnPkConstraintSQL ($ tableName , $ columnName , $ newColumn );
2307
- $ stmt = $ this ->pdo ->prepare ($ sql );
2308
- $ stmt ->execute ();
2303
+ $ this ->query ($ sql );
2309
2304
if ($ this ->canAutoIncrement ($ newColumn )) {
2310
2305
$ sql = $ this ->getSetColumnPkSequenceSQL ($ tableName , $ columnName , $ newColumn );
2311
- $ stmt = $ this ->pdo ->prepare ($ sql );
2312
- $ stmt ->execute ();
2306
+ $ this ->query ($ sql );
2313
2307
$ sql = $ this ->getSetColumnPkSequenceStartSQL ($ tableName , $ columnName , $ newColumn );
2314
- $ stmt = $ this ->pdo ->prepare ($ sql );
2315
- $ stmt ->execute ();
2308
+ $ this ->query ($ sql );
2316
2309
$ sql = $ this ->getSetColumnPkDefaultSQL ($ tableName , $ columnName , $ newColumn );
2317
- $ stmt = $ this ->pdo ->prepare ($ sql );
2318
- $ stmt ->execute ();
2310
+ $ this ->query ($ sql );
2319
2311
}
2320
2312
return true ;
2321
2313
}
@@ -2324,56 +2316,53 @@ public function removeColumnPrimaryKey(String $tableName, String $columnName, Re
2324
2316
{
2325
2317
if ($ this ->canAutoIncrement ($ newColumn )) {
2326
2318
$ sql = $ this ->getSetColumnPkDefaultSQL ($ tableName , $ columnName , $ newColumn );
2327
- $ stmt = $ this ->pdo ->prepare ($ sql );
2328
- $ stmt ->execute ();
2319
+ $ this ->query ($ sql );
2329
2320
$ sql = $ this ->getSetColumnPkSequenceSQL ($ tableName , $ columnName , $ newColumn );
2330
- $ stmt = $ this ->pdo ->prepare ($ sql );
2331
- $ stmt ->execute ();
2321
+ $ this ->query ($ sql );
2332
2322
}
2333
2323
$ sql = $ this ->getSetColumnPkConstraintSQL ($ tableName , $ columnName , $ newColumn );
2334
- $ stmt = $ this ->pdo ->prepare ($ sql );
2335
- $ stmt ->execute ();
2324
+ $ this ->query ($ sql );
2336
2325
return true ;
2337
2326
}
2338
2327
2339
2328
public function addColumnForeignKey (String $ tableName , String $ columnName , ReflectedColumn $ newColumn )
2340
2329
{
2341
2330
$ sql = $ this ->getAddColumnFkConstraintSQL ($ tableName , $ columnName , $ newColumn );
2342
- $ stmt = $ this ->pdo ->prepare ($ sql );
2343
- return $ stmt ->execute ();
2331
+ return $ this ->query ($ sql );
2344
2332
}
2345
2333
2346
2334
public function removeColumnForeignKey (String $ tableName , String $ columnName , ReflectedColumn $ newColumn )
2347
2335
{
2348
2336
$ sql = $ this ->getRemoveColumnFkConstraintSQL ($ tableName , $ columnName , $ newColumn );
2349
- $ stmt = $ this ->pdo ->prepare ($ sql );
2350
- return $ stmt ->execute ();
2337
+ return $ this ->query ($ sql );
2351
2338
}
2352
2339
2353
2340
public function addTable (ReflectedTable $ newTable )
2354
2341
{
2355
2342
$ sql = $ this ->getAddTableSQL ($ newTable );
2356
- $ stmt = $ this ->pdo ->prepare ($ sql );
2357
- return $ stmt ->execute ();
2343
+ return $ this ->query ($ sql );
2358
2344
}
2359
2345
2360
2346
public function addColumn (String $ tableName , ReflectedColumn $ newColumn )
2361
2347
{
2362
2348
$ sql = $ this ->getAddColumnSQL ($ tableName , $ newColumn );
2363
- $ stmt = $ this ->pdo ->prepare ($ sql );
2364
- return $ stmt ->execute ();
2349
+ return $ this ->query ($ sql );
2365
2350
}
2366
2351
2367
2352
public function removeTable (String $ tableName )
2368
2353
{
2369
2354
$ sql = $ this ->getRemoveTableSQL ($ tableName );
2370
- $ stmt = $ this ->pdo ->prepare ($ sql );
2371
- return $ stmt ->execute ();
2355
+ return $ this ->query ($ sql );
2372
2356
}
2373
2357
2374
2358
public function removeColumn (String $ tableName , String $ columnName )
2375
2359
{
2376
2360
$ sql = $ this ->getRemoveColumnSQL ($ tableName , $ columnName );
2361
+ return $ this ->query ($ sql );
2362
+ }
2363
+
2364
+ private function query (String $ sql ): bool
2365
+ {
2377
2366
$ stmt = $ this ->pdo ->prepare ($ sql );
2378
2367
return $ stmt ->execute ();
2379
2368
}
@@ -2448,23 +2437,20 @@ public function getDatabaseName(): String
2448
2437
2449
2438
public function getTables (): array
2450
2439
{
2451
- $ stmt = $ this ->pdo ->prepare ($ this ->getTablesSQL ());
2452
- $ stmt ->execute ([$ this ->database ]);
2453
- return $ stmt ->fetchAll ();
2440
+ $ sql = $ this ->getTablesSQL ();
2441
+ return $ this ->query ($ sql , [$ this ->database ]);
2454
2442
}
2455
2443
2456
2444
public function getTableColumns (String $ tableName ): array
2457
2445
{
2458
- $ stmt = $ this ->pdo ->prepare ($ this ->getTableColumnsSQL ());
2459
- $ stmt ->execute ([$ tableName , $ this ->database ]);
2460
- return $ stmt ->fetchAll ();
2446
+ $ sql = $ this ->getTableColumnsSQL ();
2447
+ return $ this ->query ($ sql , [$ tableName , $ this ->database ]);
2461
2448
}
2462
2449
2463
2450
public function getTablePrimaryKeys (String $ tableName ): array
2464
2451
{
2465
- $ stmt = $ this ->pdo ->prepare ($ this ->getTablePrimaryKeysSQL ());
2466
- $ stmt ->execute ([$ tableName , $ this ->database ]);
2467
- $ results = $ stmt ->fetchAll ();
2452
+ $ sql = $ this ->getTablePrimaryKeysSQL ();
2453
+ $ results = $ this ->query ($ sql , [$ tableName , $ this ->database ]);
2468
2454
$ primaryKeys = [];
2469
2455
foreach ($ results as $ result ) {
2470
2456
$ primaryKeys [] = $ result ['COLUMN_NAME ' ];
@@ -2474,9 +2460,8 @@ public function getTablePrimaryKeys(String $tableName): array
2474
2460
2475
2461
public function getTableForeignKeys (String $ tableName ): array
2476
2462
{
2477
- $ stmt = $ this ->pdo ->prepare ($ this ->getTableForeignKeysSQL ());
2478
- $ stmt ->execute ([$ tableName , $ this ->database ]);
2479
- $ results = $ stmt ->fetchAll ();
2463
+ $ sql = $ this ->getTableForeignKeysSQL ();
2464
+ $ results = $ this ->query ($ sql , [$ tableName , $ this ->database ]);
2480
2465
$ foreignKeys = [];
2481
2466
foreach ($ results as $ result ) {
2482
2467
$ foreignKeys [$ result ['COLUMN_NAME ' ]] = $ result ['REFERENCED_TABLE_NAME ' ];
@@ -2488,6 +2473,13 @@ public function toJdbcType(String $type, int $size): String
2488
2473
{
2489
2474
return $ this ->typeConverter ->toJdbc ($ type , $ size );
2490
2475
}
2476
+
2477
+ private function query (String $ sql , array $ parameters ): array
2478
+ {
2479
+ $ stmt = $ this ->pdo ->prepare ($ sql );
2480
+ $ stmt ->execute ($ parameters );
2481
+ return $ stmt ->fetchAll ();
2482
+ }
2491
2483
}
2492
2484
2493
2485
// file: src/Tqdev/PhpCrudApi/Database/TypeConverter.php
0 commit comments