ug_ch5a.htm

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

HTM
1,565
字号
<!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 5</title></head><body><p><font size="6"><a name="Manipulation" id="Manipulation"></a>Chapter 5<br>Database Manipulation</font></p><h2><a name="Introduction" id="Introduction"></a>5.1Introduction</h2><p><font size="2">Using <b><i>db.*</i></b>, databases aremanipulated by C language application programs through calls tofunctions provided in the <b><i>db.*</i></b> runtime library.Database manipulation capabilities include all functions needed tocreate, retrieve, modify and delete information in a database. Alsoincluded are functions that control the operation of the<b><i>db.*</i></b> runtime environment. The library functions thatpertain specifically to multi-user database manipulation aredescribed in the <b><i>db.*</i></b> <i>Multi-User</i><i>Guide</i>.</font></p><p>The runtime library functions are grouped into differentcategories based on each one's purpose. See the list of categoriesbelow.</p><table cellspacing="0" border="0" cellpadding="7" width="516"><tr><td width="28%" valign="top"><p><font size="2">database control</font></p></td><td width="72%" valign="top"><p><font size="2">Functions that open, close, and initializedatabases, and set runtime control parameters andoptions.</font></p></td></tr><tr><td width="28%" valign="top"><p><font size="2">currency control</font></p></td><td width="72%" valign="top"><p><font size="2">Functions that access and manipulate the currencytables.</font></p></td></tr><tr><td width="28%" valign="top"><p><font size="2">data retrieval</font></p></td><td width="72%" valign="top"><p><font size="2">Functions that access and read information fromthe database.</font></p></td></tr><tr><td width="28%" valign="top"><p><font size="2">data creation</font></p></td><td width="72%" valign="top"><p><font size="2">All functions used to store new information andrelationships in the database.</font></p></td></tr><tr><td width="28%" valign="top"><p><font size="2">data modification</font></p></td><td width="72%" valign="top"><p><font size="2">Functions that modify information andrelationships stored in the database.</font></p></td></tr><tr><td width="28%" valign="top"><p><font size="2">data deletion</font></p></td><td width="72%" valign="top"><p><font size="2">Functions used to remove information andrelationships from the database.</font></p></td></tr></table><p><font size="2">Note that all <b><i>db.*</i></b> function namesare prefixed by <b>d_</b> (for example, <b>d_keyfind</b>) so as toavoid name conflicts with other user or system library functions.The return value of all <b><i>db.*</i></b> functions is an integercompletion status for the requested operation. A status code ofzero (S_OKAY) indicates that the operation completed successfully.These status codes will be introduced as required in thediscussions that follow. A complete list can be found in section5.8, "Database Error Reporting," and complete descriptions areprovided in the <b><i>db.*</i> Reference Manual</b>.</font></p><p>The purpose of this chapter is to introduce the use of theprincipal functions through explanation and examples. Completedetails relating to the use of each function are provided in the<b><i>db.*</i> Reference Manual</b>.</p><p>Most of the <b><i>db.*</i></b> functions must be passed a taskparameter and a database number. In the examples, a task pointercalled <i>task</i> and a constant called <i>CURR_DB</i> ("use thecurrent database") has been passed to the functions. The taskpointer must always be passed to <b><i>db.*</i></b> functions tofacilitate reentrancy. The database number must always be passed,even when only one database is open. See section 5.9.2, "AccessingMultiple Databases," for complete details regarding multipledatabase access and the database number argument.</p><h2><a name="Control" id="Control"></a>5.2 Database Control</h2><p><font size="2">Database control functions provide control overthe runtime system's operational environment. They provide for theopening and closing of databases, location and names of databasefiles, initialization of databases and files, and various runtimetuning parameters and options.</font></p><p>The database control functions are listed in Table 5-1 and havebeen grouped into two categories. The "pre-open" functions arethose that can only be called prior to a <b>d_open</b> call, whichopens the database. The "post-open" functions can only be calledafter the database has been opened. Functions <b>d_off_opt</b> and<b>d_on_opt</b>, however, can be executed either before or afterthe database is opened.</p><p align="center"><b>Table 5-1 Database Control Functions</b></p><table cellspacing="0" border="0" cellpadding="7" width="542"><tr><td valign="top" colspan="2"><p><font size="2"><b>Pre-Database Open Functions</b></font></p></td></tr><tr><td width="42%" valign="top"><p><font size="2"><b>d_dbdpath</b>(<i>dbd_dir, task</i>)</font></p></td><td width="58%" valign="top"><p><font size="2">Set path to directory containing the databasedictionary.</font></p></td></tr><tr><td width="42%" valign="top"><p><font size="2"><b>d_dbfpath</b>(<i>dbf_dir, task</i>)</font></p></td><td width="58%" valign="top"><p><font size="2">Set path to directory containing the databasefiles.</font></p></td></tr><tr><td width="42%" valign="top"><p><font size="2"><b>d_dblog</b>(<i>log_name, task</i>)</font></p></td><td width="58%" valign="top"><p><font size="2">Set path or name of the database transaction logfile.</font></p></td></tr><tr><td width="42%" valign="top"><p><font size="2"><b>d_dbtaf</b>(<i>taf_name, task</i>)</font></p></td><td width="58%" valign="top"><p><font size="2">Set path or name of the database familytransaction activity file.</font></p></td></tr><tr><td width="42%" valign="top"><p><font size="2"><b>d_dbtmp</b>(<i>tmp_dir, task</i>)</font></p></td><td width="58%" valign="top"><p><font size="2">Set path to directory to contain temporaryfiles.</font></p></td></tr><tr><td width="42%" valign="top"><p><font size="2"><b>d_ctbpath</b>(<i>ctb_dir, task</i>)</font></p></td><td width="58%" valign="top"><p><font size="2">Set path to directory containing the countrytable file.</font></p></td></tr><tr><td width="42%" valign="top"><p><font size="2"><b>d_lockcomm</b>(<i>lm_type,task</i>)</font></p></td><td width="58%" valign="top"><p><font size="2">Set the protocol type of the lockmanager.</font></p></td></tr><tr><td width="42%" valign="top"><p><font size="2"><b>d_lockmgr</b>(<i>lm_name, task</i>)</font></p></td><td width="58%" valign="top"><p><font size="2">Set name of lock manager.</font></p></td></tr><tr><td width="42%" valign="top"><p><font size="2"><b>d_checkid</b>(<i>userid, task</i>)</font></p></td><td width="58%" valign="top"><p><font size="2">Check a userid to see if it is valid andunique.</font></p></td></tr><tr><td width="42%" valign="top"><p><font size="2"><b>d_dbuserid</b>(<i>userid, task</i>)</font></p></td><td width="58%" valign="top"><p><font size="2">Set database user identifier.</font></p></td></tr><tr><td width="42%" valign="top"><p><font size="2"><b>d_open</b>(<i>dbnames, mode,task</i>)</font></p></td><td width="58%" valign="top"><p><font size="2">Open a (set of) database(s).</font></p></td></tr><tr><td width="42%" valign="top"><p><font size="2"><b>d_opentask</b>(<i>&amp;task</i>)</font></p></td><td width="58%" valign="top"><p><font size="2">Create a new task context.</font></p></td></tr><tr><td width="42%" valign="top"><p><font size="2"><b>d_renfile</b>(<i>dbname, FILE,filenm,task</i>)</font></p></td><td width="58%" valign="top"><p><font size="2">Substitute a database file.</font></p></td></tr><tr><td width="42%" valign="top"><p><font size="2"><b>d_renclean</b>(<i>, task</i>)</font></p></td><td width="58%" valign="top"><p><font size="2">Clean up all memory related to previous renfilecommands.</font></p></td></tr><tr><td width="42%" valign="top"><p><font size="2"><b>d_setfiles</b>(<i>num, task</i>)</font></p></td><td width="58%" valign="top"><p><font size="2">Set the maximum number of open files.</font></p></td></tr><tr><td width="42%" valign="top"><p><font size="2"><b>d_setpages</b>(<i>num, num,task</i>)</font></p></td><td width="58%" valign="top"><p><font size="2">Set the number of pages in the cache.</font></p></td></tr><tr><td width="42%" valign="top"><p><font size="2"><b>d_dbini</b>(<i>ini_dir, task</i>)</font></p></td><td width="58%" valign="top"><p><font size="2">Set path to the <b><i>db.*</i></b> initializationfile.</font></p></td></tr><tr><td valign="top" colspan="2">&nbsp;</td></tr><tr><td valign="top" colspan="2"><p><font size="2"><b>Post-Database Open Functions</b></font></p></td></tr><tr><td width="42%" valign="top"><p><font size="2"><b>d_close</b>(<i>task</i>)</font></p></td><td width="58%" valign="top"><p><font size="2">Close database.</font></p></td></tr><tr><td width="42%" valign="top"><p><font size="2"><b>d_closeall</b>(<i>task</i>)</font></p></td><td width="58%" valign="top"><p><font size="2">Close all open data and key file handles (notdatabases).</font></p></td></tr><tr><td width="42%" valign="top"><p><font size="2"><b>d_closetask</b>(<i>task</i>)</font></p></td><td width="58%" valign="top"><p><font size="2">Close a task context.</font></p></td></tr><tr><td width="42%" valign="top"><p><font size="2"><b>d_destroy</b>(<i>dbname</i>,<i>task</i>)</font></p></td><td width="58%" valign="top"><p><font size="2">Destroy (delete) all data and key files in thedatabase.</font></p></td></tr><tr><td width="42%" valign="top"><p><font size="2"><b>d_iclose</b>(<i>task, dbn</i>)</font></p></td><td width="58%" valign="top"><p><font size="2">Incrementally close a database.</font></p></td></tr><tr><td width="42%" valign="top"><p><font size="2"><b>d_initfile</b>(<i>FILE, task,dbn</i>)</font></p></td><td width="58%" valign="top"><p><font size="2">Initialize a database file.</font></p></td></tr><tr><td width="42%" valign="top"><p><font size="2"><b>d_initialize</b>(<i>task, dbn</i>)</font></p></td><td width="58%" valign="top"><p><font size="2">Initialize all database files.</font></p></td></tr><tr><td width="42%" valign="top"><p><font size="2"><b>d_iopen</b>(<i>dbnames, task</i>)</font></p></td><td width="58%" valign="top"><p><font size="2">Incrementally open a (set of)database(s).</font></p></td></tr><tr><td width="42%" valign="top"><p><font size="2"><b>d_off_opt</b>(<i>options, task</i>)</font></p></td><td width="58%" valign="top"><p><font size="2">Turn off specified runtime options.</font></p></td></tr><tr><td width="42%" valign="top"><p><font size="2"><b>d_on_opt</b>(<i>options, task</i>)</font></p></td><td width="58%" valign="top"><p><font size="2">Turn on specified runtime options.</font></p></td></tr></table><h3><a name="Opening" id="Opening"></a>5.2.1 Opening and ClosingDatabases</h3><p><font size="2">Function <b>d_open</b> is called to open adatabase. It is called with the name(s) of the database(s) to beopened and a parameter that identifies the mode of database access(see Chapter 6, "Transaction Processing").</font></p><p>For example, the following code will open database <b>tims</b>in exclusive access:</p><pre><font color="#0000FF">d_opentask(&amp;task);d_open("tims", "x", task);</font></pre><p><font size="2">Database access or update functions called priorto a successful opening of the database will return error codeS_DBOPEN.</font></p><p>When <b>d_open</b> is called, the <b><i>db.*</i></b> runtimelibrary will allocate and initialize memory space for all of itsinternal tables, and will read into memory the database dictionary

⌨️ 快捷键说明

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