Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
61dcd2a
Fix binary type format documentation
jaapio Jan 10, 2025
77a6041
Merge pull request #6700 from jaapio/docs/fix-table-display
greg0ire Jan 29, 2025
7ad1450
Use function db2_field_name
morozov Feb 1, 2025
8db2066
Merge pull request #6752 from morozov/use-function-db2-field-name
morozov Feb 1, 2025
d81174d
Use SYSCAT.TABLES instead of SYSIBM.SYSTABLES on IBM DB2
morozov Feb 1, 2025
a0e0e49
Use sys.tables instead of sys.objects on SQL Server
morozov Feb 1, 2025
afb7544
Use the proper case for SQL Server system views
morozov Feb 1, 2025
1e13649
Remove unused columns
morozov Feb 1, 2025
483244c
Remove DISTINCT
morozov Feb 1, 2025
bf5168f
Fix introspection of table options in non-default schemas
morozov Feb 1, 2025
4443706
Refactor building schema introspection queries
morozov Jan 25, 2025
c5e1e02
Deprecate `AbstractSchemaManager::_getPortableTableDefinition()`
morozov Feb 2, 2025
62ae320
Auto-quote introspected PostgreSQL identifiers
morozov Feb 2, 2025
da19422
Merge pull request #6756 from morozov/auto-quote-postgres-identifiers
morozov Feb 2, 2025
a1932ce
Merge pull request #6753 from morozov/non-default-schema-table-commen…
morozov Feb 2, 2025
8bac6a0
Merge pull request #6755 from morozov/deprecate-get-portable-table-de…
morozov Feb 2, 2025
9aff49d
Merge pull request #6754 from morozov/introspection-cleanup
morozov Feb 2, 2025
dd703ec
Merge branch '3.9.x' into 4.2.x
morozov Feb 2, 2025
851e6be
Merge branch '4.2.x' into 4.3.x
morozov Feb 2, 2025
2d52789
Merge branch '4.3.x' into 5.0.x
morozov Feb 3, 2025
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
5 changes: 5 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ all drivers and middleware.

# Upgrade to 4.3

## Deprecated `AbstractSchemaManager::_getPortableTableDefinition()`

The `AbstractSchemaManager::_getPortableTableDefinition()` method has been deprecated. Use the schema name and the
unqualified table name separately instead.

## Deprecated `PostgreSQLSchemaManager` methods related to the current schema

The following `PostgreSQLSchemaManager` methods have been deprecated:
Expand Down
7 changes: 3 additions & 4 deletions docs/en/reference/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,6 @@ The following table shows an overview of Doctrine's type abstraction.
The matrix contains the mapping information for how a specific Doctrine
type is mapped to the database and back to PHP.
Please also notice the mapping specific footnotes for additional information.
::

+-------------------+--------------------+-----------------------------------------------------------------------------------------------+
| Doctrine | PHP | Database vendor |
Expand Down Expand Up @@ -602,10 +601,10 @@ Please also notice the mapping specific footnotes for additional information.
| | +--------------------------+ | |
| | | **PostgreSQL** | *all* | ``UUID`` |
+-------------------+--------------------+--------------------------+---------+----------------------------------------------------------+
| **binary** | ``resource`` | **MySQL** | *all* | ``VARBINARY(n)`` [3] |
| **binary** | ``string`` | **MySQL** | *all* | ``VARBINARY(n)`` [3] |
| [2] [6] | +--------------------------+ | |
| | | **SQL Server** | +----------------------------------------------------------+
| | +--------------------------+ | ``BINARY(n)`` [4] |
| | | **SQL Server** | | ``BINARY(n)`` [4] |
| | +--------------------------+---------+----------------------------------------------------------+
| | | **Oracle** | *all* | ``RAW(n)`` |
| | +--------------------------+---------+----------------------------------------------------------+
| | | **PostgreSQL** | *all* | ``BYTEA`` [15] |
Expand Down
1 change: 1 addition & 0 deletions src/Driver/IBMDB2/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use function db2_fetch_array;
use function db2_fetch_assoc;
use function db2_field_name;
use function db2_free_result;
use function db2_num_fields;
use function db2_num_rows;
Expand Down
8 changes: 7 additions & 1 deletion src/Platforms/SQLServerPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -1191,11 +1191,17 @@ protected function getLikeWildcardCharacters(): string

protected function getCommentOnTableSQL(string $tableName, string $comment): string
{
if (str_contains($tableName, '.')) {
[$schemaName, $tableName] = explode('.', $tableName);
} else {
$schemaName = 'dbo';
}

return $this->getAddExtendedPropertySQL(
'MS_Description',
$comment,
'SCHEMA',
$this->quoteStringLiteral('dbo'),
$this->quoteStringLiteral($this->unquoteSingleIdentifier($schemaName)),
'TABLE',
$this->quoteStringLiteral($this->unquoteSingleIdentifier($tableName)),
);
Expand Down
6 changes: 5 additions & 1 deletion src/Schema/AbstractSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,11 @@ protected function _getPortableTableIndexesList(array $rows): array
return $indexes;
}

/** @param array<string, string> $table */
/**
* @deprecated Use the schema name and the unqualified table name separately instead.
*
* @param array<string, string> $table
*/
abstract protected function _getPortableTableDefinition(array $table): string;

/** @param array<string, mixed> $view */
Expand Down
139 changes: 73 additions & 66 deletions src/Schema/DB2SchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use function array_change_key_case;
use function implode;
use function preg_match;
use function sprintf;
use function str_replace;
use function strpos;
use function strtolower;
Expand All @@ -23,6 +24,8 @@
/**
* IBM Db2 Schema Manager.
*
* @link https://www.ibm.com/docs/en/db2/11.5?topic=sql-catalog-views
*
* @extends AbstractSchemaManager<DB2Platform>
*/
class DB2SchemaManager extends AbstractSchemaManager
Expand Down Expand Up @@ -101,6 +104,8 @@
}

/**
* @deprecated Use the schema name and the unqualified table name separately instead.
*
* {@inheritDoc}
*/
protected function _getPortableTableDefinition(array $table): string
Expand Down Expand Up @@ -178,24 +183,29 @@
protected function selectTableNames(string $databaseName): Result
{
$sql = <<<'SQL'
SELECT NAME
FROM SYSIBM.SYSTABLES
SELECT TABNAME AS NAME
FROM SYSCAT.TABLES
WHERE TYPE = 'T'
AND CREATOR = ?
AND TABSCHEMA = ?
SQL;

return $this->connection->executeQuery($sql, [$databaseName]);
}

protected function selectTableColumns(string $databaseName, ?string $tableName = null): Result
{
$sql = 'SELECT';
$conditions = ['C.TABSCHEMA = ?'];
$params = [$databaseName];

Check warning on line 198 in src/Schema/DB2SchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/DB2SchemaManager.php#L197-L198

Added lines #L197 - L198 were not covered by tests

if ($tableName === null) {
$sql .= ' C.TABNAME AS NAME,';
if ($tableName !== null) {
$conditions[] = 'C.TABNAME = ?';
$params[] = $tableName;

Check warning on line 202 in src/Schema/DB2SchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/DB2SchemaManager.php#L200-L202

Added lines #L200 - L202 were not covered by tests
}

$sql .= <<<'SQL'
$sql = sprintf(
<<<'SQL'

Check warning on line 206 in src/Schema/DB2SchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/DB2SchemaManager.php#L205-L206

Added lines #L205 - L206 were not covered by tests
SELECT
C.TABNAME AS NAME,
C.COLNAME,
C.TYPENAME,
C.CODEPAGE,
Expand All @@ -212,30 +222,30 @@
JOIN SYSCAT.TABLES AS T
ON T.TABSCHEMA = C.TABSCHEMA
AND T.TABNAME = C.TABNAME
SQL;

$conditions = ['C.TABSCHEMA = ?', "T.TYPE = 'T'"];
$params = [$databaseName];

if ($tableName !== null) {
$conditions[] = 'C.TABNAME = ?';
$params[] = $tableName;
}

$sql .= ' WHERE ' . implode(' AND ', $conditions) . ' ORDER BY C.TABNAME, C.COLNO';
WHERE %s
AND T.TYPE = 'T'
ORDER BY C.TABNAME, C.COLNO
SQL,
implode(' AND ', $conditions),
);

Check warning on line 230 in src/Schema/DB2SchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/DB2SchemaManager.php#L228-L230

Added lines #L228 - L230 were not covered by tests

return $this->connection->executeQuery($sql, $params);
}

protected function selectIndexColumns(string $databaseName, ?string $tableName = null): Result
{
$sql = 'SELECT';
$conditions = ['IDX.TABSCHEMA = ?'];
$params = [$databaseName];

Check warning on line 238 in src/Schema/DB2SchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/DB2SchemaManager.php#L237-L238

Added lines #L237 - L238 were not covered by tests

if ($tableName === null) {
$sql .= ' IDX.TABNAME AS NAME,';
if ($tableName !== null) {
$conditions[] = 'IDX.TABNAME = ?';
$params[] = $tableName;

Check warning on line 242 in src/Schema/DB2SchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/DB2SchemaManager.php#L240-L242

Added lines #L240 - L242 were not covered by tests
}

$sql .= <<<'SQL'
$sql = sprintf(
<<<'SQL'

Check warning on line 246 in src/Schema/DB2SchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/DB2SchemaManager.php#L245-L246

Added lines #L245 - L246 were not covered by tests
SELECT
IDX.TABNAME AS NAME,
IDX.INDNAME AS KEY_NAME,
IDXCOL.COLNAME AS COLUMN_NAME,
CASE
Expand All @@ -251,30 +261,32 @@
ON IDX.TABSCHEMA = T.TABSCHEMA AND IDX.TABNAME = T.TABNAME
JOIN SYSCAT.INDEXCOLUSE AS IDXCOL
ON IDX.INDSCHEMA = IDXCOL.INDSCHEMA AND IDX.INDNAME = IDXCOL.INDNAME
SQL;

$conditions = ['IDX.TABSCHEMA = ?', "T.TYPE = 'T'"];
$params = [$databaseName];

if ($tableName !== null) {
$conditions[] = 'IDX.TABNAME = ?';
$params[] = $tableName;
}

$sql .= ' WHERE ' . implode(' AND ', $conditions) . ' ORDER BY IDX.INDNAME, IDXCOL.COLSEQ';
WHERE %s
AND T.TYPE = 'T'
ORDER BY IDX.TABNAME,
IDX.INDNAME,
IDXCOL.COLSEQ
SQL,
implode(' AND ', $conditions),
);

Check warning on line 271 in src/Schema/DB2SchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/DB2SchemaManager.php#L269-L271

Added lines #L269 - L271 were not covered by tests

return $this->connection->executeQuery($sql, $params);
}

protected function selectForeignKeyColumns(string $databaseName, ?string $tableName = null): Result
{
$sql = 'SELECT';
$conditions = ['R.TABSCHEMA = ?'];
$params = [$databaseName];

Check warning on line 279 in src/Schema/DB2SchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/DB2SchemaManager.php#L278-L279

Added lines #L278 - L279 were not covered by tests

if ($tableName === null) {
$sql .= ' R.TABNAME AS NAME,';
if ($tableName !== null) {
$conditions[] = 'R.TABNAME = ?';
$params[] = $tableName;

Check warning on line 283 in src/Schema/DB2SchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/DB2SchemaManager.php#L281-L283

Added lines #L281 - L283 were not covered by tests
}

$sql .= <<<'SQL'
$sql = sprintf(
<<<'SQL'

Check warning on line 287 in src/Schema/DB2SchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/DB2SchemaManager.php#L286-L287

Added lines #L286 - L287 were not covered by tests
SELECT
R.TABNAME AS NAME,
FKCOL.COLNAME AS LOCAL_COLUMN,
R.REFTABNAME AS FOREIGN_TABLE,
PKCOL.COLNAME AS FOREIGN_COLUMN,
Expand All @@ -300,17 +312,14 @@
AND PKCOL.TABSCHEMA = R.REFTABSCHEMA
AND PKCOL.TABNAME = R.REFTABNAME
AND PKCOL.COLSEQ = FKCOL.COLSEQ
SQL;

$conditions = ['R.TABSCHEMA = ?', "T.TYPE = 'T'"];
$params = [$databaseName];

if ($tableName !== null) {
$conditions[] = 'R.TABNAME = ?';
$params[] = $tableName;
}

$sql .= ' WHERE ' . implode(' AND ', $conditions) . ' ORDER BY R.CONSTNAME, FKCOL.COLSEQ';
WHERE %s
AND T.TYPE = 'T'
ORDER BY R.TABNAME,
R.CONSTNAME,
FKCOL.COLSEQ
SQL,
implode(' AND ', $conditions),
);

Check warning on line 322 in src/Schema/DB2SchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/DB2SchemaManager.php#L320-L322

Added lines #L320 - L322 were not covered by tests

return $this->connection->executeQuery($sql, $params);
}
Expand All @@ -320,31 +329,29 @@
*/
protected function fetchTableOptionsByTable(string $databaseName, ?string $tableName = null): array
{
$sql = 'SELECT NAME, REMARKS';

$conditions = [];
$params = [];
$conditions = ['TABSCHEMA = ?'];
$params = [$databaseName];

Check warning on line 333 in src/Schema/DB2SchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/DB2SchemaManager.php#L332-L333

Added lines #L332 - L333 were not covered by tests

if ($tableName !== null) {
$conditions[] = 'NAME = ?';
$conditions[] = 'TABNAME = ?';

Check warning on line 336 in src/Schema/DB2SchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/DB2SchemaManager.php#L336

Added line #L336 was not covered by tests
$params[] = $tableName;
}

$sql .= ' FROM SYSIBM.SYSTABLES';

if ($conditions !== []) {
$sql .= ' WHERE ' . implode(' AND ', $conditions);
}

/** @var array<string,array<string,mixed>> $metadata */
$metadata = $this->connection->executeQuery($sql, $params)
->fetchAllAssociativeIndexed();
$sql = sprintf(
<<<'SQL'

Check warning on line 341 in src/Schema/DB2SchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/DB2SchemaManager.php#L340-L341

Added lines #L340 - L341 were not covered by tests
SELECT TABNAME,
REMARKS
FROM SYSCAT.TABLES
WHERE %s
AND TYPE = 'T'
ORDER BY TABNAME
SQL,
implode(' AND ', $conditions),
);

Check warning on line 350 in src/Schema/DB2SchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/DB2SchemaManager.php#L348-L350

Added lines #L348 - L350 were not covered by tests

$tableOptions = [];
foreach ($metadata as $table => $data) {
$data = array_change_key_case($data, CASE_LOWER);

$tableOptions[$table] = ['comment' => $data['remarks']];
foreach ($this->connection->iterateKeyValue($sql, $params) as $table => $remarks) {
$tableOptions[$table] = ['comment' => $remarks];

Check warning on line 354 in src/Schema/DB2SchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/DB2SchemaManager.php#L353-L354

Added lines #L353 - L354 were not covered by tests
}

return $tableOptions;
Expand Down
Loading
Loading