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

📄 ug_ch4a.htm

📁 db.* (pronounced dee-be star) is an advanced, high performance, small footprint embedded database fo
💻 HTM
📖 第 1 页 / 共 3 页
字号:
<p><font size="2">New member records are connected (that is,inserted) at the front of the list.</font></p></td></tr><tr><td valign="top" width="21%"><p><b><font size="2">last</font></b></p></td><td valign="top" width="79%"><p><font size="2">New member records are connected at the end ofthe list.</font></p></td></tr><tr><td valign="top" width="21%"><p><b><font size="2">ascending</font></b></p></td><td valign="top" width="79%"><p><font size="2">New member records are connected in ascendingorder based on the contents of the data fields specified in the<b>by</b> part of the <b>member</b> clause of the <b>set</b>statement.</font></p></td></tr><tr><td valign="top" width="21%"><p><b><font size="2">descending</font></b></p></td><td valign="top" width="79%"><p><font size="2">New member records are connected in descendingorder based on the contents of the data fields specified in the<b>by</b> part of the <b>member</b> clause of the <b>set</b>statement.</font></p></td></tr><tr><td valign="top" width="21%"><p><b><font size="2">next</font></b></p></td><td valign="top" width="79%"><p><font size="2">New member records are connected immediatelyfollowing the current member of the set, or, if the current memberis null, at the front of the list.</font></p></td></tr></table><p><font size="2">The <b>by</b> part of the <b>member</b> clause isonly supplied when <b>ascending</b> or <b>descending</b> order isspecified. For sorted sets having more than one member record type,the sort field(s) of those record types should correspondingly beof the same type and length and be listed on the <b>by</b> clausein the same order.</font></p><p>When the sort field values of new member records of a sorted setduplicate existing members, the new members are added in front ofthe members with matching values.</p><p>The set owner may be specified as <b>system</b>. Use of thesystem record is not required. If one is used, do not declare it ina DDL record statement. <b>ddlp</b> automatically creates thesystem record when it is specified in a data file statement. Thereis only one occurrence of the system record in the database. It isused as the owner of any number of sets providing the means wherebyrecords can be connected to the top or root of the network. When adatabase is opened, the current record and the current owner of allsystem-owned sets are initialized to the system record (see section5.3, "Currency Tables," for a discussion of currency).</p><p>Connecting member records to sets of order <b>first</b>,<b>last</b>, or <b>next</b> is faster than connecting to sets oforder <b>ascending</b> or <b>descending</b>. This is because thelist of member records associated with <b>ascending</b> or<b>descending</b> sets must be scanned each time a new member isconnected, in order to find the proper insertion point. Thus, aconnection to an <b>ascending</b> or <b>descending</b> set with alarge number of members can be relatively slow. If you need a largesorted set, explore alternative approaches using keys or reverseordering to maintain the ordering.</p><blockquote><i>Note</i>: <b><i>db.*</i></b> does not implement<b>ascending</b> or <b>descending</b> sets through an index. Aswith all sets, they are implemented as a linked list (or chained)structure. <b><i>db.*</i></b> does provide a keyed record access(through a B-tree index) but it is totally distinct from sets. Arecord can both have keys and be an owner and/or member of sets,but sets do not use keys and keys do not use sets. Thus, sortfields of ascending or descending sets do not need to be declaredas key fields.</blockquote><h5>Examples:</h5><pre><font color="#0000FF">set transactions {   order last;   owner budget;   member check;}</font></pre><p><font size="2"><b>Transactions</b> is a set between the<b>budget</b> record and the <b>check</b> record in the checkingaccount database. Each check written is to be applied to aparticular budget account. Each budget account has a set of checksthat have been written against it. As a new check is written andentered into the database, it is connected to the<b>transactions</b> set instance, where the appropriate<b>budget</b> record has been identified as the current owner ofthe set. The new <b>check</b> record will be connected to the endof the set. Thus (assuming checks are written in order), they willbe stored in check number order (and probably date order aswell).</font></p><p>To ensure that checks are stored in date order, the setspecification could be modified as follows:</p><pre><font color="#0000FF">set transactions {   order ascending;   owner budget;   member check by check_date;}</font></pre><p><font size="2">Here the order has been changed to<b>ascending</b> and the member clause now includes the <b>by</b>part to indicate that the set is to be sorted on the<b>check_date</b> field of the <b>check</b> record. Again, theconnect operation will be slower than if the order is <b>last</b>.However, if the sort field is known to usually force the insertionto be at the end of the set instance, the ordering of the set couldbe reversed so that the set remained sorted and so that theinsertion was usually made quickly at the front of thelist.</font></p><pre><font color="#0000FF">set comment {   order first;   owner note;   member project;   member task;   member work_day;}</font></pre><p><font size="2">The <b>comment</b> set illustrates a use ofmultiple member sets to reduce unnecessary space overhead. Each ofthe <b>project</b>, <b>task</b>, and <b>work_day</b> record typesin a project management database can have an optional commentassociated with it in the <b>note</b> record. In this example, anoccurrence of <b>project</b>, <b>task</b>, or <b>work_day</b> canbe associated with only a single occurrence of <b>note</b>. Thuseach set instance is strictly one-to-one. Use of a single set ispreferred over three separate sets because it will use less spacefor the set overhead (one set pointer is needed instead of three).See section 4.4.2, "Physical Design Considerations," for moreinformation.</font></p><h2><a name="Operation" id="Operation"></a>4.3 DDL ProcessorOperation</h2><h3><a name="Execution" id="Execution"></a>4.3.1 DDL ProcessorExecution</h3><p><font size="2">The Database Definition Language Processor,<b>ddlp</b>, is executed as follows:</font></p><p><b>ddlp</b> <i>[</i>-r<i>] [</i>-x<i>] [[</i>-c<i>][</i>-l<i>n]] [</i>-d<i>] [</i>-n<i>] [</i>-s<i>[</i>-<i>]][</i>-oxxxx<i>] [</i>-z<i>] [</i>-axxx<i>]</i> <i>ddlspec</i></p><p>File <b>ddlspec</b> is the name of the text file containing theDDL specification. This file is sometimes called the schemafile.</p><p>The <b>ddlp</b> will compile the DDL in file <b>ddlspec</b> andreport any errors to <b>stdout</b> with the line number where theerror was detected.</p><p>The compiled DDL is stored in the database dictionary file foruse by the <b><i>db.*</i></b> runtime library functions. The nameof the dictionary is taken from the <i>dbname</i> of the databaseDDL statement and given an extension <b>.dbd</b>, forming<b>dbname.dbd</b>. The amount of dynamically allocated memoryrequired by the <b><i>db.*</i></b> runtime for storage of thedictionary is reported by <b>ddlp</b> upon completion, if no errorswere detected. Otherwise, the dictionary file is not created.</p><p>If the <b>-r</b> option is specified, <b>ddlp</b> will display(in <b>stdout</b>) the File Structure Report. (See "<b>ddlp</b>File Structure Report" in section 4.4.2 for an explanation of theuse of this report.)</p><p>If the <b>-x</b> option is given, a cross-reference listing ofthe records, fields, and set identifiers is displayed in<b>stdout</b>. An example report is shown below for the checkingaccount schema.</p><pre><font color="#0000FF">db.* 1.0.0, DDL X-Ref Listing of File: ckngacct.ddlTue Feb 29 14:12:24 2000alloc        field      13amount       field      22balance      field      14budget       record     3   5    9    27cat_desc     field      12check        record     5   17   28check_date   field      7   20check_no     field      7   19code         field      6   11paid_to      field      21transactions set        24</font></pre><p><font size="2">The names are listed in alphabetical order, withthe associated type and the line numbers in the DDL file where thename is referenced.</font></p><p>With the <b>-d</b> option, <b>ddlp</b> allows duplicate fieldnames, such that field types within different record types may havethe same name. The record structures created by <b>ddlp</b> willcontain the name as specified in the schema. The constantdefinitions for all fields will be a concatenation of the recordtype and field type, separated by an underscore. For example:</p><pre><font color="#0000FF">record ticket {   .   .   float unit_cost;}record invoice {   .   float unit_cost}</font></pre><p><font size="2">will cause the following constantdefinitions:</font></p><pre><font color="#0000FF">#define TICKET_UNIT_COST 4005#define INVOICE_UNIT_COST 6014</font></pre><p><font size="2">If duplicate field names are used with keyfields, then each reference to the key field name in the <b>keyfile</b> statement must have a prefix showing the record type thatcontains the field. The syntax is<b>recname.fldname</b>.</font></p><p>The <b>-n</b> option instructs <b>ddlp</b> to omit writing theASCII record, set, and field names to the dictionary file. Thiscreates a smaller dictionary file, but makes names unavailable toutilities such as <b>ida</b>, <b>dal</b>, and <b>dbimp</b>.</p><p><b>ddlp</b> creates C <b>struct</b> declarations for each recordtype and compound key field defined in the DDL and stored with fileid, record, field, and set constants in a header file also namedfrom the <i>dbname</i> of the <b>database</b> statement forming<b>dbname.h</b>. By default, case is preserved on all of the namesused. The <b>-s-</b> option may be used to instruct <b>ddlp</b> toconvert all of the names to lowercase to be compatible withprevious versions.</p><p>The <b>ddlp</b> can process constants, <b>#define</b>s,predefined structures, and typedefs. All of these keywords must beused before <b>ddlp</b> recognizes the keyword <b>database</b>.Everything before the keyword <b>database</b> is copied to theresulting header file, so the application will not need to redefineanything.</p><p>As an example, the contents of file <b>ckngacct.h</b>, which wascreated when the checking account schema (as given in section4.2.1, "DDL Basics") was processed by <b>ddlp</b>, is shownbelow.</p><pre><font color="#0000FF">#ifndef CKNGACCT_H#define CKNGACCT_H/* db.* 1.0.0 *//* database ckngacct record/key structure declarations */struct budget {   char  code[6];   char  cat_desc[48];   float  alloc;   float  balance;};struct check {   int  check_no;   int  check_date;   char  paid_to[48];   float  amount;};/* record, field and set table entry definitions *//* File Id Constants */#define DATFILE 0#define KEYFILE1 1#define KEYFILE2 2/* Record Name Constants */#define BUDGET 10000#define CHECK 10001/* Field Name Constants */#define CODE 0L#define CAT_DESC 1L#define ALLOC 2L#define BALANCE 3L#define CHECK_NO 1000L#define CHECK_DATE 1001L#define PAID_TO 1002L#define AMOUNT 1003L/* Set Name Constants */#define TRANSACTIONS 20000/* Field Sizes */#define SIZEOF_CODE 6#define SIZEOF_CAT_DESC 48#define SIZEOF_ALLOC 4#define SIZEOF_BALANCE 4#define SIZEOF_CHECK_NO 2#define SIZEOF_CHECK_DATE 2#define SIZEOF_PAID_TO 48#define SIZEOF_AMOUNT 4#endef    /* CKNGACCT_H */</font></pre><p><font size="2">The <b>#define</b> constants are passed toruntime library functions to identify the particular file, record,field, or set type involved in the operation. The actual valuesrepresent entries into the tables that make up the databasedictionary. The constants also have some additional controlinformation encoded, as follows:</font></p><div style="margin-left: 2em"><p><font size="2"><i>Record name constants</i> consist of a recordnumber (record 0 is the first record defined in the DDL, record 1is the second, and so on) plus 10000.</font></p><p><i>Set name constants</i> consist of a set number (numberedsequentially, as are records) plus 20000. This information is usedby <b><i>db.*</i></b> runtime functions to distinguish betweenrecord and set constants.</p></div><p><font size="2">Field name constants are formed using thefollowing formula:</font></p><div style="margin-left: 2em"><p><font size="2">(record number * 1000) + number of field withinrecord</font></p></div><p><font size="2">This can simplify the work involved in adding anew field to a record. With this technique, if a new field is onlyadded to the end of a record, only those modules that need toreference the new field need to be recompiled. Note that fieldconstants are long integers, whereas file, record, and setconstants are standard integers.</font></p><p><font size="2">The <b>SIZEOF_??????</b> constants are added inthe header file as a convenience of the user. If they are notneeded, or are causing problems with large databases, they can beremoved with a <b>-z</b> option.</font></p><p><font size="2">The database header file should be<b>#include</b>d in every C source module that needs to access thedatabase.</font></p><p><a href="UG_Ch4b.htm">Next Page</a></p></body></html>

⌨️ 快捷键说明

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