ug_ch3.htm
来自「db.* (pronounced dee-be star) is an adva」· HTM 代码 · 共 1,084 行 · 第 1/3 页
HTM
1,084 行
(containing id_code keys) and <b>tims.k02</b> (containing authorkeys).</p><p>One record type named <b>info</b> is declared to contain each ofthe data fields. To accommodate the null byte that terminatesstrings in C, each character field is one character longer thanspecified in the requirements . Note that id_code is identified asa unique key and that author is identified as a key. (Duplicatekeys are allowed unless the unique qualifier is present).</p><p>The schema is compiled with the following command:</p><pre><font color="#0000FF">ddlp tims.ddl</font></pre><p><font size="2">The <b>ddlp</b> will display the followingtext:</font></p><pre><font color="#0000FF">db.* 1.0.0 Database Definition LanguageProcessor Utility Copyright (C) 2000 Centura Corporation, All Rights Reserved. Runtime dictionary memory requirements: file table : 876 record table: 12 field table : 120 set table : 0 member table: 0 sort table : 0 key table : 0 total : 10080 errors detected</font></pre><p><font size="2">The <b>ddlp</b> reports the amount of dynamicmemory that will be allocated by the <b><i>db.*</i></b> runtimesystem for the dictionary.</font></p><p>Upon successful completion, the <b>ddlp</b> will have createdtwo files. File <b>tims.dbd</b> contains the database dictionary.File <b>tims.h</b> is the header file to be included in each Csource file using the tims database. The contents of <b>tims.h</b>are shown below.</p><pre><font color="#0000FF">#ifndef TIMS_H#define TIMS_H/* <b><i>db.*</i></b> 1.0.0 *//* Technical Information Management System*/ /* database tims record/key structure declarations */struct info { char id_code[16]; char info_title[80]; char author[32]; char publisher[32]; char pub_date[12]; int info_type;};/* record, field and set table entry definitions *//* File Id Constants *//* Record Name Constants */#define INFO 10000/* Field Name Constants */#define ID_CODE 0L#define INFO_TITLE 1L#define AUTHOR 2L#define PUBLISHER 3L#define PUB_DATE 4L#define INFO_TYPE 5L/* Set Name Constants *//* Field Sizes */#define SIZEOF_ID_CODE 16#define SIZEOF_INFO_TITLE 80#define SIZEOF_AUTHOR 32#define SIZEOF_PUBLISHER 32#define SIZEOF_PUB_DATE 12#define SIZEOF_INFO_TYPE 2#endif /* TIMS_H */</font></pre><p><font size="2">This file contains a <b>struct</b> declarationfor the <b>info</b> record. This <b>struct</b> is for use by theC/C++ application in declaring variables that contain occurrencesof the <b>info</b> record from the database. Also included in thisfile are constant definitions for the <b>info</b> record and foreach data field. These constants will be passed to the<b><i>db.*</i></b> C functions that require them.</font></p><p>The next step is to initialize the database with the followingcommand:</p><pre><font color="#0000FF">initdb tims</font></pre><p><font size="2">Then <b><i>db.*</i></b> will display thefollowing text and, except in the very first initialization, promptyou for confirmation:</font></p><pre><font color="#0000FF">Database Initialization Utility db.* 1.0.0Copyright (C) 2000 Centura Corporation, All Rights ReservedInitialization of database: timsWARNING: this will destroy contents of the following files: tims.d01 tims.k01 tims.k02continue? (y/n)</font></pre><p><font size="2">A "y" (yes) response will complete theinitialization of the database files; the listed files will beoverwritten.</font></p><h3><a name="ProgramDesign" id="ProgramDesign"></a>3.4.3 ProgramDesign</h3><p><font size="2">The program for this example consists of thefollowing functions:</font></p><table cellspacing="0" border="0" cellpadding="7" width="542"><tr><td width="18%" valign="top"><p><b><font size="2">main</font></b></p></td><td width="82%" valign="top"><p><font size="2">Main program, command menu control</font></p></td></tr><tr><td width="18%" valign="top"><p><b><font size="2">ent_info</font></b></p></td><td width="82%" valign="top"><p><font size="2">Enter technical information data</font></p></td></tr><tr><td width="18%" valign="top"><p><b><font size="2">del_info</font></b></p></td><td width="82%" valign="top"><p><font size="2">Delete technical information data</font></p></td></tr><tr><td width="18%" valign="top"><p><b><font size="2">by_id</font></b></p></td><td width="82%" valign="top"><p><font size="2">Find technical information by<b>id_code</b></font></p></td></tr><tr><td width="18%" valign="top"><p><b><font size="2">by_author</font></b></p></td><td width="82%" valign="top"><p><font size="2">Find technical information by author</font></p></td></tr><tr><td width="18%" valign="top"><p><b><font size="2">get_info</font></b></p></td><td width="82%" valign="top"><p><font size="2">Get technical information data fromuser</font></p></td></tr><tr><td width="18%" valign="top"><p><b><font size="2">pr_info</font></b></p></td><td width="82%" valign="top"><p><font size="2">Print technical information data</font></p></td></tr></table><p><font size="2">Figure 3-3 shows the function call structure forthe program.</font></p><p align="center"> </p><p align="center"><b><font size="2"><img alt="dbstar_3-3.gif - 2237 Bytes" border="0" height="151" src="dbstar_3-3.gif" width="307"></font></b></p><p align="center">Fig. 3-3. Call Structure of the ExampleProgram</p><p>The <b><i>db.*</i></b> runtime library functions to be used inthe example are summarized in the following table. Note that, byconvention, all <b><i>db.*</i></b> runtime functions begin with a<b>d_</b> prefix.</p><table cellspacing="0" border="0" cellpadding="7" width="535"><tr><td width="24%" valign="top"><p><b><font face="Palatino,Book Antiqua" size="2">d_lockcomm</font></b></p></td><td width="76%" valign="top"><p><font face="Palatino,Book Antiqua" size="2">Select a lockmanager communication protocol</font></p></td></tr><tr><td width="24%" valign="top"><p><b><font face="Palatino,Book Antiqua" size="2">d_open</font></b></p></td><td width="76%" valign="top"><p><font face="Palatino,Book Antiqua" size="2">Open adatabase</font></p></td></tr><tr><td width="24%" valign="top"><p><b><font face="Palatino,Book Antiqua" size="2">d_close</font></b></p></td><td width="76%" valign="top"><p><font face="Palatino,Book Antiqua" size="2">Close adatabase</font></p></td></tr><tr><td width="24%" valign="top"><p><b><font face="Palatino,Book Antiqua" size="2">d_fillnew</font></b></p></td><td width="76%" valign="top"><p><font face="Palatino,Book Antiqua" size="2">Fill and store a newrecord occurrence</font></p></td></tr><tr><td width="24%" valign="top"><p><b><font face="Palatino,Book Antiqua" size="2">d_keyfind</font></b></p></td><td width="76%" valign="top"><p><font face="Palatino,Book Antiqua" size="2">Find a keyoccurrence</font></p></td></tr><tr><td width="24%" valign="top"><p><b><font face="Palatino,Book Antiqua" size="2">d_keynext</font></b></p></td><td width="76%" valign="top"><p><font face="Palatino,Book Antiqua" size="2">Find the next keyoccurrence</font></p></td></tr><tr><td width="24%" valign="top"><p><b><font face="Palatino,Book Antiqua" size="2">d_keyread</font></b></p></td><td width="76%" valign="top"><p><font face="Palatino,Book Antiqua" size="2">Read value of lastfound key</font></p></td></tr><tr><td width="24%" valign="top"><p><b><font face="Palatino,Book Antiqua" size="2">d_recread</font></b></p></td><td width="76%" valign="top"><p><font face="Palatino,Book Antiqua" size="2">Read a recordcontents</font></p></td></tr><tr><td width="24%" valign="top"><p><b><font face="Palatino,Book Antiqua" size="2">d_delete</font></b></p></td><td width="76%" valign="top"><p><font face="Palatino,Book Antiqua" size="2">Delete a recordoccurrence</font></p></td></tr></table><h3><a name="Description" id="Description"></a>3.4.4 ProgramDescription</h3><p><font size="2">The C code for the main program is given below.The first four lines include directives to incorporate the standardC header file <b>stdio.h</b>, the standard <b><i>db.*</i></b>header file <b>db.star.h</b>, and the <b>tims</b> database headerfile <b>tims.h</b>. The <b><i>db.*</i></b> header file contains theconstant definitions for the <b><i>db.*</i></b> function returnstatus code. The definition of LOCKCOMM_DATA needs to be donebefore <b>db.star.h</b> is included in one module in yourapplication.</font></p><p>A variable called <b>irec</b> is a globally declared <b>info</b>structure (declared in <b>tims.h</b>) to be used by all of thefunctions for storing <b>info</b> record data.</p><pre><font color="#0000FF">#include <stdio.h>#define LOCKCOMM_DATA#include "db.star.h"#include "tims.h"DB_TASK *Currtask;struct info irec; /* Technical Information Management System */main(){ char cmd[20]; /* command entry string */ int err;/* open the "tims" database */ if ((err=d_opentask(&Currtask)) != S_OKAY || (err=d_open("tims","o", Currtask)) != S_OKAY) { printf("Failure to open database, error=%d\n", err); return (0); } for ( ; ; ) { /* display command menu */ printf("\nTIMS Commands:\n"); printf(" 1 - Enter technical information\n"); printf(" 2 - Delete technical information\n"); printf(" 3 - Find technical info by id_code\n"); printf(" 4 - Find technical info by author\n"); printf(" q - Quit\n"); printf("enter command: "); gets(cmd); switch (cmd[0]) { case '1': ent_info(); break; case '2': del_info(); break; case '3': by_id(); break; case '4': by_author(); break; case 'q': d_close(Currtask); exit(0); default : printf("*** bad command--re-enter\n"); break; } }}</font></pre><p><font size="2">In this example we are opening the database insingle user mode, so we are using no lock manager. For a fullexplanation of the various lock manager communication options andissues, see the <b><i>db.*</i></b> <i>Multi-UserGuide</i>.</font></p><p>The <b>d_opentask</b> call requires one parameter, a pointer tothe task pointer. <b>db.*</b> will allocate a task structure andreturn the pointer to the program for use in all subsequent callsthat are associated with the task. The <b>d_open</b> call requiresthree arguments. The first argument is the name of the database tobe opened. The second argument (<b>o</b>) indicates that thedatabase is to be opened in one user mode (that is, only one userwill access the database, and the lock manager is not required). In
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?