Documentation TYPO3 par Ameos

tbl_indexes.lib.php

00001 <?php
00002 /* $Id: tbl_indexes.lib.php,v 2.2 2005/02/14 17:00:08 nijel Exp $ */
00003 // vim: expandtab sw=4 ts=4 sts=4:
00004 
00013     function PMA_get_indextypes() {
00014         return array(
00015             'PRIMARY',
00016             'INDEX',
00017             'UNIQUE',
00018             'FULLTEXT'
00019         );
00020     }
00021 
00031     function PMA_get_indexes($tbl_name, $err_url_0 = '') {
00032         $tbl_local_query = 'SHOW KEYS FROM ' . PMA_backquote($tbl_name);
00033         $tbl_result      = PMA_DBI_query($tbl_local_query) or PMA_mysqlDie('', $tbl_local_query, '', $err_url_0);
00034         $tbl_ret_keys    = array();
00035         while ($tbl_row = PMA_DBI_fetch_assoc($tbl_result)) {
00036             $tbl_ret_keys[]  = $tbl_row;
00037         }
00038         PMA_DBI_free_result($tbl_result);
00039 
00040         return $tbl_ret_keys;
00041     }
00042 
00053     function PMA_check_indexes($idx_collection, $table = true) {
00054         $index_types = PMA_get_indextypes();
00055         $output  = '';
00056         if (is_array($idx_collection) && isset($idx_collection['ALL'])) {
00057             foreach($idx_collection['ALL'] AS $w_keyname => $w_count) {
00058                 if (isset($idx_collection['PRIMARY'][$w_keyname]) && (isset($idx_collection['INDEX'][$w_keyname]) || isset($idx_collection['UNIQUE'][$w_keyname]))) {
00059                     $output .= PMA_index_warning(sprintf($GLOBALS['strIndexWarningPrimary'], htmlspecialchars($w_keyname)), $table);
00060                 } elseif (isset($idx_collection['UNIQUE'][$w_keyname]) && isset($idx_collection['INDEX'][$w_keyname])) {
00061                     $output .= PMA_index_warning(sprintf($GLOBALS['strIndexWarningUnique'], htmlspecialchars($w_keyname)), $table);
00062                 }
00063 
00064                 foreach($index_types AS $index_type) {
00065                     if (isset($idx_collection[$index_type][$w_keyname]) && $idx_collection[$index_type][$w_keyname] > 1) {
00066                         $output .= PMA_index_warning(sprintf($GLOBALS['strIndexWarningMultiple'], $index_type, htmlspecialchars($w_keyname)), $table);
00067                     }
00068                 }
00069             }
00070         }
00071 
00072         return $output;
00073     }
00074 
00088     function PMA_extract_indexes(&$ret_keys, &$indexes, &$indexes_info, &$indexes_data) {
00089         if (!is_array($ret_keys)) {
00090             return false;
00091         }
00092 
00093         $prev_index   = '';
00094         foreach ($ret_keys as $row) {
00095             if ($row['Key_name'] != $prev_index ){
00096                 $indexes[]  = $row['Key_name'];
00097                 $prev_index = $row['Key_name'];
00098             }
00099 
00100             $indexes_info[$row['Key_name']]['Sequences'][]     = $row['Seq_in_index'];
00101             $indexes_info[$row['Key_name']]['Non_unique']      = $row['Non_unique'];
00102 
00103             if (isset($row['Cardinality'])) {
00104                 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
00105             }
00106 
00107             //    I don't know what does following column mean....
00108             //    $indexes_info[$row['Key_name']]['Packed']          = $row['Packed'];
00109             $indexes_info[$row['Key_name']]['Comment']         = (isset($row['Comment']))
00110                                                                ? $row['Comment']
00111                                                                : '';
00112             $indexes_info[$row['Key_name']]['Index_type']      = (isset($row['Index_type']))
00113                                                                ? $row['Index_type']
00114                                                                : '';
00115 
00116             $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name']  = $row['Column_name'];
00117             if (isset($row['Sub_part'])) {
00118                 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
00119             }
00120         } // end while
00121 
00122         return true;
00123     }
00124 
00139     function PMA_show_indexes($table, &$indexes, &$indexes_info, &$indexes_data, $display_html = true, $print_mode = false) {
00140         $idx_collection = array();
00141         foreach ($indexes AS $index_no => $index_name) {
00142             if ($display_html) {
00143                 if ($print_mode) {
00144                     $index_td = '        <td class="print" rowspan="' . count($indexes_info[$index_name]['Sequences']) . '">' . "\n";
00145                 } else {
00146                     $cell_bgd = (($index_no % 2) ? $GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo']);
00147                     $index_td = '            <td bgcolor="' . $cell_bgd . '" rowspan="' . count($indexes_info[$index_name]['Sequences']) . '">' . "\n";
00148                 }
00149                 echo '        <tr>' . "\n";
00150                 echo $index_td
00151                      . '                ' . htmlspecialchars($index_name) . "\n"
00152                      . '            </td>' . "\n";
00153             }
00154 
00155             if ((PMA_MYSQL_INT_VERSION < 40002 && $indexes_info[$index_name]['Comment'] == 'FULLTEXT')
00156                 || (PMA_MYSQL_INT_VERSION >= 40002 && $indexes_info[$index_name]['Index_type'] == 'FULLTEXT')) {
00157                 $index_type = 'FULLTEXT';
00158             } else if ($index_name == 'PRIMARY') {
00159                 $index_type = 'PRIMARY';
00160             } else if ($indexes_info[$index_name]['Non_unique'] == '0') {
00161                 $index_type = 'UNIQUE';
00162             } else {
00163                 $index_type = 'INDEX';
00164             }
00165 
00166             if ($display_html) {
00167                 echo $index_td
00168                      . '                ' . $index_type . "\n"
00169                      . '            </td>' . "\n";
00170 
00171                 echo str_replace('">' . "\n", '" align="right">' . "\n", $index_td)
00172                      . '                ' . (isset($indexes_info[$index_name]['Cardinality']) ? $indexes_info[$index_name]['Cardinality'] : $GLOBALS['strNone']) . '&nbsp;' . "\n"
00173                      . '            </td>' . "\n";
00174 
00175                 if (!$print_mode) {
00176                     echo $index_td
00177                          . '                <a href="tbl_indexes.php?' . $GLOBALS['url_query'] . '&amp;index=' . urlencode($index_name) . '">' . $GLOBALS['edit_link_text'] . '</a>' . "\n"
00178                          . '            </td>' . "\n";
00179                 }
00180 
00181                 if ($index_name == 'PRIMARY') {
00182                     $local_query = urlencode('ALTER TABLE ' . PMA_backquote($table) . ' DROP PRIMARY KEY');
00183                     $js_msg      = 'ALTER TABLE ' . PMA_jsFormat($table) . ' DROP PRIMARY KEY';
00184                     $zero_rows   = urlencode($GLOBALS['strPrimaryKeyHasBeenDropped']);
00185                 } else {
00186                     $local_query = urlencode('ALTER TABLE ' . PMA_backquote($table) . ' DROP INDEX ' . PMA_backquote($index_name));
00187                     $js_msg      = 'ALTER TABLE ' . PMA_jsFormat($table) . ' DROP INDEX ' . PMA_jsFormat($index_name);
00188                     $zero_rows   = urlencode(sprintf($GLOBALS['strIndexHasBeenDropped'], htmlspecialchars($index_name)));
00189                 }
00190 
00191                 if (!$print_mode) {
00192                     echo $index_td
00193                          . '                <a href="sql.php?' . $GLOBALS['url_query'] . '&amp;sql_query=' . $local_query . '&amp;zero_rows=' . $zero_rows . '" onclick="return confirmLink(this, \'' . $js_msg . '\')">' . $GLOBALS['drop_link_text']  . '</a>' . "\n"
00194                          . '            </td>' . "\n";
00195                 }
00196             }
00197 
00198             foreach ($indexes_info[$index_name]['Sequences'] AS $row_no => $seq_index) {
00199                 $col_name = $indexes_data[$index_name][$seq_index]['Column_name'];
00200                 if ($row_no == 0) {
00201                     if (isset($idx_collection[$index_type][$col_name])) {
00202                         $idx_collection[$index_type][$col_name]++;
00203                     } else {
00204                         $idx_collection[$index_type][$col_name] = 1;
00205                     }
00206 
00207                     if (isset($idx_collection['ALL'][$col_name])) {
00208                         $idx_collection['ALL'][$col_name]++;
00209                     } else {
00210                         $idx_collection['ALL'][$col_name] = 1;
00211                     }
00212                 }
00213 
00214                 if ($display_html) {
00215                     if ($row_no > 0) {
00216                         echo '        <tr>' . "\n";
00217                     }
00218 
00219                     if ($print_mode) {
00220                         $bgcolor = 'class="print"';
00221                     } else {
00222                         $bgcolor = 'bgcolor="' . $cell_bgd . '"';
00223                     }
00224 
00225                     if (!empty($indexes_data[$index_name][$seq_index]['Sub_part'])) {
00226                         echo '            <td ' . $bgcolor . '>' . "\n"
00227                              . '                ' . $col_name . "\n"
00228                              . '            </td>' . "\n";
00229                         echo '            <td align="right" ' . $bgcolor . '>' . "\n"
00230                              . '                ' . $indexes_data[$index_name][$seq_index]['Sub_part'] . "\n"
00231                              . '            </td>' . "\n";
00232                         echo '        </tr>' . "\n";
00233                     } else {
00234                         echo '            <td ' . $bgcolor . ' colspan="2">' . "\n"
00235                              . '                ' . htmlspecialchars($col_name) . "\n"
00236                              . '            </td>' . "\n";
00237                         echo '        </tr>' . "\n";
00238                     }
00239                 }
00240             } // end while
00241         } // end while
00242 
00243         return $idx_collection;
00244     }
00245 
00256     function PMA_index_warning($string, $table = true) {
00257         $output = '';
00258         if ($table) {
00259             $output .= "\n" . '        <tr><td colspan=7">' . "\n";
00260         }
00261 
00262         if ($GLOBALS['cfg']['ErrorIconic']) {
00263             $output .=  '<img src="' . $GLOBALS['pmaThemeImage'] . 's_warn.png" width="16" height="16" border="0" alt="Warning" hspace="2" align="middle" />';
00264         }
00265 
00266         $output .=  '        <b>' . $string . '</b>';
00267 
00268         if ($table) {
00269             $output .=  '</td></tr>';
00270         } else {
00271             $output .=  '<br />';
00272         }
00273 
00274         $output .=  "\n\n";
00275         return $output;
00276     }
00277 ?>


Généré par L'expert TYPO3 avec  doxygen 1.4.6