diff --git a/UPGRADE.md b/UPGRADE.md index 3e65299cfd6..10becb94a6d 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -8,6 +8,30 @@ awareness about deprecated code. # Upgrade to 3.2 +## Deprecated `udf*` methods of the `SQLitePlatform` methods. + +The following `SQLServerPlatform` methods have been deprecated in favor of their implementations +in the `UserDefinedFunctions` class: +- `udfSqrt()`, +- `udfMod()`, +- `udfLocate()`. + +## `SQLServerPlatform` methods marked internal. + +The following `SQLServerPlatform` methods have been marked internal: +- `getDefaultConstraintDeclarationSQL()`, +- `getAddExtendedPropertySQL()`, +- `getDropExtendedPropertySQL()`, +- `getUpdateExtendedPropertySQL()`. + +## `OraclePlatform` methods marked internal. + +The `OraclePlatform::getCreateAutoincrementSql()` and `::getDropAutoincrementSql()` have been marked internal. + +## Deprecated `OraclePlatform::assertValidIdentifier()` + +The `OraclePlatform::assertValidIdentifier()` method has been deprecated. + ## Deprecated features of `Table::getColumns()` 1. Using the returned array keys as column names is deprecated. Retrieve the name from the column diff --git a/psalm.xml.dist b/psalm.xml.dist index 1775c8e02a6..a0099aad042 100644 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -150,6 +150,10 @@ TODO: remove in 4.0.0 --> + + diff --git a/src/Driver/API/SQLite/UserDefinedFunctions.php b/src/Driver/API/SQLite/UserDefinedFunctions.php new file mode 100644 index 00000000000..6bce02291e0 --- /dev/null +++ b/src/Driver/API/SQLite/UserDefinedFunctions.php @@ -0,0 +1,52 @@ + 0) { + $offset -= 1; + } + + $pos = strpos($str, $substr, $offset); + + if ($pos !== false) { + return $pos + 1; + } + + return 0; + } +} diff --git a/src/Platforms/OraclePlatform.php b/src/Platforms/OraclePlatform.php index a5a01cb963b..7a0d82e0b2f 100644 --- a/src/Platforms/OraclePlatform.php +++ b/src/Platforms/OraclePlatform.php @@ -35,6 +35,8 @@ class OraclePlatform extends AbstractPlatform /** * Assertion for Oracle identifiers. * + * @deprecated + * * @link http://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements008.htm * * @param string $identifier @@ -490,6 +492,8 @@ public function getDropViewSQL($name) } /** + * @internal The method should be only used from within the OraclePlatform class hierarchy. + * * @param string $name * @param string $table * @param int $start @@ -557,6 +561,8 @@ public function getCreateAutoincrementSql($name, $table, $start = 1) } /** + * @internal The method should be only used from within the OracleSchemaManager class hierarchy. + * * Returns the SQL statements to drop the autoincrement for the given table name. * * @param string $table The table name to drop the autoincrement for. diff --git a/src/Platforms/SQLServerPlatform.php b/src/Platforms/SQLServerPlatform.php index b9e862851b3..3c61cce87d2 100644 --- a/src/Platforms/SQLServerPlatform.php +++ b/src/Platforms/SQLServerPlatform.php @@ -438,6 +438,8 @@ protected function getCreateColumnCommentSQL($tableName, $columnName, $comment) /** * Returns the SQL snippet for declaring a default constraint. * + * @internal The method should be only used from within the SQLServerPlatform class hierarchy. + * * @param string $table Name of the table to return the default constraint declaration for. * @param mixed[] $column Column definition. * @@ -843,6 +845,8 @@ protected function getRenameIndexSQL($oldIndexName, Index $index, $tableName) /** * Returns the SQL statement for adding an extended property to a database object. * + * @internal The method should be only used from within the SQLServerPlatform class hierarchy. + * * @link http://msdn.microsoft.com/en-us/library/ms180047%28v=sql.90%29.aspx * * @param string $name The name of the property to add. @@ -876,6 +880,8 @@ public function getAddExtendedPropertySQL( /** * Returns the SQL statement for dropping an extended property from a database object. * + * @internal The method should be only used from within the SQLServerPlatform class hierarchy. + * * @link http://technet.microsoft.com/en-gb/library/ms178595%28v=sql.90%29.aspx * * @param string $name The name of the property to drop. @@ -907,6 +913,8 @@ public function getDropExtendedPropertySQL( /** * Returns the SQL statement for updating an extended property of a database object. * + * @internal The method should be only used from within the SQLServerPlatform class hierarchy. + * * @link http://msdn.microsoft.com/en-us/library/ms186885%28v=sql.90%29.aspx * * @param string $name The name of the property to update. diff --git a/src/Platforms/SqlitePlatform.php b/src/Platforms/SqlitePlatform.php index 7f6e6c1619c..07dad0cca65 100644 --- a/src/Platforms/SqlitePlatform.php +++ b/src/Platforms/SqlitePlatform.php @@ -2,6 +2,7 @@ namespace Doctrine\DBAL\Platforms; +use Doctrine\DBAL\Driver\API\SQLite\UserDefinedFunctions; use Doctrine\DBAL\Exception; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\Constraint; @@ -27,7 +28,6 @@ use function sqrt; use function str_replace; use function strlen; -use function strpos; use function strtolower; use function trim; @@ -594,6 +594,8 @@ public function getTruncateTableSQL($tableName, $cascade = false) /** * User-defined function for Sqlite that is used with PDO::sqliteCreateFunction(). * + * @deprecated The driver will use {@link sqrt()} in the next major release. + * * @param int|float $value * * @return float @@ -606,6 +608,8 @@ public static function udfSqrt($value) /** * User-defined function for Sqlite that implements MOD(a, b). * + * @deprecated The driver will use {@link UserDefinedFunctions::mod()} in the next major release. + * * @param int $a * @param int $b * @@ -613,10 +617,12 @@ public static function udfSqrt($value) */ public static function udfMod($a, $b) { - return $a % $b; + return UserDefinedFunctions::mod($a, $b); } /** + * @deprecated The driver will use {@link UserDefinedFunctions::locate()} in the next major release. + * * @param string $str * @param string $substr * @param int $offset @@ -625,19 +631,7 @@ public static function udfMod($a, $b) */ public static function udfLocate($str, $substr, $offset = 0) { - // SQL's LOCATE function works on 1-based positions, while PHP's strpos works on 0-based positions. - // So we have to make them compatible if an offset is given. - if ($offset > 0) { - $offset -= 1; - } - - $pos = strpos($str, $substr, $offset); - - if ($pos !== false) { - return $pos + 1; - } - - return 0; + return UserDefinedFunctions::locate($str, $substr, $offset); } /**