本節提供關於 ForeignKey
類別的資訊,此類別對 NDB
資料表上的外部索引鍵進行建模。
- 父類別
- 子類別
無.
- 方法
-
下表列出
ForeignKey
類別的公用方法,以及每個方法的目的或用途表 2.20 ForeignKey 類別方法與描述
名稱 描述 ForeignKey()
類別建構函式 ~ForeignKey()
類別解構函式 getName()
取得外部索引鍵的名稱 getParentTable()
取得外部索引鍵的父資料表 getChildTable()
取得外部索引鍵的子資料表 getParentColumnCount()
取得父資料表中的資料行數 getChildColumnCount()
取得子資料表中的資料行數 getParentColumnNo()
取得父資料表中的資料行號碼 getChildColumnNo()
取得子資料表中的資料行號碼 getParentIndex()
若索引鍵指向父資料表的主索引鍵,則傳回 0 getChildIndex()
若使用子資料表的主索引鍵解析子參考,則傳回 0 getOnUpdateAction()
取得外部索引鍵的更新動作 ( FkAction
)getOnDeleteAction()
取得外部索引鍵的刪除動作 ( FkAction
)setName()
設定外部索引鍵的名稱 setParent()
設定外部索引鍵的父資料表 setChild()
設定外部索引鍵的子資料表 setOnUpdateAction()
設定外部索引鍵的更新動作 ( FkAction
)setOnDeleteAction()
設定外部索引鍵的刪除動作 ( FkAction
)getObjectStatus()
取得物件狀態 getObjectId()
取得物件 ID getObjectVersion()
取得物件版本
- 類型
ForeignKey
類別有一個公用類型,即FkAction
類型。
- 描述
建立全新的外部索引鍵參考,或是現有外部索引鍵參考的複本。
- 簽名
-
新執行個體
ForeignKey ( void )
複製建構函式
ForeignKey ( const ForeignKey& )
- 參數
-
對於新執行個體:無。
對於複製建構函式:現有
ForeignKey
執行個體的參考。 - 傳回值
ForeignKey
的新執行個體。
- 描述
擷取呼叫此方法的
ForeignKey
執行個體的父資料表。- 簽名
const char* getParentTable ( void ) const
- 參數
無.
- 傳回值
指向
ForeignKey
父資料表的指標。
- 描述
擷取呼叫此方法的
ForeignKey
執行個體的子資料表。- 簽名
const char* getChildTable ( void ) const
- 參數
無.
- 傳回值
指向此
ForeignKey
子資料表的指標。
- 描述
此方法會取得指定索引的父資料表中外鍵欄位的序號。關於在 NDB API 中處理欄位的資訊,請參閱
Column::getColumnNo()
的文件。- 簽名
int getParentColumnNo ( unsigned no ) const
- 參數
無.
- 傳回值
欄位的序號。
- 描述
此方法會取得指定索引的子資料表中外鍵欄位的序號。關於在 NDB API 中處理欄位的資訊,請參閱
Column::getColumnNo()
的文件。- 簽名
int getChildColumnNo ( unsigned no ) const
- 參數
無.
- 傳回值
欄位的序號。
- 描述
取得外鍵的
ON UPDATE
動作。這是一個ForeignKey::FkAction
,且具有下列其中一個值:NoAction
、Restrict
、Cascade
或SetNull
。- 簽名
FkAction getOnUpdateAction ( void ) const
- 參數
無.
- 傳回值
欄位的序號。
- 描述
取得外鍵的
ON DELETE
動作。這是一個ForeignKey::FkAction
,且具有下列其中一個值:NoAction
、Restrict
、Cascade
或SetNull
。- 簽名
FkAction getOnDeleteAction ( void ) const
- 參數
無.
- 傳回值
欄位的序號。
- 描述
設定
ForeignKey
的父資料表,可提供資料表的參考,以及選擇性地提供一個索引來作為外鍵。- 簽名
void setParent ( const Table&, const Index* index = 0, const Column* cols[] = 0 )
- 參數
一個
Table
的參考 (必要)。選擇性地,可以使用指定的欄位或多個欄位的索引。- 傳回值
無.
- 描述
設定
ForeignKey
的子資料表,可提供資料表的參考,以及選擇性地提供一個索引來作為外鍵。- 簽名
void setChild ( const Table&, const Index* index = 0, const Column* cols[] = 0 )
- 參數
一個
Table
的參考 (必要)。選擇性地,可以使用指定的欄位或多個欄位的索引。- 傳回值
無.
- 描述
設定外鍵的
ON UPDATE
動作。- 簽名
void setOnUpdateAction ( FkAction )
- 參數
要執行的
ON UPDATE
動作。這必須是一個ForeignKey::FkAction
,其值必須是NoAction
、Restrict
、Cascade
或SetNull
其中之一。- 傳回值
無
- 描述
設定外鍵的
ON DELETE
動作。- 簽名
void setOnUpdateAction ( FkAction )
- 參數
要執行的
ON UPDATE
動作,類型為ForeignKey::FkAction
。必須是NoAction
、Restrict
、Cascade
或SetNull
其中之一的值。- 傳回值
無
- 描述
取得此
ForeignKey
物件的物件狀態 (請參閱 Object::Status)。- 簽名
virtual Object::Status getObjectStatus ( void ) const
- 參數
無.
- 傳回值
ForeignKey
物件的狀態,以Object::Status
類型的值表示。請參閱此類型的文件,以了解可能的值及其解釋。
- 描述
取得此
ForeignKey
物件的物件 ID (請參閱 Object::getObjectId())。- 簽名
virtual int getObjectId ( void ) const
- 參數
無.
- 傳回值
由
Object::getObjectId()
傳回的ForeignKey
物件 ID。
- 描述
取得此
ForeignKey
物件的物件版本 (請參閱 Object::getObjectVersion())。- 簽名
virtual int getObjectVersion ( void ) const
- 參數
無.
- 傳回值
由
Object::getObjectVersion()
傳回的ForeignKey
物件的版本號碼 (整數)。