Esempio n. 1
0
 /**
  * Returns the generation expression for virtual columns
  *
  * @param string $column name of the column
  *
  * @return array|boolean associative array of column name and their expressions
  *                       or false on failure
  */
 public function getColumnGenerationExpression($column = null)
 {
     $serverType = Util::getServerType();
     if ($serverType == 'MySQL' && PMA_MYSQL_INT_VERSION > 50705 && !$GLOBALS['cfg']['Server']['DisableIS']) {
         $sql = "SELECT\n                `COLUMN_NAME` AS `Field`,\n                `GENERATION_EXPRESSION` AS `Expression`\n                FROM\n                `information_schema`.`COLUMNS`\n                WHERE\n                `TABLE_SCHEMA` = '" . Util::sqlAddSlashes($this->_db_name) . "'\n                AND `TABLE_NAME` = '" . Util::sqlAddSlashes($this->_name) . "'";
         if ($column != null) {
             $sql .= " AND  `COLUMN_NAME` = '" . Util::sqlAddSlashes($column) . "'";
         }
         $columns = $this->_dbi->fetchResult($sql, 'Field', 'Expression');
         return $columns;
     }
     $createTable = $this->showCreate();
     if (!$createTable) {
         return false;
     }
     $parser = new Parser($createTable);
     /**
      * @var \SqlParser\Statements\CreateStatement $stmt
      */
     $stmt = $parser->statements[0];
     $fields = Table::getFields($stmt);
     if ($column != null) {
         $expression = isset($fields[$column]['expr']) ? substr($fields[$column]['expr'], 1, -1) : '';
         return array($column => $expression);
     }
     $ret = array();
     foreach ($fields as $field => $options) {
         if (isset($options['expr'])) {
             $ret[$field] = substr($options['expr'], 1, -1);
         }
     }
     return $ret;
 }