Documentation TYPO3 par Ameos

tbl_alter.php

00001 <?php
00002 /* $Id: tbl_alter.php,v 2.17 2005/04/13 14:44:14 lem9 Exp $ */
00003 // vim: expandtab sw=4 ts=4 sts=4:
00004 
00008 require_once('./libraries/grab_globals.lib.php');
00009 $js_to_run = 'functions.js';
00010 require_once('./header.inc.php');
00011 
00012 // Check parameters
00013 PMA_checkParameters(array('db', 'table'));
00014 
00018 require('./tbl_properties_common.php');
00019 require('./tbl_properties_table_info.php');
00023 $active_page = 'tbl_properties_structure.php';
00024 // I don't see the need to display the links here, they will be displayed later
00025 //require('./tbl_properties_links.php');
00026 
00027 
00031 $err_url = 'tbl_properties_structure.php?' . PMA_generate_common_url($db, $table);
00032 
00033 
00037 $abort = false;
00038 if (isset($do_save_data)) {
00039     $field_cnt = count($field_orig);
00040     for ($i = 0; $i < $field_cnt; $i++) {
00041         // to "&quot;" in tbl_properties.php
00042         $field_orig[$i]     = urldecode($field_orig[$i]);
00043         if (strcmp(str_replace('"', '&quot;', $field_orig[$i]), $field_name[$i]) == 0) {
00044             $field_name[$i] = $field_orig[$i];
00045         }
00046         $field_default_orig[$i] = urldecode($field_default_orig[$i]);
00047         if (strcmp(str_replace('"', '&quot;', $field_default_orig[$i]), $field_default[$i]) == 0) {
00048             $field_default[$i]  = $field_default_orig[$i];
00049         }
00050         $field_length_orig[$i] = urldecode($field_length_orig[$i]);
00051         if (strcmp(str_replace('"', '&quot;', $field_length_orig[$i]), $field_length[$i]) == 0) {
00052             $field_length[$i] = $field_length_orig[$i];
00053         }
00054         if (!isset($query)) {
00055             $query = '';
00056         } else {
00057             $query .= ', CHANGE ';
00058         }
00059 
00060         $full_field_type = $field_type[$i];
00061         if ($field_length[$i] != ''
00062             && !preg_match('@^(DATE|DATETIME|TIME|TINYBLOB|TINYTEXT|BLOB|TEXT|MEDIUMBLOB|MEDIUMTEXT|LONGBLOB|LONGTEXT)$@i', $field_type[$i])) {
00063             $full_field_type .= '(' . $field_length[$i] . ')';
00064         }
00065         if ($field_attribute[$i] != '') {
00066             $full_field_type .= ' ' . $field_attribute[$i];
00067         }
00068         // take care of native MySQL comments here
00069 
00070         $query .= PMA_generateAlterTable($field_orig[$i], $field_name[$i], $full_field_type, (PMA_MYSQL_INT_VERSION >= 40100 && $field_collation[$i] != '' ? $field_collation[$i] : ''), $field_null[$i], $field_default[$i], (isset($field_default_current_timestamp[$i]) ? $field_default_current_timestamp[$i] : ''), $field_extra[$i], (PMA_MYSQL_INT_VERSION >= 40100 && isset($field_comments[$i]) && $field_comments[$i] != '' ? $field_comments[$i] : ''));
00071     } // end for
00072 
00073     // To allow replication, we first select the db to use and then run queries
00074     // on this db.
00075      PMA_DBI_select_db($db) or PMA_mysqlDie(PMA_DBI_getError(), 'USE ' . PMA_backquote($db) . ';', '', $err_url);
00076     // Optimization fix - 2 May 2001 - Robbat2
00077     $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' CHANGE ' . $query;
00078     $error_create = FALSE;
00079     $result    = PMA_DBI_try_query($sql_query) or $error_create = TRUE;
00080 
00081     if ($error_create == FALSE) {
00082         $message   = $strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenAltered;
00083         $btnDrop   = 'Fake';
00084 
00085         // garvin: If comments were sent, enable relation stuff
00086         require_once('./libraries/relation.lib.php');
00087         require_once('./libraries/transformations.lib.php');
00088 
00089         $cfgRelation = PMA_getRelationsParam();
00090 
00091         // take care of pmadb internal comments here
00092         // garvin: Update comment table, if a comment was set.
00093         if (PMA_MYSQL_INT_VERSION < 40100 && isset($field_comments) && is_array($field_comments) && $cfgRelation['commwork']) {
00094             foreach ($field_comments AS $fieldindex => $fieldcomment) {
00095                 PMA_setComment($db, $table, $field_name[$fieldindex], $fieldcomment, $field_orig[$fieldindex], 'pmadb');
00096             }
00097         }
00098 
00099         // garvin: Rename relations&display fields, if altered.
00100         if (($cfgRelation['displaywork'] || $cfgRelation['relwork']) && isset($field_orig) && is_array($field_orig)) {
00101             foreach ($field_orig AS $fieldindex => $fieldcontent) {
00102                 if ($field_name[$fieldindex] != $fieldcontent) {
00103                     if ($cfgRelation['displaywork']) {
00104                         $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['table_info'])
00105                                       . ' SET     display_field = \'' . PMA_sqlAddslashes($field_name[$fieldindex]) . '\''
00106                                       . ' WHERE db_name  = \'' . PMA_sqlAddslashes($db) . '\''
00107                                       . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
00108                                       . ' AND display_field = \'' . PMA_sqlAddslashes($fieldcontent) . '\'';
00109                         $tb_rs    = PMA_query_as_cu($table_query);
00110                         unset($table_query);
00111                         unset($tb_rs);
00112                     }
00113 
00114                     if ($cfgRelation['relwork']) {
00115                         $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['relation'])
00116                                       . ' SET     master_field = \'' . PMA_sqlAddslashes($field_name[$fieldindex]) . '\''
00117                                       . ' WHERE master_db  = \'' . PMA_sqlAddslashes($db) . '\''
00118                                       . ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\''
00119                                       . ' AND master_field = \'' . PMA_sqlAddslashes($fieldcontent) . '\'';
00120                         $tb_rs    = PMA_query_as_cu($table_query);
00121                         unset($table_query);
00122                         unset($tb_rs);
00123 
00124                         $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['relation'])
00125                                       . ' SET     foreign_field = \'' . PMA_sqlAddslashes($field_name[$fieldindex]) . '\''
00126                                       . ' WHERE foreign_db  = \'' . PMA_sqlAddslashes($db) . '\''
00127                                       . ' AND foreign_table = \'' . PMA_sqlAddslashes($table) . '\''
00128                                       . ' AND foreign_field = \'' . PMA_sqlAddslashes($fieldcontent) . '\'';
00129                         $tb_rs    = PMA_query_as_cu($table_query);
00130                         unset($table_query);
00131                         unset($tb_rs);
00132                     } // end if relwork
00133                 } // end if fieldname has changed
00134             } // end while check fieldnames
00135         } // end if relations/display has to be changed
00136 
00137         // garvin: Update comment table for mime types [MIME]
00138         if (isset($field_mimetype) && is_array($field_mimetype) && $cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfg['BrowseMIME']) {
00139             foreach ($field_mimetype AS $fieldindex => $mimetype) {
00140                 PMA_setMIME($db, $table, $field_name[$fieldindex], $mimetype, $field_transformation[$fieldindex], $field_transformation_options[$fieldindex]);
00141             }
00142         }
00143 
00144         $active_page = 'tbl_properties_structure.php';
00145         require('./tbl_properties_structure.php');
00146     } else {
00147         PMA_mysqlDie('', '', '', $err_url, FALSE);
00148         // garvin: An error happened while inserting/updating a table definition.
00149         // to prevent total loss of that data, we embed the form once again.
00150         // The variable $regenerate will be used to restore data in tbl_properties.inc.php
00151         if (isset($orig_field)) {
00152                 $field = $orig_field;
00153         }
00154 
00155         $regenerate = true;
00156     }
00157 }
00158 
00162 if ($abort == FALSE) {
00163     if (!isset($selected)) {
00164         PMA_checkParameters(array('field'));
00165         $selected[]   = $field;
00166         $selected_cnt = 1;
00167     } else { // from a multiple submit
00168         $selected_cnt = count($selected);
00169     }
00170 
00171     // TODO: optimize in case of multiple fields to modify
00172     for ($i = 0; $i < $selected_cnt; $i++) {
00173         if (!empty($submit_mult)) {
00174             $field = PMA_sqlAddslashes(urldecode($selected[$i]), TRUE);
00175         } else {
00176             $field = PMA_sqlAddslashes($selected[$i], TRUE);
00177         }
00178         $result        = PMA_DBI_query('SHOW FULL FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db) . ' LIKE \'' . $field . '\';');
00179         $fields_meta[] = PMA_DBI_fetch_assoc($result);
00180         PMA_DBI_free_result($result);
00181     }
00182     $num_fields  = count($fields_meta);
00183     $action      = 'tbl_alter.php';
00184 
00185     // Get more complete field information
00186     // For now, this is done just for MySQL 4.1.2+ new TIMESTAMP options
00187     // but later, if the analyser returns more information, it
00188     // could be executed for any MySQL version and replace
00189     // the info given by SHOW FULL FIELDS FROM.
00190     // TODO: put this code into a require()
00191     // or maybe make it part of PMA_DBI_get_fields();
00192 
00193     if (PMA_MYSQL_INT_VERSION >= 40102) {
00194         $show_create_table_query = 'SHOW CREATE TABLE '
00195             . PMA_backquote($db) . '.' . PMA_backquote($table);
00196         $show_create_table_res = PMA_DBI_query($show_create_table_query);
00197         list(,$show_create_table) = PMA_DBI_fetch_row($show_create_table_res);
00198         PMA_DBI_free_result($show_create_table_res);
00199         unset($show_create_table_res, $show_create_table_query);
00200         $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
00201     }
00202 
00203     require('./tbl_properties.inc.php');
00204 }
00205 
00206 
00210 require_once('./footer.inc.php');
00211 ?>


Généré par Les spécialistes TYPO3 avec  doxygen 1.4.6