mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 11:06:15 +00:00
fix a DboDataSource buildJoinStatement bug that table prefix is appended to subquery
This commit is contained in:
parent
ee08fe5c1f
commit
5ac5e784de
2 changed files with 38 additions and 3 deletions
|
@ -1691,9 +1691,8 @@ class DboSource extends DataSource {
|
||||||
if (!empty($data['conditions'])) {
|
if (!empty($data['conditions'])) {
|
||||||
$data['conditions'] = trim($this->conditions($data['conditions'], true, false));
|
$data['conditions'] = trim($this->conditions($data['conditions'], true, false));
|
||||||
}
|
}
|
||||||
if (!empty($data['table'])) {
|
if (!empty($data['table']) && (!is_string($data['table']) || strpos($data['table'], '(') !== 0)){
|
||||||
$schema = !(is_string($data['table']) && strpos($data['table'], '(') === 0);
|
$data['table'] = $this->fullTableName($data['table']);
|
||||||
$data['table'] = $this->fullTableName($data['table'], true, $schema);
|
|
||||||
}
|
}
|
||||||
return $this->renderJoinStatement($data);
|
return $this->renderJoinStatement($data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1121,6 +1121,42 @@ class DboSourceTest extends CakeTestCase {
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* data provider for testBuildJoinStatementWithTablePrefix
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function joinStatementsWithPrefix($schema) {
|
||||||
|
return array(
|
||||||
|
array(array(
|
||||||
|
'type' => 'LEFT',
|
||||||
|
'alias' => 'PostsTag',
|
||||||
|
'table' => 'posts_tags',
|
||||||
|
'conditions' => array('PostsTag.post_id = Post.id')
|
||||||
|
), 'LEFT JOIN pre_posts_tags AS PostsTag ON (PostsTag.post_id = Post.id)'),
|
||||||
|
array(array(
|
||||||
|
'type' => 'LEFT',
|
||||||
|
'alias' => 'Stock',
|
||||||
|
'table' => '(SELECT Stock.article_id, sum(quantite) quantite FROM stocks AS Stock GROUP BY Stock.article_id)',
|
||||||
|
'conditions' => 'Stock.article_id = Article.id'
|
||||||
|
), 'LEFT JOIN (SELECT Stock.article_id, sum(quantite) quantite FROM stocks AS Stock GROUP BY Stock.article_id) AS Stock ON (Stock.article_id = Article.id)')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test buildJoinStatement()
|
||||||
|
* ensure that prefix is not added when table value is a subquery
|
||||||
|
*
|
||||||
|
* @dataProvider joinStatementsWithPrefix
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testBuildJoinStatementWithTablePrefix($join, $expected) {
|
||||||
|
$db = new DboTestSource;
|
||||||
|
$db->config['prefix'] = 'pre_';
|
||||||
|
$result = $db->buildJoinStatement($join);
|
||||||
|
$this->assertEquals($expected, $result);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test conditionKeysToString()
|
* Test conditionKeysToString()
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue