/**
  * Given one xmldb_table and one xmldb_field, return the SQL statements needed to add the field to the table.
  *
  * @param xmldb_table $xmldb_table The table related to $xmldb_field.
  * @param xmldb_field $xmldb_field The instance of xmldb_field to create the SQL from.
  * @param string $skip_type_clause The type clause on alter columns, NULL by default.
  * @param string $skip_default_clause The default clause on alter columns, NULL by default.
  * @param string $skip_notnull_clause The null/notnull clause on alter columns, NULL by default.
  * @return array The SQL statement for adding a field to the table.
  */
 public function getAddFieldSQL($xmldb_table, $xmldb_field, $skip_type_clause = NULL, $skip_default_clause = NULL, $skip_notnull_clause = NULL)
 {
     $sqls = parent::getAddFieldSQL($xmldb_table, $xmldb_field, $skip_type_clause, $skip_default_clause, $skip_notnull_clause);
     if ($this->table_exists($xmldb_table)) {
         $tablename = $xmldb_table->getName();
         $size = $this->guess_antolope_row_size($this->mdb->get_columns($tablename));
         $size += $this->guess_antolope_row_size(array($xmldb_field));
         if ($size > self::ANTELOPE_MAX_ROW_SIZE) {
             if ($this->mdb->is_compressed_row_format_supported()) {
                 $format = strtolower($this->mdb->get_row_format($tablename));
                 if ($format === 'compact' or $format === 'redundant') {
                     // Change the format before conversion so that we do not run out of space.
                     array_unshift($sqls, "ALTER TABLE {$this->prefix}{$tablename} ROW_FORMAT=Compressed");
                 }
             }
         }
     }
     return $sqls;
 }
 /**
  * Given one xmldb_table and one xmldb_field, return the SQL statements needded to add the field to the table
  * PostgreSQL is pretty standard but with one severe restriction under 7.4 that forces us to overload
  * this function: Default clause is not allowed when adding fields.
  *
  * This function can be safely removed once min req. for PG will be 8.0
  */
 public function getAddFieldSQL($xmldb_table, $xmldb_field, $skip_type_clause = NULL, $skip_default_clause = NULL, $skip_notnull_clause = NULL)
 {
     $skip_type_clause = is_null($skip_type_clause) ? $this->alter_column_skip_type : $skip_type_clause;
     $skip_default_clause = is_null($skip_default_clause) ? $this->alter_column_skip_default : $skip_default_clause;
     $skip_notnull_clause = is_null($skip_notnull_clause) ? $this->alter_column_skip_notnull : $skip_notnull_clause;
     $results = array();
     $tablename = $this->getTableName($xmldb_table);
     $fieldname = $this->getEncQuoted($xmldb_field->getName());
     $defaultvalue = $xmldb_field->getDefault();
     $results = parent::getAddFieldSQL($xmldb_table, $xmldb_field, $skip_type_clause, $skip_default_clause, $skip_notnull_clause);
     /// Add default (only if not skip_default)
     if (!$skip_default_clause) {
         $default_clause = $this->getDefaultClause($xmldb_field);
         if ($default_clause) {
             $sql = 'ALTER TABLE ' . $tablename . ' ALTER COLUMN ' . $fieldname . ' SET' . $default_clause;
             /// Add default clause
             $results[] = $sql;
         }
         /// Update default value (if exists) to all the records
         if ($defaultvalue !== null) {
             if (!is_numeric($defaultvalue)) {
                 $defaultvalue = "'" . $this->addslashes($defaultvalue) . "'";
             }
             $sql = 'UPDATE ' . $tablename . ' SET ' . $fieldname . '=' . $defaultvalue;
             $results[] = $sql;
         }
     }
     /// Add not null (only if no skip_notnull)
     if (!$skip_notnull_clause) {
         if ($xmldb_field->getNotnull()) {
             $results[] = 'ALTER TABLE ' . $tablename . ' ALTER COLUMN ' . $fieldname . ' SET NOT NULL';
             /// Add not null
         }
     }
     return $results;
 }