mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-07 02:31:40 +09:00
Implement modifyColumn() for Cubrid
This commit is contained in:
parent
ccae599b24
commit
3a586c2c32
1 changed files with 62 additions and 0 deletions
|
|
@ -539,6 +539,68 @@ class DBCubrid extends DB
|
|||
$this->_query($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify a column (only supported in CUBRID 8.4 and above, otherwise returns false)
|
||||
* @param string $table_name table name
|
||||
* @param string $column_name column name
|
||||
* @param string $type column type, default value is 'number'
|
||||
* @param int $size column size
|
||||
* @param string|int $default default value
|
||||
* @param boolean $notnull not null status, default value is false
|
||||
* @return bool
|
||||
*/
|
||||
function modifyColumn($table_name, $column_name, $type = 'number', $size = '', $default = '', $notnull = FALSE)
|
||||
{
|
||||
if(!version_compare(__CUBRID_VERSION__, '8.4.0', '>='))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$type = strtoupper($this->column_type[$type]);
|
||||
if($type == 'INTEGER')
|
||||
{
|
||||
$size = '';
|
||||
}
|
||||
|
||||
$query = sprintf("alter class \"%s%s\" modify \"%s\" ", $this->prefix, $table_name, $column_name);
|
||||
|
||||
if($type == 'char' || $type == 'varchar')
|
||||
{
|
||||
if($size)
|
||||
{
|
||||
$size = $size * 3;
|
||||
}
|
||||
}
|
||||
|
||||
if($size)
|
||||
{
|
||||
$query .= sprintf("%s(%s) ", $type, $size);
|
||||
}
|
||||
else
|
||||
{
|
||||
$query .= sprintf("%s ", $type);
|
||||
}
|
||||
|
||||
if($default)
|
||||
{
|
||||
if($type == 'INTEGER' || $type == 'BIGINT' || $type == 'INT')
|
||||
{
|
||||
$query .= sprintf("default %d ", $default);
|
||||
}
|
||||
else
|
||||
{
|
||||
$query .= sprintf("default '%s' ", $default);
|
||||
}
|
||||
}
|
||||
|
||||
if($notnull)
|
||||
{
|
||||
$query .= "not null ";
|
||||
}
|
||||
|
||||
return $this->_query($query) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check column exist status of the table
|
||||
* @param string $table_name table name
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue