CDbColumnSchema

优质
小牛编辑
123浏览
2023-12-01
所有包 | 属性 | 方法
system.db.schema
继承class CDbColumnSchema » CComponent
子类CMssqlColumnSchema, CMysqlColumnSchema, COciColumnSchema, CPgsqlColumnSchema, CSqliteColumnSchema
源自1.0
版本$Id: CDbColumnSchema.php 3558 2012-02-09 17:39:04Z alexander.makarow $
源码framework/db/schema/CDbColumnSchema.php
CDbColumnSchema类描述数据表的列元数据。

公共属性

隐藏继承属性

属性类型描述定义在
allowNullboolean该列是否可以为nullCDbColumnSchema
autoIncrementboolean该列是否为自增列CDbColumnSchema
dbTypestring该列的数据类型。CDbColumnSchema
defaultValuemixed该列的默认值CDbColumnSchema
isForeignKeyboolean该列是否为外键CDbColumnSchema
isPrimaryKeyboolean该列是否为主键CDbColumnSchema
namestring列名(无引号)。CDbColumnSchema
precisioninteger该列数据的精度,若它是一个数。CDbColumnSchema
rawNamestring原始列名。它被引用了以便在SQL查询中使用。CDbColumnSchema
scaleinteger该列数据的规模,若它是一个数。CDbColumnSchema
sizeinteger该列的大小。CDbColumnSchema
typestring该列的HP类型。CDbColumnSchema

公共方法

隐藏继承方法

方法描述定义在
__call()如果类中没有调的方法名,则调用这个方法。CComponent
__get()返回一个属性值、一个事件处理程序列表或一个行为名称。CComponent
__isset()检查一个属性是否为null。CComponent
__set()设置一个组件的属性值。CComponent
__unset()设置一个组件的属性为null。CComponent
asa()返回这个名字的行为对象。CComponent
attachBehavior()附加一个行为到组件。CComponent
attachBehaviors()附加一个行为列表到组件。CComponent
attachEventHandler()为事件附加一个事件处理程序。CComponent
canGetProperty()确定属性是否可读。CComponent
canSetProperty()确定属性是否可写。CComponent
detachBehavior()从组件中分离一个行为。CComponent
detachBehaviors()从组件中分离所有行为。CComponent
detachEventHandler()分离一个存在的事件处理程序。CComponent
disableBehavior()禁用一个附加行为。CComponent
disableBehaviors()禁用组件附加的所有行为。CComponent
enableBehavior()启用一个附加行为。CComponent
enableBehaviors()启用组件附加的所有行为。CComponent
evaluateExpression()计算一个PHP表达式,或根据组件上下文执行回调。CComponent
getEventHandlers()返回一个事件的附加处理程序列表。CComponent
hasEvent()确定一个事件是否定义。CComponent
hasEventHandler()检查事件是否有附加的处理程序。CComponent
hasProperty()确定属性是否被定义。CComponent
init()根据它的数据类型和默认值初始化该列。CDbColumnSchema
raiseEvent()发起一个事件。CComponent
typecast()将输入值转换为本列的类型。CDbColumnSchema

受保护方法

隐藏继承方法

方法描述定义在
extractDefault()提取列的默认值。CDbColumnSchema
extractLimit()从列类型中提取大小、精确度和规模。CDbColumnSchema
extractType()从数据类型中提取PHP类型。CDbColumnSchema

属性详细

allowNull 属性 public boolean $allowNull;

该列是否可以为null

autoIncrement 属性 (可用自 v1.1.7) public boolean $autoIncrement;

该列是否为自增列

dbType 属性 public string $dbType;

该列的数据类型。

defaultValue 属性 public mixed $defaultValue;

该列的默认值

isForeignKey 属性 public boolean $isForeignKey;

该列是否为外键

isPrimaryKey 属性 public boolean $isPrimaryKey;

该列是否为主键

name 属性 public string $name;

列名(无引号)。

precision 属性 public integer $precision;

该列数据的精度,若它是一个数。

rawName 属性 public string $rawName;

原始列名。它被引用了以便在SQL查询中使用。

scale 属性 public integer $scale;

该列数据的规模,若它是一个数。

size 属性 public integer $size;

该列的大小。

type 属性 public string $type;

该列的HP类型。

方法详细

extractDefault() 方法
protected void extractDefault(mixed $defaultValue)
$defaultValuemixed从元数据中获得的默认值。
源码: framework/db/schema/CDbColumnSchema.php#123 (显示) protectedfunctionextractDefault($defaultValue)
{
$this->defaultValue=$this->typecast($defaultValue);
}

提取列的默认值。 该值会被转换到正确的PHP类型。

extractLimit() 方法
protected void extractLimit(string $dbType)
$dbTypestring列类型。
源码: framework/db/schema/CDbColumnSchema.php#107 (显示) protectedfunctionextractLimit($dbType)
{
if(strpos($dbType,'(')&&preg_match('/((.*))/',$dbType,$matches))
{
$values=explode(',',$matches[1]);
$this->size=$this->precision=(int)$values[0];
if(isset($values[1]))
$this->scale=(int)$values[1];
}
}

从列类型中提取大小、精确度和规模。

extractType() 方法
protected void extractType(string $dbType)
$dbTypestring数据类型
源码: framework/db/schema/CDbColumnSchema.php#91 (显示) protectedfunctionextractType($dbType)
{
if(stripos($dbType,'int')!==false&&stripos($dbType,'unsignedint')===false)
$this->type='integer';
elseif(stripos($dbType,'bool')!==false)
$this->type='boolean';
elseif(preg_match('/(real|floa|doub)/i',$dbType))
$this->type='double';
else
$this->type='string';
}

从数据类型中提取PHP类型。

init() 方法
public void init(string $dbType, mixed $defaultValue)
$dbTypestring该列的数据类型。
$defaultValuemixed默认值
源码: framework/db/schema/CDbColumnSchema.php#78 (显示) publicfunctioninit($dbType,$defaultValue)
{
$this->dbType=$dbType;
$this->extractType($dbType);
$this->extractLimit($dbType);
if($defaultValue!==null)
$this->extractDefault($defaultValue);
}

根据它的数据类型和默认值初始化该列。 同时会设置列的PHP类型,大小,精度,规模。

typecast() 方法
public mixed typecast(mixed $value)
$valuemixed输入值
{return}mixed转换后的值
源码: framework/db/schema/CDbColumnSchema.php#133 (显示) publicfunctiontypecast($value)
{
if(gettype($value)===$this->type||$value===null||$valueinstanceofCDbExpression)
return$value;
if($value===''&&$this->allowNull)
return$this->type==='string'?'':null;
switch($this->type)
{
case'string':return(string)$value;
case'integer':return(integer)$value;
case'boolean':return(boolean)$value;
case'double':
default:return$value;
}
}

将输入值转换为本列的类型。