Configuring the SQL Interface
Prev | Chapter 6. Building Berkeley DB for UNIX/POSIX | Next

## Configuring the SQL Interface

There are a set of configuration options to assist you in building the Berkeley DB SQL interface. These configuration options include:

  To build the command line interpreter dbsql, enter --enable-sql as an argument to configure. Along with dbsql, this argument also builds the libdb_sqlXX.{so|la} library, a C API library that mirrors the SQLite C API.

  To build the command line tool sqlite3, enter --enable-sql_compat as an argument to configure. sqlite3 enables you to manually enter and execute SQL commands. The sqlite3 command line tool is identical to the dbsql executable but named so that existing scripts for SQLite can easily work with Berkeley DB. Along with sqlite3, this argument also builds libsqlite3.{so|la}, a C API library. libsqlite3.{so|la} mirrors the SQLite C API, and has the same name as the library generated by an SQLite build also for ease of use with existing sripts. In addition to building sqlite3 and libsqlite3.{so|la}, the --enable-sql_compat argument also builds a libdb_sqlXX.{so|la} and dbsql, as is done with the --enable-sql argument.

  To build the Berkeley DB SQL interface test suite, enter --enable-test as an argument to configure. This argument can also be used with either --enable-sql or --enable-sql_compat to build the SQLite Tcl test runner.

The following configuration options are useful when debugging applications:

  To build Berkeley DB SQL interface with symbols for debugging enter --enable-debug as an argument to configure.
  To build Berkeley DB SQL interface with run-time debugging checks, enter --enable-diagnostic as an argument to configure.

Any arguments that you can provide to the standard SQLite configure script can also be supplied when configuring Berkeley DB SQL interface.

### Enabling Extensions

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.

  To enable building the full text search layer in the Berkeley DB interface, add the SQLITE_ENABLE_FTS3 option to the CPPFLAGS variable.

  To enable building the R-Tree layer in the Berkeley DB interface, add the SQLITE_ENABLE_RTREE option to the CPPFLAGS variable.

See the SQLite Documentation for more information on full text search and R-Tree.

### Building the JDBC Driver

This section describes how to build the JDBC driver code using `autoconf`, which is the only method supported and tested by the Berkeley DB team.

To build the JDBC driver, you must have Sun Java Development Kit 1.1 or above installed.

    cd build_unix
    CFLAGS="-fPIC" ../dist/configure --enable-sql_compat --disable-shared
    make
    cd ../sql/jdbc
    CFLAGS="-DHAVE_SQLITE3_MALLOC -DHAVE_ERRNO_H \
           -I../../build_unix -I../../dbinc" \
           LDFLAGS="../../build_unix/libdb-5.0.a" \
           ./configure --with-sqlite3=../generated
    make

Note: The defined process is known to generate a link warning during the final step. The warning is generated by libtool when linking a library without a library information file present (.la). It is safe to ignore the warning. If you have problems when using the JDBC driver, use the shared library version of Berkeley DB.

You can test the build by entering the following commands from the `sql/jdbc` directory:

javac -classpath ./sqlite.jar test3.java
java -Djava.library.path=./.libs -classpath ./sqlite.jar:. test3

### Building the ODBC Driver

This section describes the steps required to build the ODBC driver.

#### Configuring Your System

To configure your system prior to building the ODBC driver, do the following:

1. Download and install the latest unixODBC if ODBC is not already installed on your system.
2. Configure the ODBC server to work with SQLite databases. Follow these instructions from Christian Werner.

#### Building the Library

To build the library, do the following

    $ cd db-5.0.XX/build_unix
    $ CFLAGS="-fPIC" ../dist/configure --enable-sql_compat --disable-shared
    $ make
    $ cd ../sql/odbc
    $ CFLAGS="-DHAVE_ERRNO_H -I../../build_unix -I../../dbinc \
             -I../sqlite/src" LDFLAGS="../../build_unix/libdb-5.0.a" \
             ./configure --with-sqlite3=../generated
    $ make

The `libsqlite3odbc.so` library containing a statically linked version of Berkeley DB SQL is now built.

NOTE: The final `make` command above is known to generate a warning when using GCC. The warning states: `Warning: Linking the shared library libsqlite3odbc.la against the static library ../../build_unix/libdb-5.0.a is not portable!`. It is generally safe to ignore the warning when using the generated library.

#### Testing the ODBC Driver

The steps to verify that the installed driver works are as follows:

1. Alter the `/etc/odbcinst.ini` and `~/.odbc.ini` configuration files to refer to the libsqlite3odbc.so file built above.

2. Create a data source, and launch a data source viewer application by doing the following:

       $ mkdir ~/databases
       $ cd ~/databases
       $ /path/to/Berkeley DB/build_unix/sqlite3 mytest.db
       dbsql> CREATE TABLE t1(x);
       dbsql> .quit;
       $ DataManager

   The final step opens a GUI application that displays ODBC data sources on a system. You should be able to find the `mytest.db` data source just created.

Prev | Up | Next
Configuring Berkeley DB | Home | Building a small memory footprint library