1<?xml version="1.0" encoding="UTF-8" standalone="no"?> 2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 3<html xmlns="http://www.w3.org/1999/xhtml"> 4 <head> 5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 6 <title>Specifying a Berkeley DB schema using SQL DDL</title> 7 <link rel="stylesheet" href="gettingStarted.css" type="text/css" /> 8 <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /> 9 <link rel="start" href="index.html" title="Berkeley DB Programmer's Reference Guide" /> 10 <link rel="up" href="am_misc.html" title="Chapter 4. Access Method Wrapup" /> 11 <link rel="prev" href="am_misc_diskspace.html" title="Disk space requirements" /> 12 <link rel="next" href="am_misc_tune.html" title="Access method tuning" /> 13 </head> 14 <body> 15 <div class="navheader"> 16 <table width="100%" summary="Navigation header"> 17 <tr> 18 <th colspan="3" align="center">Specifying a Berkeley DB schema using SQL DDL</th> 19 </tr> 20 <tr> 21 <td width="20%" align="left"><a accesskey="p" href="am_misc_diskspace.html">Prev</a> </td> 22 <th width="60%" align="center">Chapter 4. 23 Access Method Wrapup 24 </th> 25 <td width="20%" align="right"> <a accesskey="n" href="am_misc_tune.html">Next</a></td> 26 </tr> 27 </table> 28 <hr /> 29 </div> 30 <div class="sect1" lang="en" xml:lang="en"> 31 <div class="titlepage"> 32 <div> 33 <div> 34 <h2 class="title" style="clear: both"><a id="am_misc_db_sql"></a>Specifying a Berkeley DB schema using SQL DDL</h2> 35 </div> 36 </div> 37 </div> 38 <p> 39 When starting a new Berkeley DB project, much of the code that you 40 must write is dedicated to defining the BDB environment: what 41 databases it contains, the types of the databases, and so forth. 42 Also, since records in BDB are just byte arrays, you must write 43 code that assembles and interprets these byte arrays. 44 </p> 45 <p> 46 Much of this code can be written automatically (in C) by the 47 <a href="../api_reference/C/db_sql.html" class="olink">db_sql utility</a>. To use it, you first specify the schema of your Berkeley 48 DB environment in SQL Data Definition Language (DDL). Then you 49 invoke the db_sql command, giving the DDL as input. 50 <span class="command"><strong>db_sql</strong></span> reads the DDL, and writes C code that 51 implements a storage-layer API suggested by the DDL. 52 </p> 53 <p> 54 The generated API includes a general-purpose initialization 55 function, which sets up the environment and the databases (creating 56 them if they don't already exist). It also includes C structure 57 declarations for each record type, and numerous specialized 58 functions for storing and retrieving those records. 59 </p> 60 <p> 61 <span class="command"><strong>db_sql</strong></span> can also produce a simple test program 62 that exercises the generated API. This program is useful as an 63 example of how to use the API. It contains calls to all of the 64 interface functions, along with commentary explaining what the code 65 is doing. 66 </p> 67 <p> 68 Once the storage layer API is produced, your application may use it 69 as is, or you may customize it as much as you like by editing the 70 generated source code. Be warned, however: 71 <span class="command"><strong>db_sql</strong></span> is a one-way process; there is no way to 72 automatically incorporate customizations into newly generated code, 73 if you decide to run <span class="command"><strong>db_sql</strong></span> again. 74 </p> 75 <p> 76 To learn more about <span class="command"><strong>db_sql</strong></span>, please consult the 77 <a href="../api_reference/C/db_sql.html" class="olink">db_sql utility</a> manual page in the Berkeley DB C API guide. 78 </p> 79 </div> 80 <div class="navfooter"> 81 <hr /> 82 <table width="100%" summary="Navigation footer"> 83 <tr> 84 <td width="40%" align="left"><a accesskey="p" href="am_misc_diskspace.html">Prev</a> </td> 85 <td width="20%" align="center"> 86 <a accesskey="u" href="am_misc.html">Up</a> 87 </td> 88 <td width="40%" align="right"> <a accesskey="n" href="am_misc_tune.html">Next</a></td> 89 </tr> 90 <tr> 91 <td width="40%" align="left" valign="top">Disk space requirements </td> 92 <td width="20%" align="center"> 93 <a accesskey="h" href="index.html">Home</a> 94 </td> 95 <td width="40%" align="right" valign="top"> Access method tuning</td> 96 </tr> 97 </table> 98 </div> 99 </body> 100</html> 101