[ Index ]
 

Code source de phpMyAdmin 2.10.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/ -> tbl_create.php (source)

   1  <?php
   2  /* $Id: tbl_create.php 10144 2007-03-20 11:22:31Z cybot_tm $ */
   3  // vim: expandtab sw=4 ts=4 sts=4:
   4  
   5  /**
   6   * Get some core libraries
   7   */
   8  require_once  './libraries/common.lib.php';
   9  require_once  './libraries/Table.class.php';
  10  
  11  $js_to_run = 'functions.js';
  12  
  13  if (isset($table)) {
  14      $table = PMA_sanitize($table);
  15  }
  16  
  17  require_once  './libraries/header.inc.php';
  18  
  19  // Check parameters
  20  PMA_checkParameters(array('db', 'table'));
  21  
  22  /**
  23   * Defines the url to return to in case of error in a sql statement
  24   */
  25  $err_url = $cfg['DefaultTabTable'] . '?' . PMA_generate_common_url($db, $table);
  26  
  27  
  28  /**
  29   * Selects the database to work with
  30   */
  31  PMA_DBI_select_db($db);
  32  
  33  
  34  /**
  35   * The form used to define the structure of the table has been submitted
  36   */
  37  $abort = false;
  38  if (isset($submit_num_fields)) {
  39      $regenerate = true;
  40      $num_fields = $orig_num_fields + $added_fields;
  41  } elseif (isset($do_save_data)) {
  42      $sql_query = $query_cpy = '';
  43  
  44      // Transforms the radio button field_key into 3 arrays
  45      $field_cnt = count($field_name);
  46      for ($i = 0; $i < $field_cnt; ++$i) {
  47          if (isset(${'field_key_' . $i})) {
  48              if (${'field_key_' . $i} == 'primary_' . $i) {
  49                  $field_primary[] = $i;
  50              }
  51              if (${'field_key_' . $i} == 'index_' . $i) {
  52                  $field_index[]   = $i;
  53              }
  54              if (${'field_key_' . $i} == 'unique_' . $i) {
  55                  $field_unique[]  = $i;
  56              }
  57          } // end if
  58      } // end for
  59      // Builds the fields creation statements
  60      for ($i = 0; $i < $field_cnt; $i++) {
  61          // '0' is also empty for php :-(
  62          if (empty($field_name[$i]) && $field_name[$i] != '0') {
  63              continue;
  64          }
  65  
  66          $query = PMA_Table::generateFieldSpec($field_name[$i], $field_type[$i], $field_length[$i], $field_attribute[$i], isset($field_collation[$i]) ? $field_collation[$i] : '', $field_null[$i], $field_default[$i], isset($field_default_current_timestamp[$i]), $field_extra[$i], isset($field_comments[$i]) ? $field_comments[$i] : '', $field_primary, $i);
  67  
  68          $query .= ', ';
  69          $sql_query .= $query;
  70          $query_cpy .= "\n" . '  ' . $query;
  71      } // end for
  72      unset($field_cnt);
  73      unset($query);
  74      $sql_query = preg_replace('@, $@', '', $sql_query);
  75      $query_cpy = preg_replace('@, $@', '', $query_cpy);
  76  
  77      // Builds the primary keys statements
  78      $primary     = '';
  79      $primary_cnt = (isset($field_primary) ? count($field_primary) : 0);
  80      for ($i = 0; $i < $primary_cnt; $i++) {
  81          $j = $field_primary[$i];
  82          if (isset($field_name[$j]) && strlen($field_name[$j])) {
  83              $primary .= PMA_backquote($field_name[$j]) . ', ';
  84          }
  85      } // end for
  86      unset($primary_cnt);
  87      $primary = preg_replace('@, $@', '', $primary);
  88      if (strlen($primary)) {
  89          $sql_query .= ', PRIMARY KEY (' . $primary . ')';
  90          $query_cpy .= ',' . "\n" . '  PRIMARY KEY (' . $primary . ')';
  91      }
  92      unset($primary);
  93  
  94      // Builds the indexes statements
  95      $index     = '';
  96      $index_cnt = (isset($field_index) ? count($field_index) : 0);
  97      for ($i = 0;$i < $index_cnt; $i++) {
  98          $j = $field_index[$i];
  99          if (isset($field_name[$j]) && strlen($field_name[$j])) {
 100              $index .= PMA_backquote($field_name[$j]) . ', ';
 101          }
 102      } // end for
 103      unset($index_cnt);
 104      $index = preg_replace('@, $@', '', $index);
 105      if (strlen($index)) {
 106          $sql_query .= ', INDEX (' . $index . ')';
 107          $query_cpy .= ',' . "\n" . '  INDEX (' . $index . ')';
 108      }
 109      unset($index);
 110  
 111      // Builds the uniques statements
 112      $unique     = '';
 113      $unique_cnt = (isset($field_unique) ? count($field_unique) : 0);
 114      for ($i = 0; $i < $unique_cnt; $i++) {
 115          $j = $field_unique[$i];
 116          if (isset($field_name[$j]) && strlen($field_name[$j])) {
 117             $unique .= PMA_backquote($field_name[$j]) . ', ';
 118          }
 119      } // end for
 120      unset($unique_cnt);
 121      $unique = preg_replace('@, $@', '', $unique);
 122      if (strlen($unique)) {
 123          $sql_query .= ', UNIQUE (' . $unique . ')';
 124          $query_cpy .= ',' . "\n" . '  UNIQUE (' . $unique . ')';
 125      }
 126      unset($unique);
 127  
 128      // Builds the FULLTEXT statements
 129      $fulltext     = '';
 130      $fulltext_cnt = (isset($field_fulltext) ? count($field_fulltext) : 0);
 131      for ($i = 0; $i < $fulltext_cnt; $i++) {
 132          $j = $field_fulltext[$i];
 133          if (isset($field_name[$j]) && strlen($field_name[$j])) {
 134             $fulltext .= PMA_backquote($field_name[$j]) . ', ';
 135          }
 136      } // end for
 137  
 138      $fulltext = preg_replace('@, $@', '', $fulltext);
 139      if (strlen($fulltext)) {
 140          $sql_query .= ', FULLTEXT (' . $fulltext . ')';
 141          $query_cpy .= ',' . "\n" . '  FULLTEXT (' . $fulltext . ')';
 142      }
 143      unset($fulltext);
 144  
 145      // Builds the 'create table' statement
 146      $sql_query      = 'CREATE TABLE ' . PMA_backquote($table) . ' (' . $sql_query . ')';
 147      $query_cpy      = 'CREATE TABLE ' . PMA_backquote($table) . ' (' . $query_cpy . "\n" . ')';
 148  
 149      // Adds table type, character set and comments
 150      if (!empty($tbl_type) && ($tbl_type != 'Default')) {
 151          $sql_query .= ' ' . PMA_ENGINE_KEYWORD  . ' = ' . $tbl_type;
 152          $query_cpy .= "\n" . PMA_ENGINE_KEYWORD . ' = ' . $tbl_type;
 153      }
 154      if (PMA_MYSQL_INT_VERSION >= 40100 && !empty($tbl_collation)) {
 155          $sql_query .= PMA_generateCharsetQueryPart($tbl_collation);
 156          $query_cpy .= "\n" . PMA_generateCharsetQueryPart($tbl_collation);
 157      }
 158  
 159      if (!empty($comment)) {
 160          $sql_query .= ' COMMENT = \'' . PMA_sqlAddslashes($comment) . '\'';
 161          $query_cpy .= "\n" . 'COMMENT = \'' . PMA_sqlAddslashes($comment) . '\'';
 162      }
 163  
 164      // Executes the query
 165      $error_create = false;
 166      $result    = PMA_DBI_try_query($sql_query) or $error_create = true;
 167  
 168      if ($error_create == false) {
 169          $sql_query = $query_cpy . ';';
 170          unset($query_cpy);
 171          $message   = $strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenCreated;
 172  
 173          // garvin: If comments were sent, enable relation stuff
 174          require_once  './libraries/relation.lib.php';
 175          require_once  './libraries/transformations.lib.php';
 176  
 177          $cfgRelation = PMA_getRelationsParam();
 178  
 179          // garvin: Update comment table, if a comment was set.
 180          if (isset($field_comments) && is_array($field_comments) && $cfgRelation['commwork'] && PMA_MYSQL_INT_VERSION < 40100) {
 181              foreach ($field_comments AS $fieldindex => $fieldcomment) {
 182                  if (isset($field_name[$fieldindex]) && strlen($field_name[$fieldindex])) {
 183                      PMA_setComment($db, $table, $field_name[$fieldindex], $fieldcomment, '', 'pmadb');
 184                  }
 185              }
 186          }
 187  
 188          // garvin: Update comment table for mime types [MIME]
 189          if (isset($field_mimetype) && is_array($field_mimetype) && $cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfg['BrowseMIME']) {
 190              foreach ($field_mimetype AS $fieldindex => $mimetype) {
 191                  if (isset($field_name[$fieldindex]) && strlen($field_name[$fieldindex])) {
 192                      PMA_setMIME($db, $table, $field_name[$fieldindex], $mimetype, $field_transformation[$fieldindex], $field_transformation_options[$fieldindex]);
 193                  }
 194              }
 195          }
 196  
 197          $message = $strTable . ' '
 198           . htmlspecialchars(PMA_backquote($db) . '.' . PMA_backquote($table))
 199           . ' ' . $strHasBeenCreated;
 200          $display_query = $sql_query;
 201          unset($sql_query);
 202  
 203          // do not switch to sql.php - as there is no row to be displayed on a new table
 204          if ($cfg['DefaultTabTable'] === 'sql.php') {
 205              require  './tbl_structure.php';
 206          } else {
 207              require './' . $cfg['DefaultTabTable'];
 208          }
 209          exit;
 210      } else {
 211          PMA_mysqlDie('', '', '', $err_url, false);
 212          // garvin: An error happened while inserting/updating a table definition.
 213          // to prevent total loss of that data, we embed the form once again.
 214          // The variable $regenerate will be used to restore data in libraries/tbl_properties.inc.php
 215          $num_fields = $orig_num_fields;
 216          $regenerate = true;
 217      }
 218  } // end do create table
 219  
 220  /**
 221   * Displays the form used to define the structure of the table
 222   */
 223  if ($abort == false) {
 224      if (isset($num_fields)) {
 225          $num_fields = intval($num_fields);
 226      }
 227      // No table name
 228      if (!isset($table) || trim($table) == '') {
 229          PMA_mysqlDie($strTableEmpty, '', '', $err_url);
 230      }
 231      // No valid number of fields
 232      elseif (empty($num_fields) || !is_int($num_fields)) {
 233          PMA_mysqlDie($strFieldsEmpty, '', '', $err_url);
 234      }
 235      // Does table exist?
 236      elseif (!(PMA_DBI_get_fields($db, $table) === false)) {
 237          PMA_mysqlDie(sprintf($strTableAlreadyExists, htmlspecialchars($table)), '', '', $err_url);
 238      }
 239      // Table name and number of fields are valid -> show the form
 240      else {
 241          $action = 'tbl_create.php';
 242          require  './libraries/tbl_properties.inc.php';
 243          // Displays the footer
 244          require_once  './libraries/footer.inc.php';
 245     }
 246  }
 247  
 248  ?>


Généré le : Mon Nov 26 15:18:20 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics