Skip to content

Commit

Permalink
DBAL-#2517: Fixed ORA-01427 when listing columns
Browse files Browse the repository at this point in the history
  • Loading branch information
marius-meissner authored and deeky666 committed Jan 14, 2017
1 parent a526d0d commit ecbfc68
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
10 changes: 6 additions & 4 deletions lib/Doctrine/DBAL/Platforms/OraclePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -655,25 +655,27 @@ public function getListTableColumnsSQL($table, $database = null)

$tabColumnsTableName = "user_tab_columns";
$colCommentsTableName = "user_col_comments";
$ownerCondition = '';
$tabColumnsOwnerCondition = '';
$colCommentsOwnerCondition = '';

if (null !== $database && '/' !== $database) {
$database = $this->normalizeIdentifier($database);
$database = $this->quoteStringLiteral($database->getName());
$tabColumnsTableName = "all_tab_columns";
$colCommentsTableName = "all_col_comments";
$ownerCondition = "AND c.owner = " . $database;
$tabColumnsOwnerCondition = "AND c.owner = " . $database;
$colCommentsOwnerCondition = "AND d.OWNER = c.OWNER";
}

return "SELECT c.*,
(
SELECT d.comments
FROM $colCommentsTableName d
WHERE d.TABLE_NAME = c.TABLE_NAME
WHERE d.TABLE_NAME = c.TABLE_NAME " . $colCommentsOwnerCondition . "
AND d.COLUMN_NAME = c.COLUMN_NAME
) AS comments
FROM $tabColumnsTableName c
WHERE c.table_name = " . $table . " $ownerCondition
WHERE c.table_name = " . $table . " $tabColumnsOwnerCondition
ORDER BY c.column_name";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Doctrine\Tests\DBAL\Functional\Schema;

use Doctrine\DBAL\Schema;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Types\Type;
use Doctrine\Tests\TestUtil;

require_once __DIR__ . '/../../../TestInit.php';
Expand Down Expand Up @@ -218,4 +220,17 @@ public function testListTableDetailsWithDifferentIdentifierQuotingRequirements()
$onlineForeignTable->getForeignKey('"Primary_Table_Fk"')->getQuotedForeignColumns($platform)
);
}

public function testListTableColumnsSameTableNamesInDifferentSchemas()
{
$table = $this->createListTableColumns();
$this->_sm->dropAndCreateTable($table);

$otherTable = new Table($table->getName());
$otherTable->addColumn('id', Type::STRING);
TestUtil::getTempConnection()->getSchemaManager()->dropAndCreateTable($otherTable);

$columns = $this->_sm->listTableColumns($table->getName(), $this->_conn->getUsername());
$this->assertCount(7, $columns);
}
}
6 changes: 3 additions & 3 deletions tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ public function getReturnsGetListTableColumnsSQL()
(
SELECT d.comments
FROM user_col_comments d
WHERE d.TABLE_NAME = c.TABLE_NAME
WHERE d.TABLE_NAME = c.TABLE_NAME
AND d.COLUMN_NAME = c.COLUMN_NAME
) AS comments
FROM user_tab_columns c
Expand All @@ -740,7 +740,7 @@ public function getReturnsGetListTableColumnsSQL()
(
SELECT d.comments
FROM user_col_comments d
WHERE d.TABLE_NAME = c.TABLE_NAME
WHERE d.TABLE_NAME = c.TABLE_NAME
AND d.COLUMN_NAME = c.COLUMN_NAME
) AS comments
FROM user_tab_columns c
Expand All @@ -753,7 +753,7 @@ public function getReturnsGetListTableColumnsSQL()
(
SELECT d.comments
FROM all_col_comments d
WHERE d.TABLE_NAME = c.TABLE_NAME
WHERE d.TABLE_NAME = c.TABLE_NAME AND d.OWNER = c.OWNER
AND d.COLUMN_NAME = c.COLUMN_NAME
) AS comments
FROM all_tab_columns c
Expand Down

0 comments on commit ecbfc68

Please sign in to comment.