PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/phpMyAdmin_old/tbl_alter.php

https://bitbucket.org/steve_delbar/iepsm-projet-de-d-veloppement-internet-2013
PHP | 211 lines | 137 code | 27 blank | 47 comment | 49 complexity | 813996ba94fe600751076713c9c202e8 MD5 | raw file
  1. <?php
  2. /* $Id: tbl_alter.php,v 2.15.2.2 2005/04/13 14:41:46 lem9 Exp $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4. /**
  5. * Gets some core libraries
  6. */
  7. require_once('./libraries/grab_globals.lib.php');
  8. $js_to_run = 'functions.js';
  9. require_once('./header.inc.php');
  10. // Check parameters
  11. PMA_checkParameters(array('db', 'table'));
  12. /**
  13. * Gets tables informations
  14. */
  15. require('./tbl_properties_common.php');
  16. require('./tbl_properties_table_info.php');
  17. /**
  18. * Displays top menu links
  19. */
  20. $active_page = 'tbl_properties_structure.php';
  21. // I don't see the need to display the links here, they will be displayed later
  22. //require('./tbl_properties_links.php');
  23. /**
  24. * Defines the url to return to in case of error in a sql statement
  25. */
  26. $err_url = 'tbl_properties_structure.php?' . PMA_generate_common_url($db, $table);
  27. /**
  28. * Modifications have been submitted -> updates the table
  29. */
  30. $abort = false;
  31. if (isset($do_save_data)) {
  32. $field_cnt = count($field_orig);
  33. for ($i = 0; $i < $field_cnt; $i++) {
  34. // to "&quot;" in tbl_properties.php
  35. $field_orig[$i] = urldecode($field_orig[$i]);
  36. if (strcmp(str_replace('"', '&quot;', $field_orig[$i]), $field_name[$i]) == 0) {
  37. $field_name[$i] = $field_orig[$i];
  38. }
  39. $field_default_orig[$i] = urldecode($field_default_orig[$i]);
  40. if (strcmp(str_replace('"', '&quot;', $field_default_orig[$i]), $field_default[$i]) == 0) {
  41. $field_default[$i] = $field_default_orig[$i];
  42. }
  43. $field_length_orig[$i] = urldecode($field_length_orig[$i]);
  44. if (strcmp(str_replace('"', '&quot;', $field_length_orig[$i]), $field_length[$i]) == 0) {
  45. $field_length[$i] = $field_length_orig[$i];
  46. }
  47. if (!isset($query)) {
  48. $query = '';
  49. } else {
  50. $query .= ', CHANGE ';
  51. }
  52. $full_field_type = $field_type[$i];
  53. if ($field_length[$i] != ''
  54. && !preg_match('@^(DATE|DATETIME|TIME|TINYBLOB|TINYTEXT|BLOB|TEXT|MEDIUMBLOB|MEDIUMTEXT|LONGBLOB|LONGTEXT)$@i', $field_type[$i])) {
  55. $full_field_type .= '(' . $field_length[$i] . ')';
  56. }
  57. if ($field_attribute[$i] != '') {
  58. $full_field_type .= ' ' . $field_attribute[$i];
  59. }
  60. // take care of native MySQL comments here
  61. $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] : ''));
  62. } // end for
  63. // To allow replication, we first select the db to use and then run queries
  64. // on this db.
  65. PMA_DBI_select_db($db) or PMA_mysqlDie(PMA_DBI_getError(), 'USE ' . PMA_backquote($db) . ';', '', $err_url);
  66. // Optimization fix - 2 May 2001 - Robbat2
  67. $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' CHANGE ' . $query;
  68. $error_create = FALSE;
  69. $result = PMA_DBI_try_query($sql_query) or $error_create = TRUE;
  70. if ($error_create == FALSE) {
  71. $message = $strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenAltered;
  72. $btnDrop = 'Fake';
  73. // garvin: If comments were sent, enable relation stuff
  74. require_once('./libraries/relation.lib.php');
  75. require_once('./libraries/transformations.lib.php');
  76. $cfgRelation = PMA_getRelationsParam();
  77. // take care of pmadb internal comments here
  78. // garvin: Update comment table, if a comment was set.
  79. if (PMA_MYSQL_INT_VERSION < 40100 && isset($field_comments) && is_array($field_comments) && $cfgRelation['commwork']) {
  80. foreach ($field_comments AS $fieldindex => $fieldcomment) {
  81. PMA_setComment($db, $table, $field_name[$fieldindex], $fieldcomment, $field_orig[$fieldindex], 'pmadb');
  82. }
  83. }
  84. // garvin: Rename relations&display fields, if altered.
  85. if (($cfgRelation['displaywork'] || $cfgRelation['relwork']) && isset($field_orig) && is_array($field_orig)) {
  86. foreach ($field_orig AS $fieldindex => $fieldcontent) {
  87. if ($field_name[$fieldindex] != $fieldcontent) {
  88. if ($cfgRelation['displaywork']) {
  89. $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['table_info'])
  90. . ' SET display_field = \'' . PMA_sqlAddslashes($field_name[$fieldindex]) . '\''
  91. . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
  92. . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
  93. . ' AND display_field = \'' . PMA_sqlAddslashes($fieldcontent) . '\'';
  94. $tb_rs = PMA_query_as_cu($table_query);
  95. unset($table_query);
  96. unset($tb_rs);
  97. }
  98. if ($cfgRelation['relwork']) {
  99. $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['relation'])
  100. . ' SET master_field = \'' . PMA_sqlAddslashes($field_name[$fieldindex]) . '\''
  101. . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\''
  102. . ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\''
  103. . ' AND master_field = \'' . PMA_sqlAddslashes($fieldcontent) . '\'';
  104. $tb_rs = PMA_query_as_cu($table_query);
  105. unset($table_query);
  106. unset($tb_rs);
  107. $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['relation'])
  108. . ' SET foreign_field = \'' . PMA_sqlAddslashes($field_name[$fieldindex]) . '\''
  109. . ' WHERE foreign_db = \'' . PMA_sqlAddslashes($db) . '\''
  110. . ' AND foreign_table = \'' . PMA_sqlAddslashes($table) . '\''
  111. . ' AND foreign_field = \'' . PMA_sqlAddslashes($fieldcontent) . '\'';
  112. $tb_rs = PMA_query_as_cu($table_query);
  113. unset($table_query);
  114. unset($tb_rs);
  115. } // end if relwork
  116. } // end if fieldname has changed
  117. } // end while check fieldnames
  118. } // end if relations/display has to be changed
  119. // garvin: Update comment table for mime types [MIME]
  120. if (isset($field_mimetype) && is_array($field_mimetype) && $cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfg['BrowseMIME']) {
  121. foreach ($field_mimetype AS $fieldindex => $mimetype) {
  122. PMA_setMIME($db, $table, $field_name[$fieldindex], $mimetype, $field_transformation[$fieldindex], $field_transformation_options[$fieldindex]);
  123. }
  124. }
  125. $active_page = 'tbl_properties_structure.php';
  126. require('./tbl_properties_structure.php');
  127. } else {
  128. PMA_mysqlDie('', '', '', $err_url, FALSE);
  129. // garvin: An error happened while inserting/updating a table definition.
  130. // to prevent total loss of that data, we embed the form once again.
  131. // The variable $regenerate will be used to restore data in tbl_properties.inc.php
  132. if (isset($orig_field)) {
  133. $field = $orig_field;
  134. }
  135. $regenerate = true;
  136. }
  137. }
  138. /**
  139. * No modifications yet required -> displays the table fields
  140. */
  141. if ($abort == FALSE) {
  142. if (!isset($selected)) {
  143. PMA_checkParameters(array('field'));
  144. $selected[] = $field;
  145. $selected_cnt = 1;
  146. } else { // from a multiple submit
  147. $selected_cnt = count($selected);
  148. }
  149. // TODO: optimize in case of multiple fields to modify
  150. for ($i = 0; $i < $selected_cnt; $i++) {
  151. if (!empty($submit_mult)) {
  152. $field = PMA_sqlAddslashes(urldecode($selected[$i]), TRUE);
  153. } else {
  154. $field = PMA_sqlAddslashes($selected[$i], TRUE);
  155. }
  156. $result = PMA_DBI_query('SHOW FULL FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db) . ' LIKE \'' . $field . '\';');
  157. $fields_meta[] = PMA_DBI_fetch_assoc($result);
  158. PMA_DBI_free_result($result);
  159. }
  160. $num_fields = count($fields_meta);
  161. $action = 'tbl_alter.php';
  162. // Get more complete field information
  163. // For now, this is done just for MySQL 4.1.2+ new TIMESTAMP options
  164. // but later, if the analyser returns more information, it
  165. // could be executed for any MySQL version and replace
  166. // the info given by SHOW FULL FIELDS FROM.
  167. // TODO: put this code into a require()
  168. // or maybe make it part of PMA_DBI_get_fields();
  169. if (PMA_MYSQL_INT_VERSION >= 40102) {
  170. $show_create_table_query = 'SHOW CREATE TABLE '
  171. . PMA_backquote($db) . '.' . PMA_backquote($table);
  172. $show_create_table_res = PMA_DBI_query($show_create_table_query);
  173. list(,$show_create_table) = PMA_DBI_fetch_row($show_create_table_res);
  174. PMA_DBI_free_result($show_create_table_res);
  175. unset($show_create_table_res, $show_create_table_query);
  176. $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
  177. }
  178. require('./tbl_properties.inc.php');
  179. }
  180. /**
  181. * Displays the footer
  182. */
  183. require_once('./footer.inc.php');
  184. ?>