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