📄 ug_ch14.htm
字号:
<pre><font color="#0000FF">typedef struct { char fd_key; char fd_type; DB_SHORT fd_len; DB_SHORT fd_dim[MAXDIMS]; DB_SHORT fd_keyfile; DB_SHORT fd_keyno; DB_SHORT fd_ptr; DB_SHORT fd_rec; DB_SHORT fd_flags;} FIELD_ENTRY;</font></pre><p><font size="2">The <b>fd_key</b> element defines the type of keythat this field is:</font></p><ul><li>'n' = not a key</li><li>'d' = non-unique key (duplicates allowed)</li><li>'u' = unique key</li></ul><p>The <b>fd_type</b> element defines the data type of thisfield:</p><ul><li>'c' = char</li><li>'s' = short</li><li>'i' = int</li><li>'l' = long</li><li>'d' = <b>DB_ADDR</b></li><li>'f' = float</li><li>'F' = double</li><li>'g' = grouped (struct)</li><li>'k' = compound key</li></ul><p>The 'g' (grouped), and 'k' (compound key) fields have no data oftheir own, as the rest of the field types do.</p><p>A group of fields is ordered in a specific way. First, the groupdefinition occurs, then the elements of the group occur, eachhaving a flag set (see <b>fd_flags</b>) indicating that they aregroup elements. The group ends when there is a field without thisflag set, or at the end of the table.</p><p>If the field is flagged as a compound key field ('k'), it willalways follow the normal field definitions in a record. Thiscompound key field redefines the purpose of <b>fd_ptr</b> so thatit points to an entry in the key table rather than marking the byteoffset from the start of the record to the contents of thisfield.</p><p>The <b>fd_len</b> element is the length of the field in bytes.If the field is an array, this length is the basic data type lengthtimes the dimensions of the array.</p><p>The <b>fd_dim[MAXDIMS]</b> element is a three-element(<b>MAXDIMS</b> is three) array containing the values of anydeclared dimensions. By default, all are zeros. If one dimension isdeclared with the field type, then <b>fd_dim[0]</b> will containthat value, and the others will remain zero.</p><p>If this field is a key field (that is, <b>fd_key</b> is 'd' or'u'), then <b>fd_keyfile</b> is an index into the file table thatreferences the key file that contains this field.</p><p>The <b>fd_keyno</b> element is the key prefix number, which isstored in the first two bytes of each key of this type (see section14.2.3, "Key File Organization").</p><p>The <b>fd_ptr</b> element is the byte offset from the start ofthe record to the contents of this field in a record. If this fieldtype is 'k' (compound key), this is an index into the key table ofthe first field definition of the compound key.</p><p>The <b>fd_rec</b> element is an index into the record table ofthe record that contains this field.</p><p>The <b>fd_flags</b> element is a bit map for field options. Thehigh-order six bits store non-zero optional key numbers. Thelow-order 10 bits store the options for the field.</p><h3><a name="SetTable" id="SetTable"></a>14.3.5 Set Table</h3><p><font size="2">The set table contains one entry for every setdefined in the schema. It defines the set ordering and the positionof the set pointers in the record. Since there may be many members,the member record types for this set type are defined in the membertable, which is referenced by this table. The set table referencesthe member and record tables, and is referenced only by the sorttable. The <b>set_table</b> declaration is given below.</font></p><pre><font color="#0000FF">typedef struct { DB_SHORT st_order: DB_SHORT st_own_rt; DB_SHORT st_own_ptr; DB_SHORT st_members; DB_SHORT st_memtot; DB_SHORT st_flags;} SET_ENTRY;</font></pre><p><font size="2">The <b>st_order</b> element defines the setordering:</font></p><ul><li>'f' = order first</li><li>'l' = order last</li><li>'a' = order ascending</li><li>'d' = order descending</li><li>'n' = order next</li></ul><p>The <b>st_own_rt</b> element is an index to the record table ofthe record type owning the set type.</p><p>The <b>st_own_ptr</b> element is the offset in the record of theset pointers used for this set.</p><p>The <b>st_members</b> element is an index into the member tableof the first set member definition.</p><p>The <b>st_memtot</b> element is the total number of memberrecord types in this set.</p><p>The <b>st_flags</b> element is a bit map for set options. See<b>dbtype.h</b> for a list.</p><h3><a name="MemberTable" id="MemberTable"></a>14.3.6 MemberTable</h3><p><font size="2">The member table contains one entry for each setmember in a database. Since one set may contain multiple members,the set table will point to a range of consecutive entries in themember table. Since a set member may be sorted by multiple fields,each member entry may point to a range of consecutive entries inthe sort table.</font></p><p>The member table references the record and sort tables, and isreferenced by the set table.</p><pre><font color="#0000FF">typedef struct { DB_SHORT mt_record; DB_SHORT mt_mem_ptr; DB_SHORT mt_sort_fld; DB_SHORT mt_totsf;} MEMBER_ENTRY;</font></pre><p><font size="2">The <b>mt_record</b> element is an index into therecord table of the member record type.</font></p><p>The <b>mt_mem_ptr</b> element is the offset, in the record, ofthe member pointers.</p><p>The <b>mt_sort_fld</b> element is an index into the first entryof the sort table of a sort field definition, if the set issorted.</p><p>The <b>mt_totsf</b> element is the number of sort table entriesused by this set member. This contains zero if the set is notsorted.</p><h3><a name="SortTable" id="SortTable"></a>14.3.7 Sort Table</h3><p><font size="2">The sort table contains one entry for each fieldthat is referenced in an <b>order by</b> clause in a setdefinition. The list of sorting fields occurs in the setdefinition, following the naming of a member record type. Themember table refers to a range of entries in the sort table inorder to locate the field table entries involved insorting.</font></p><pre><font color="#0000FF">typedef struct { DB_SHORT se_fld; DB_SHORT se_set;} SORT_ENTRY;</font></pre><p><font size="2">The <b>se_fld</b> element is an index into thefield table of one field definition involved in the fieldsort.</font></p><p>The <b>se_set</b> element is an index into the set table of theset type that owns this sorted list of members.</p><h3><a name="KeyTable" id="KeyTable"></a>14.3.8 Compound KeyTable</h3><p><font size="2">The compound key table contains one entry foreach field listed in each compound key statement. One compound keystatement may list several fields. For each compound key statement,there is one entry in the field table, which points to a range ofentries in the compound key table. This range of entries is used toform a single key from the fields referenced by the key tableentries.</font></p><p>Each entry in this table refers to the compound key and anassociated field, the position of the field in the key, and whetherthe field is ascending or descending.</p><pre><font color="#0000FF">typedef struct { DB_SHORT kt_key; DB_SHORT kt_field; DB_SHORT kt_ptr; DB_SHORT kt_sort;} KEY_ENTRY;</font></pre><p><font size="2">The <b>kt_key</b> element is an index into thefield table of the compound key definition in which this entry isincluded.</font></p><p>The <b>kt_field</b> element is an index into the field table ofa field used in the compound key.</p><p>The <b>kt_ptr</b> element is an offset from the start of theactual key to where the contents of this field begins.</p><p>The <b>kt_sort</b> element is the sorting order of this field.The possible values are:</p><ul><li>'a' = ascending</li><li>'d' = descending</li></ul><h3><a name="Example" id="Example"></a>14.3.9 Dictionary TablesExample</h3><p><font size="2">This section provides a simple example of aschema and shows the tables that are generated as a result. Thisshort example contains most of the elements of a <b><i>db.*</i></b>schema, and uses all seven table types. The text of the schemais:</font></p><pre><font color="#0000FF">database mgrs { data file "data" contains manager, dept; key file "keys" contains name, emp_no; record manager { key long emp_no; char last_name[20]; char first_name[20]; compound optional key name { last_name ascending; first_name ascending; } } record dept { char title[10]; int loc_code; float budget; } set manages { order ascending; owner manager; member dept by title, loc_code; }}</font></pre><p><font size="2">The <b>prdbd</b> utility can be used to print thecontents of the dictionary tables. The report from a run of<b>prdbd -c</b> on the above DDL specification is shownbelow.</font></p><pre><font color="#0000FF">db.* Version 1.0.0 Ansi [29-Feb-2000]Database Dictionary Tables for Database: mgrsDBD Version: 3.00REQUIRED MEMORY: 792 BYTES------------------------------------------------------------------FILE TABLE:file sta type slots sl sz pg sz initial next pct flgs name---- --- ---- ----- ----- ----- -------- -------- --- ---- ---- 0 c d 15 64 1024 0 0 0 0000 data 1 c k 20 50 1024 0 0 0 0000 keys------------------------------------------------------------------RECORD TABLE: [#]first tot [#]record file len data field flds flags-------------- ---------- ---- ---- --------------- ---- -----[ 0]MANAGER data.d00 63 19 [ 0]EMP_NO 3 0010[ 1]DEPT data.k01 38 18 [ 4]TITLE 3 0000------------------------------------------------------------------FIELD TABLE: key key record [#]field key type len file num offset [#]record flags dims--------------- --- ---- --- ------ --- ------ -------------- ----- ----[ 0]EMP_NO d l 4 keys.k 0 19 [ 0]MANAGER 0000[ 1]LAST_NAME n c 20 0 23 [ 0]MANAGER 0010 [20][ 2]FIRST_NAME n c 20 0 43 [ 0]MANAGER 0010 [20][ 3]NAME d k 40 keys.k 1 0 [ 0]MANAGER 0400[ 4]TITLE n c 10 0 18 [ 1]DEPT 0001 [10][ 5]LOC_CODE n i 4 0 30 [ 1]DEPT 0001[ 6]BUDGET n f 4 0 34 [ 1]DEPT 0000------------------------------------------------------------------SET TABLE: [#]owner own ptr first total [#]set order record offset member members flags--------------- ----- -------------- ------- ------ ------- -----[ 0]MANAGES a [ 0]MANAGER 7 0 1 0000------------------------------------------------------------------MEMBER TABLE: mem ptr # of 1st totalmem # [#]record offset sort fld sort flds----- -------------- ------- -------- --------- 0 [ 1]DEPT 6 0 2------------------------------------------------------------------SORT TABLE:sort # [#]field [#]set------ --------------- --------------- 0 [ 4]TITLE [ 0]MANAGES 1 [ 5]LOC_CODE [ 0]MANAGES ------------------------------------------------------------------COMPOUND KEY TABLE: [#]compound [#]componentkey # key field field ptr order----- --------------- --------------- --- ----- 0 [ 3]NAME [ 1]LAST_NAME 0 a 1 [ 3]NAME [ 2]FIRST_NAME 20 a</font></pre><p><font size="2">Figure 14-15 shows the values that would becontained in the dictionary tables for this database. The valuescorrespond to the element definitions contained in the abovesections. The table interrelationships are also shown.</font></p><p align="center"><b><img alt="dbstar_14-15.gif - 11765 Bytes"border="0" height="458" src="dbstar_14-15.gif" width="462"></b></p><p align="center">Fig. 14-15. Dictionary TableInterrelationships</p><h3><a name="Database" id="Database"></a>14.3.10 DatabaseTable</h3><p><font size="2">The database table is not contained in thedatabase dictionary file because it contains information thatpertains to multiple database usage.</font></p><p>When multiple databases are opened, the various dictionarytables are, in effect, concatenated into larger tables so that theyappear to represent one large database. The inter-table referencesare all offset to point directly to their new positions in thetables.</p><p>When a <b><i>db.*</i></b> runtime function is called, first thecurrent database number is determined (if not supplied in thecall). Using the current database number as an index into thedatabase table, the offsets to the starting positions in the tablesfor that database are obtained. If any adjustments are necessary tothe function parameters, the offset values stored in this tablewill be used. For example, a record type might be passed to<b>d_fillnew</b> that would require translation to a higher numberif the current database is not the first one.</p><p>The structure of the database table is as follows:</p><pre><font color="#0000FF">typedef struct { DB_SHORT size_ft; DB_SHORT ft_offset; DB_SHORT size_rt; DB_SHORT rt_offset; DB_SHORT size_fd; DB_SHORT fd_offset; DB_SHORT size_st; DB_SHORT st_offset; DB_SHORT size_mt; DB_SHORT mt_offset; DB_SHORT size_srt; DB_SHORT srt_offset; DB_SHORT size_kt; DB_SHORT kt_offset; DB_SHORT key_offset; DB_ADDR sysdba; DB_ADDR curr_dbt_rec; DB_ULONG curr_dbt_ts; DB_SHORT page_size; char db_path[PATHLEN]; char db_name[DBNMLEN];} DB_ENTRY;</font></pre><p><font size="2">The <b>size_ft</b> element is the number ofelements in this database's file table.</font></p><p>The <b>ft_offset</b> element is the index in the global filetable to the first element of this database's file table.</p><p>The <b>size_rt</b> element is the number of elements in thisdatabase's record table.</p><p>The <b>rt_offset</b> element is the index in the global recordtable to the first element of this database's record table.</p><p>The <b>size_fd</b> element is the number of elements in thisdatabase's field table.</p><p>The <b>fd_offset</b> element is the index in the global fieldtable to the first element of this database's field table.</p><p>The <b>size_st</b> element is the number of elements in thisdatabase's set table.</p><p>The <b>st_offset</b> element is the index in the global settable to the first element of this database's set table.</p><p>The <b>size_mt</b> element is the number of elements in thisdatabase's member table.</p><p>The <b>mt_offset</b> element is the index in the global membertable to the first element of this database's member table.</p><p>The <b>size_srt</b> element is the number of elements in thisdatabase's sort table.</p><p>The <b>srt_offset</b> element is the index in the global sorttable to the first element of this database's sort table.</p><p>The <b>size_kt</b> element is the number of elements in thisdatabase's key
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -