/**
  * Test for PMA_findExistingColNames
  *
  * @return void
  */
 public function testPMAFindExistingColNames()
 {
     $GLOBALS['dbi']->expects($this->at(1))->method('fetchResult')->with("SELECT * FROM `pma_central_columns` WHERE db_name = 'phpmyadmin'" . " AND col_name IN ('col1');", null, null, $GLOBALS['controllink'])->will($this->returnValue(array_slice($this->_columnData, 1, 1)));
     $this->assertEquals(array_slice($this->_modifiedColumnData, 1, 1), PMA_findExistingColNames('phpmyadmin', "'col1'", true));
 }
示例#2
0
/**
 * return the columns present in central list of columns for a given
 * table of a given database
 *
 * @param string  $db        given database
 * @param string  $table     given table
 * @param boolean $allFields set if need all the fields of existing columns,
 * otherwise only column_name is returned
 *
 * @return array columns present in central list from given table of given db.
 */
function PMA_getCentralColumnsFromTable($db, $table, $allFields = false)
{
    $cfgCentralColumns = PMA_centralColumnsGetParams();
    if (empty($cfgCentralColumns)) {
        return array();
    }
    $GLOBALS['dbi']->selectDb($db, $GLOBALS['userlink']);
    $fields = (array) $GLOBALS['dbi']->getColumnNames($db, $table, $GLOBALS['userlink']);
    $cols = '';
    foreach ($fields as $col_select) {
        $cols .= '\'' . PMA_Util::sqlAddSlashes($col_select) . '\',';
    }
    $cols = trim($cols, ',');
    $has_list = PMA_findExistingColNames($db, $cols, $allFields);
    if (isset($has_list) && $has_list) {
        return (array) $has_list;
    } else {
        return array();
    }
}
/**
 * Get HTML for editing page central columns
 *
 * @param array  $selected_fld Array containing the selected fields
 * @param string $selected_db  String containing the name of database
 *
 * @return string HTML for complete editing page for central columns
 */
function PMA_getHTMLforEditingPage($selected_fld, $selected_db)
{
    $html = '<form id="multi_edit_central_columns">';
    $header_cells = array(__('Name'), __('Type'), __('Length/Values'), __('Default'), __('Collation'), __('Attributes'), __('Null'), __('A_I'));
    $html .= PMA_getCentralColumnsEditTableHeader($header_cells);
    $selected_fld_safe = array();
    foreach ($selected_fld as $key) {
        $selected_fld_safe[] = Util::sqlAddSlashes($key);
    }
    $columns_list = implode("','", $selected_fld_safe);
    $columns_list = "'" . $columns_list . "'";
    $list_detail_cols = PMA_findExistingColNames($selected_db, $columns_list, true);
    $odd_row = false;
    $row_num = 0;
    foreach ($list_detail_cols as $row) {
        $tableHtmlRow = PMA_getHTMLforCentralColumnsEditTableRow($row, $odd_row, $row_num);
        $html .= $tableHtmlRow;
        $odd_row = !$odd_row;
        $row_num++;
    }
    $html .= '</table>';
    $html .= PMA_getCentralColumnsEditTableFooter();
    $html .= '</form>';
    return $html;
}
 /**
  * Test for PMA_findExistingColNames
  *
  * @return void
  */
 public function testPMAFindExistingColNames()
 {
     $this->assertEquals(array('id', 'col1'), PMA_findExistingColNames('phpmyadmin', 'col1', true));
 }