@@ -2276,46 +2276,38 @@ private function getRemoveColumnSQL(String $tableName, String $columnName): Stri
22762276 public function renameTable (String $ tableName , String $ newTableName )
22772277 {
22782278 $ sql = $ this ->getTableRenameSQL ($ tableName , $ newTableName );
2279- $ stmt = $ this ->pdo ->prepare ($ sql );
2280- return $ stmt ->execute ();
2279+ return $ this ->query ($ sql );
22812280 }
22822281
22832282 public function renameColumn (String $ tableName , String $ columnName , ReflectedColumn $ newColumn )
22842283 {
22852284 $ sql = $ this ->getColumnRenameSQL ($ tableName , $ columnName , $ newColumn );
2286- $ stmt = $ this ->pdo ->prepare ($ sql );
2287- return $ stmt ->execute ();
2285+ return $ this ->query ($ sql );
22882286 }
22892287
22902288 public function retypeColumn (String $ tableName , String $ columnName , ReflectedColumn $ newColumn )
22912289 {
22922290 $ sql = $ this ->getColumnRetypeSQL ($ tableName , $ columnName , $ newColumn );
2293- $ stmt = $ this ->pdo ->prepare ($ sql );
2294- return $ stmt ->execute ();
2291+ return $ this ->query ($ sql );
22952292 }
22962293
22972294 public function setColumnNullable (String $ tableName , String $ columnName , ReflectedColumn $ newColumn )
22982295 {
22992296 $ sql = $ this ->getSetColumnNullableSQL ($ tableName , $ columnName , $ newColumn );
2300- $ stmt = $ this ->pdo ->prepare ($ sql );
2301- return $ stmt ->execute ();
2297+ return $ this ->query ($ sql );
23022298 }
23032299
23042300 public function addColumnPrimaryKey (String $ tableName , String $ columnName , ReflectedColumn $ newColumn )
23052301 {
23062302 $ sql = $ this ->getSetColumnPkConstraintSQL ($ tableName , $ columnName , $ newColumn );
2307- $ stmt = $ this ->pdo ->prepare ($ sql );
2308- $ stmt ->execute ();
2303+ $ this ->query ($ sql );
23092304 if ($ this ->canAutoIncrement ($ newColumn )) {
23102305 $ sql = $ this ->getSetColumnPkSequenceSQL ($ tableName , $ columnName , $ newColumn );
2311- $ stmt = $ this ->pdo ->prepare ($ sql );
2312- $ stmt ->execute ();
2306+ $ this ->query ($ sql );
23132307 $ sql = $ this ->getSetColumnPkSequenceStartSQL ($ tableName , $ columnName , $ newColumn );
2314- $ stmt = $ this ->pdo ->prepare ($ sql );
2315- $ stmt ->execute ();
2308+ $ this ->query ($ sql );
23162309 $ sql = $ this ->getSetColumnPkDefaultSQL ($ tableName , $ columnName , $ newColumn );
2317- $ stmt = $ this ->pdo ->prepare ($ sql );
2318- $ stmt ->execute ();
2310+ $ this ->query ($ sql );
23192311 }
23202312 return true ;
23212313 }
@@ -2324,56 +2316,53 @@ public function removeColumnPrimaryKey(String $tableName, String $columnName, Re
23242316 {
23252317 if ($ this ->canAutoIncrement ($ newColumn )) {
23262318 $ sql = $ this ->getSetColumnPkDefaultSQL ($ tableName , $ columnName , $ newColumn );
2327- $ stmt = $ this ->pdo ->prepare ($ sql );
2328- $ stmt ->execute ();
2319+ $ this ->query ($ sql );
23292320 $ sql = $ this ->getSetColumnPkSequenceSQL ($ tableName , $ columnName , $ newColumn );
2330- $ stmt = $ this ->pdo ->prepare ($ sql );
2331- $ stmt ->execute ();
2321+ $ this ->query ($ sql );
23322322 }
23332323 $ sql = $ this ->getSetColumnPkConstraintSQL ($ tableName , $ columnName , $ newColumn );
2334- $ stmt = $ this ->pdo ->prepare ($ sql );
2335- $ stmt ->execute ();
2324+ $ this ->query ($ sql );
23362325 return true ;
23372326 }
23382327
23392328 public function addColumnForeignKey (String $ tableName , String $ columnName , ReflectedColumn $ newColumn )
23402329 {
23412330 $ sql = $ this ->getAddColumnFkConstraintSQL ($ tableName , $ columnName , $ newColumn );
2342- $ stmt = $ this ->pdo ->prepare ($ sql );
2343- return $ stmt ->execute ();
2331+ return $ this ->query ($ sql );
23442332 }
23452333
23462334 public function removeColumnForeignKey (String $ tableName , String $ columnName , ReflectedColumn $ newColumn )
23472335 {
23482336 $ sql = $ this ->getRemoveColumnFkConstraintSQL ($ tableName , $ columnName , $ newColumn );
2349- $ stmt = $ this ->pdo ->prepare ($ sql );
2350- return $ stmt ->execute ();
2337+ return $ this ->query ($ sql );
23512338 }
23522339
23532340 public function addTable (ReflectedTable $ newTable )
23542341 {
23552342 $ sql = $ this ->getAddTableSQL ($ newTable );
2356- $ stmt = $ this ->pdo ->prepare ($ sql );
2357- return $ stmt ->execute ();
2343+ return $ this ->query ($ sql );
23582344 }
23592345
23602346 public function addColumn (String $ tableName , ReflectedColumn $ newColumn )
23612347 {
23622348 $ sql = $ this ->getAddColumnSQL ($ tableName , $ newColumn );
2363- $ stmt = $ this ->pdo ->prepare ($ sql );
2364- return $ stmt ->execute ();
2349+ return $ this ->query ($ sql );
23652350 }
23662351
23672352 public function removeTable (String $ tableName )
23682353 {
23692354 $ sql = $ this ->getRemoveTableSQL ($ tableName );
2370- $ stmt = $ this ->pdo ->prepare ($ sql );
2371- return $ stmt ->execute ();
2355+ return $ this ->query ($ sql );
23722356 }
23732357
23742358 public function removeColumn (String $ tableName , String $ columnName )
23752359 {
23762360 $ sql = $ this ->getRemoveColumnSQL ($ tableName , $ columnName );
2361+ return $ this ->query ($ sql );
2362+ }
2363+
2364+ private function query (String $ sql ): bool
2365+ {
23772366 $ stmt = $ this ->pdo ->prepare ($ sql );
23782367 return $ stmt ->execute ();
23792368 }
@@ -2448,23 +2437,20 @@ public function getDatabaseName(): String
24482437
24492438 public function getTables (): array
24502439 {
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 ]);
24542442 }
24552443
24562444 public function getTableColumns (String $ tableName ): array
24572445 {
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 ]);
24612448 }
24622449
24632450 public function getTablePrimaryKeys (String $ tableName ): array
24642451 {
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 ]);
24682454 $ primaryKeys = [];
24692455 foreach ($ results as $ result ) {
24702456 $ primaryKeys [] = $ result ['COLUMN_NAME ' ];
@@ -2474,9 +2460,8 @@ public function getTablePrimaryKeys(String $tableName): array
24742460
24752461 public function getTableForeignKeys (String $ tableName ): array
24762462 {
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 ]);
24802465 $ foreignKeys = [];
24812466 foreach ($ results as $ result ) {
24822467 $ foreignKeys [$ result ['COLUMN_NAME ' ]] = $ result ['REFERENCED_TABLE_NAME ' ];
@@ -2488,6 +2473,13 @@ public function toJdbcType(String $type, int $size): String
24882473 {
24892474 return $ this ->typeConverter ->toJdbc ($ type , $ size );
24902475 }
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+ }
24912483}
24922484
24932485// file: src/Tqdev/PhpCrudApi/Database/TypeConverter.php
0 commit comments