Yii Framework v1.1.10 绫诲弬鑰

CDbColumnSchema

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绫绘弿杩版暟鎹〃鐨勫垪鍏冩暟鎹

鍏叡灞炴

闅愯棌缁ф壙灞炴

灞炴绫诲瀷鎻忚堪瀹氫箟鍦
allowNull boolean 璇ュ垪鏄惁鍙互涓簄ull CDbColumnSchema
autoIncrement boolean 璇ュ垪鏄惁涓鸿嚜澧炲垪 CDbColumnSchema
dbType string 璇ュ垪鐨勬暟鎹被鍨嬨 CDbColumnSchema
defaultValue mixed 璇ュ垪鐨勯粯璁ゅ CDbColumnSchema
isForeignKey boolean 璇ュ垪鏄惁涓哄閿 CDbColumnSchema
isPrimaryKey boolean 璇ュ垪鏄惁涓轰富閿 CDbColumnSchema
name string 鍒楀悕锛堟棤寮曞彿锛夈 CDbColumnSchema
precision integer 璇ュ垪鏁版嵁鐨勭簿搴︼紝鑻ュ畠鏄竴涓暟銆 CDbColumnSchema
rawName string 鍘熷鍒楀悕銆傚畠琚紩鐢ㄤ簡浠ヤ究鍦⊿QL鏌ヨ涓娇鐢ㄣ CDbColumnSchema
scale integer 璇ュ垪鏁版嵁鐨勮妯★紝鑻ュ畠鏄竴涓暟銆 CDbColumnSchema
size integer 璇ュ垪鐨勫ぇ灏忋 CDbColumnSchema
type string 璇ュ垪鐨凥P绫诲瀷銆 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() 璁$畻涓涓狿HP琛ㄨ揪寮忥紝鎴栨牴鎹粍浠朵笂涓嬫枃鎵ц鍥炶皟銆 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;

璇ュ垪鏄惁鍙互涓簄ull

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;

鍘熷鍒楀悕銆傚畠琚紩鐢ㄤ簡浠ヤ究鍦⊿QL鏌ヨ涓娇鐢ㄣ

scale 灞炴
public integer $scale;

璇ュ垪鏁版嵁鐨勮妯★紝鑻ュ畠鏄竴涓暟銆

size 灞炴
public integer $size;

璇ュ垪鐨勫ぇ灏忋

type 灞炴
public string $type;

璇ュ垪鐨凥P绫诲瀷銆

鏂规硶璇︾粏

extractDefault() 鏂规硶
protected void extractDefault(mixed $defaultValue)
$defaultValue mixed 浠庡厓鏁版嵁涓幏寰楃殑榛樿鍊笺
婧愮爜锛 framework/db/schema/CDbColumnSchema.php#123 (鏄剧ず)
protected function extractDefault($defaultValue)
{
    
$this->defaultValue=$this->typecast($defaultValue);
}

鎻愬彇鍒楃殑榛樿鍊笺 璇ュ间細琚浆鎹㈠埌姝g‘鐨凱HP绫诲瀷銆

extractLimit() 鏂规硶
protected void extractLimit(string $dbType)
$dbType string 鍒楃被鍨嬨
婧愮爜锛 framework/db/schema/CDbColumnSchema.php#107 (鏄剧ず)
protected function extractLimit($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)
$dbType string 鏁版嵁绫诲瀷
婧愮爜锛 framework/db/schema/CDbColumnSchema.php#91 (鏄剧ず)
protected function extractType($dbType)
{
    if(
stripos($dbType,'int')!==false && stripos($dbType,'unsigned int')===false)
        
$this->type='integer';
    else if(
stripos($dbType,'bool')!==false)
        
$this->type='boolean';
    else if(
preg_match('/(real|floa|doub)/i',$dbType))
        
$this->type='double';
    else
        
$this->type='string';
}

浠庢暟鎹被鍨嬩腑鎻愬彇PHP绫诲瀷銆

init() 鏂规硶
public void init(string $dbType, mixed $defaultValue)
$dbType string 璇ュ垪鐨勬暟鎹被鍨嬨
$defaultValue mixed 榛樿鍊
婧愮爜锛 framework/db/schema/CDbColumnSchema.php#78 (鏄剧ず)
public function init($dbType$defaultValue)
{
    
$this->dbType=$dbType;
    
$this->extractType($dbType);
    
$this->extractLimit($dbType);
    if(
$defaultValue!==null)
        
$this->extractDefault($defaultValue);
}

鏍规嵁瀹冪殑鏁版嵁绫诲瀷鍜岄粯璁ゅ煎垵濮嬪寲璇ュ垪銆 鍚屾椂浼氳缃垪鐨凱HP绫诲瀷锛屽ぇ灏忥紝绮惧害锛岃妯°

typecast() 鏂规硶
public mixed typecast(mixed $value)
$value mixed 杈撳叆鍊
{return} mixed 杞崲鍚庣殑鍊
婧愮爜锛 framework/db/schema/CDbColumnSchema.php#133 (鏄剧ず)
public function typecast($value)
{
    if(
gettype($value)===$this->type || $value===null || $value instanceof CDbExpression)
        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;
    }
}

灏嗚緭鍏ュ艰浆鎹负鏈垪鐨勭被鍨嬨

Copyright © 2008-2011 by Yii Software LLC
All Rights Reserved.