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_columnspec = PMA_extractColumnSpec($row['Type']); $type = $extracted_columnspec['print_type']; $attribute = $extracted_columnspec['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 }
</th> <?php if ($have_rel) { echo '<th>' . __('Links to') . '</th>' . "\n"; } echo ' <th>' . __('Comments') . '</th>' . "\n"; if ($cfgRelation['mimework']) { echo ' <th>MIME</th>' . "\n"; } ?> </tr> </thead> <tbody> <?php foreach ($columns as $row) { $extracted_columnspec = PMA_extractColumnSpec($row['Type']); $type = $extracted_columnspec['print_type']; $attribute = $extracted_columnspec['attribute']; if (!isset($row['Default'])) { if ($row['Null'] != '' && $row['Null'] != 'NO') { $row['Default'] = '<i>NULL</i>'; } } else { $row['Default'] = htmlspecialchars($row['Default']); } $field_name = htmlspecialchars($row['Field']); // here, we have a TIMESTAMP that SHOW FULL COLUMNS reports as having the // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe // the latter. /** * @todo merge this logic with the one in tbl_structure.php
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'; break; default: $table_fields[$i]['pma_type'] = $table_fields[$i]['Type']; $table_fields[$i]['wrap'] = ' nowrap'; break; } } $field = $table_fields[$i]; $extracted_columnspec = PMA_extractColumnSpec($field['Type']); if (-1 === $field['len']) { $field['len'] = PMA_DBI_field_len($vresult, $i); // length is unknown for geometry fields, make enough space to edit very simple WKTs if (-1 === $field['len']) { $field['len'] = 30; } } //Call validation when the form submited... $unnullify_trigger = $chg_evt_handler . "=\"return verificationsAfterFieldChange('" . PMA_escapeJsString($field['Field_md5']) . "', '" . PMA_escapeJsString($jsvkey) . "','" . $field['pma_type'] . "')\""; // 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'] . ']'; 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());
/** * Test case for parsing SHOW COLUMNS output * * @dataProvider provider */ public function testParsing($in, $out) { $this->assertEquals($out, PMA_extractColumnSpec($in)); }
/** * 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 string $export_mode 'create_table', 'triggers', 'create_view', * 'stand_in' * @param string $export_type 'server', 'database', 'table' * @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 * * @return bool Whether it succeeded * * @access public */ function PMA_exportStructure($db, $table, $crlf, $error_url, $export_mode, $export_type, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false) { global $cfgRelation; /** * 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_columnspec = PMA_extractColumnSpec($row['Type']); $type = $extracted_columnspec['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); }
* first, load the definitions for all columns */ $columns = PMA_DBI_get_columns_full($db, $table); $column_names = array_keys($columns); $changes = array(); $we_dont_change_keys = array(); // move columns from first to last for ($i = 0, $l = count($_REQUEST['move_columns']); $i < $l; $i++) { $column = $_REQUEST['move_columns'][$i]; // is this column already correctly placed? if ($column_names[$i] == $column) { continue; } // it is not, let's move it to index $i $data = $columns[$column]; $extracted_columnspec = PMA_extractColumnSpec($data['Type']); if (isset($data['Extra']) && $data['Extra'] == 'on update CURRENT_TIMESTAMP') { $extracted_columnspec['attribute'] = $data['Extra']; unset($data['Extra']); } $current_timestamp = false; if ($data['Type'] == 'timestamp' && $data['Default'] == 'CURRENT_TIMESTAMP') { $current_timestamp = true; } $default_type = $data['Null'] === 'YES' && $data['Default'] === null ? 'NULL' : ($current_timestamp ? 'CURRENT_TIMESTAMP' : ($data['Default'] == '' ? 'NONE' : 'USER_DEFINED')); $changes[] = 'CHANGE ' . PMA_Table::generateAlter($column, $column, strtoupper($extracted_columnspec['type']), $extracted_columnspec['spec_in_brackets'], $extracted_columnspec['attribute'], isset($data['Collation']) ? $data['Collation'] : '', $data['Null'] === 'YES' ? 'NULL' : 'NOT NULL', $default_type, $current_timestamp ? '' : $data['Default'], isset($data['Extra']) && $data['Extra'] !== '' ? $data['Extra'] : false, isset($data['Comments']) && $data['Comments'] !== '' ? $data['Comments'] : false, $we_dont_change_keys, $i, $i === 0 ? '-first' : $column_names[$i - 1]); // update current column_names array, first delete old position for ($j = 0, $ll = count($column_names); $j < $ll; $j++) { if ($column_names[$j] == $column) { unset($column_names[$j]); }
/** * Formats the definition for one column * * @param array $column info about this column * @param array $unique_keys unique keys of the table * * @return string Formatted column definition * * @access public */ function PMA_formatOneColumnDefinition($column, $unique_keys) { $definition = '<tr class="print-category">'; $extracted_columnspec = PMA_extractColumnSpec($column['Type']); $type = htmlspecialchars($extracted_columnspec['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 = '<strong>' . $fmt_pre; $fmt_post = $fmt_post . '</strong>'; } if ($column['Key'] == 'PRI') { $fmt_pre = '<em>' . $fmt_pre; $fmt_post = $fmt_post . '</em>'; } $definition .= '<td class="print">' . $fmt_pre . htmlspecialchars($column['Field']) . $fmt_post . '</td>'; $definition .= '<td class="print">' . htmlspecialchars($type) . '</td>'; $definition .= '<td class="print">' . ($column['Null'] == '' || $column['Null'] == 'NO' ? __('No') : __('Yes')) . '</td>'; $definition .= '<td class="print">' . htmlspecialchars(isset($column['Default']) ? $column['Default'] : '') . '</td>'; return $definition; }
/** * Formats the definition for one column * * @param array $column info about this column * * @return string Formatted column definition * * @access public */ function PMA_formatOneColumnDefinition($column) { $field_name = $column['Field']; $definition = '<table:table-row>'; $definition .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars($field_name) . '</text:p>' . '</table:table-cell>'; $extracted_columnspec = PMA_extractColumnSpec($column['Type']); $type = htmlspecialchars($extracted_columnspec['print_type']); if (empty($type)) { $type = ' '; } $definition .= '<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']; } $definition .= '<table:table-cell office:value-type="string">' . '<text:p>' . ($column['Null'] == '' || $column['Null'] == 'NO' ? __('No') : __('Yes')) . '</text:p>' . '</table:table-cell>'; $definition .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars($column['Default']) . '</text:p>' . '</table:table-cell>'; return $definition; }
/** * Formats the definition for one column * * @param array $column info about this column * @param array $unique_keys unique keys for this table * * @return string Formatted column definition * * @access public */ function PMA_formatOneColumnDefinition($column, $unique_keys) { $extracted_columnspec = PMA_extractColumnSpec($column['Type']); $type = $extracted_columnspec['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 = '**' . $fmt_pre; $fmt_post = $fmt_post . '**'; } if ($column['Key'] == 'PRI') { $fmt_pre = '//' . $fmt_pre; $fmt_post = $fmt_post . '//'; } $definition = '|' . $fmt_pre . htmlspecialchars($column['Field']) . $fmt_post; $definition .= '|' . htmlspecialchars($type); $definition .= '|' . ($column['Null'] == '' || $column['Null'] == 'NO' ? __('No') : __('Yes')); $definition .= '|' . htmlspecialchars(isset($column['Default']) ? $column['Default'] : ''); return $definition; }