Skip to content

Commit

Permalink
Remove the CrossSchemaTableExpression
Browse files Browse the repository at this point in the history
This change has caused regressions for a few folks. It also doesn't work
in all the scenarios that people need it to. Not having a problematic
feature is better than having a broken one.

There was a reasonable solution in the past that involved using
`$this->table('db.table_name')` this is a decent solution that makes the
cross db joins explicit.

Refs #9293
Refs #8679
  • Loading branch information
markstory committed Aug 18, 2016
1 parent 25bcf1b commit b5787a0
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 290 deletions.
32 changes: 0 additions & 32 deletions src/Database/Connection.php
Expand Up @@ -711,38 +711,6 @@ public function log($sql)
$this->logger()->log($query);
}

/**
* Check if cross talk is supported between two connections
*
* @param ConnectionInterface $target Connection to check cross talk with
*
* @return bool
*/
public function supportsCrossWith(ConnectionInterface $target)
{
$sourceConfig = $this->config();
$targetConfig = $target->config();

// No need to do report cross support in case the same connection is being used
if ($sourceConfig['name'] === $targetConfig['name']) {
return false;
}

$configToCheck = [
'driver',
'host',
'port'
];

foreach ($configToCheck as $config) {
if ((isset($sourceConfig[$config])) && ($sourceConfig[$config] !== $targetConfig[$config])) {
return false;
}
}

return true;
}

/**
* Returns a new statement object that will log the activity
* for the passed original statement instance.
Expand Down
129 changes: 0 additions & 129 deletions src/Database/Expression/CrossSchemaTableExpression.php

This file was deleted.

22 changes: 0 additions & 22 deletions src/Database/IdentifierQuoter.php
Expand Up @@ -14,7 +14,6 @@
*/
namespace Cake\Database;

use Cake\Database\Expression\CrossSchemaTableExpression;
use Cake\Database\Expression\FieldInterface;
use Cake\Database\Expression\IdentifierExpression;
use Cake\Database\Expression\OrderByExpression;
Expand Down Expand Up @@ -93,11 +92,6 @@ public function quoteExpression($expression)
if ($expression instanceof IdentifierExpression) {
$this->_quoteIdentifierExpression($expression);

return;
}
if ($expression instanceof CrossSchemaTableExpression) {
$this->_quoteCrossSchemaTableExpression($expression);

return;
}
}
Expand Down Expand Up @@ -267,20 +261,4 @@ protected function _quoteIdentifierExpression(IdentifierExpression $expression)
$this->_driver->quoteIdentifier($expression->getIdentifier())
);
}

/**
* Quotes the cross schema table identifier
*
* @param CrossSchemaTableExpression $expression The identifier to quote
* @return void
*/
protected function _quoteCrossSchemaTableExpression(CrossSchemaTableExpression $expression)
{
if (!$expression->schema() instanceof ExpressionInterface) {
$expression->schema($this->_driver->quoteIdentifier($expression->schema()));
}
if (!$expression->table() instanceof ExpressionInterface) {
$expression->table($this->_driver->quoteIdentifier($expression->table()));
}
}
}
8 changes: 0 additions & 8 deletions src/ORM/Association.php
Expand Up @@ -16,7 +16,6 @@

use Cake\Collection\Collection;
use Cake\Core\ConventionsTrait;
use Cake\Database\Expression\CrossSchemaTableExpression;
use Cake\Database\Expression\IdentifierExpression;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetDecorator;
Expand Down Expand Up @@ -557,14 +556,7 @@ public function attachTo(Query $query, array $options = [])
{
$target = $this->target();
$joinType = empty($options['joinType']) ? $this->joinType() : $options['joinType'];

$table = $target->table();
if ($this->source()->connection()->supportsCrossWith($target->connection())) {
$table = new CrossSchemaTableExpression(
$target->connection()->driver()->schema(),
$table
);
}

$options += [
'includeFields' => true,
Expand Down
28 changes: 0 additions & 28 deletions tests/TestCase/Database/ConnectionTest.php
Expand Up @@ -987,32 +987,4 @@ public function testSchemaCollection()
$connection->schemaCollection($schema);
$this->assertSame($schema, $connection->schemaCollection());
}

/**
* Tests supportsCrossWith
*
* @return void
*/
public function testSupportsCrossWith()
{
$connection = new Connection(ConnectionManager::config('test'));
$targetConnection = new Connection(ConnectionManager::config('test'));

$this->assertFalse($connection->supportsCrossWith($targetConnection), 'The same connection can\'t used in cross');

$connection = new Connection(ConnectionManager::config('test'));
$targetConnection = new Connection(['name' => 'test2'] + ConnectionManager::config('test'));

$this->assertTrue($connection->supportsCrossWith($targetConnection), 'Cross should be supported on databases on the same server');

$connection = new Connection(ConnectionManager::config('test'));
$targetConnection = new Connection(['port' => 999999] + ConnectionManager::config('test'));

$this->assertFalse($connection->supportsCrossWith($targetConnection), 'Cross is not supported across different server instances');

$connection = new Connection(ConnectionManager::config('test'));
$targetConnection = new Connection(['host' => 'db2.example.com'] + ConnectionManager::config('test'));

$this->assertFalse($connection->supportsCrossWith($targetConnection), 'Cross is not supported across different server instances');
}
}

This file was deleted.

0 comments on commit b5787a0

Please sign in to comment.