Complex classes like Connection often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Connection, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 60 | class Connection implements DriverConnection |
||
| 61 | { |
||
| 62 | /** |
||
| 63 | * Constant for transaction isolation level READ UNCOMMITTED. |
||
| 64 | * |
||
| 65 | * @deprecated Use TransactionIsolationLevel::READ_UNCOMMITTED. |
||
| 66 | */ |
||
| 67 | public const TRANSACTION_READ_UNCOMMITTED = TransactionIsolationLevel::READ_UNCOMMITTED; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Constant for transaction isolation level READ COMMITTED. |
||
| 71 | * |
||
| 72 | * @deprecated Use TransactionIsolationLevel::READ_COMMITTED. |
||
| 73 | */ |
||
| 74 | public const TRANSACTION_READ_COMMITTED = TransactionIsolationLevel::READ_COMMITTED; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Constant for transaction isolation level REPEATABLE READ. |
||
| 78 | * |
||
| 79 | * @deprecated Use TransactionIsolationLevel::REPEATABLE_READ. |
||
| 80 | */ |
||
| 81 | public const TRANSACTION_REPEATABLE_READ = TransactionIsolationLevel::REPEATABLE_READ; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Constant for transaction isolation level SERIALIZABLE. |
||
| 85 | * |
||
| 86 | * @deprecated Use TransactionIsolationLevel::SERIALIZABLE. |
||
| 87 | */ |
||
| 88 | public const TRANSACTION_SERIALIZABLE = TransactionIsolationLevel::SERIALIZABLE; |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Represents an array of ints to be expanded by Doctrine SQL parsing. |
||
| 92 | * |
||
| 93 | * @var int |
||
| 94 | */ |
||
| 95 | public const PARAM_INT_ARRAY = ParameterType::INTEGER + self::ARRAY_PARAM_OFFSET; |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Represents an array of strings to be expanded by Doctrine SQL parsing. |
||
| 99 | * |
||
| 100 | * @var int |
||
| 101 | */ |
||
| 102 | public const PARAM_STR_ARRAY = ParameterType::STRING + self::ARRAY_PARAM_OFFSET; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * Offset by which PARAM_* constants are detected as arrays of the param type. |
||
| 106 | * |
||
| 107 | * @var int |
||
| 108 | */ |
||
| 109 | const ARRAY_PARAM_OFFSET = 100; |
||
| 110 | |||
| 111 | /** |
||
| 112 | * The wrapped driver connection. |
||
| 113 | * |
||
| 114 | * @var \Doctrine\DBAL\Driver\Connection|null |
||
| 115 | */ |
||
| 116 | protected $_conn; |
||
| 117 | |||
| 118 | /** |
||
| 119 | * @var \Doctrine\DBAL\Configuration |
||
| 120 | */ |
||
| 121 | protected $_config; |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @var \Doctrine\Common\EventManager |
||
| 125 | */ |
||
| 126 | protected $_eventManager; |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @var \Doctrine\DBAL\Query\Expression\ExpressionBuilder |
||
| 130 | */ |
||
| 131 | protected $_expr; |
||
| 132 | |||
| 133 | /** |
||
| 134 | * Whether or not a connection has been established. |
||
| 135 | * |
||
| 136 | * @var bool |
||
| 137 | */ |
||
| 138 | private $_isConnected = false; |
||
| 139 | |||
| 140 | /** |
||
| 141 | * The current auto-commit mode of this connection. |
||
| 142 | * |
||
| 143 | * @var bool |
||
| 144 | */ |
||
| 145 | private $autoCommit = true; |
||
| 146 | |||
| 147 | /** |
||
| 148 | * The transaction nesting level. |
||
| 149 | * |
||
| 150 | * @var int |
||
| 151 | */ |
||
| 152 | private $_transactionNestingLevel = 0; |
||
| 153 | |||
| 154 | /** |
||
| 155 | * The currently active transaction isolation level. |
||
| 156 | * |
||
| 157 | * @var int |
||
| 158 | */ |
||
| 159 | private $_transactionIsolationLevel; |
||
| 160 | |||
| 161 | /** |
||
| 162 | * If nested transactions should use savepoints. |
||
| 163 | * |
||
| 164 | * @var bool |
||
| 165 | */ |
||
| 166 | private $_nestTransactionsWithSavepoints = false; |
||
| 167 | |||
| 168 | /** |
||
| 169 | * The parameters used during creation of the Connection instance. |
||
| 170 | * |
||
| 171 | * @var array |
||
| 172 | */ |
||
| 173 | private $_params = []; |
||
| 174 | |||
| 175 | /** |
||
| 176 | * The DatabasePlatform object that provides information about the |
||
| 177 | * database platform used by the connection. |
||
| 178 | * |
||
| 179 | * @var \Doctrine\DBAL\Platforms\AbstractPlatform |
||
| 180 | */ |
||
| 181 | private $platform; |
||
| 182 | |||
| 183 | /** |
||
| 184 | * The schema manager. |
||
| 185 | * |
||
| 186 | * @var \Doctrine\DBAL\Schema\AbstractSchemaManager |
||
| 187 | */ |
||
| 188 | protected $_schemaManager; |
||
| 189 | |||
| 190 | /** |
||
| 191 | * The used DBAL driver. |
||
| 192 | * |
||
| 193 | * @var \Doctrine\DBAL\Driver |
||
| 194 | */ |
||
| 195 | protected $_driver; |
||
| 196 | |||
| 197 | /** |
||
| 198 | * Flag that indicates whether the current transaction is marked for rollback only. |
||
| 199 | * |
||
| 200 | * @var bool |
||
| 201 | */ |
||
| 202 | private $_isRollbackOnly = false; |
||
| 203 | |||
| 204 | /** |
||
| 205 | * @var int |
||
| 206 | */ |
||
| 207 | protected $defaultFetchMode = FetchMode::ASSOCIATIVE; |
||
| 208 | |||
| 209 | /** |
||
| 210 | * Initializes a new instance of the Connection class. |
||
| 211 | * |
||
| 212 | * @param array $params The connection parameters. |
||
| 213 | * @param \Doctrine\DBAL\Driver $driver The driver to use. |
||
| 214 | * @param \Doctrine\DBAL\Configuration|null $config The configuration, optional. |
||
| 215 | * @param \Doctrine\Common\EventManager|null $eventManager The event manager, optional. |
||
| 216 | * |
||
| 217 | * @throws \Doctrine\DBAL\DBALException |
||
| 218 | */ |
||
| 219 | public function __construct(array $params, Driver $driver, Configuration $config = null, |
||
| 256 | |||
| 257 | /** |
||
| 258 | * Gets the parameters used during instantiation. |
||
| 259 | * |
||
| 260 | * @return array |
||
| 261 | */ |
||
| 262 | public function getParams() |
||
| 266 | |||
| 267 | /** |
||
| 268 | * Gets the name of the database this Connection is connected to. |
||
| 269 | * |
||
| 270 | * @return string |
||
| 271 | */ |
||
| 272 | public function getDatabase() |
||
| 276 | |||
| 277 | /** |
||
| 278 | * Gets the hostname of the currently connected database. |
||
| 279 | * |
||
| 280 | * @return string|null |
||
| 281 | */ |
||
| 282 | public function getHost() |
||
| 286 | |||
| 287 | /** |
||
| 288 | * Gets the port of the currently connected database. |
||
| 289 | * |
||
| 290 | * @return mixed |
||
| 291 | */ |
||
| 292 | public function getPort() |
||
| 296 | |||
| 297 | /** |
||
| 298 | * Gets the username used by this connection. |
||
| 299 | * |
||
| 300 | * @return string|null |
||
| 301 | */ |
||
| 302 | public function getUsername() |
||
| 306 | |||
| 307 | /** |
||
| 308 | * Gets the password used by this connection. |
||
| 309 | * |
||
| 310 | * @return string|null |
||
| 311 | */ |
||
| 312 | public function getPassword() |
||
| 316 | |||
| 317 | /** |
||
| 318 | * Gets the DBAL driver instance. |
||
| 319 | * |
||
| 320 | * @return \Doctrine\DBAL\Driver |
||
| 321 | */ |
||
| 322 | public function getDriver() |
||
| 326 | |||
| 327 | /** |
||
| 328 | * Gets the Configuration used by the Connection. |
||
| 329 | * |
||
| 330 | * @return \Doctrine\DBAL\Configuration |
||
| 331 | */ |
||
| 332 | public function getConfiguration() |
||
| 336 | |||
| 337 | /** |
||
| 338 | * Gets the EventManager used by the Connection. |
||
| 339 | * |
||
| 340 | * @return \Doctrine\Common\EventManager |
||
| 341 | */ |
||
| 342 | public function getEventManager() |
||
| 346 | |||
| 347 | /** |
||
| 348 | * Gets the DatabasePlatform for the connection. |
||
| 349 | * |
||
| 350 | * @return \Doctrine\DBAL\Platforms\AbstractPlatform |
||
| 351 | * |
||
| 352 | * @throws \Doctrine\DBAL\DBALException |
||
| 353 | */ |
||
| 354 | public function getDatabasePlatform() |
||
| 362 | |||
| 363 | /** |
||
| 364 | * Gets the ExpressionBuilder for the connection. |
||
| 365 | * |
||
| 366 | * @return \Doctrine\DBAL\Query\Expression\ExpressionBuilder |
||
| 367 | */ |
||
| 368 | public function getExpressionBuilder() |
||
| 372 | |||
| 373 | /** |
||
| 374 | * Establishes the connection with the database. |
||
| 375 | * |
||
| 376 | * @return bool TRUE if the connection was successfully established, FALSE if |
||
| 377 | * the connection is already open. |
||
| 378 | */ |
||
| 379 | public function connect() |
||
| 403 | |||
| 404 | /** |
||
| 405 | * Detects and sets the database platform. |
||
| 406 | * |
||
| 407 | * Evaluates custom platform class and version in order to set the correct platform. |
||
| 408 | * |
||
| 409 | * @throws DBALException if an invalid platform was specified for this connection. |
||
| 410 | */ |
||
| 411 | private function detectDatabasePlatform() |
||
| 425 | |||
| 426 | /** |
||
| 427 | * Returns the version of the related platform if applicable. |
||
| 428 | * |
||
| 429 | * Returns null if either the driver is not capable to create version |
||
| 430 | * specific platform instances, no explicit server version was specified |
||
| 431 | * or the underlying driver connection cannot determine the platform |
||
| 432 | * version without having to query it (performance reasons). |
||
| 433 | * |
||
| 434 | * @return string|null |
||
| 435 | * |
||
| 436 | * @throws Exception |
||
| 437 | */ |
||
| 438 | private function getDatabasePlatformVersion() |
||
| 489 | |||
| 490 | /** |
||
| 491 | * Returns the database server version if the underlying driver supports it. |
||
| 492 | * |
||
| 493 | * @return string|null |
||
| 494 | */ |
||
| 495 | private function getServerVersion() |
||
| 507 | |||
| 508 | /** |
||
| 509 | * Returns the current auto-commit mode for this connection. |
||
| 510 | * |
||
| 511 | * @return bool True if auto-commit mode is currently enabled for this connection, false otherwise. |
||
| 512 | * |
||
| 513 | * @see setAutoCommit |
||
| 514 | */ |
||
| 515 | public function isAutoCommit() |
||
| 519 | |||
| 520 | /** |
||
| 521 | * Sets auto-commit mode for this connection. |
||
| 522 | * |
||
| 523 | * If a connection is in auto-commit mode, then all its SQL statements will be executed and committed as individual |
||
| 524 | * transactions. Otherwise, its SQL statements are grouped into transactions that are terminated by a call to either |
||
| 525 | * the method commit or the method rollback. By default, new connections are in auto-commit mode. |
||
| 526 | * |
||
| 527 | * NOTE: If this method is called during a transaction and the auto-commit mode is changed, the transaction is |
||
| 528 | * committed. If this method is called and the auto-commit mode is not changed, the call is a no-op. |
||
| 529 | * |
||
| 530 | * @param bool $autoCommit True to enable auto-commit mode; false to disable it. |
||
| 531 | * |
||
| 532 | * @see isAutoCommit |
||
| 533 | */ |
||
| 534 | public function setAutoCommit($autoCommit) |
||
| 550 | |||
| 551 | /** |
||
| 552 | * Sets the fetch mode. |
||
| 553 | * |
||
| 554 | * @param int $fetchMode |
||
| 555 | * |
||
| 556 | * @return void |
||
| 557 | */ |
||
| 558 | public function setFetchMode($fetchMode) |
||
| 562 | |||
| 563 | /** |
||
| 564 | * Prepares and executes an SQL query and returns the first row of the result |
||
| 565 | * as an associative array. |
||
| 566 | * |
||
| 567 | * @param string $statement The SQL query. |
||
| 568 | * @param array $params The query parameters. |
||
| 569 | * @param array $types The query parameter types. |
||
| 570 | * |
||
| 571 | * @return array|bool False is returned if no rows are found. |
||
| 572 | * |
||
| 573 | * @throws \Doctrine\DBAL\DBALException |
||
| 574 | */ |
||
| 575 | public function fetchAssoc($statement, array $params = [], array $types = []) |
||
| 579 | |||
| 580 | /** |
||
| 581 | * Prepares and executes an SQL query and returns the first row of the result |
||
| 582 | * as a numerically indexed array. |
||
| 583 | * |
||
| 584 | * @param string $statement The SQL query to be executed. |
||
| 585 | * @param array $params The prepared statement params. |
||
| 586 | * @param array $types The query parameter types. |
||
| 587 | * |
||
| 588 | * @return array|bool False is returned if no rows are found. |
||
| 589 | */ |
||
| 590 | public function fetchArray($statement, array $params = [], array $types = []) |
||
| 594 | |||
| 595 | /** |
||
| 596 | * Prepares and executes an SQL query and returns the value of a single column |
||
| 597 | * of the first row of the result. |
||
| 598 | * |
||
| 599 | * @param string $statement The SQL query to be executed. |
||
| 600 | * @param array $params The prepared statement params. |
||
| 601 | * @param int $column The 0-indexed column number to retrieve. |
||
| 602 | * @param array $types The query parameter types. |
||
| 603 | * |
||
| 604 | * @return mixed|bool False is returned if no rows are found. |
||
|
|
|||
| 605 | * |
||
| 606 | * @throws \Doctrine\DBAL\DBALException |
||
| 607 | */ |
||
| 608 | public function fetchColumn($statement, array $params = [], $column = 0, array $types = []) |
||
| 612 | |||
| 613 | /** |
||
| 614 | * Whether an actual connection to the database is established. |
||
| 615 | * |
||
| 616 | * @return bool |
||
| 617 | */ |
||
| 618 | public function isConnected() |
||
| 622 | |||
| 623 | /** |
||
| 624 | * Checks whether a transaction is currently active. |
||
| 625 | * |
||
| 626 | * @return bool TRUE if a transaction is currently active, FALSE otherwise. |
||
| 627 | */ |
||
| 628 | public function isTransactionActive() |
||
| 632 | |||
| 633 | /** |
||
| 634 | * Gathers conditions for an update or delete call. |
||
| 635 | * |
||
| 636 | * @param array $identifiers Input array of columns to values |
||
| 637 | * |
||
| 638 | * @return string[][] a triplet with: |
||
| 639 | * - the first key being the columns |
||
| 640 | * - the second key being the values |
||
| 641 | * - the third key being the conditions |
||
| 642 | */ |
||
| 643 | private function gatherConditions(array $identifiers) |
||
| 662 | |||
| 663 | /** |
||
| 664 | * Executes an SQL DELETE statement on a table. |
||
| 665 | * |
||
| 666 | * Table expression and columns are not escaped and are not safe for user-input. |
||
| 667 | * |
||
| 668 | * @param string $tableExpression The expression of the table on which to delete. |
||
| 669 | * @param array $identifier The deletion criteria. An associative array containing column-value pairs. |
||
| 670 | * @param array $types The types of identifiers. |
||
| 671 | * |
||
| 672 | * @return int The number of affected rows. |
||
| 673 | * |
||
| 674 | * @throws \Doctrine\DBAL\DBALException |
||
| 675 | * @throws InvalidArgumentException |
||
| 676 | */ |
||
| 677 | public function delete($tableExpression, array $identifier, array $types = []) |
||
| 691 | |||
| 692 | /** |
||
| 693 | * Closes the connection. |
||
| 694 | * |
||
| 695 | * @return void |
||
| 696 | */ |
||
| 697 | public function close() |
||
| 703 | |||
| 704 | /** |
||
| 705 | * Sets the transaction isolation level. |
||
| 706 | * |
||
| 707 | * @param int $level The level to set. |
||
| 708 | * |
||
| 709 | * @return int |
||
| 710 | */ |
||
| 711 | public function setTransactionIsolation($level) |
||
| 717 | |||
| 718 | /** |
||
| 719 | * Gets the currently active transaction isolation level. |
||
| 720 | * |
||
| 721 | * @return int The current transaction isolation level. |
||
| 722 | */ |
||
| 723 | public function getTransactionIsolation() |
||
| 731 | |||
| 732 | /** |
||
| 733 | * Executes an SQL UPDATE statement on a table. |
||
| 734 | * |
||
| 735 | * Table expression and columns are not escaped and are not safe for user-input. |
||
| 736 | * |
||
| 737 | * @param string $tableExpression The expression of the table to update quoted or unquoted. |
||
| 738 | * @param array $data An associative array containing column-value pairs. |
||
| 739 | * @param array $identifier The update criteria. An associative array containing column-value pairs. |
||
| 740 | * @param array $types Types of the merged $data and $identifier arrays in that order. |
||
| 741 | * |
||
| 742 | * @return int The number of affected rows. |
||
| 743 | * |
||
| 744 | * @throws \Doctrine\DBAL\DBALException |
||
| 745 | */ |
||
| 746 | public function update($tableExpression, array $data, array $identifier, array $types = []) |
||
| 771 | |||
| 772 | /** |
||
| 773 | * Inserts a table row with specified data. |
||
| 774 | * |
||
| 775 | * Table expression and columns are not escaped and are not safe for user-input. |
||
| 776 | * |
||
| 777 | * @param string $tableExpression The expression of the table to insert data into, quoted or unquoted. |
||
| 778 | * @param array $data An associative array containing column-value pairs. |
||
| 779 | * @param array $types Types of the inserted data. |
||
| 780 | * |
||
| 781 | * @return int The number of affected rows. |
||
| 782 | * |
||
| 783 | * @throws \Doctrine\DBAL\DBALException |
||
| 784 | */ |
||
| 785 | public function insert($tableExpression, array $data, array $types = []) |
||
| 808 | |||
| 809 | /** |
||
| 810 | * Extract ordered type list from an ordered column list and type map. |
||
| 811 | * |
||
| 812 | * @param array $columnList |
||
| 813 | * @param array $types |
||
| 814 | * |
||
| 815 | * @return array |
||
| 816 | */ |
||
| 817 | private function extractTypeValues(array $columnList, array $types) |
||
| 827 | |||
| 828 | /** |
||
| 829 | * Quotes a string so it can be safely used as a table or column name, even if |
||
| 830 | * it is a reserved name. |
||
| 831 | * |
||
| 832 | * Delimiting style depends on the underlying database platform that is being used. |
||
| 833 | * |
||
| 834 | * NOTE: Just because you CAN use quoted identifiers does not mean |
||
| 835 | * you SHOULD use them. In general, they end up causing way more |
||
| 836 | * problems than they solve. |
||
| 837 | * |
||
| 838 | * @param string $str The name to be quoted. |
||
| 839 | * |
||
| 840 | * @return string The quoted name. |
||
| 841 | */ |
||
| 842 | public function quoteIdentifier($str) |
||
| 846 | |||
| 847 | /** |
||
| 848 | * Quotes a given input parameter. |
||
| 849 | * |
||
| 850 | * @param mixed $input The parameter to be quoted. |
||
| 851 | * @param int|null $type The type of the parameter. |
||
| 852 | * |
||
| 853 | * @return string The quoted parameter. |
||
| 854 | */ |
||
| 855 | public function quote($input, $type = null) |
||
| 863 | |||
| 864 | /** |
||
| 865 | * Prepares and executes an SQL query and returns the result as an associative array. |
||
| 866 | * |
||
| 867 | * @param string $sql The SQL query. |
||
| 868 | * @param array $params The query parameters. |
||
| 869 | * @param array $types The query parameter types. |
||
| 870 | * |
||
| 871 | * @return array |
||
| 872 | */ |
||
| 873 | public function fetchAll($sql, array $params = [], $types = []) |
||
| 877 | |||
| 878 | /** |
||
| 879 | * Prepares an SQL statement. |
||
| 880 | * |
||
| 881 | * @param string $statement The SQL statement to prepare. |
||
| 882 | * |
||
| 883 | * @return DriverStatement The prepared statement. |
||
| 884 | * |
||
| 885 | * @throws \Doctrine\DBAL\DBALException |
||
| 886 | */ |
||
| 887 | public function prepare($statement) |
||
| 899 | |||
| 900 | /** |
||
| 901 | * Executes an, optionally parametrized, SQL query. |
||
| 902 | * |
||
| 903 | * If the query is parametrized, a prepared statement is used. |
||
| 904 | * If an SQLLogger is configured, the execution is logged. |
||
| 905 | * |
||
| 906 | * @param string $query The SQL query to execute. |
||
| 907 | * @param array $params The parameters to bind to the query, if any. |
||
| 908 | * @param array $types The types the previous parameters are in. |
||
| 909 | * @param \Doctrine\DBAL\Cache\QueryCacheProfile|null $qcp The query cache profile, optional. |
||
| 910 | * |
||
| 911 | * @return ResultStatement The executed statement. |
||
| 912 | * |
||
| 913 | * @throws \Doctrine\DBAL\DBALException |
||
| 914 | */ |
||
| 915 | public function executeQuery($query, array $params = [], $types = [], QueryCacheProfile $qcp = null) |
||
| 954 | |||
| 955 | /** |
||
| 956 | * Executes a caching query. |
||
| 957 | * |
||
| 958 | * @param string $query The SQL query to execute. |
||
| 959 | * @param array $params The parameters to bind to the query, if any. |
||
| 960 | * @param array $types The types the previous parameters are in. |
||
| 961 | * @param \Doctrine\DBAL\Cache\QueryCacheProfile $qcp The query cache profile. |
||
| 962 | * |
||
| 963 | * @return ResultStatement |
||
| 964 | * |
||
| 965 | * @throws \Doctrine\DBAL\Cache\CacheException |
||
| 966 | */ |
||
| 967 | public function executeCacheQuery($query, $params, $types, QueryCacheProfile $qcp) |
||
| 994 | |||
| 995 | /** |
||
| 996 | * Executes an, optionally parametrized, SQL query and returns the result, |
||
| 997 | * applying a given projection/transformation function on each row of the result. |
||
| 998 | * |
||
| 999 | * @param string $query The SQL query to execute. |
||
| 1000 | * @param array $params The parameters, if any. |
||
| 1001 | * @param \Closure $function The transformation function that is applied on each row. |
||
| 1002 | * The function receives a single parameter, an array, that |
||
| 1003 | * represents a row of the result set. |
||
| 1004 | * |
||
| 1005 | * @return array The projected result of the query. |
||
| 1006 | */ |
||
| 1007 | public function project($query, array $params, Closure $function) |
||
| 1020 | |||
| 1021 | /** |
||
| 1022 | * Executes an SQL statement, returning a result set as a Statement object. |
||
| 1023 | * |
||
| 1024 | * @return \Doctrine\DBAL\Driver\Statement |
||
| 1025 | * |
||
| 1026 | * @throws \Doctrine\DBAL\DBALException |
||
| 1027 | */ |
||
| 1028 | public function query() |
||
| 1053 | |||
| 1054 | /** |
||
| 1055 | * Executes an SQL INSERT/UPDATE/DELETE query with the given parameters |
||
| 1056 | * and returns the number of affected rows. |
||
| 1057 | * |
||
| 1058 | * This method supports PDO binding types as well as DBAL mapping types. |
||
| 1059 | * |
||
| 1060 | * @param string $query The SQL query. |
||
| 1061 | * @param array $params The query parameters. |
||
| 1062 | * @param array $types The parameter types. |
||
| 1063 | * |
||
| 1064 | * @return int The number of affected rows. |
||
| 1065 | * |
||
| 1066 | * @throws \Doctrine\DBAL\DBALException |
||
| 1067 | */ |
||
| 1068 | public function executeUpdate($query, array $params = [], array $types = []) |
||
| 1102 | |||
| 1103 | /** |
||
| 1104 | * Executes an SQL statement and return the number of affected rows. |
||
| 1105 | * |
||
| 1106 | * @param string $statement |
||
| 1107 | * |
||
| 1108 | * @return int The number of affected rows. |
||
| 1109 | * |
||
| 1110 | * @throws \Doctrine\DBAL\DBALException |
||
| 1111 | */ |
||
| 1112 | public function exec($statement) |
||
| 1133 | |||
| 1134 | /** |
||
| 1135 | * Returns the current transaction nesting level. |
||
| 1136 | * |
||
| 1137 | * @return int The nesting level. A value of 0 means there's no active transaction. |
||
| 1138 | */ |
||
| 1139 | public function getTransactionNestingLevel() |
||
| 1143 | |||
| 1144 | /** |
||
| 1145 | * Fetches the SQLSTATE associated with the last database operation. |
||
| 1146 | * |
||
| 1147 | * @return string|null The last error code. |
||
| 1148 | */ |
||
| 1149 | public function errorCode() |
||
| 1155 | |||
| 1156 | /** |
||
| 1157 | * Fetches extended error information associated with the last database operation. |
||
| 1158 | * |
||
| 1159 | * @return array The last error information. |
||
| 1160 | */ |
||
| 1161 | public function errorInfo() |
||
| 1167 | |||
| 1168 | /** |
||
| 1169 | * Returns the ID of the last inserted row, or the last value from a sequence object, |
||
| 1170 | * depending on the underlying driver. |
||
| 1171 | * |
||
| 1172 | * Note: This method may not return a meaningful or consistent result across different drivers, |
||
| 1173 | * because the underlying database may not even support the notion of AUTO_INCREMENT/IDENTITY |
||
| 1174 | * columns or sequences. |
||
| 1175 | * |
||
| 1176 | * @param string|null $seqName Name of the sequence object from which the ID should be returned. |
||
| 1177 | * |
||
| 1178 | * @return string A string representation of the last inserted ID. |
||
| 1179 | */ |
||
| 1180 | public function lastInsertId($seqName = null) |
||
| 1186 | |||
| 1187 | /** |
||
| 1188 | * Executes a function in a transaction. |
||
| 1189 | * |
||
| 1190 | * The function gets passed this Connection instance as an (optional) parameter. |
||
| 1191 | * |
||
| 1192 | * If an exception occurs during execution of the function or transaction commit, |
||
| 1193 | * the transaction is rolled back and the exception re-thrown. |
||
| 1194 | * |
||
| 1195 | * @param \Closure $func The function to execute transactionally. |
||
| 1196 | * |
||
| 1197 | * @return mixed The value returned by $func |
||
| 1198 | * |
||
| 1199 | * @throws Exception |
||
| 1200 | * @throws Throwable |
||
| 1201 | */ |
||
| 1202 | public function transactional(Closure $func) |
||
| 1217 | |||
| 1218 | /** |
||
| 1219 | * Sets if nested transactions should use savepoints. |
||
| 1220 | * |
||
| 1221 | * @param bool $nestTransactionsWithSavepoints |
||
| 1222 | * |
||
| 1223 | * @return void |
||
| 1224 | * |
||
| 1225 | * @throws \Doctrine\DBAL\ConnectionException |
||
| 1226 | */ |
||
| 1227 | public function setNestTransactionsWithSavepoints($nestTransactionsWithSavepoints) |
||
| 1239 | |||
| 1240 | /** |
||
| 1241 | * Gets if nested transactions should use savepoints. |
||
| 1242 | * |
||
| 1243 | * @return bool |
||
| 1244 | */ |
||
| 1245 | public function getNestTransactionsWithSavepoints() |
||
| 1249 | |||
| 1250 | /** |
||
| 1251 | * Returns the savepoint name to use for nested transactions are false if they are not supported |
||
| 1252 | * "savepointFormat" parameter is not set |
||
| 1253 | * |
||
| 1254 | * @return mixed A string with the savepoint name or false. |
||
| 1255 | */ |
||
| 1256 | protected function _getNestedTransactionSavePointName() |
||
| 1260 | |||
| 1261 | /** |
||
| 1262 | * Starts a transaction by suspending auto-commit mode. |
||
| 1263 | * |
||
| 1264 | * @return void |
||
| 1265 | */ |
||
| 1266 | public function beginTransaction() |
||
| 1292 | |||
| 1293 | /** |
||
| 1294 | * Commits the current transaction. |
||
| 1295 | * |
||
| 1296 | * @return void |
||
| 1297 | * |
||
| 1298 | * @throws \Doctrine\DBAL\ConnectionException If the commit failed due to no active transaction or |
||
| 1299 | * because the transaction was marked for rollback only. |
||
| 1300 | */ |
||
| 1301 | public function commit() |
||
| 1338 | |||
| 1339 | /** |
||
| 1340 | * Commits all current nesting transactions. |
||
| 1341 | */ |
||
| 1342 | private function commitAll() |
||
| 1356 | |||
| 1357 | /** |
||
| 1358 | * Cancels any database changes done during the current transaction. |
||
| 1359 | * |
||
| 1360 | * @throws \Doctrine\DBAL\ConnectionException If the rollback operation failed. |
||
| 1361 | */ |
||
| 1362 | public function rollBack() |
||
| 1400 | |||
| 1401 | /** |
||
| 1402 | * Creates a new savepoint. |
||
| 1403 | * |
||
| 1404 | * @param string $savepoint The name of the savepoint to create. |
||
| 1405 | * |
||
| 1406 | * @return void |
||
| 1407 | * |
||
| 1408 | * @throws \Doctrine\DBAL\ConnectionException |
||
| 1409 | */ |
||
| 1410 | public function createSavepoint($savepoint) |
||
| 1418 | |||
| 1419 | /** |
||
| 1420 | * Releases the given savepoint. |
||
| 1421 | * |
||
| 1422 | * @param string $savepoint The name of the savepoint to release. |
||
| 1423 | * |
||
| 1424 | * @return void |
||
| 1425 | * |
||
| 1426 | * @throws \Doctrine\DBAL\ConnectionException |
||
| 1427 | */ |
||
| 1428 | public function releaseSavepoint($savepoint) |
||
| 1438 | |||
| 1439 | /** |
||
| 1440 | * Rolls back to the given savepoint. |
||
| 1441 | * |
||
| 1442 | * @param string $savepoint The name of the savepoint to rollback to. |
||
| 1443 | * |
||
| 1444 | * @return void |
||
| 1445 | * |
||
| 1446 | * @throws \Doctrine\DBAL\ConnectionException |
||
| 1447 | */ |
||
| 1448 | public function rollbackSavepoint($savepoint) |
||
| 1456 | |||
| 1457 | /** |
||
| 1458 | * Gets the wrapped driver connection. |
||
| 1459 | * |
||
| 1460 | * @return \Doctrine\DBAL\Driver\Connection |
||
| 1461 | */ |
||
| 1462 | public function getWrappedConnection() |
||
| 1468 | |||
| 1469 | /** |
||
| 1470 | * Gets the SchemaManager that can be used to inspect or change the |
||
| 1471 | * database schema through the connection. |
||
| 1472 | * |
||
| 1473 | * @return \Doctrine\DBAL\Schema\AbstractSchemaManager |
||
| 1474 | */ |
||
| 1475 | public function getSchemaManager() |
||
| 1483 | |||
| 1484 | /** |
||
| 1485 | * Marks the current transaction so that the only possible |
||
| 1486 | * outcome for the transaction to be rolled back. |
||
| 1487 | * |
||
| 1488 | * @return void |
||
| 1489 | * |
||
| 1490 | * @throws \Doctrine\DBAL\ConnectionException If no transaction is active. |
||
| 1491 | */ |
||
| 1492 | public function setRollbackOnly() |
||
| 1499 | |||
| 1500 | /** |
||
| 1501 | * Checks whether the current transaction is marked for rollback only. |
||
| 1502 | * |
||
| 1503 | * @return bool |
||
| 1504 | * |
||
| 1505 | * @throws \Doctrine\DBAL\ConnectionException If no transaction is active. |
||
| 1506 | */ |
||
| 1507 | public function isRollbackOnly() |
||
| 1515 | |||
| 1516 | /** |
||
| 1517 | * Converts a given value to its database representation according to the conversion |
||
| 1518 | * rules of a specific DBAL mapping type. |
||
| 1519 | * |
||
| 1520 | * @param mixed $value The value to convert. |
||
| 1521 | * @param string $type The name of the DBAL mapping type. |
||
| 1522 | * |
||
| 1523 | * @return mixed The converted value. |
||
| 1524 | */ |
||
| 1525 | public function convertToDatabaseValue($value, $type) |
||
| 1529 | |||
| 1530 | /** |
||
| 1531 | * Converts a given value to its PHP representation according to the conversion |
||
| 1532 | * rules of a specific DBAL mapping type. |
||
| 1533 | * |
||
| 1534 | * @param mixed $value The value to convert. |
||
| 1535 | * @param string $type The name of the DBAL mapping type. |
||
| 1536 | * |
||
| 1537 | * @return mixed The converted type. |
||
| 1538 | */ |
||
| 1539 | public function convertToPHPValue($value, $type) |
||
| 1543 | |||
| 1544 | /** |
||
| 1545 | * Binds a set of parameters, some or all of which are typed with a PDO binding type |
||
| 1546 | * or DBAL mapping type, to a given statement. |
||
| 1547 | * |
||
| 1548 | * @param \Doctrine\DBAL\Driver\Statement $stmt The statement to bind the values to. |
||
| 1549 | * @param array $params The map/list of named/positional parameters. |
||
| 1550 | * @param array $types The parameter types (PDO binding types or DBAL mapping types). |
||
| 1551 | * |
||
| 1552 | * @return void |
||
| 1553 | * |
||
| 1554 | * @internal Duck-typing used on the $stmt parameter to support driver statements as well as |
||
| 1555 | * raw PDOStatement instances. |
||
| 1556 | */ |
||
| 1557 | private function _bindTypedValues($stmt, array $params, array $types) |
||
| 1588 | |||
| 1589 | /** |
||
| 1590 | * Gets the binding type of a given type. The given type can be a PDO or DBAL mapping type. |
||
| 1591 | * |
||
| 1592 | * @param mixed $value The value to bind. |
||
| 1593 | * @param mixed $type The type to bind (PDO or DBAL). |
||
| 1594 | * |
||
| 1595 | * @return array [0] => the (escaped) value, [1] => the binding type. |
||
| 1596 | */ |
||
| 1597 | private function getBindingInfo($value, $type) |
||
| 1611 | |||
| 1612 | /** |
||
| 1613 | * Resolves the parameters to a format which can be displayed. |
||
| 1614 | * |
||
| 1615 | * @internal This is a purely internal method. If you rely on this method, you are advised to |
||
| 1616 | * copy/paste the code as this method may change, or be removed without prior notice. |
||
| 1617 | * |
||
| 1618 | * @param array $params |
||
| 1619 | * @param array $types |
||
| 1620 | * |
||
| 1621 | * @return array |
||
| 1622 | */ |
||
| 1623 | public function resolveParams(array $params, array $types) |
||
| 1658 | |||
| 1659 | /** |
||
| 1660 | * Creates a new instance of a SQL query builder. |
||
| 1661 | * |
||
| 1662 | * @return \Doctrine\DBAL\Query\QueryBuilder |
||
| 1663 | */ |
||
| 1664 | public function createQueryBuilder() |
||
| 1668 | |||
| 1669 | /** |
||
| 1670 | * Ping the server |
||
| 1671 | * |
||
| 1672 | * When the server is not available the method returns FALSE. |
||
| 1673 | * It is responsibility of the developer to handle this case |
||
| 1674 | * and abort the request or reconnect manually: |
||
| 1675 | * |
||
| 1676 | * @example |
||
| 1677 | * |
||
| 1678 | * if ($conn->ping() === false) { |
||
| 1679 | * $conn->close(); |
||
| 1680 | * $conn->connect(); |
||
| 1681 | * } |
||
| 1682 | * |
||
| 1683 | * It is undefined if the underlying driver attempts to reconnect |
||
| 1684 | * or disconnect when the connection is not available anymore |
||
| 1685 | * as long it returns TRUE when a reconnect succeeded and |
||
| 1686 | * FALSE when the connection was dropped. |
||
| 1687 | * |
||
| 1688 | * @return bool |
||
| 1689 | */ |
||
| 1690 | public function ping() |
||
| 1706 | } |
||
| 1707 |
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.