PMA\libraries\Table::generateAlter PHP Method

generateAlter() public static method

Generates column specification for ALTER syntax
See also: Table::generateFieldSpec()
public static generateAlter ( string $oldcol, string $newcol, string $type, string $length, string $attribute, string $collation, boolean | string $null, string $default_type, string $default_value, string $extra, string $comment, string $virtuality, string $expression, string $move_to ) : string
$oldcol string old column name
$newcol string new column name
$type string type ('INT', 'VARCHAR', 'BIT', ...)
$length string length ('2', '5,2', '', ...)
$attribute string attribute
$collation string collation
$null boolean | string with 'NULL' or 'NOT NULL'
$default_type string whether default is CURRENT_TIMESTAMP, NULL, NONE, USER_DEFINED
$default_value string default value for USER_DEFINED default type
$extra string 'AUTO_INCREMENT'
$comment string field comment
$virtuality string virtuality of the column
$expression string expression for the virtual column
$move_to string new position for column
return string field specification
    public static function generateAlter($oldcol, $newcol, $type, $length, $attribute, $collation, $null, $default_type, $default_value, $extra, $comment, $virtuality, $expression, $move_to)
    {
        return Util::backquote($oldcol) . ' ' . Table::generateFieldSpec($newcol, $type, $length, $attribute, $collation, $null, $default_type, $default_value, $extra, $comment, $virtuality, $expression, $move_to);
    }

Usage Example

Example #1
0
 /**
  * Test for generateAlter
  *
  * @return void
  */
 public function testGenerateAlter()
 {
     //parameter
     $oldcol = 'name';
     $newcol = 'new_name';
     $type = 'VARCHAR';
     $length = '2';
     $attribute = 'new_name';
     $collation = 'charset1';
     $null = 'NULL';
     $default_type = 'USER_DEFINED';
     $default_value = 'VARCHAR';
     $extra = 'AUTO_INCREMENT';
     $comment = 'PMA comment';
     $virtuality = '';
     $expression = '';
     $move_to = 'new_name';
     $result = Table::generateAlter($oldcol, $newcol, $type, $length, $attribute, $collation, $null, $default_type, $default_value, $extra, $comment, $virtuality, $expression, $move_to);
     $expect = "`name` `new_name` VARCHAR(2) new_name CHARACTER SET " . "charset1 NULL DEFAULT 'VARCHAR' " . "AUTO_INCREMENT COMMENT 'PMA comment' AFTER `new_name`";
     $this->assertEquals($expect, $result);
 }
All Usage Examples Of PMA\libraries\Table::generateAlter