Beispiel #1
0
 /**
  * ALTER TABLE
  *
  * @param	string	$alter_type	ALTER type
  * @param	string	$table		Table name
  * @param	mixed	$field		Column definition
  * @return	string|string[]
  */
 protected function _alter_table($alter_type, $table, $field)
 {
     if ($alter_type === 'CHANGE') {
         $alter_type = 'MODIFY';
     }
     return parent::_alter_table($alter_type, $table, $field);
 }
Beispiel #2
0
 /**
  * ALTER TABLE
  *
  * @param	string	$alter_type	ALTER type
  * @param	string	$table		Table name
  * @param	mixed	$field		Column definition
  * @return	string|string[]
  */
 protected function _alter_table($alter_type, $table, $field)
 {
     if ($alter_type === 'DROP') {
         return parent::_alter_table($alter_type, $table, $field);
     } elseif ($alter_type === 'CHANGE') {
         $alter_type = 'MODIFY';
     }
     $sql = 'ALTER TABLE ' . $this->db->escape_identifiers($table);
     $sqls = array();
     for ($i = 0, $c = count($field); $i < $c; $i++) {
         if ($field[$i]['_literal'] !== FALSE) {
             $field[$i] = "\n\t" . $field[$i]['_literal'];
         } else {
             $field[$i]['_literal'] = "\n\t" . $this->_process_column($field[$i]);
             if (!empty($field[$i]['comment'])) {
                 $sqls[] = 'COMMENT ON COLUMN ' . $this->db->escape_identifiers($table) . '.' . $this->db->escape_identifiers($field[$i]['name']) . ' IS ' . $field[$i]['comment'];
             }
             if ($alter_type === 'MODIFY' && !empty($field[$i]['new_name'])) {
                 $sqls[] = $sql . ' RENAME COLUMN ' . $this->db->escape_identifiers($field[$i]['name']) . ' ' . $this->db->escape_identifiers($field[$i]['new_name']);
             }
         }
     }
     $sql .= ' ' . $alter_type . ' ';
     $sql .= count($field) === 1 ? $field[0] : '(' . implode(',', $field) . ')';
     // RENAME COLUMN must be executed after MODIFY
     array_unshift($sqls, $sql);
     return $sql;
 }
Beispiel #3
0
 /**
  * ALTER TABLE
  *
  * @param	string	$alter_type	ALTER type
  * @param	string	$table		Table name
  * @param	mixed	$field		Column definition
  * @return	string|string[]
  */
 protected function _alter_table($alter_type, $table, $field)
 {
     if (in_array($alter_type, array('ADD', 'DROP'), TRUE)) {
         return parent::_alter_table($alter_type, $table, $field);
     }
     $sql = 'ALTER TABLE ' . $this->db->escape_identifiers($table) . ' ALTER COLUMN ';
     $sqls = array();
     for ($i = 0, $c = count($field); $i < $c; $i++) {
         $sqls[] = $sql . $this->_process_column($field[$i]);
     }
     return $sqls;
 }
Beispiel #4
0
 /**
  * ALTER TABLE
  *
  * @param	string	$alter_type	ALTER type
  * @param	string	$table		Table name
  * @param	mixed	$field		Column definition
  * @return	string|string[]
  */
 protected function _alter_table($alter_type, $table, $field)
 {
     if (in_array($alter_type, array('DROP', 'ADD'), TRUE)) {
         return parent::_alter_table($alter_type, $table, $field);
     }
     $sql = 'ALTER TABLE ' . $this->db->escape_identifiers($table);
     $sqls = array();
     for ($i = 0, $c = count($field); $i < $c; $i++) {
         if ($field[$i]['_literal'] !== FALSE) {
             $sqls[] = $sql . ' CHANGE ' . $field[$i]['_literal'];
         } else {
             $alter_type = empty($field[$i]['new_name']) ? ' MODIFY ' : ' CHANGE ';
             $sqls[] = $sql . $alter_type . $this->_process_column($field[$i]);
         }
     }
     return $sqls;
 }
Beispiel #5
0
 /**
  * ALTER TABLE
  *
  * @param	string	$alter_type	ALTER type
  * @param	string	$table		Table name
  * @param	mixed	$field		Column definition
  * @return	string|string[]
  */
 protected function _alter_table($alter_type, $table, $field)
 {
     if (in_array($alter_type, array('DROP', 'ADD'), TRUE)) {
         return parent::_alter_table($alter_type, $table, $field);
     }
     $sql = 'ALTER TABLE ' . $this->db->escape_identifiers($table);
     $sqls = array();
     for ($i = 0, $c = count($field); $i < $c; $i++) {
         if ($field[$i]['_literal'] !== FALSE) {
             return FALSE;
         }
         if (version_compare($this->db->version(), '8', '>=') && isset($field[$i]['type'])) {
             $sqls[] = $sql . ' ALTER COLUMN ' . $this->db->escape_identifiers($field[$i]['name']) . ' TYPE ' . $field[$i]['type'] . $field[$i]['length'];
         }
         if (!empty($field[$i]['default'])) {
             $sqls[] = $sql . ' ALTER COLUMN ' . $this->db->escape_identifiers($field[$i]['name']) . ' SET DEFAULT ' . $field[$i]['default'];
         }
         if (isset($field[$i]['null'])) {
             $sqls[] = $sql . ' ALTER COLUMN ' . $this->db->escape_identifiers($field[$i]['name']) . ($field[$i]['null'] === TRUE ? ' DROP NOT NULL' : ' SET NOT NULL');
         }
         if (!empty($field[$i]['new_name'])) {
             $sqls[] = $sql . ' RENAME COLUMN ' . $this->db->escape_identifiers($field[$i]['name']) . ' TO ' . $this->db->escape_identifiers($field[$i]['new_name']);
         }
         if (!empty($field[$i]['comment'])) {
             $sqls[] = 'COMMENT ON COLUMN ' . $this->db->escape_identifiers($table) . '.' . $this->db->escape_identifiers($field[$i]['name']) . ' IS ' . $field[$i]['comment'];
         }
     }
     return $sqls;
 }
Beispiel #6
0
 /**
  * ALTER TABLE
  *
  * @param	string	$alter_type	ALTER type
  * @param	string	$table		Table name
  * @param	mixed	$field		Column definition
  * @return	string|string[]
  */
 protected function _alter_table($alter_type, $table, $field)
 {
     if (in_array($alter_type, array('ADD', 'DROP'), TRUE)) {
         return parent::_alter_table($alter_type, $table, $field);
     }
     // No method of modifying columns is supported
     return FALSE;
 }
Beispiel #7
0
 /**
  * ALTER TABLE
  *
  * @param	string	$alter_type	ALTER type
  * @param	string	$table		Table name
  * @param	mixed	$field		Column definition
  * @return	string|string[]
  */
 protected function _alter_table($alter_type, $table, $field)
 {
     if (in_array($alter_type, array('DROP', 'ADD'), TRUE)) {
         return parent::_alter_table($alter_type, $table, $field);
     }
     $sql = 'ALTER TABLE ' . $this->db->escape_identifiers($table);
     $sqls = array();
     for ($i = 0, $c = count($field); $i < $c; $i++) {
         if ($field[$i]['_literal'] !== FALSE) {
             return FALSE;
         }
         if (isset($field[$i]['type'])) {
             $sqls[] = $sql . ' ALTER COLUMN ' . $this->db->escape_identifiers($field[$i]['name']) . ' TYPE ' . $field[$i]['type'] . $field[$i]['length'];
         }
         if (!empty($field[$i]['default'])) {
             $sqls[] = $sql . ' ALTER COLUMN ' . $this->db->escape_identifiers($field[$i]['name']) . ' SET DEFAULT ' . $field[$i]['default'];
         }
         if (isset($field[$i]['null'])) {
             $sqls[] = 'UPDATE "RDB$RELATION_FIELDS" SET "RDB$NULL_FLAG" = ' . ($field[$i]['null'] === TRUE ? 'NULL' : '1') . ' WHERE "RDB$FIELD_NAME" = ' . $this->db->escape($field[$i]['name']) . ' AND "RDB$RELATION_NAME" = ' . $this->db->escape($table);
         }
         if (!empty($field[$i]['new_name'])) {
             $sqls[] = $sql . ' ALTER COLUMN ' . $this->db->escape_identifiers($field[$i]['name']) . ' TO ' . $this->db->escape_identifiers($field[$i]['new_name']);
         }
     }
     return $sqls;
 }
Beispiel #8
0
 /**
  * ALTER TABLE
  *
  * @param	string	$alter_type	ALTER type
  * @param	string	$table		Table name
  * @param	mixed	$field		Column definition
  * @return	string|string[]
  */
 protected function _alter_table($alter_type, $table, $field)
 {
     if ($alter_type === 'DROP') {
         return parent::_alter_table($alter_type, $table, $field);
     }
     $sql = 'ALTER TABLE ' . $this->db->escape_identifiers($table);
     for ($i = 0, $c = count($field); $i < $c; $i++) {
         if ($field[$i]['_literal'] !== FALSE) {
             $field[$i] = $alter_type === 'ADD' ? "\n\tADD " . $field[$i]['_literal'] : "\n\tMODIFY " . $field[$i]['_literal'];
         } else {
             if ($alter_type === 'ADD') {
                 $field[$i]['_literal'] = "\n\tADD ";
             } else {
                 $field[$i]['_literal'] = empty($field[$i]['new_name']) ? "\n\tMODIFY " : "\n\tCHANGE ";
             }
             $field[$i] = $field[$i]['_literal'] . $this->_process_column($field[$i]);
         }
     }
     return array($sql . implode(',', $field));
 }
Beispiel #9
0
 /**
  * ALTER TABLE
  *
  * @param	string	$alter_type	ALTER type
  * @param	string	$table		Table name
  * @param	mixed	$field		Column definition
  * @return	string|string[]
  */
 protected function _alter_table($alter_type, $table, $field)
 {
     if ($alter_type === 'DROP' or $alter_type === 'CHANGE') {
         // drop_column():
         //	BEGIN TRANSACTION;
         //	CREATE TEMPORARY TABLE t1_backup(a,b);
         //	INSERT INTO t1_backup SELECT a,b FROM t1;
         //	DROP TABLE t1;
         //	CREATE TABLE t1(a,b);
         //	INSERT INTO t1 SELECT a,b FROM t1_backup;
         //	DROP TABLE t1_backup;
         //	COMMIT;
         return FALSE;
     }
     return parent::_alter_table($alter_type, $table, $field);
 }