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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
|
<?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>Configuring the SQL Interface</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 Installation and Build Guide" />
<link rel="up" href="build_unix.html" title="Chapter 6. Building Berkeley DB for UNIX/POSIX" />
<link rel="prev" href="build_unix_conf.html" title="Configuring Berkeley DB" />
<link rel="next" href="build_unix_small.html" title="Building a small memory footprint library" />
</head>
<body>
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr>
<th colspan="3" align="center">Configuring the SQL Interface</th>
</tr>
<tr>
<td width="20%" align="left"><a accesskey="p" href="build_unix_conf.html">Prev</a> </td>
<th width="60%" align="center">Chapter 6.
Building Berkeley DB for UNIX/POSIX
</th>
<td width="20%" align="right"> <a accesskey="n" href="build_unix_small.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="build_unix_sql"></a>Configuring the SQL Interface</h2>
</div>
</div>
</div>
<div class="toc">
<dl>
<dt>
<span class="sect2">
<a href="build_unix_sql.html#idp50701368">Changing Compile Options</a>
</span>
</dt>
<dt>
<span class="sect2">
<a href="build_unix_sql.html#idp50564616">Enabling Extensions</a>
</span>
</dt>
<dt>
<span class="sect2">
<a href="build_unix_sql.html#build_unix_jdbc">Building the JDBC Driver
</a>
</span>
</dt>
<dt>
<span class="sect2">
<a href="build_unix_sql.html#idp50694384">Using the JDBC Driver
</a>
</span>
</dt>
<dt>
<span class="sect2">
<a href="build_unix_sql.html#idp50727840">Building the ODBC Driver</a>
</span>
</dt>
</dl>
</div>
<p>
There are a set of options you can provide to
<span class="command"><strong>configure</strong></span> in order to control how the Berkeley DB
SQL interface is built. These configuration options include:
</p>
<div class="variablelist">
<dl>
<dt>
<span class="term">--enable-sql</span>
</dt>
<dd>
Causes the <span class="command"><strong>dbsql</strong></span> command line interpreter to
be built. Along with <span class="command"><strong>dbsql</strong></span>, this argument
also builds the libdb_sqlXX.{so|la} library, a C API library
that mirrors the SQLite C API.
</dd>
<dt>
<span class="term">--enable-sql_compat</span>
</dt>
<dd>
<p>
Causes the <span class="command"><strong>sqlite3</strong></span> command line tool to
be built. This tool is identical to the
<span class="command"><strong>dbsql</strong></span> command line tool, except that it
has the same name as the command line tool that comes with
standard SQLite.
</p>
<p>
In addition, the libsqlite3.{so|la} C API library is built
if this option is specified. This library is identical to
the libdb_sqlXX.{so|la} library that is normally built for Berkeley
DB's sql interface, except that it has the same name as the
library which is built for standard SQLite.
</p>
<div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Warning</h3>
<p>
Use this compatibility option with
<span class="emphasis"><em>extreme</em></span> care. Standard SQLite is
used by many programs and utilities on many different
platforms. Some platforms, such as Mac OS X, come with
standard SQLite built in because default applications for the
platform use that library.
</p>
<p>
<span class="bold"><strong>Use of this option on platforms where standard SQLite
is in production use can cause unexpected runtime
errors either for your own application, or for
applications and utilities commonly found on the
platform, depending on which library is found first
in the platform's library search path.</strong></span>
</p>
<p>
Use this option <span class="emphasis"><em>only</em></span> if you know
exactly what you are doing.
</p>
</div>
<p>
This option is provided so that there is an easy upgrade
path for legacy SQLite tools and scripts that want to use
BDB SQL without rewriting the tool or script. However,
data contained in standard SQLite databases must be
manually migrated from the old database to your BDB SQL
database even if you use this option. See the
<em class="citetitle">Berkeley DB Getting Started with the SQL APIs</em> guide for information on
migrating data from standard SQLite to BDB SQL databases.
</p>
<p>
Note that in addition to the renamed command line tool and
library, this option also causes versions of the command
line tool and library to be built that use the normal BDB
SQLite names (<span class="command"><strong>dbsql</strong></span> and libdb_sqlXX.{so|la}).
</p>
</dd>
<dt>
<span class="term">--enable-test</span>
</dt>
<dd>
Cause the Berkeley DB SQL interface test suite to be built.
This argument can also be used with either
<code class="literal">--enable-sql</code> or
<code class="literal">--enable-sql_compat</code> to build the SQLite Tcl
test runner.
</dd>
<dt>
<span class="term">--enable-jdbc</span>
</dt>
<dd>
Causes the JDBC driver to be built.
</dd>
</dl>
</div>
<p>
The following configuration options are useful when debugging applications:
</p>
<div class="variablelist">
<dl>
<dt>
<span class="term">
<a class="link" href="build_unix_conf.html#build_unix_conf.--enable-debug">--enable-debug</a>
</span>
</dt>
<dd>
Builds the Berkeley DB SQL interface with debug symbols.
</dd>
<dt>
<span class="term">
<a class="link" href="build_unix_conf.html#build_unix_conf.--enable-diagnostic">--enable-diagnostic</a>
</span>
</dt>
<dd>
Builds the Berkeley DB SQL interface with run-time debugging checks.
</dd>
</dl>
</div>
<p>
Any arguments that you can provide to the standard SQLite configure
script can also be supplied when configuring Berkeley DB SQL interface.
</p>
<div class="sect2" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a id="idp50701368"></a>Changing Compile Options</h3>
</div>
</div>
</div>
<div class="itemizedlist">
<ul type="disc">
<li>
For Berkeley DB SQL to generate each table in a separate file, rather than as subdatabases in a single file, specify the BDBSQL_FILE_PER_TABLE flag as an argument to the configure script using the standard environment variable, CPPFLAGS.
When this option is enabled, the SQL database name is used as a directory name. This directory contains one file for the metadata and one file each for every table created by the SQL API.
Note that adding or deleting files from the database directory may corrupt your database.
To backup the metadata (schema), make a copy of the <code class="literal">metadata</code> and <code class="literal">table00001</code> files from the database directory.
Make a new copy whenever the schema is changed.
</li>
<li>
For Berkeley DB SQL to set the default page size when you create a database, specify the BDBSQL_DEFAULT_PAGE_SIZE flag as an argument to the configure script
using the standard environment variable, CPPFLAGS.
The value assigned must be a 0, 512, 1024, 2048, 4096, 8192 16384, 32768, or 65536. The default value is 4096.
If the value is set to zero, Berkeley DB queries the file system to determine the best page size,
and the value of SQLITE_DEFAULT_PAGE_SIZE is used to calculate the cache size, as the cache size is specified as a number of pages.
</li>
</ul>
</div>
</div>
<div class="sect2" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a id="idp50564616"></a>Enabling Extensions</h3>
</div>
</div>
</div>
<p>
The Berkeley DB SQL API provides extensions such as full text
search and R-Tree index. By default, these two extensions are
disabled. To enable an extension in the Berkeley DB SQL interface,
specify the related option as an argument to the configure script
using the standard environment variable, CPPFLAGS.
</p>
<div class="variablelist">
<dl>
<dt>
<span class="term">SQLITE_ENABLE_FTS3</span>
</dt>
<dd>
Enable building the Berkeley DB full text search layer
</dd>
<dt>
<span class="term">SQLITE_ENABLE_RTREE</span>
</dt>
<dd>
Enables the Berkeley DB R-Tree layer.
</dd>
</dl>
</div>
<p>
See the SQLite Documentation for more information on
<a class="ulink" href="http://www.sqlite.org/fts3.html" target="_top">full text search</a>
and <a class="ulink" href="http://www.sqlite.org/rtree.html" target="_top">R-Tree</a>.
</p>
</div>
<div class="sect2" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a id="build_unix_jdbc"></a>Building the JDBC Driver
</h3>
</div>
</div>
</div>
<p>This section describes how to build the JDBC driver code using <code class="literal">autoconf</code>, which is the only method supported and tested by the Berkeley DB team.</p>
<p>To build the JDBC driver, you must have Sun Java Development Kit 1.1 or above installed.</p>
<pre class="programlisting">
cd build_unix
../dist/configure --enable-jdbc --prefix=<install path>
make install
</pre>
<p>
You can test the build by entering the following commands from the <code class="literal">build_unix/jdbc</code> directory:
</p>
<table class="simplelist" border="0" summary="Simple list">
<tr>
<td>javac -classpath ./sqlite.jar test3.java</td>
</tr>
<tr>
<td>java -Djava.library.path=./.libs -classpath ./sqlite.jar:. test3 </td>
</tr>
</table>
<p>
</p>
</div>
<div class="sect2" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a id="idp50694384"></a>Using the JDBC Driver
</h3>
</div>
</div>
</div>
<p>This section describes the steps to download, build, and run sample programs using the built JDBC driver.</p>
<div class="sect3" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h4 class="title"><a id="idp50708184"></a>Downloading JDBC Sample Code</h4>
</div>
</div>
</div>
<p>The download link for JDBC sample code is available on the <a class="ulink" href="http://java.sun.com/products/jdbc/reference/codesamples/index.html" target="_top">Oracle Sun Developer Network (SDN)</a>. You can identify the link by the "JDBC programming examples from all three editions (ZIP format)" text beside it.
</p>
</div>
<div class="sect3" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h4 class="title"><a id="idp50686072"></a>Modifying Sample Code</h4>
</div>
</div>
</div>
<p>Before running the example code, do the following:</p>
<div class="orderedlist">
<ol type="1">
<li>Unzip the file containing the sample code to a new directory (for example, jdbc_ex).</li>
<li>Substitute <code class="literal">jdbc:sqlite:/<db-file-name></code> for the generic JDBC URL that appears in the code. That is, put <code class="literal">jdbc:sqlite:/<db-file-name></code> between the quotation marks in the line:
<p><code class="literal"> String url = "jdbc:mySubprotocol:myDataSource";</code></p><p> Note: The <db-file-name> can either be an absolute path name like <code class="literal">"/jdbc_ex_db/myDataSource"</code>, or a relative path-file-name like <code class="literal">"../jdbc_ex_db/myDataSource"</code>, or a file name, like <code class="literal">"myDataSource"</code>, in which the database file will be stored at the current directory.</p></li>
<li>Substitute <code class="literal">SQLite.JDBCDriver</code> for <code class="literal">myDriver.ClassName</code> in the line: <code class="literal">Class.forName("myDriver.ClassName");</code></li>
<li>Substitute the username and password you use for your database in the following: <code class="literal">"myLogin", "myPassword"</code>. <p>This is optional.</p></li>
<li>If your JDK version is above 1.5, change the variable name <code class="literal">enum</code> in <code class="literal">OutputApplet.java</code> to some other variable name because, as of JDK release 5 <code class="literal">enum</code> is a keyword and can not be used as an identifier.</li>
</ol>
</div>
</div>
<div class="sect3" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h4 class="title"><a id="idp50704248"></a>Building and Running the JDBC Sample code</h4>
</div>
</div>
</div>
<p>See <a class="xref" href="build_unix_sql.html#build_unix_jdbc" title="Building the JDBC Driver">Building the JDBC Driver
</a> for instructions about building JDBC driver.</p>
<p>To build and run the JDBC examples do the following:</p>
<div class="orderedlist">
<ol type="1">
<li>Copy <code class="literal">build_unix/jdbc/sqlite.jar</code> and <code class="literal">build_unix/jdbc/.libs/libsqlite_jni.so</code> to the <code class="literal">jdbc_ex</code> directory.</li>
<li>In the <code class="literal">jdbc_ex</code> directory, run the following commands:
<pre class="programlisting">
$ javac -classpath ./sqlite.jar *.java
$ java -classpath .:sqlite.jar -Djava.library.path=. \
<ClassName, eg. CreateCoffees>
</pre></li>
<li>After you run the CreateCoffees example, use the <code class="literal">dbsql</code> executable to open the <code class="literal">myDataSource</code> database file and check if the table <code class="literal">COFFEES</code> has been successfully created in the database.
<pre class="programlisting">
$ dbsql myDataSourcedbsql> .tables
COFFEES
dbsql> .dump
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE COFFEES (COF_NAME varchar(32),\
SUP_ID int, PRICE float, SALES int, TOTAL int);
COMMIT;
dbsql>
</pre></li>
<li>Repeat step 3 to run other examples.
<p>Note: Some examples like AutoGenKeys are not yet supported by BDB JDBC driver. The <code class="literal">SQLFeatureNotSupportedException</code> is displayed for those unsupported examples.</p></li>
</ol>
</div>
</div>
</div>
<div class="sect2" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a id="idp50727840"></a>Building the ODBC Driver</h3>
</div>
</div>
</div>
<p>
This section describes the steps required to build the ODBC driver.</p>
<div class="sect3" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h4 class="title"><a id="idp50726544"></a>Configuring Your System</h4>
</div>
</div>
</div>
<p>
To configure your system prior to building the ODBC driver, do the following:
</p>
<div class="orderedlist">
<ol type="1">
<li>Download and install the latest <a class="ulink" href="http://www.unixodbc.org" target="_top">unixODBC</a> if ODBC is not already installed on your system.</li>
<li>Configure the ODBC server to work with SQLite databases. Follow <a class="ulink" href="http://www.ch-werner.de/sqliteodbc/html/index.html" target="_top">these instructions</a> from Christian Werner.</li>
</ol>
</div>
</div>
<div class="sect3" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h4 class="title"><a id="idp50738632"></a>Building the Library</h4>
</div>
</div>
</div>
<p>To build the library, do the following</p>
<pre class="programlisting">
$ cd db-5.1.XX/build_unix
$ CFLAGS="-fPIC" ../dist/configure --enable-sql_compat --disable-shared
$ make
$ cd ..lang/sql/odbc
$ CFLAGS="-DHAVE_ERRNO_H -I../../../build_unix -I../../../src/dbinc \
-I../sqlite/src" LDFLAGS="../../../build_unix/libdb-5.1.a" \
./configure --with-sqlite3=../generated
$ make
</pre>
<p>The <code class="literal">libsqlite3odbc.so</code> library containing a statically linked version of Berkeley DB SQL is now built.</p>
<p>NOTE: The final <code class="literal">make</code> command above is known to generate a warning when using GCC. The warning states: <code class="literal">Warning: Linking the shared library libsqlite3odbc.la against the static library ../../build_unix/libdb-5.1.a is not portable!</code>. It is generally safe to ignore the warning when using the generated library.</p>
</div>
<div class="sect3" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h4 class="title"><a id="idp50739712"></a>Testing the ODBC Driver</h4>
</div>
</div>
</div>
<p>The steps to verify that the installed driver works are as follows:</p>
<div class="orderedlist">
<ol type="1">
<li>Alter the <code class="literal">/etc/odbcinst.ini</code> and <code class="literal">~/.odbc.ini</code> configuration files to refer to the libsqlite3odbc.so file built above.</li>
<li><p>Create a data source, and launch a data source viewer application by doing the following:</p><pre class="programlisting">$ mkdir ~/databases
$ cd ~/databases
$ /path/to/Berkeley DB/build_unix/sqlite3 mytest.db
dbsql> CREATE TABLE t1(x);
dbsql> .quit;
$ DataManager
</pre>
The final step opens a GUI application that displays ODBC data sources on a system. You should be able to find the <code class="literal">mytest.db</code> data source just created.</li>
</ol>
</div>
</div>
</div>
</div>
<div class="navfooter">
<hr />
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left"><a accesskey="p" href="build_unix_conf.html">Prev</a> </td>
<td width="20%" align="center">
<a accesskey="u" href="build_unix.html">Up</a>
</td>
<td width="40%" align="right"> <a accesskey="n" href="build_unix_small.html">Next</a></td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Configuring Berkeley DB </td>
<td width="20%" align="center">
<a accesskey="h" href="index.html">Home</a>
</td>
<td width="40%" align="right" valign="top"> Building a small memory footprint library</td>
</tr>
</table>
</div>
</body>
</html>
|