Bug#4511: QBE fails to generate LEFT join for InnoDB foreign keys in absence of configuration storage.

Signed-off-by: Ashutosh Dhundhara <ashutoshdhundhara@yahoo.com>
This commit is contained in:
Ashutosh Dhundhara 2014-08-11 01:50:33 +05:30
parent 90e96a736a
commit 9191c1aa4e
4 changed files with 33 additions and 7 deletions

View File

@ -1366,7 +1366,7 @@ class PMA_DbQbe
} // end while
// Create LEFT JOINS out of Relations
if ($cfgRelation['relwork'] && count($all_tables) > 0) {
if (count($all_tables) > 0) {
// Get tables and columns with valid where clauses
$valid_where_clauses = $this->_getWhereClauseTablesAndColumns();
$where_clause_tables = $valid_where_clauses['where_clause_tables'];

View File

@ -1334,7 +1334,7 @@ function PMA_getRelatives($all_tables, $master)
$known_tables = array();
$known_tables[$master] = $master;
$run = 0;
while (count($remaining_tables) > 0) {
while ($GLOBALS['cfgRelation']['relwork'] && count($remaining_tables) > 0) {
// Whether to go from master to foreign or vice versa
if ($run % 2 == 0) {
$from = 'master';

View File

@ -152,7 +152,8 @@ $columns = $GLOBALS['dbi']->getColumns($db, $table);
// common form
$html_output .= PMA_getHtmlForCommonForm(
$db, $table, $columns, $cfgRelation, $tbl_storage_engine, $existrel,
$db, $table, $columns, $cfgRelation, $tbl_storage_engine,
isset($existrel) ? $existrel : null,
isset($existrel_foreign) ? $existrel_foreign['foreign_keys_data'] : null,
$options_array
);

View File

@ -16,6 +16,7 @@ require_once 'libraries/core.lib.php';
require_once 'libraries/database_interface.inc.php';
require_once 'libraries/Tracker.class.php';
require_once 'libraries/relation.lib.php';
require_once 'libraries/sqlparser.lib.php';
/**
* Tests for PMA_DBQbe class
@ -39,6 +40,30 @@ class PMA_DBQbe_Test extends PHPUnit_Framework_TestCase
protected function setUp()
{
$this->object = new PMA_DBQbe('pma_test');
$GLOBALS['server'] = 0;
$GLOBALS['db'] = 'pma_test';
//mock DBI
$dbi = $this->getMockBuilder('PMA_DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$create_table = 'CREATE TABLE `table1` ('
. '`id` int(11) NOT NULL,'
. '`value` int(11) NOT NULL,'
. 'PRIMARY KEY (`id`,`value`),'
. 'KEY `value` (`value`)'
. ') ENGINE=InnoDB DEFAULT CHARSET=latin1';
$dbi->expects($this->any())
->method('fetchValue')
->with('SHOW CREATE TABLE `pma_test`.`table1`', 0, 1)
->will($this->returnValue($create_table));
$dbi->expects($this->any())
->method('getTableIndexes')
->will($this->returnValue(array()));
$GLOBALS['dbi'] = $dbi;
}
/**
@ -400,7 +425,7 @@ class PMA_DBQbe_Test extends PHPUnit_Framework_TestCase
$this->_callProtectedFunction(
'_getIndexes',
array(
array('table1','table2'),
array('`table1`','table2'),
array('column1', 'column2', 'column3'),
array('column2')
)
@ -422,7 +447,7 @@ class PMA_DBQbe_Test extends PHPUnit_Framework_TestCase
$this->_callProtectedFunction(
'_getLeftJoinColumnCandidates',
array(
array('table1','table2'),
array('`table1`','table2'),
array('column1', 'column2', 'column3'),
array('column2')
)
@ -490,7 +515,7 @@ class PMA_DBQbe_Test extends PHPUnit_Framework_TestCase
'table1.deleted'
);
$this->assertEquals(
'table1',
'`table1`',
$this->_callProtectedFunction(
'_getFromClause',
array(array('relwork' => false))
@ -512,7 +537,7 @@ class PMA_DBQbe_Test extends PHPUnit_Framework_TestCase
'table1.deleted'
);
$this->assertEquals(
'FROM table1
'FROM `table1`
',
$this->_callProtectedFunction(
'_getSQLQuery',