/** * Test case for parsing SHOW COLUMNS output * * @dataProvider provider */ public function testParsing($in, $out) { $this->assertEquals($out, PMA_extractFieldSpec($in)); }
public function dataDictionaryDoc($alltables) { global $db, $pdf, $orientation, $paper; // TOC $pdf->addpage($_POST['orientation']); $pdf->Cell(0, 9, __('Table of contents'), 1, 0, 'C'); $pdf->Ln(15); $i = 1; foreach ($alltables as $table) { $pdf->PMA_links['doc'][$table]['-'] = $pdf->AddLink(); $pdf->SetX(10); // $pdf->Ln(1); $pdf->Cell(0, 6, __('Page number:') . ' {' . sprintf("%02d", $i) . '}', 0, 0, 'R', 0, $pdf->PMA_links['doc'][$table]['-']); $pdf->SetX(10); $pdf->Cell(0, 6, $i . ' ' . $table, 0, 1, 'L', 0, $pdf->PMA_links['doc'][$table]['-']); // $pdf->Ln(1); $fields = PMA_DBI_get_columns($GLOBALS['db'], $table); foreach ($fields as $row) { $pdf->SetX(20); $field_name = $row['Field']; $pdf->PMA_links['doc'][$table][$field_name] = $pdf->AddLink(); //$pdf->Cell( // 0, 6, $field_name, 0, 1, // 'L', 0, $pdf->PMA_links['doc'][$table][$field_name] //); } $i++; } $pdf->PMA_links['RT']['-'] = $pdf->AddLink(); $pdf->SetX(10); $pdf->Cell(0, 6, __('Page number:') . ' {00}', 0, 0, 'R', 0, $pdf->PMA_links['RT']['-']); $pdf->SetX(10); $pdf->Cell(0, 6, $i . ' ' . __('Relational schema'), 0, 1, 'L', 0, $pdf->PMA_links['RT']['-']); $z = 0; foreach ($alltables as $table) { $z++; $pdf->SetAutoPageBreak(true, 15); $pdf->addpage($_POST['orientation']); $pdf->Bookmark($table); $pdf->SetAlias('{' . sprintf("%02d", $z) . '}', $pdf->PageNo()); $pdf->PMA_links['RT'][$table]['-'] = $pdf->AddLink(); $pdf->SetLink($pdf->PMA_links['doc'][$table]['-'], -1); $pdf->SetFont($this->_ff, 'B', 18); $pdf->Cell(0, 8, $z . ' ' . $table, 1, 1, 'C', 0, $pdf->PMA_links['RT'][$table]['-']); $pdf->SetFont($this->_ff, '', 8); $pdf->ln(); $cfgRelation = PMA_getRelationsParam(); $comments = PMA_getComments($db, $table); if ($cfgRelation['mimework']) { $mime_map = PMA_getMIME($db, $table, true); } /** * Gets table informations */ $showtable = PMA_Table::sGetStatusInfo($db, $table); $show_comment = isset($showtable['Comment']) ? $showtable['Comment'] : ''; $create_time = isset($showtable['Create_time']) ? PMA_localisedDate(strtotime($showtable['Create_time'])) : ''; $update_time = isset($showtable['Update_time']) ? PMA_localisedDate(strtotime($showtable['Update_time'])) : ''; $check_time = isset($showtable['Check_time']) ? PMA_localisedDate(strtotime($showtable['Check_time'])) : ''; /** * Gets table keys and retains them */ $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';'); $primary = ''; $indexes = array(); $lastIndex = ''; $indexes_info = array(); $indexes_data = array(); $pk_array = array(); // will be use to emphasis prim. keys in the table // view while ($row = PMA_DBI_fetch_assoc($result)) { // Backups the list of primary keys if ($row['Key_name'] == 'PRIMARY') { $primary .= $row['Column_name'] . ', '; $pk_array[$row['Column_name']] = 1; } // Retains keys informations if ($row['Key_name'] != $lastIndex) { $indexes[] = $row['Key_name']; $lastIndex = $row['Key_name']; } $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index']; $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique']; if (isset($row['Cardinality'])) { $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality']; } // I don't know what does following column mean.... // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed']; $indexes_info[$row['Key_name']]['Comment'] = $row['Comment']; $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name']; if (isset($row['Sub_part'])) { $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part']; } } // end while if ($result) { PMA_DBI_free_result($result); } /** * Gets fields properties */ $columns = PMA_DBI_get_columns($db, $table); // Check if we can use Relations if (!empty($cfgRelation['relation'])) { // Find which tables are related with the current one and write it in // an array $res_rel = PMA_getForeigners($db, $table); if (count($res_rel) > 0) { $have_rel = true; } else { $have_rel = false; } } else { $have_rel = false; } // end if /** * Displays the comments of the table if MySQL >= 3.23 */ $break = false; if (!empty($show_comment)) { $pdf->Cell(0, 3, __('Table comments') . ' : ' . $show_comment, 0, 1); $break = true; } if (!empty($create_time)) { $pdf->Cell(0, 3, __('Creation') . ': ' . $create_time, 0, 1); $break = true; } if (!empty($update_time)) { $pdf->Cell(0, 3, __('Last update') . ': ' . $update_time, 0, 1); $break = true; } if (!empty($check_time)) { $pdf->Cell(0, 3, __('Last check') . ': ' . $check_time, 0, 1); $break = true; } if ($break == true) { $pdf->Cell(0, 3, '', 0, 1); $pdf->Ln(); } $pdf->SetFont($this->_ff, 'B'); if (isset($orientation) && $orientation == 'L') { $pdf->Cell(25, 8, __('Column'), 1, 0, 'C'); $pdf->Cell(20, 8, __('Type'), 1, 0, 'C'); $pdf->Cell(20, 8, __('Attributes'), 1, 0, 'C'); $pdf->Cell(10, 8, __('Null'), 1, 0, 'C'); $pdf->Cell(20, 8, __('Default'), 1, 0, 'C'); $pdf->Cell(25, 8, __('Extra'), 1, 0, 'C'); $pdf->Cell(45, 8, __('Links to'), 1, 0, 'C'); if ($paper == 'A4') { $comments_width = 67; } else { // this is really intended for 'letter' /** * @todo find optimal width for all formats */ $comments_width = 50; } $pdf->Cell($comments_width, 8, __('Comments'), 1, 0, 'C'); $pdf->Cell(45, 8, 'MIME', 1, 1, 'C'); $pdf->SetWidths(array(25, 20, 20, 10, 20, 25, 45, $comments_width, 45)); } else { $pdf->Cell(20, 8, __('Column'), 1, 0, 'C'); $pdf->Cell(20, 8, __('Type'), 1, 0, 'C'); $pdf->Cell(20, 8, __('Attributes'), 1, 0, 'C'); $pdf->Cell(10, 8, __('Null'), 1, 0, 'C'); $pdf->Cell(15, 8, __('Default'), 1, 0, 'C'); $pdf->Cell(15, 8, __('Extra'), 1, 0, 'C'); $pdf->Cell(30, 8, __('Links to'), 1, 0, 'C'); $pdf->Cell(30, 8, __('Comments'), 1, 0, 'C'); $pdf->Cell(30, 8, 'MIME', 1, 1, 'C'); $pdf->SetWidths(array(20, 20, 20, 10, 15, 15, 30, 30, 30)); } $pdf->SetFont($this->_ff, ''); foreach ($columns as $row) { $extracted_fieldspec = PMA_extractFieldSpec($row['Type']); $type = $extracted_fieldspec['print_type']; $attribute = $extracted_fieldspec['attribute']; if (!isset($row['Default'])) { if ($row['Null'] != '' && $row['Null'] != 'NO') { $row['Default'] = 'NULL'; } } $field_name = $row['Field']; // $pdf->Ln(); $pdf->PMA_links['RT'][$table][$field_name] = $pdf->AddLink(); $pdf->Bookmark($field_name, 1, -1); $pdf->SetLink($pdf->PMA_links['doc'][$table][$field_name], -1); $pdf_row = array($field_name, $type, $attribute, $row['Null'] == '' || $row['Null'] == 'NO' ? __('No') : __('Yes'), isset($row['Default']) ? $row['Default'] : '', $row['Extra'], isset($res_rel[$field_name]) ? $res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'] : '', isset($comments[$field_name]) ? $comments[$field_name] : '', isset($mime_map) && isset($mime_map[$field_name]) ? str_replace('_', '/', $mime_map[$field_name]['mimetype']) : ''); $links[0] = $pdf->PMA_links['RT'][$table][$field_name]; if (isset($res_rel[$field_name]['foreign_table']) and isset($res_rel[$field_name]['foreign_field']) and isset($pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']])) { $links[6] = $pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']]; } else { unset($links[6]); } $pdf->Row($pdf_row, $links); } // end foreach $pdf->SetFont($this->_ff, '', 14); } //end each }
if (!$timestamp_seen) { // can only occur once per table $timestamp_seen = 1; $table_fields[$i]['first_timestamp'] = true; } $table_fields[$i]['pma_type'] = $table_fields[$i]['Type']; $table_fields[$i]['wrap'] = ' nowrap="nowrap"'; break; default: $table_fields[$i]['pma_type'] = $table_fields[$i]['Type']; $table_fields[$i]['wrap'] = ' nowrap="nowrap"'; break; } } $field = $table_fields[$i]; $extracted_fieldspec = PMA_extractFieldSpec($field['Type']); if (-1 === $field['len']) { $field['len'] = PMA_DBI_field_len($vresult, $i); } $unnullify_trigger = $chg_evt_handler . "=\"return unNullify('" . PMA_escapeJsString($field['Field_md5']) . "', '" . PMA_escapeJsString($jsvkey) . "')\""; // Use an MD5 as an array index to avoid having special characters in the name atttibute (see bug #1746964 ) $field_name_appendix = $vkey . '[' . $field['Field_md5'] . ']'; $field_name_appendix_md5 = $field['Field_md5'] . $vkey . '[]'; if ($field['Type'] == 'datetime' && !isset($field['Default']) && !is_null($field['Default']) && ($insert_mode || !isset($vrow[$field['Field']]))) { // INSERT case or // UPDATE case with an NULL value $vrow[$field['Field']] = date('Y-m-d H:i:s', time()); } ?> <tr class="<?php echo $odd_row ? 'odd' : 'even';
/** * Outputs table's structure * * @param string $db database name * @param string $table table name * @param string $crlf the end of line sequence * @param string $error_url the url to go back in case of error * @param bool $do_relation whether to include relation comments * @param bool $do_comments whether to include the pmadb-style column comments * as comments in the structure; this is deprecated * but the parameter is left here because export.php * calls PMA_exportStructure() also for other export * types which use this parameter * @param bool $do_mime whether to include mime comments * @param bool $dates whether to include creation/update/check dates * @param string $export_mode 'create_table', 'triggers', 'create_view', 'stand_in' * @param string $export_type 'server', 'database', 'table' * * @return bool Whether it succeeded * * @access public */ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false, $export_mode, $export_type) { global $cfgRelation; /* We do not export triggers */ if ($export_mode == 'triggers') { return true; } /** * Get the unique keys in the table */ $unique_keys = array(); $keys = PMA_DBI_get_table_indexes($db, $table); foreach ($keys as $key) { if ($key['Non_unique'] == 0) { $unique_keys[] = $key['Column_name']; } } /** * Gets fields properties */ PMA_DBI_select_db($db); // Check if we can use Relations if ($do_relation && !empty($cfgRelation['relation'])) { // Find which tables are related with the current one and write it in // an array $res_rel = PMA_getForeigners($db, $table); if ($res_rel && count($res_rel) > 0) { $have_rel = true; } else { $have_rel = false; } } else { $have_rel = false; } // end if /** * Displays the table structure */ $buffer = $crlf . '%' . $crlf . '% ' . __('Structure') . ': ' . $table . $crlf . '%' . $crlf . ' \\begin{longtable}{'; if (!PMA_exportOutputHandler($buffer)) { return false; } $columns_cnt = 4; $alignment = '|l|c|c|c|'; if ($do_relation && $have_rel) { $columns_cnt++; $alignment .= 'l|'; } if ($do_comments) { $columns_cnt++; $alignment .= 'l|'; } if ($do_mime && $cfgRelation['mimework']) { $columns_cnt++; $alignment .= 'l|'; } $buffer = $alignment . '} ' . $crlf; $header = ' \\hline '; $header .= '\\multicolumn{1}{|c|}{\\textbf{' . __('Column') . '}} & \\multicolumn{1}{|c|}{\\textbf{' . __('Type') . '}} & \\multicolumn{1}{|c|}{\\textbf{' . __('Null') . '}} & \\multicolumn{1}{|c|}{\\textbf{' . __('Default') . '}}'; if ($do_relation && $have_rel) { $header .= ' & \\multicolumn{1}{|c|}{\\textbf{' . __('Links to') . '}}'; } if ($do_comments) { $header .= ' & \\multicolumn{1}{|c|}{\\textbf{' . __('Comments') . '}}'; $comments = PMA_getComments($db, $table); } if ($do_mime && $cfgRelation['mimework']) { $header .= ' & \\multicolumn{1}{|c|}{\\textbf{MIME}}'; $mime_map = PMA_getMIME($db, $table, true); } // Table caption for first page and label if (isset($GLOBALS['latex_caption'])) { $buffer .= ' \\caption{' . PMA_expandUserString($GLOBALS['latex_structure_caption'], 'PMA_texEscape', array('table' => $table, 'database' => $db)) . '} \\label{' . PMA_expandUserString($GLOBALS['latex_structure_label'], null, array('table' => $table, 'database' => $db)) . '} \\\\' . $crlf; } $buffer .= $header . ' \\\\ \\hline \\hline' . $crlf . '\\endfirsthead' . $crlf; // Table caption on next pages if (isset($GLOBALS['latex_caption'])) { $buffer .= ' \\caption{' . PMA_expandUserString($GLOBALS['latex_structure_continued_caption'], 'PMA_texEscape', array('table' => $table, 'database' => $db)) . '} \\\\ ' . $crlf; } $buffer .= $header . ' \\\\ \\hline \\hline \\endhead \\endfoot ' . $crlf; if (!PMA_exportOutputHandler($buffer)) { return false; } $fields = PMA_DBI_get_columns($db, $table); foreach ($fields as $row) { $extracted_fieldspec = PMA_extractFieldSpec($row['Type']); $type = $extracted_fieldspec['print_type']; if (empty($type)) { $type = ' '; } if (!isset($row['Default'])) { if ($row['Null'] != 'NO') { $row['Default'] = 'NULL'; } } $field_name = $row['Field']; $local_buffer = $field_name . "" . $type . "" . ($row['Null'] == '' || $row['Null'] == 'NO' ? __('No') : __('Yes')) . "" . (isset($row['Default']) ? $row['Default'] : ''); if ($do_relation && $have_rel) { $local_buffer .= ""; if (isset($res_rel[$field_name])) { $local_buffer .= $res_rel[$field_name]['foreign_table'] . ' (' . $res_rel[$field_name]['foreign_field'] . ')'; } } if ($do_comments && $cfgRelation['commwork']) { $local_buffer .= ""; if (isset($comments[$field_name])) { $local_buffer .= $comments[$field_name]; } } if ($do_mime && $cfgRelation['mimework']) { $local_buffer .= ""; if (isset($mime_map[$field_name])) { $local_buffer .= str_replace('_', '/', $mime_map[$field_name]['mimetype']); } } $local_buffer = PMA_texEscape($local_buffer); if ($row['Key'] == 'PRI') { $pos = strpos($local_buffer, ""); $local_buffer = '\\textit{' . substr($local_buffer, 0, $pos) . '}' . substr($local_buffer, $pos); } if (in_array($field_name, $unique_keys)) { $pos = strpos($local_buffer, ""); $local_buffer = '\\textbf{' . substr($local_buffer, 0, $pos) . '}' . substr($local_buffer, $pos); } $buffer = str_replace("", ' & ', $local_buffer); $buffer .= ' \\\\ \\hline ' . $crlf; if (!PMA_exportOutputHandler($buffer)) { return false; } } // end while $buffer = ' \\end{longtable}' . $crlf; return PMA_exportOutputHandler($buffer); }
/** * Outputs table's structure * * @param string $db database name * @param string $table table name * @param string $crlf the end of line sequence * @param string $error_url the url to go back in case of error * @param bool $do_relation whether to include relation comments * @param bool $do_comments whether to include the pmadb-style column comments * as comments in the structure; this is deprecated * but the parameter is left here because export.php * calls PMA_exportStructure() also for other export * types which use this parameter * @param bool $do_mime whether to include mime comments * @param bool $dates whether to include creation/update/check dates * @param string $export_mode 'create_table', 'triggers', 'create_view', 'stand_in' * @param string $export_type 'server', 'database', 'table' * * @return bool Whether it succeeded * * @access public */ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false, $export_mode, $export_type) { global $cfgRelation; /* We do not export triggers */ if ($export_mode == 'triggers') { return true; } /* Heading */ $GLOBALS['odt_buffer'] .= '<text:h text:outline-level="2" text:style-name="Heading_2" text:is-list-header="true">' . __('Table structure for table') . ' ' . htmlspecialchars($table) . '</text:h>'; /** * Get the unique keys in the table */ $unique_keys = array(); $keys = PMA_DBI_get_table_indexes($db, $table); foreach ($keys as $key) { if ($key['Non_unique'] == 0) { $unique_keys[] = $key['Column_name']; } } /** * Gets fields properties */ PMA_DBI_select_db($db); // Check if we can use Relations if ($do_relation && !empty($cfgRelation['relation'])) { // Find which tables are related with the current one and write it in // an array $res_rel = PMA_getForeigners($db, $table); if ($res_rel && count($res_rel) > 0) { $have_rel = true; } else { $have_rel = false; } } else { $have_rel = false; } // end if /** * Displays the table structure */ $GLOBALS['odt_buffer'] .= '<table:table table:name="' . htmlspecialchars($table) . '_data">'; $columns_cnt = 4; if ($do_relation && $have_rel) { $columns_cnt++; } if ($do_comments) { $columns_cnt++; } if ($do_mime && $cfgRelation['mimework']) { $columns_cnt++; } $GLOBALS['odt_buffer'] .= '<table:table-column table:number-columns-repeated="' . $columns_cnt . '"/>'; /* Header */ $GLOBALS['odt_buffer'] .= '<table:table-row>'; $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . __('Column') . '</text:p>' . '</table:table-cell>'; $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . __('Type') . '</text:p>' . '</table:table-cell>'; $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . __('Null') . '</text:p>' . '</table:table-cell>'; $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . __('Default') . '</text:p>' . '</table:table-cell>'; if ($do_relation && $have_rel) { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . __('Links to') . '</text:p>' . '</table:table-cell>'; } if ($do_comments) { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . __('Comments') . '</text:p>' . '</table:table-cell>'; $comments = PMA_getComments($db, $table); } if ($do_mime && $cfgRelation['mimework']) { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . __('MIME type') . '</text:p>' . '</table:table-cell>'; $mime_map = PMA_getMIME($db, $table, true); } $GLOBALS['odt_buffer'] .= '</table:table-row>'; $columns = PMA_DBI_get_columns($db, $table); foreach ($columns as $column) { $field_name = $column['Field']; $GLOBALS['odt_buffer'] .= '<table:table-row>'; $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars($field_name) . '</text:p>' . '</table:table-cell>'; $extracted_fieldspec = PMA_extractFieldSpec($column['Type']); $type = htmlspecialchars($extracted_fieldspec['print_type']); if (empty($type)) { $type = ' '; } $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars($type) . '</text:p>' . '</table:table-cell>'; if (!isset($column['Default'])) { if ($column['Null'] != 'NO') { $column['Default'] = 'NULL'; } else { $column['Default'] = ''; } } else { $column['Default'] = $column['Default']; } $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . ($column['Null'] == '' || $column['Null'] == 'NO' ? __('No') : __('Yes')) . '</text:p>' . '</table:table-cell>'; $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars($column['Default']) . '</text:p>' . '</table:table-cell>'; if ($do_relation && $have_rel) { if (isset($res_rel[$field_name])) { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' (' . $res_rel[$field_name]['foreign_field'] . ')') . '</text:p>' . '</table:table-cell>'; } } if ($do_comments) { if (isset($comments[$field_name])) { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars($comments[$field_name]) . '</text:p>' . '</table:table-cell>'; } else { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p></text:p>' . '</table:table-cell>'; } } if ($do_mime && $cfgRelation['mimework']) { if (isset($mime_map[$field_name])) { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype'])) . '</text:p>' . '</table:table-cell>'; } else { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p></text:p>' . '</table:table-cell>'; } } $GLOBALS['odt_buffer'] .= '</table:table-row>'; } // end while $GLOBALS['odt_buffer'] .= '</table:table>'; return true; }
/** * Outputs table's structure * * @param string $db database name * @param string $table table name * @param string $crlf the end of line sequence * @param string $error_url the url to go back in case of error * @param bool $do_relation whether to include relation comments * @param bool $do_comments whether to include the pmadb-style column comments * as comments in the structure; this is deprecated * but the parameter is left here because export.php * calls PMA_exportStructure() also for other export * types which use this parameter * @param bool $do_mime whether to include mime comments * @param bool $dates whether to include creation/update/check dates * @param string $export_mode 'create_table', 'triggers', 'create_view', 'stand_in' * @param string $export_type 'server', 'database', 'table' * @return bool Whether it succeeded * * @access public */ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false, $export_mode, $export_type) { global $cfgRelation; if (!PMA_exportOutputHandler('<h2>' . __('Table structure for table') . ' ' . htmlspecialchars($table) . '</h2>')) { return false; } /** * Get the unique keys in the table */ $unique_keys = array(); $keys = PMA_DBI_get_table_indexes($db, $table); foreach ($keys as $key) { if ($key['Non_unique'] == 0) { $unique_keys[] = $key['Column_name']; } } /** * Gets fields properties */ PMA_DBI_select_db($db); // Check if we can use Relations if ($do_relation && !empty($cfgRelation['relation'])) { // Find which tables are related with the current one and write it in // an array $res_rel = PMA_getForeigners($db, $table); if ($res_rel && count($res_rel) > 0) { $have_rel = true; } else { $have_rel = false; } } else { $have_rel = false; } // end if /** * Displays the table structure */ if (!PMA_exportOutputHandler('<table class="width100" cellspacing="1">')) { return false; } $columns_cnt = 4; if ($do_relation && $have_rel) { $columns_cnt++; } if ($do_comments && $cfgRelation['commwork']) { $columns_cnt++; } if ($do_mime && $cfgRelation['mimework']) { $columns_cnt++; } $schema_insert = '<tr class="print-category">'; $schema_insert .= '<th class="print">' . __('Column') . '</th>'; $schema_insert .= '<td class="print"><b>' . __('Type') . '</b></td>'; $schema_insert .= '<td class="print"><b>' . __('Null') . '</b></td>'; $schema_insert .= '<td class="print"><b>' . __('Default') . '</b></td>'; if ($do_relation && $have_rel) { $schema_insert .= '<td class="print"><b>' . __('Links to') . '</b></td>'; } if ($do_comments) { $schema_insert .= '<td class="print"><b>' . __('Comments') . '</b></td>'; $comments = PMA_getComments($db, $table); } if ($do_mime && $cfgRelation['mimework']) { $schema_insert .= '<td class="print"><b>' . htmlspecialchars('MIME') . '</b></td>'; $mime_map = PMA_getMIME($db, $table, true); } $schema_insert .= '</tr>'; if (!PMA_exportOutputHandler($schema_insert)) { return false; } $columns = PMA_DBI_get_columns($db, $table); foreach ($columns as $column) { $schema_insert = '<tr class="print-category">'; $extracted_fieldspec = PMA_extractFieldSpec($column['Type']); $type = htmlspecialchars($extracted_fieldspec['print_type']); if (empty($type)) { $type = ' '; } if (!isset($column['Default'])) { if ($column['Null'] != 'NO') { $column['Default'] = 'NULL'; } } $fmt_pre = ''; $fmt_post = ''; if (in_array($column['Field'], $unique_keys)) { $fmt_pre = '<b>' . $fmt_pre; $fmt_post = $fmt_post . '</b>'; } if ($column['Key'] == 'PRI') { $fmt_pre = '<i>' . $fmt_pre; $fmt_post = $fmt_post . '</i>'; } $schema_insert .= '<td class="print">' . $fmt_pre . htmlspecialchars($column['Field']) . $fmt_post . '</td>'; $schema_insert .= '<td class="print">' . htmlspecialchars($type) . '</td>'; $schema_insert .= '<td class="print">' . ($column['Null'] == '' || $column['Null'] == 'NO' ? __('No') : __('Yes')) . '</td>'; $schema_insert .= '<td class="print">' . htmlspecialchars(isset($column['Default']) ? $column['Default'] : '') . '</td>'; $field_name = $column['Field']; if ($do_relation && $have_rel) { $schema_insert .= '<td class="print">' . (isset($res_rel[$field_name]) ? htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' (' . $res_rel[$field_name]['foreign_field'] . ')') : '') . '</td>'; } if ($do_comments && $cfgRelation['commwork']) { $schema_insert .= '<td class="print">' . (isset($comments[$field_name]) ? htmlspecialchars($comments[$field_name]) : '') . '</td>'; } if ($do_mime && $cfgRelation['mimework']) { $schema_insert .= '<td class="print">' . (isset($mime_map[$field_name]) ? htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype'])) : '') . '</td>'; } $schema_insert .= '</tr>'; if (!PMA_exportOutputHandler($schema_insert)) { return false; } } // end while return PMA_exportOutputHandler('</table>'); }
$arr['type'] = preg_replace('@BINARY([^\\(])@i', '', $arr['type']); $arr['type'] = preg_replace('@ZEROFILL@i', '', $arr['type']); $arr['type'] = preg_replace('@UNSIGNED@i', '', $arr['type']); // some types, for example longtext, are reported as // "longtext character set latin7" when their charset and / or collation // differs from the ones of the corresponding database. $tmp = strpos($arr['type'], 'character set'); if ($tmp) { $arr['type'] = substr($arr['type'], 0, $tmp - 1); } $c['Default'] = $r_data[$c['Field']]; $col[$c['Field']] = array_merge($arr, array('Default' => $c['Default'])); } } else { while ($c = $cl->fetch_assoc()) { $arr = PMA_extractFieldSpec($c['Type']); // strip the "BINARY" attribute, except if we find "BINARY(" because // this would be a BINARY or VARBINARY field type $arr['type'] = preg_replace('@BINARY([^\\(])@i', '', $arr['type']); $arr['type'] = preg_replace('@ZEROFILL@i', '', $arr['type']); $arr['type'] = preg_replace('@UNSIGNED@i', '', $arr['type']); // some types, for example longtext, are reported as // "longtext character set latin7" when their charset and / or collation // differs from the ones of the corresponding database. $tmp = strpos($arr['type'], 'character set'); if ($tmp) { $arr['type'] = substr($arr['type'], 0, $tmp - 1); } if ($arr['type'] == 'date' and $c['Default'] == '') { $c['Default'] = date("Y-m-d", time()); }
$_msg = htmlentities($_POST['name']); } else { $_err = 1; $_msg = $db->error; } } else { $col_data = $check_cl->fetch_array(); $_q = "SHOW FULL COLUMNS FROM " . PMA_bkq($tb_name); if ($data = $db->query($_q)) { while ($_d = $data->fetch_object()) { $_cols[] = $_d->Field; } } //ok here we go :) //grab the type and lenght $extracted_fieldspec = PMA_extractFieldSpec($col_data['Type']); $type = $extracted_fieldspec['type']; if ('set' == $extracted_fieldspec['type'] || 'enum' == $extracted_fieldspec['type']) { $length = $extracted_fieldspec['spec_in_brackets']; } else { // strip the "BINARY" attribute, except if we find "BINARY(" because // this would be a BINARY or VARBINARY field type $type = preg_replace('@BINARY([^\\(])@i', '', $type); $type = preg_replace('@ZEROFILL@i', '', $type); $type = preg_replace('@UNSIGNED@i', '', $type); $length = $extracted_fieldspec['spec_in_brackets']; } // end if else // some types, for example longtext, are reported as // "longtext character set latin7" when their charset and / or collation // differs from the ones of the corresponding database.