📄 ug_ch12.htm
字号:
<!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 12</title></head><body><h1><a name="dbedit" id="dbedit"></a>Chapter 12<br>Database Editor (dbedit)</h1><h2><a name="Introduction" id="Introduction"></a>12.1Introduction</h2><p><font size="2">The low-level database editor (called<b>dbedit</b>) allows any <b><i>db.*</i></b> database to be changedand repaired by an operator who is trained in its use. It does notuse the runtime library and is not multi-user. Anyone who uses<b>dbedit</b> must be familiar with the binary format of<b><i>db.*</i></b> data files as described in Chapter 14, "FileFormats and Dictionary Tables."</font></p><blockquote>Caution: Improper use of <b>dbedit</b> can cause severedamage to a database.</blockquote><p><font size="2">The <b>dbedit</b> utility, together with<b>dbcheck</b>, is most useful for finding and correcting errors inset pointers and other overhead fields. Also, if any corruptionexists in page zero of a data file, <b>dbedit</b> can correct it.All other areas of database update or repair should be handledthrough the runtime library, or through <b>ida</b>, <b>dchain</b>,or <b>keybuild</b>. For example, <b>dbedit</b> can alter the valueof a data field, but it is best to use <b>ida</b> for such a taskbecause <b>ida</b> will maintain database consistency (for example,by changing a key value to match the changed field).</font></p><p>With <b>dbedit</b> you can perform updates to a data fileregardless of its internal consistency. While the runtime libraryand <b>ida</b> must be able to successfully open a full database,<b>dbedit</b> can operate on a file-by-file basis, and will notassume that any fields in the data file are valid.</p><p>The <b>dbedit</b> program is line-oriented, instead of fullscreen-oriented. It is driven by a set of commands that are readfrom standard input, and will print all information to standardoutput.</p><h2><a name="Usage" id="Usage"></a>12.2 Usage of dbedit</h2><p><font size="2">To edit a database, the database must reside inthe current directory. The following command will invoke<b>dbedit</b>:</font></p><pre><font color="#0000FF">dbedit <i>dbname</i></font></pre><p><font size="2">If <b>dbedit</b> finds a file named<b><i>dbname</i>.dbd</b>, it will read the dictionary into memoryand respond with the prompt:</font></p><pre><font color="#0000FF">dbedit> </font></pre><p><font size="2">If a system record exists, it will become theinitial current record. If no system record exists, the initialcurrent record will be database address [0:1]. If no records existin file 0, there will be no initial current record.</font></p><p>Because of the low-level nature of <b>dbedit</b>, it will notuse the <b><i>db.*</i></b> environment variables, such as DBDPATH.Nor will it use the <b>db.star.ini</b> file.</p><p>The <b>dbedit</b> utility operates in one of two modes:interpreted or non-interpreted modes. In the interpreted mode,<b>dbedit</b> will display a record's contents according to itstype. It displays set and member pointers in our standard databaseaddress representation. It indicates whether optional keys are set,and displays field values in the format used by <b>ida</b>.Navigation with <b>dbedit</b> means moving from one record toanother. There will almost always be a "current record." Edits madeto a record will be written to the file when the editor moves to anew current record.</p><p>The non-interpreted mode is entered by typing:</p><pre><font color="#0000FF">dbedit> edit hex</font></pre><p><font size="2">which responds with the prompt:</font></p><pre><font color="#0000FF">hex> </font></pre><p><font size="2">In this mode, no notion exists of current record.All data is displayed and edited as hexadecimal bytes. All editsare written to the data file when the hex edit mode isended.</font></p><h2><a name="Display" id="Display"></a>12.3 InformationDisplay</h2><p><font size="2">Three commands are available to print<b>dbedit</b> or database information:</font></p><p>help<br>display<br>show</p><p>The <b>help</b> command prints a short list of <b>dbedit</b>commands.</p><pre><font color="#0000FF">help | ?</font></pre><p><font size="2">This command lists the current file name andcurrent record's database address. It does not list the hex editcommands unless in hex edit mode.</font></p><p>The <b>display</b> command displays the current record.</p><pre><font color="#0000FF">display [type | dba | ts | opt | set [setname] | mem [setname] | fld [fldname]]</font></pre><p><font size="2">The current record is displayed in a format thatshows both the hexadecimal and textual representation of therecord. The textual display is similar to that used by <b>ida</b>or <b>datdump</b>. An example is shown in Figure 12-1.</font></p><p>The scope of the display may be restricted by adding a secondkeyword to the command. Each keyword represents one section of thefull record display, and will cause only that section to bedisplayed. These subsections are:</p><table border="1" cellspacing="1" cellpadding="7" width="451"><tr><td width="24%" valign="top"><p><b><font size="2">type</font></b></p></td><td width="76%" valign="top"><p><font size="2">The record type</font></p></td></tr><tr><td width="24%" valign="top"><p><b><font size="2">dba</font></b></p></td><td width="76%" valign="top"><p><font size="2">The record database address</font></p></td></tr><tr><td width="24%" valign="top"><p><b><font size="2">ts</font></b></p></td><td width="76%" valign="top"><p><font size="2">The record creation and updatetimestamp</font></p></td></tr><tr><td width="24%" valign="top"><p><b><font size="2">opt</font></b></p></td><td width="76%" valign="top"><p><font size="2">The optional key bit map</font></p></td></tr><tr><td width="24%" valign="top"><p><b><font size="2">set</font></b></p></td><td width="76%" valign="top"><p><font size="2">The set owner pointers</font></p></td></tr><tr><td width="24%" valign="top"><p><b><font size="2">mem</font></b></p></td><td width="76%" valign="top"><p><font size="2">The set member pointers</font></p></td></tr><tr><td width="24%" valign="top"><p><b><font size="2">fld</font></b></p></td><td width="76%" valign="top"><p><font size="2">The data fields</font></p></td></tr></table><pre><font color="#0000FF"> Record Type005344: 01 00 INFO (1)<br> Database Address005346: 12 00 00 01 [1:18]<br> Set Owner Pointers (C/F/L)005350: 00 00 00 00 00 00 00 00 00 00 00 00 0 [0:0] [0:0] ARTICLE_LIST005362: 00 00 00 00 00 00 00 00 00 00 00 00 0 [0:0] [0:0] LOANED_BOOKS005374: 01 00 00 00 29 00 00 01 29 00 00 01 1 [1:41] [1:41] ABSTRACT005386: 02 00 00 00 1d 00 00 00 1e 00 00 00 2 [0:29] [0:30] INFO_TO_KEY<br> Set Member Pointers (O/P/N)005398: 01 00 00 01 28 00 00 01 13 00 00 01 [1:1] [1:40] [1:19] HAS_PUBLISHED005410: 00 00 00 00 00 00 00 00 00 00 00 00 [0:0] [0:0] [0:0] ARTICLE_LIST<br> Field ID_CODE005422: 64 62 30 30 31 00 00 00 00 00 00 00 db001 00 00 00 00 Field INFO_TITLE005438: 46 6f 75 72 74 68 2d 47 65 6e 65 72 Fourth-Generation Language 61 74 69 6f 6e 20 4c 61 6e 67 75 61 s Vol 1 - Principles 67 65 73 20 56 6f 6c 20 31 20 2d 20 50 72 69 6e 63 69 70 6c 65 73 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 Field PUBLISHER005518: 50 72 65 6e 74 69 63 65 2d 48 61 6c Prentice-Hall 6c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 Field PUB_DATE005550: 31 39 38 35 00 00 00 00 00 00 00 00 1985 Field INFO_TYPE005562: 00 00 0</font></pre><p align="center"><font size="2"><b>Fig. 12-1. Display of CurrentRecord</b></font></p><p>In addition, the <b>set</b>, <b>mem</b>, and <b>fld</b> keywordsmay be further restricted with the name of one owner set, memberset, or field.</p><p>The <b>show</b> command displays schema information, such aslists of sets, records, or keys.</p><pre><font color="#0000FF">show {fld [<i>fldname</i>] | file [<i>filename</i>] | key [<i>keyname</i>] | record [<i>recname</i>] | set [<i>setname</i>]}</font></pre><p><font size="2">The <b>show fld</b> command lists all fields inthe database, or, if <i>fldname</i> is given, shows that fieldonly.</font></p><p>The <b>show file</b> command lists the names of all files in thedatabase, or, if <i>filename</i> is given, shows the record typesor key types contained in the file.</p><p>The <b>show key</b> command lists all keys in the database, or,if <i>keyname</i> is given, shows that key only. Each key will bedisplayed as a field.</p><p>The <b>show record</b> command lists the names of all recordtypes in the database, or, if <i>recname</i> is given, shows thatrecord type in the format shown in Figure 12-2.</p><pre><font color="#0000FF">Record Type: INFO (1)Contained in file: tims.d02Record Length: 220Offset to Data: 78Flags: Fields: unique key char ID_CODE[16] char INFO_TITLE[80] Flags: SORTFLD char PUBLISHER[32] char PUB_DATE[12] int INFO_TYPE</font></pre><p align="center"><font size="2"><b>Fig. 12-2. Show RecordInfo</b></font></p><p>The <b>show set</b> command lists the names of all set types inthe database, or, if <i>setname</i> is given, shows that set typein the format shown in Figure 12-3.</p><pre><font color="#0000FF">Set Type: HAS_PUBLISHED (1)Order: Ascending By Field(s): INFO_TITLEOwner: AUTHOR (0)Member(s): INFO (1)Flags:</font></pre><p align="center"><font size="2"><b>Fig. 12-3. Show SetHas_published</b></font></p><h2><a name="Navigation" id="Navigation"></a>12.4 Navigation</h2><p><font size="2">Movement through the database is accomplishedwith the <b>goto</b> command. This command is used to set thecurrent record and has several forms.</font></p><pre><font color="#0000FF">goto<i> {dba</i> | nextrec | prevrec <i>}</i>goto<i> {</i>first | last<i>} setname</i>goto<i> {</i>own | prev | next<i>} setname</i>goto <i>{</i>file<i> {filenum</i> | <i>filename}}</i></font></pre><p><font size="2">The most basic <b>goto</b> command allows you toset the current to a specified database address as shown in thefollowing example:</font></p><pre><font color="#0000FF">goto 2:345</font></pre><p><font size="2">The <b>goto nextrec</b> and <b>goto prevrec</b>commands allow you to move sequentially through the current datafile one record slot at a time. If the current record is the firstrecord in a file, then <b>goto prevrec</b> will produce an errormessage, and the current record will remain unchanged. If thecurrent record is the last record in a file, then <b>gotonextrec</b> will also produce an error message, and the currentrecord will remain unchanged.</font></p><p>Set pointers contained in the current record may be referencedto set the current record to the first or last member using the<b>goto first</b> and <b>goto last</b> commands. The specified<i>setname</i> must be a set for which the current record is anowner.</p><p>Set member pointers contained in the current record may bereferenced to set the current record to the owner (<b>gotoown</b>), next (<b>goto next</b>), or previous (<b>goto prev</b>)member of the specified <i>setname</i>.</p><p>If an invalid slot is formed by any of the above forms of the<b>goto</b>, an error is printed, and no action is taken. It islegal to go to a database address that is beyond the current sizeof a data file. Such a record is initially filled with zeroesunless the file already has readable contents at the selectedlocation. A warning message is printed if a selected slot is morethan two pages beyond the current end of the database (as indicatedin page zero).</p><p>A data file may be selected with the <b>goto</b> <b>file</b>command. It may be selected by specifying either a file number orfile name. When a new file is selected, there will be no currentrecord. A <b>goto nextrec</b> will select the first record, and<b>goto prevrec</b> will select the last record. Until there is acurrent record, only the page zero of the file may be edited.</p><h2><a name="Editing" id="Editing"></a>12.5 Editing</h2><p><font size="2">The <b>edit</b> command is used to specify that aportion of the current record slot or page zero is to be modified.All edits are performed in memory and are reflected in subsequentdisplay commands. An edited record is written to the database onexecution of a following <b>goto</b> or <b>exit</b> command.Unwanted edits on the current record may be discarded by issuing a<b>reread</b> command. The complete syntax of the <b>edit</b>command is shown below.</font></p><pre><font color="#0000FF">edit typeedit <i>{</i>first | last | count<i>}</i> <i>setname</i>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -