/** * Analysing where clauses array * * @param array $where_clause_array array of where clauses * @param string $table name of the table * @param string $db name of the database * * @return array $where_clauses, $result, $rows */ function PMA_analyzeWhereClauses($where_clause_array, $table, $db) { $rows = array(); $result = array(); $where_clauses = array(); $found_unique_key = false; foreach ($where_clause_array as $key_id => $where_clause) { $local_query = 'SELECT * FROM ' . PMA_Util::backquote($db) . '.' . PMA_Util::backquote($table) . ' WHERE ' . $where_clause . ';'; $result[$key_id] = $GLOBALS['dbi']->query($local_query, null, PMA_DatabaseInterface::QUERY_STORE); $rows[$key_id] = $GLOBALS['dbi']->fetchAssoc($result[$key_id]); $where_clauses[$key_id] = str_replace('\\', '\\\\', $where_clause); $has_unique_condition = PMA_showEmptyResultMessageOrSetUniqueCondition($rows, $key_id, $where_clause_array, $local_query, $result); if ($has_unique_condition) { $found_unique_key = true; } } return array($where_clauses, $result, $rows, $found_unique_key); }
/** * Test for PMA_showEmptyResultMessageOrSetUniqueCondition * * @return void */ public function testShowEmptyResultMessageOrSetUniqueCondition() { $temp = new stdClass(); $temp->orgname = 'orgname'; $temp->table = 'table'; $temp->type = 'real'; $temp->primary_key = 1; $meta_arr = array($temp); $dbi = $this->getMockBuilder('PMA_DatabaseInterface')->disableOriginalConstructor()->getMock(); $dbi->expects($this->at(0))->method('getFieldsMeta')->with('result1')->will($this->returnValue($meta_arr)); $GLOBALS['dbi'] = $dbi; $result = PMA_showEmptyResultMessageOrSetUniqueCondition(array('1' => array('1' => 1)), 1, array(), 'SELECT', array('1' => 'result1')); $this->assertTrue($result); // case 2 $GLOBALS['cfg']['ShowSQL'] = false; $responseMock = $this->getMockBuilder('PMA_Response')->disableOriginalConstructor()->setMethods(array('addHtml'))->getMock(); $response = new ReflectionProperty('PMA_Response', '_instance'); $response->setAccessible(true); $response->setValue(null, $responseMock); $result = PMA_showEmptyResultMessageOrSetUniqueCondition(array(false), 0, array('1'), 'SELECT', array('1' => 'result1')); $this->assertFalse($result); }
/** * Analysing where clauses array * * @param array $where_clause_array array of where clauses * @param string $table name of the table * @param string $db name of the database * * @return array $where_clauses, $result, $rows */ function PMA_analyzeWhereClauses($where_clause_array, $table, $db) { $rows = array(); $result = array(); $where_clauses = array(); $found_unique_key = false; foreach ($where_clause_array as $key_id => $where_clause) { $local_query = 'SELECT * FROM ' . PMA_CommonFunctions::getInstance()->backquote($db) . '.' . PMA_CommonFunctions::getInstance()->backquote($table) . ' WHERE ' . $where_clause . ';'; $result[$key_id] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE); $rows[$key_id] = PMA_DBI_fetch_assoc($result[$key_id]); $where_clauses[$key_id] = str_replace('\\', '\\\\', $where_clause); $has_unique_condition = PMA_showEmptyResultMessageOrSetUniqueCondition($rows, $key_id, $where_clause_array, $local_query, $result); if ($has_unique_condition) { $found_unique_key = true; } } return array($where_clauses, $result, $rows, $found_unique_key); }