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