ug_ch3.htm

来自「db.* (pronounced dee-be star) is an adva」· HTM 代码 · 共 1,084 行 · 第 1/3 页

HTM
1,084
字号
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta name="generator" content="HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org"><meta http-equiv="content-type" content="text/html; charset=us-ascii"><meta name="Generator" content="Microsoft Word 97"><title>db.* User's Guide Chapter 3</title></head><body><h1><a name="Overview" id="Overview"></a>Chapter 3<br>Operational Overview</h1><h2><a name="Introduction" id="Introduction"></a>3.1Introduction</h2><p><font size="2">This chapter presents an overview of the basicoperation of the <b><i>db.*</i></b> DBMS. Each system component isidentified and described, and the operational flow of a<b><i>db.*</i></b> C or C++ program is given. A simple,introductory example is then developed illustrating the basic useof the system. Your understanding of what each component does andhow it fits into the overall system is essential to your ability touse <b><i>db.*</i></b> effectively.</font></p><h2><a name="Components" id="Components"></a>3.2 SystemComponents</h2><p><font size="2">Figure 3-1 is a diagram of all of the<b><i>db.*</i></b> system components. Arrows indicate input andoutput between the components and text files (for example, schema),specific file types in the database (for example, key files), orthe database in general.</font></p><h4>ddlp</h4><p><font size="2">The Database Definition Language Processor,<b>ddlp</b>, is a utility that compiles a DDL specification, calleda schema, and produces the database dictionary. The dictionarycontains database content and organization data that is used by the<b><i>db.*</i></b> runtime library functions (seebelow).</font></p><p>A C or C++ header file (not shown in Figure 3-1) also is createdby the <b>ddlp</b>. This file contains constants and declarationsassociated with a specific database for use by the C or C++programs that access the database.</p><p align="center">&nbsp;</p><p align="center"><b><img alt="db.* System Components" border="0"height="603" src="dbstar_3-1.gif" width="375"></b></p><p align="center">Fig. 3-1. <i>db.*</i> System Components</p><h4>initdb</h4><p><font size="2">The initialization of the data and key files fora new database is performed by the database initialization utility,<b>initdb</b>.</font></p><h4>The <i>db.*</i> Runtime Library</h4><p><font size="2">Database manipulation and control is performedthrough calls to C functions contained in the <b><i>db.*</i></b>runtime library. The library is linked with the object code for a Cor C++ database application program to produce the executableprogram.</font></p><p>The runtime library functions contained in the library performsuch operations as opening and closing the database, creating andmodifying records and fields, connecting and disconnecting sets,searching for records through keys and sets, and controllingmulti-user access through interaction with the system lockmanager.</p><h4>lock manager</h4><p><font size="2">Management of system-wide multi-user lockinformation and database recovery control is performed by the<b><i>db.*</i></b> lock manager. The lock manager runs as abackground task under the UNIX/Linux operating systems.</font></p><p>All multi-user <b><i>db.*</i></b> programs communicate with thelock manager to request permission to access data and key filescontained in a <b><i>db.*</i></b> database.</p><h4>lmclear</h4><p><b><font size="2">lmclear</font> is a utility used to clear adatabase user process that has failed or terminated without havingproperly closed a database. The actual effect of the operationdepends upon the operating environment but, in general, lmclearinforms the lock manager of the failed condition (when the lockmanager cannot get this information from the operating system onits own) so that certain user tables maintained by the lock managercan be properly cleared.</b></p><h4>dbclrlb</h4><p><font size="2">The clear lock bit utility, <b>dbclrlb</b>,clears any set record lock bits in the specified data files. It isusually considered to be an error for these advisory recordinstance locks to remain set after the applicationterminates.</font></p><h4>ida</h4><p><font size="2">The Interactive Database Access utility,<b>ida</b>, is a menu-driven database manipulation tool thatprovides an easy-to-use interface for entering, modifying, andretrieving database information through most of the<b><i>db.*</i></b> functions.</font></p><p>The <b>ida</b> utility is a useful tool for learning to use<b><i>db.*</i></b> as well as a tool for maintaining existingdatabases.</p><h4>dal</h4><p><font size="2">The Database Access Language, <b>dal</b>, is asimple, interpreted language that includes most of the<b><i>db.*</i></b> user-level functions as its commands. Withbuilt-in variables and a looping construct, it allows quickprototyping of simple sequences of <b><i>db.*</i></b> functioncalls. In addition, a database programmer can learn more about<b><i>db.*</i></b> by using <b>dal</b>.</font></p><h4>dbcheck</h4><p><font size="2">The consistency of a <b><i>db.*</i></b> databasecan be checked using the <b>dbcheck</b> utility. This utilitychecks to ensure that data and key files are consistent and thatall set linkages are correct. Thus, <b>dbcheck</b> is used to checkfor database corruption.</font></p><h4>dbedit</h4><p><font size="2">The <b>dbedit</b> utility is a low-level databaseeditor that allows a skilled developer to change a<b><i>db.*</i></b> data file. It interprets the databasedictionary, but does not perform a formal database open. Editing ofall portions of all records is allowed.</font></p><h4>dbimp</h4><p><font size="2">Data from ASCII text files can be imported into a<b><i>db.*</i></b> database using the <b>dbimp</b> utility. Thisutility is able to create, store, and form set connectionsinvolving one or more record types from data in a standard ASCIIformat.</font></p><p>The <b>dbimp</b> utility is useful in setting up test data,transporting <b><i>db.*</i></b> data between systems, importingdata from another DBMS, and, in conjunction with <b>dbexp</b>,performing ASCII file dumps and reloads of a <b><i>db.*</i></b>database.</p><h4>dbexp</h4><p><font size="2">The database export utility, <b>dbexp</b>, isused to output the contents of a <b><i>db.*</i></b> database into astandard ASCII format. The exported data can then be used byanother DBMS. You may also use <b>dbexp</b> with <b>dbimp</b> totransfer a database to a different environment or for performing anASCII file dump and reload.</font></p><h4>keybuild</h4><p><font size="2">Utility <b>keybuild</b> is used to recreate key(index) files from the contents of data files. It is useful forimplementing DDL changes where non-key fields are changed to keyfields or key fields are changed to non-key fields. It can also beused to rebuild the key files after a database corruption (forexample, as reported by <b>dbcheck</b>).</font></p><h4>keypack</h4><p><font size="2">The Key File Packing utility can be used todecrease the size of existing key files. This utility is designedespecially for large, static key files which will require verylittle or no modification after they are packed. The <b>keypack</b>utility places as many keys as possible into each B-tree node sothat the key file is smaller and lookups are quicker. However,modification of the key file after it has been packed becomes avery expensive operation.</font></p><h4>prdbd</h4><p><font size="2">The print database dictionary utility,<b>prdbd</b>, prints a formatted report showing the contents of allthe dictionary tables for a particular database. This detailedinformation on the structure of the dictionary enables you to writedatabase utilities or to perform database maintenance.</font></p><h4>console</h4><p><font size="2">The <b>console</b> utility will display the lockmanager tables. This information can be useful to systemadministrators.</font></p><h4>datdump</h4><p><font size="2">The data file dump utility, <b>datdump</b>,produces a formatted dump of the contents of a data file. Thisreport shows the data field contents and set linkage pointers foreach record occurrence on a data file. It is primarily for use inperforming database maintenance and for learning how data files areorganized.</font></p><h4>keydump</h4><p><font size="2">Similar to <b>datdump</b>, the <b>keydump</b>utility produces a formatted dump of the contents of a key file. Itis primarily for use in performing database maintenance and forlearning how key files are organized.</font></p><h2><a name="Flow" id="Flow"></a>3.3 Operational Flow</h2><p><font size="2">The basic operational flow for creating a<b><i>db.*</i></b> C or C++ application program is shown in Figure3-2.</font></p><p align="center">&nbsp;</p><p align="center"><b><img alt="db.* Operation" border="0" height="401" src="dbstar_3-2.gif" width="287"></b></p><p align="center">Fig. 3-2. <i>db.*</i> Operation</p><p>The Database Definition Language specification is submitted tothe DDL processor, which compiles the DDL and creates the databasedictionary. The DDL processor also creates a C or C++ header fileof structure, constant, and class declarations for use with the Cor C++ programs that access the database.</p><p>The source code for your C or C++ application program, whichincludes the header file created by <b>ddlp</b> and the standard<b><i>db.*</i></b> header file (<b>db.star.h)</b>, is thencompiled, and the resulting object code is linked with the<b><i>db.*</i></b> runtime library to create the executableapplication program. The <b><i>db.*</i></b> library functionscalled from within the program manipulate the database content asdefined by the dictionary.</p><p>The following procedure summarizes the basic steps necessary tocreate a <b><i>db.*</i></b> application.</p><ol><li>Design the database. That is, determine what data is to bestored in the database and how it should be organized.</li><li>Prepare the DDL specification using your usual texteditor.</li><li>Compile the DDL specification using the DDL processor,<b>ddlp</b>.</li><li>Correct any DDL errors reported by <b>ddlp</b>.</li><li>Initialize the database using <b>initdb</b>.</li><li>Experiment with the database, using <b>dal</b> or <b>ida</b> tocreate and access some test data. Refine your database design asnecessary.</li><li>Design and code your C or C++ application program,incorporating the appropriate calls to the <b><i>db.*</i></b>functions. Your program should include the <b>db.star.h</b> headerand the header file created by <b>ddlp</b>.</li><li>Compile the C or C++ program.</li><li>Link the program with the <b><i>db.*</i></b> library to createyour executable.</li><li>If it is a multi-user application, start the lock manager.</li><li>Run your <b><i>db.*</i></b> application program.</li></ol><p>The following section illustrates each of these steps bydescribing the development of a simple database application.</p><h2><a name="Example" id="Example"></a>3.4 IntroductoryExample</h2><p><font size="2">This section introduces the use of<b><i>db.*</i></b> through the development of a simple databaseapplication. A description of the program requirements is given inthe next section. The database design is then explained followed bythe program design. Finally, the program code is described withparticular attention paid to the <b><i>db.*</i></b> functioncalls.</font></p><h3><a name="Requirements" id="Requirements"></a>3.4.1Requirements</h3><p><font size="2">The purpose of the example project is to write aprogram that will maintain a database of books, magazines(journals), and articles contained in a technical library.Information to be stored in the database includes:</font></p><ul><li>Identification code: a text field containing a Dewey-Decimalcode or other kind of code to be determined by a user.</li><li>Author name: a text field containing the name of the author in"last, first, middle" format.</li><li>Title: a text field containing the title of the book, magazine,or article.</li><li>Publisher: a text field containing the name of thepublisher.</li><li>Date published: a date field containing the copyright date ofthe publication.</li><li>Information type: an integer field containing a code thatidentifies whether the information is a book, magazine, orarticle.</li></ul><p>The stored information must be retrievable by either theidentification code or author name. If an author has more than onepublication in the library, all of the publications must bedisplayed.</p><p>User interaction will be performed by using simple text inputand output. Five commands will be provided:</p><ul><li>Enter technical information</li><li>Delete technical information</li><li>Find technical information by id code</li><li>Find technical information by author</li><li>Close database and quit</li></ul><p>The commands will be selected from a simple menu.</p><h3><a name="DatabaseDesign" id="DatabaseDesign"></a>3.4.2 DatabaseDesign</h3><p><font size="2">The database will be composed of one record typewhich contains the following data fields:</font></p><table cellspacing="0" border="0" cellpadding="7" width="542"><tr><td width="20%" valign="top"><p><font size="2"><em>id_code</em></font></p></td><td width="80%" valign="top"><p><font size="2">15-character field containing the identificationcode</font></p></td></tr><tr><td width="20%" valign="top"><p><font size="2"><em>info_title</em></font></p></td><td width="80%" valign="top"><p><font size="2">79-character field containing thetitle</font></p></td></tr><tr><td width="20%" valign="top"><p><font size="2"><em>author</em></font></p></td><td width="80%" valign="top"><p><font size="2">31-character field containing authorname</font></p></td></tr><tr><td width="20%" valign="top"><p><font size="2"><em>publisher</em></font></p></td><td width="80%" valign="top"><p><font size="2">31-character field containing publishername</font></p></td></tr><tr><td width="20%" valign="top"><p><font size="2"><em>pub_date</em></font></p></td><td width="80%" valign="top"><p><font size="2">11-character field containing publicationdate</font></p></td></tr><tr><td width="20%" valign="top"><p><font size="2"><em>info_type</em></font></p></td><td width="80%" valign="top"><p><font size="2">Integer code field which identifies theinformation type<br>as follows: 0 = book, 1 = magazine, 2 = article</font></p></td></tr></table><p><font size="2">Field id_code will be a unique key field. Thatis, it will be used to uniquely access a single record occurrencein the database.</font></p><p>The author field will be a non-unique key field. This willprovide access to all information records associated with aparticular author. This is because keys are maintained in the indexin sorted order and, thus, all duplicate keys will be groupedtogether.</p><p>The <b><i>db.*</i></b> DDL that implements this database design(assume it is contained in file <b>tims.ddl</b>) is givenbelow.</p><pre><font color="#0000FF"><a name="DDE_LINK1" id="DDE_LINK1">/* Technical Information Management System*/<br>database tims</a><br>{<br>   data file "tims.d01" contains info;<br>   key file  "tims.k01" contains id_code;   key file  "tims.k02" contains author;   record info   {      unique key char id_code[16];      char info_title[80];      key char author[32];      char publisher[32];      char pub_date[12];      int info_type;   }}</font></pre><p><font size="2">The first line is a comment that describes thedatabase. As in C, comments are specified in DDL between "/*" and"*/" pairs. Although comments may be placed throughout the databasedefinition file, those comments before the keyword <b>database</b>will be copied into the resulting header file.</font></p><p>The database statement names the database. The name chosen here,<b>tims</b>, is an acronym for "Technical Information ManagementSystem."</p><p>The DDL file (or schema) defines the database to be composed ofone data file, <b>tims.d01</b>, and two key files, <b>tims.k01</b>

⌨️ 快捷键说明

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