Shape APPEND 命令將子 Recordset 分配給父 Recordset 中 Field 對(duì)象的 Value 屬性。
語法
SHAPE {parent-command} [[AS] parent-alias]
APPEND ({child-command} [AS] child-alias
RELATE parent-column TO child-column...) [[AS] chapter-alias] ...
組成說明
該命令的組成部分為:
parent-command, child-command 如下之一。
? | 在尖括號(hào)(“{}”)中的查詢命令,返回 Recordset 對(duì)象。命令發(fā)布給基本數(shù)據(jù)提供者,其語法取決于該提供者的要求。雖然 ADO 并不要求使用任何指定的查詢語言,但通常是使用結(jié)構(gòu)化查詢語言 (SQL)。圓括號(hào)(“()”)是必需的關(guān)鍵字,它們將子集列追加到引用由查詢命令返回的 Recordset 的父。 |
? | 以前成形的 Recordset 的名稱。 |
? | 另一個(gè) Shape 命令。 |
? | TABLE 關(guān)鍵字,后跟表的名稱。 |
parent-column 由 parent-command 返回的 Recordset 中的列。
child-column 由 child-command 返回的 Recordset 中的列。
... “parent-column TO child-column”子句實(shí)際上是列表,并用逗號(hào)將每個(gè)定義關(guān)系分隔開。
chapter-alias 別名,對(duì)追加到父的列的引用。
parent-alias 別名,對(duì)父 Recordset 的引用。
child-alias 別名,對(duì)子 Recordset 的引用。
... 在 APPEND 關(guān)鍵字后面的子句實(shí)際上是列表(每個(gè)子句使用逗號(hào)分隔),定義被追加到父的另一個(gè)列。
操作
發(fā)出 parent-command 并返回父 Recordset。然后發(fā)出 child-command 并返回子 Recordset。
例如,parent-command 可以從客戶表返回公司的客戶 Recordset,而 child-command 從定貨表返回所有客戶的定單 Recordset。
一般,父和子 Recordset 對(duì)象必須各自擁有用于關(guān)聯(lián)父和子的列。列在 RELATE 子句中命名,parent-column 在先,child-column 在后。在各自的 Recordset 中,列可以有不同名稱,但必須引用相同信息以便指定有意義的關(guān)系。例如,Customers 和 Orders Recordsets 可以同時(shí)擁有 customerID 字段。
數(shù)據(jù)構(gòu)形將子集列追加到父 Recordset。子集列中的值是對(duì)子 Recordset 中列的引用,子 Recordset 滿足 RELATE 子句。即在給定父行中的 parent-column 與在子集子的所有行中的 child-column 具有相同的值。
當(dāng)您訪問在子集列中的引用時(shí),ADO 將自動(dòng)檢索由引用表示的 Recordset。注意盡管已經(jīng)檢索了全部子 Recordset,但子集(chapter)僅表示行的子集。
如果追加的列沒有 chapter-alias,則會(huì)自動(dòng)生成其名稱。列的 Field 對(duì)象將被追加到 Recordset 對(duì)象的 Fields 集合,其數(shù)據(jù)類型將是 adChapter。
有關(guān)定位分級(jí) Recordset 的詳細(xì)信息,請(qǐng)參閱訪問分級(jí) Recordset 中的行。
參數(shù)化命令
如果您正在處理大的子 Recordset(尤其是比父 Recordset 大),卻只需要訪問部分子子集,那么,使用參數(shù)化命令會(huì)更有效。
non-parameterized command(非參數(shù)化命令)同時(shí)檢索整個(gè)父和子 Recordsets,并將子集列追加到父,然后為每個(gè)父行指定相關(guān)子子集的引用。
parameterized command(參數(shù)化命令)檢索整個(gè)父 Recordset,但在訪問子集列時(shí)僅檢索子集 Recordset。這種檢索策略的差別可以有益的性能好處。
例如,可以指定如下:
"SHAPE {SELECT * FROM customer}
APPEND ({SELECT * FROM orders WHERE cust_id = ?}
RELATE cust_id TO PARAMETER 0)"
父和子表通常擁有列名 cust_id。child-command 有占位符(即“?”),受 RELATE 子句引用(即“...PARAMETER 0”)。關(guān)系在于顯性標(biāo)識(shí)的 customer 表 parent-column(即 cust_id)和隱性標(biāo)識(shí)的 orders 表 child-column(即 cust_id)之間,由占位符和“PARAMETER 0”指定。
注意 PARAMETER 子句僅屬于 Shape 命令語法。與 ADO Parameter 屬性和 Parameters 集合均無關(guān)聯(lián)。
在執(zhí)行 Shape 命令時(shí),發(fā)生如下情形:
1. | 執(zhí)行 parent-command,并返回 customer 表的父 Recordset。 |
2. | 子集列被追加到父 Recordset。 |
3. | 在訪問父行的子集列時(shí),customer.cust_id 列的值將替換 orders.cust_id 的占位符,并執(zhí)行 child-command。 |
4. | orders 表(在此,orders.cust_id 列的值與 customer.cust_id 列的值相匹配)的所有行被檢索。 |
5. | 對(duì)檢索到的子行(即子 Recordset 的 chapter)的引用被放置在父 Recordset 當(dāng)前行的子集列。 |
6. | 當(dāng)訪問另一個(gè)行的子集列時(shí),重復(fù)步驟 3-5。 |
插入 Shape COMPUTE 命令
現(xiàn)在將參數(shù)化 Shape 命令的參數(shù)化命令嵌入任意嵌套數(shù)量的形狀 COMPUTE 命令中是有效的。例如:
SHAPE {select au_lname, state from authors} APPEND
((SHAPE
(SHAPE
{select * from authors where state = ?} rs
COMPUTE rs, ANY(rs.state) state, ANY(rs.au_lname) au_lname
BY au_id) rs2
COMPUTE rs2, ANY(rs2.state) BY au_lname)
RELATE state TO PARAMETER 0)