⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ug_ch4a.htm

📁 db.* (pronounced dee-be star) is an advanced, high performance, small footprint embedded database fo
💻 HTM
📖 第 1 页 / 共 3 页
字号:
<p>The <b>static</b> attribute specifies that the records are neverupdated when the database is opened in shared mode. This allows the<b><i>db.*</i></b> runtime to optimize access to the static recordoccurrence, yielding much better performance. Static records areused for storing information such as menus, data entry forms, helpscreens, system messages, coded value information, etc. Multi-userdatabase programs are not required to place locks on this data inorder to access it. Static records can only be modified when thedatabase is opened in exclusive access mode. Single-userapplications may modify static records at any time. The data andkey files containing static record information can only containstatic data. The system record is a special case and can beincluded in a data file that contains either static or not staticrecords. Static records can only be used in sets which themselvesare not modified except in exclusive access mode.</p><h5>Example:</h5><pre><font color="#0000FF">record check {   unique key int check_no;   key int check_date;   char paid_to[49];   float amount;}</font></pre><p><font size="2">The <b>check</b> record type in the checkingaccount database contains two integer fields (one of which is akey), a character string field, and a floating point field. File<b>chkgacct.h</b> will contain the following definitions associatedwith the check record type:</font></p><pre><font color="#0000FF">struct check {   int  check_no;   int  check_date;   char  paid_to[49];   float  amount;};#define CHECK 10001</font></pre><p><font size="2">Record <b>trans</b> below contains two compoundkey field declarations. (For more information, see "Use of Keys" insection 4.4.1, "Logical Design Considerations."</font></p><pre><font color="#0000FF">record trans {   unique key int checkno;   int trdate;   char vendid[8];   long amount;   compound key tr_key {      trdate descending;      vendid ascending;   }   compound key ven_chks {      vendid; checkno;   }}</font></pre><p><font size="2">Below are two record types and a set that mightbe defined for a multi-user data entry, forms management system.Note that both records are declared to be static, since duringnormal operation of an application using the forms manager, formand field records are not modified.</font></p><pre><font color="#0000FF">   static record form {   unique key char form_id[11];}static record field {   unique key char field_id[21]; /* Display name of field */   int  id_row;         /* Row where field_id displayed */   int  id_col;         /* Column where field_id displayed /   int  data_row;      /* Row where data starts */   int  data_col;      /* Column where data starts */   int  field_len;      /* Editable field length */   char required;      /* Required field */   int  edit_fcn;      /* Editing function called on entry */   int  disp_fcn;      /* Display function called on output /   int  rtype;         /* Record type containing the field */   long ftype;         /* db.* field type */}set form_fields {   order last;   owner form;   member field;}</font></pre><h3><a name="Field" id="Field"></a>4.2.6 Field Declarations</h3><h4><a name="Data" id="Data"></a>Data Fields</h4><p><b><font size="2">Syntax:</font></b></p><pre><font color="#0000FF">   <i>[[</i>optional<i>] [</i>unique<i>]</i> key<i>]</i> type <i>fldname [ [dim]...] [</i>om_field<i>]</i> ;or    <i>[[</i>optional<i>] [</i>unique<i>]</i> key<i>]</i> struct {      field_stmt      ...   } <i>fldname [[dim]...]</i> ;type =   <i>[</i>unsigned<i>]</i> int | <i>[</i>unsigned<i>]</i> short | <i>[</i>unsigned<i>]</i> long |    char | float | double | DB_ADDRom_field =    directref <i>recname</i>or   relatedto <i>recname</i> thru <i>fldname</i></font></pre><h5>Description:</h5><p><font size="2">The <i>fldname</i> is an identifier that namesthe particular data field. Field names may not duplicate record orset names, nor by default other field names.</font></p><p>The syntax for a data field statement is similar to, althoughnot as general as, a C data declaration. In fact, most of the basicdata types in C are directly supported in the DDL. Arrays of anytype are available, where <i>dim</i> specifies the size of a givenarray dimension.</p><p>One-dimensional character arrays are treated by the<b><i>db.*</i></b> runtime functions as C strings. Thus, thesefields should always be terminated by a null byte, and the lengthas specified in the field declaration should include the null byte.If a one-dimensional character array is needed that is not intendedto be treated like a string (for example, a byte array), it shouldbe declared as a two-dimensional array where the second dimensionis one.</p><p>A data field that is also to be used as a key to the record hasthe <b>key</b> attribute. Key field values are stored on the keyfile in the natural order based on the data type. If only uniquekeys are allowed then the field should be qualified as a <b>uniquekey</b> field. The maximum length of a key field is 246 bytes.Fields defined as a <b>unique key</b> must contain a value thatdoes not already exist on the key file at the time its associatedrecord is entered into the database. If a record is entered(modified) with a duplicate value, in a <b>unique</b> <b>key</b>field, the status code S_DUPLICATE is returned and the record isnot entered (or modified).</p><p>The <b>optional</b> attribute indicates that the data field isan <b>optional key</b>. <b>Optional key</b> values are not insertedinto the key file until the application program calls function<b>d_keystore</b>. Optional keys can be manually deleted usingfunction <b>d_keydel</b>. When an optional key is modified (througha <b>d_recwrite</b> or <b>d_crwrite</b> call), the key file will beupdated only if the current value exists in the key file.</p><p>Fields declared as <b>struct</b> cannot be nested. Sub-fields ofan arrayed <b>struct</b> field cannot be defined as key fields noraccessed individually.</p><p>Data fields of type <b>DB_ADDR</b> contain the databaseaddresses of specific record occurrences in the database. Databaseaddresses can be directly accessed using the currency table accessfunctions described in section 5.3, "Currency Tables." This allowsyou to maintain your own record linkages directly, if desired.</p><p>Data fields will be aligned within the record in order to matchthe <b>struct</b> field alignment rules followed by your particularcompiler and computer. A <b>ddlp</b> option can be used to disablethis alignment if desired (see section 4.3, "DDL ProcessorOperation").</p><h5>Examples:</h5><pre><font color="#0000FF">unique key char code[6];</font></pre><p><font size="2">Field <b>code</b> is a character string field ofsix characters long (five characters plus one null terminator) thatis defined as a <b>unique key</b>.</font></p><pre><font color="#0000FF">float balance;</font></pre><p><font size="2">Field <b>balance</b> is a floating point fieldwhich, in the checking account database, contains a monetaryvalue.</font></p><pre><font color="#0000FF">key int check_date;</font></pre><p><font size="2">Key field <b>check_date</b> is used to store adate in the application-defined Julian format (for example, numberof elapsed days since January 1, 1900). Its values are stored onthe key file in integer order. Thus, check records can be retrievedin check date order through use of the key retrieval functions (seesection 5.4.1, "Data Retrieval Using Keys").</font></p><pre><font color="#0000FF">struct {   double imag;   double real;} complex[3];</font></pre><p><font size="2">This field statement defines a structure arrayfield, <b>complex</b>, which stores an array of three complexnumbers composed of an imaginary part and a real part.</font></p><pre><font color="#0000FF">key long coordinates[3];</font></pre><p><b><font size="2">Coordinates</font> is an array of three longtype variables, and is also a key. It may be used to locate anobject on a large three-dimensional grid.</b></p><pre><font color="#0000FF">int bitmap;</font></pre><p><font size="2">Field <b>bitmap</b> is used to store a bitmap ofattribute flags, which are tested using binary operators and masks.For example, assuming this field was declared in record type<b>rec, rec.bitmap &amp; 0x0001</b> is non-zero if the low orderbit is set. (Note that <b><i>db.*</i></b> does not directly supportC bit fields.)</font></p><pre><font color="#0000FF">char byte_array[16][1];</font></pre><p><font size="2">Byte array fields are implemented, as in<b>byte_array</b>, as a two-dimensional character array where thesecond dimension is one. This will force the <b><i>db.*</i></b>runtime to manipulate all 16 bytes of the field rather thanstopping at the first null byte as it does with stringfields.</font></p><pre><font color="#0000FF">DB_ADDR ptr_array[20];</font></pre><p><font size="2">Field <b>ptr_array</b> is an array of type<b>DB_ADDR</b>. It is used to store an array of the databaseaddresses of record occurrences that are related to the record typein which <b>ptr_array</b> is defined. Use of <b>DB_ADDR</b> fieldsprovides unlimited data organization possibilities to theprogrammer. However, these alternatives should only be used inthose rare instances when the standard capabilities provided bykeys and sets are insufficient for a particularrequirement.</font></p><pre><font color="#0000FF">optional key struct {   char last_name[21];   char first_name[21];   char initial[2];} name;</font></pre><p><font size="2"><b>Name</b> is a <b>struct</b> field to containperson names and is composed of three string fields for the lastand first names and the middle initial. <b>Last_name</b> is thefirst field specified since, because <b>name</b> is a key field,the last name can be used in a partial key search to find, forexample, all the Smiths on file. Thus, the order of the fields in akeyed <b>struct</b> field specifies the major and minor sortsequences for the key on the key file.</font></p><p>This field is defined as an <b>optional key</b>. Optional keysare often used to defer the overhead associated with storing keysto a time when the system is less busy. For example, it might bethat the record which contains <b>name</b> needs to be stored asrapidly as possible during the day. At night a batch program can berun to create the optional keys.</p><h4><a name="Compound" id="Compound"></a>Compound Key Fields</h4><p><b><font size="2">Syntax:</font></b></p><pre><font color="#0000FF">compound <i>[</i>optional<i>] [</i>unique<i>]</i> key <i>keyname</i> {   <i>fldname</i> <i>[</i> <u>asc</u><i>[</i>ending<i>]</i> | desc<i>[</i>ending<i>] ]</i> ;   ...}</font></pre><h5>Description:</h5><p><font size="2">The preceding syntax is used to define a compoundkey field named <i>keyname</i>. Compound keys are key fielddefinitions consisting of any combination of fields (notnecessarily contiguous) from a given record. Each sub-field of thecompound key can be specified to be sorted in either ascending(default) or descending sequence. Compound keys differ from normalkey fields in that they do not define additional data fields in therecord. By using compound keys, you can have a field appear inmultiple keys within a record, without needing to duplicate thefield's value in the data file.</font></p><p>The compound key specifications must follow all other fieldstatements in a record declaration. The order in which thesub-fields are specified determines the major and minor sortsequences. The <i>fldname</i> must be the name of a field that isdefined in the record and is not defined as a <b>struct</b>. If the<b>optional</b> qualifier is specified, the key will only be storedwhen <b>d_keystore</b> is called. Otherwise, the key is createdwhen the record is created. All of the key functions that apply tonormal key fields also apply to compound keys.</p><p><b>ddlp</b> will create in the <b>dbname.h</b> file a<b>struct</b> declaration named <i>keyname</i> for each compoundkey defined in the schema, similar to the <b>struct</b>declarations associated with records. These can be used inconjunction with the key manipulation functions of the<b><i>db.*</i></b> runtime library.</p><p>Because of the nature of compound keys, records containing themcan only be created using function <b>d_fillnew</b> (not<b>d_makenew).</b>).</p><h5>Examples:</h5><pre><font color="#0000FF">compound key tr_key {   trdate descending;   vendid ascending;}compound key ven_chks {   vendid;   checkno;}</font></pre><p><font size="2">Assume that a record type called trans(transaction) contains two compound key definitions. Key<b>tr_key</b> is composed of fields <b>trdate</b> and<b>vendid</b>. Scanning through transaction records by<b>tr_key</b> would produce a sorted list in descending transactiondate order, and ascending vendor id order within each date. Key<b>ven_chks</b> consists of two fields: <b>vendid</b> and<b>checkno</b>. Scanning through transaction records by<b>ven_chks</b> would give a sorted list in ascending vendor idorder, and in ascending check number order within eachvendor.</font></p><h3><a name="Set" id="Set"></a>4.2.7 Set Declarations</h3><p><b><font size="2">Syntax:</font></b></p><pre><i><font color="#0000FF">[</font> bitmap | blob | varilen ] set setname {   order { asc[ending] | desc[ending] | first | last | next }    owner recname ;   member recname [ by fldname [, fldname...] ];   ...}</i></pre><h5>Description:</h5><p><font size="2">Set declarations define explicit, one-to-manyrelationships between record types. Sets are implemented as alinked list of member record instances connected to a singleinstance of an owner record, which serves as the root or head ofthe list (see "Set and Member Pointers" in section 14.2.2, "DataFile Organization"). The order in which member records are insertedinto this list is specified in the <b>set order</b>clause.</font></p><p>Possible set orderings are defined as follows:</p><table border="0" cellpadding="7" cellspacing="0" width="542"><tr><td valign="top" width="21%"><p><b><font size="2">first</font></b></p></td><td valign="top" width="79%">

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -