文件首頁
MySQL NDB Cluster API 開發人員指南
相關文件 下載本手冊
PDF (美式信紙) - 3.6Mb
PDF (A4) - 3.6Mb


2.3.14 NdbDictionary 類別

本節提供有關 NdbDictionary 類別的資訊,該類別儲存有關 NDB 資料庫物件 (例如資料表、資料行與索引) 的中繼資訊。

雖然建立與刪除資料庫物件的偏好方法是透過 MySQL 伺服器,但 NdbDictionary 也允許開發人員透過 NDB API 執行這些工作。

NdbDictionary 類別概觀

父類別

子類別

DictionaryColumnObject

如需 NdbDictionary 子類別列舉的數值對等項目,請參閱 NDB Cluster 原始碼樹狀結構中的 /storage/ndb/include/ndbapi/NdbDictionary.hpp 檔案。

描述

這是一個資料字典類別,支援有關資料表、資料行與索引的查詢。它也提供定義這些資料庫物件以及移除它們的方法。這兩種功能都是透過模擬這些物件的內部類別來提供。這些包括下列內部類別

  • Table 用於處理資料表

  • Column 用於建立資料表資料行

  • Index 用於處理次要索引

  • Dictionary 用於建立資料庫物件並進行結構描述查詢

  • Event 用於處理叢集中的事件。

其他 Object 子類別會模擬使用 NDB Cluster 磁碟資料表以及外部索引鍵限制所需的工作區、記錄檔群組、資料檔案與復原檔。

使用 NdbDictionary 建立的資料表與索引無法從 MySQL 伺服器檢視。

透過 NDB API 捨棄最初從 NDB Cluster 建立的索引會導致不一致。可能使用 NDB API 捨棄一個或多個索引的資料表在這些作業之後將無法再被 MySQL 使用。在此情況下,必須捨棄資料表,然後使用 MySQL 重新建立,才能再次讓 MySQL 存取。

方法

NdbDictionary 本身沒有公用執行個體方法,只有用於處理 NdbRecord 物件的靜態方法。不使用 NdbRecord 的作業是透過 NdbDictionary 子類別執行個體方法來完成。下表列出 NdbDictionary 的公用方法,以及每個方法的用途或用法

表 2.37 NdbDictionary 類別方法與描述

名稱 描述
getEmptyBitmask() 傳回空的資料行存在位元遮罩,可以搭配 NdbRecord 使用
getFirstAttrId() 取得給定 NdbRecord 物件指定的第一個屬性 ID
getRecordIndexName() 取得 NdbRecord 所參考之索引物件的名稱
getRecordRowLength() 取得使用給定 NdbRecord 儲存一列資料所需的位元組數
getRecordTableName() 取得 NdbRecord 所參考之資料表物件的名稱
getRecordType() 取得 NdbRecord 的 RecordType
getValuePtr() 傳回屬性 ID 指定之儲存資料開頭的指標,使用 NdbRecord
isNull() 顯示資料行的 Null 位元是否為 true 或 false
setNull() 設定資料行的 Null 位元

類型

NdbDictionary 定義了兩個資料結構,列示於此

NdbDictionary::AutoGrowSpecification

摘要

本節提供有關 AutoGrowSpecification 資料結構的資訊。

父類別

NdbDictionary

描述

AutoGrowSpecification 是在 NdbDictionary 類別中定義的資料結構,用作 TablespaceLogfileGroup 類別部分方法之參數或傳回值。

成員

AutoGrowSpecification 具有下表顯示的成員

表 2.38 NdbDictionary::AutoGrowSpecification 資料結構成員名稱與描述

名稱 描述
min_free ???
max_size ???
file_size ???
filename_pattern ???

NdbDictionary::getEmptyBitmask()

描述

傳回空的資料行存在位元遮罩,該遮罩可以與任何 NdbRecord 搭配使用,以指定作業中不應包含任何 NdbRecord 資料行。

簽章
static const unsigned char* getEmptyBitmask
    (
      void
    )
參數

.

傳回值

空的位元遮罩。

NdbDictionary::getFirstAttrId()

描述

取得 NdbRecord 物件指定的第一個屬性 ID。如果未指定任何屬性 ID,則傳回 false

簽章
static bool getFirstAttrId
    (
      const NdbRecord* record,
      Uint32& firstAttrId
    )
參數

指向 NdbRecord 的指標,以及屬性 (firstAttrID) 的參考。

傳回值

布林值 false,當無法取得任何屬性 ID 時。

NdbDictionary::getNextAttrId()

描述

取得 NdbRecord 物件在傳入的屬性 ID 之後指定的下一個屬性 ID。當沒有更多要傳回的屬性 ID 時,傳回 false

簽章
static bool getNextAttrId
    (
      const NdbRecord* record,
      Uint32& attrId
    )
參數

指向 NdbRecord 的指標,以及屬性 ID 的參考。

傳回值

布林值 false,當無法取得任何屬性 ID 時。

NdbDictionary::getNullBitOffset()

描述

NdbRecord 列的開頭取得給定屬性 ID 的 Null 位元偏移量。如果屬性 ID 不存在,則傳回 false

簽章
static bool getNullBitOffset
    (
      const NdbRecord* record,
      Uint32 attrId,
      Uint32& bytes,
      Uint32& bit
    )
參數

NdbRecord record 中,取得給定屬性 ID (attrId) 的 Null 位元偏移量。偏移量表示為位元組數 (bytes) 加上最後一個位元組中的位元數 (bit)。

傳回值

如果具有給定 ID 的屬性不存在,則為布林值 false

NdbDictionary::getOffset()

描述

NdbRecord 列的開頭取得給定屬性 ID 的儲存偏移量。如果屬性 ID 不存在,則傳回 false

簽章
static bool getOffset
    (
      const NdbRecord* record,
      Uint32 attrId,
      Uint32& offset
    )
參數

給定屬性 ID 的儲存從 NdbRecord 列開頭的 offset

傳回值

如果找不到任何屬性 ID,則為布林值 false

NdbDictionary::getRecordIndexName()

描述

取得 Index 物件的名稱,NdbRecord 指向該物件。

簽章
static const char* getRecordIndexName
    (
      const NdbRecord* record
    )
參數

指向要取得名稱的 NdbRecord 的指標。

傳回值

名稱 (若有的話)。否則,如果 NdbRecord 物件不是 IndexAccess 類型,此方法會傳回 null。

NdbDictionary::getRecordRowLength()

描述

取得儲存一個資料列所需的位元組數,該資料列的佈局由傳遞給此方法的 NdbRecord 結構描述。

簽章
static Uint32 getRecordRowLength
    (
      const NdbRecord* record
    )
參數

NdbRecord 物件。

傳回值

每列所需的位元組數。

NdbDictionary::getRecordTableName()

描述

傳回 NdbRecord 指向的表格物件名稱。如果記錄不是 TableAccess,此方法會傳回 null。

簽章
static const char* getRecordTableName
    (
      const NdbRecord* record
    )
參數

要取得表格名稱的 record (NdbRecord 物件)。

傳回值

表格名稱,如果 NdbRecord 物件類型不是 TableAccess,則為 null。

NdbDictionary::getRecordType()

描述

傳回傳遞的 NdbRecord 物件類型。

簽章
static RecordType getRecordType
    (
      const NdbRecord* record
    )
參數

NdbRecord 物件。

傳回值

NdbRecordRecordType (IndexAccessTableAccess)。

NdbDictionary::getValuePtr()

描述

透過查閱儲存在 NdbRecord 物件中的欄位偏移量,並傳回列位置和偏移量的總和,來傳回指向由屬性 ID 指定的已儲存資料開頭的指標。

簽章

此方法提供列常數和非列常數版本

static const char* getValuePtr
    (
      const NdbRecord* record,
      const char* row,
      Uint32 attrId
    )

static char* getValuePtr
    (
      const NdbRecord* record,
      char* row,
      Uint32 attrId
    )
參數

指向描述列格式的 NdbRecord 物件的指標、指向列資料開頭的指標(在此方法的常數版本中為 const),以及欄位的屬性 ID。

傳回值

指向列中屬性開頭的指標。如果屬性不是 NdbRecord 定義的一部分,則為 null。

NdbDictionary::isNull()

描述

指出給定欄的 Null 位元是否設為 truefalse。相對於列指標的 Null 位元位置是從傳遞的 NdbRecord 物件取得。如果欄位不可為 Null,或如果欄位不是 NdbRecord 定義的一部分,則此方法會傳回 false

簽章
static bool isNull
    (
      const NdbRecord* record,
      const char* row,
      Uint32 attrId
    )
參數

指向描述列格式的 NdbRecord 物件的指標、指向列資料開頭的指標,以及要檢查之欄的屬性 ID。

傳回值

如果此 NdbRecord 中存在屬性 ID,且可為 Null,且此列的 Null 位元已設定,則為布林值 true;否則,為布林值 false

NdbDictionary::RecordSpecification

本節提供有關 RecordSpecification 結構的資訊。

父類別

NdbDictionary

描述

此結構用於在建立 NdbRecord 物件時指定欄和範圍偏移量。

成員

組成此結構的元素顯示在下表中

表格 2.39 NdbDictionary::RecordSpecification 屬性,包含類型和描述

名稱 類型 描述
此條目所描述的欄(欄的最大大小定義了列的欄位大小)。即使在為索引建立 NdbRecord 時,也必須指向從基礎表格而非索引本身取得的欄。
偏移量 Uint32 資料從列開頭的偏移量。對於讀取 Blob,Blob 控制代碼 (NdbBlob) 而不是實際的 Blob 資料會寫入列中。這表示列中必須至少有 sizeof(NdbBlob*) 可用。
nullbit_byte_offset Uint32 包含 NULL 位元的位元組從列開頭的偏移量。
nullbit_bit_in_byte Uint32 NULL 位元 (0-7)。

nullbit_byte_offsetnullbit_bit_in_byte 不適用於不可為 Null 的欄。

如需更多資訊,請參閱第 2.3.22 節,「The NdbRecord Interface」

NdbDictionary::setNull()

描述

將給定欄的 Null 位元設定為提供的值。Null 位元的偏移量是從傳遞的 NdbRecord 物件取得。如果屬性 ID 不是 NdbRecord 的一部分,或如果它不可為 Null,則此方法會傳回錯誤 (-1)。

簽章
static int setNull
    (
      const NdbRecord* record,
      char* row,
      Uint32 attrId,
      bool value
    )
參數

指向描述列格式的 record (NdbRecord 物件) 的指標;指向 row 資料開頭的指標;欄位 (attrId) 的屬性 ID;以及要將 Null 位元設定為的 value (truefalse)。

傳回值

成功時傳回 0;如果 attrId 不是 record 的一部分,或不可為 Null,則傳回 -1。