Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Platform API cleanup #4802

Merged
merged 4 commits into from
Sep 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@
TODO: remove in 4.0.0
-->
<referencedMethod name="Doctrine\DBAL\Schema\Schema::getMigrateToSql"/>
<!--
TODO: remove in 4.0.0
-->
<referencedMethod name="Doctrine\DBAL\Platforms\OraclePlatform::assertValidIdentifier"/>
</errorLevel>
</DeprecatedMethod>
<DeprecatedProperty>
Expand Down
52 changes: 52 additions & 0 deletions src/Driver/API/SQLite/UserDefinedFunctions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Doctrine\DBAL\Driver\API\SQLite;

use function strpos;

/**
* User-defined SQLite functions.
*
* @internal
*/
final class UserDefinedFunctions
{
/**
* User-defined function that implements MOD().
*
* @param int $a
* @param int $b
*
* @return int
*/
public static function mod($a, $b)
{
return $a % $b;
}

/**
* User-defined function that implements LOCATE().
*
* @param string $str
* @param string $substr
* @param int $offset
*
* @return int
*/
public static function locate($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;
}
}
6 changes: 6 additions & 0 deletions src/Platforms/OraclePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions src/Platforms/SQLServerPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
24 changes: 9 additions & 15 deletions src/Platforms/SqlitePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,7 +28,6 @@
use function sqrt;
use function str_replace;
use function strlen;
use function strpos;
use function strtolower;
use function trim;

Expand Down Expand Up @@ -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
Expand All @@ -606,17 +608,21 @@ 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
*
* @return int
*/
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
Expand All @@ -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);
}

/**
Expand Down