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 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478
|
<?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>Building the SQL API</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_win.html" title="Chapter 4. Building Berkeley DB for Windows" />
<link rel="prev" href="build_win_csharp.html" title="Building the C# API" />
<link rel="next" href="build_win_tcl.html" title="Building the Tcl API" />
</head>
<body>
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr>
<th colspan="3" align="center">Building the SQL API</th>
</tr>
<tr>
<td width="20%" align="left"><a accesskey="p" href="build_win_csharp.html">Prev</a> </td>
<th width="60%" align="center">Chapter 4.
Building Berkeley DB for Windows
</th>
<td width="20%" align="right"> <a accesskey="n" href="build_win_tcl.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_win_sql"></a>Building the SQL API</h2>
</div>
</div>
</div>
<div class="toc">
<dl>
<dt>
<span class="sect2">
<a href="build_win_sql.html#idp50449688">Binary Compatibility With SQLite</a>
</span>
</dt>
<dt>
<span class="sect2">
<a href="build_win_sql.html#idp50427488">Setting Preprocessor Flags
</a>
</span>
</dt>
<dt>
<span class="sect2">
<a href="build_win_sql.html#idp50447848">Enabling Extensions</a>
</span>
</dt>
<dt>
<span class="sect2">
<a href="build_win_sql.html#build_jdbc">Building the JDBC Driver</a>
</span>
</dt>
<dt>
<span class="sect2">
<a href="build_win_sql.html#idp50458920">Using the JDBC Driver</a>
</span>
</dt>
<dt>
<span class="sect2">
<a href="build_win_sql.html#idp50482120">Building the ODBC Driver</a>
</span>
</dt>
<dt>
<span class="sect2">
<a href="build_win_sql.html#idp50455320"> Using the ADO.NET Driver
</a>
</span>
</dt>
</dl>
</div>
<p>
SQL support is built as part of the default build on Windows.
For information on the build instructions, see <a class="xref" href="build_win.html" title="Chapter 4. Building Berkeley DB for Windows">
Building Berkeley DB for Windows
</a>.
</p>
<p>
The SQL library is built as <code class="literal">libdb_sql51.dll</code>
in the Release mode or <code class="literal">libdb_sql51d.dll</code> in
the Debug mode. An SQL command line interpreter called
<code class="literal">dbsql.exe</code> is also built.
</p>
<div class="sect2" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a id="idp50449688"></a>Binary Compatibility With SQLite</h3>
</div>
</div>
</div>
<p>
<code class="literal">libdb_sql51.dll</code> is compatible with
<code class="literal">sqlite3.dll</code>. You can copy
<code class="literal">libdb_sql51.dll</code> to
<code class="literal">sqlite3.dll</code> and
<code class="literal">dbsql.exe</code> to
<code class="literal">sqlite3.exe</code>, and use these applications
as a replacement for the standard SQLite binaries with the same
names. However, if you want to do this, then any legacy data in use by
those tools must be migrated from the standard SQLite database
to a Berkeley DB SQL database <span class="emphasis"><em>before</em></span> you
replace the standard SQLite dll and executable with the
Berkeley DB equivalent. For information on migrating data from
standard SQLite databases to a Berkeley DB SQL database, see
the <em class="citetitle">Berkeley DB Getting Started with the SQL APIs</em> guide.
</p>
<div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Warning</h3>
<p>
Rename your dlls and executables to the standard SQLite
names with <span class="emphasis"><em>extreme</em></span> care. Doing this
will cause all existing tools to break that currently
have data stored in a standard SQLite database.
</p>
<p>
<span class="emphasis"><em>
For best results, rename your dlls and command
line tool to use the standard SQLite names only if you
know there are no other tools on your production
platform that rely on standard SQLite.
</em></span>
</p>
</div>
</div>
<div class="sect2" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a id="idp50427488"></a>Setting Preprocessor Flags
</h3>
</div>
</div>
</div>
<p>By default, Berkeley DB SQL generates each table as a subdatabase in a single file. To generate each table in a separate file, specify <span class="emphasis"><em>BDBSQL_FILE_PER_TABLE</em></span> in <span class="emphasis"><em>Preprocessor Definitions </em></span>of the <code class="literal">db_sql</code> project. </p>
<p>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. Do not add or delete files from the database directory. Adding or deleting
files may corrupt the database. To backup just 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.
</p>
</div>
<div class="sect2" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a id="idp50447848"></a>Enabling Extensions</h3>
</div>
</div>
</div>
<p>The Berkeley DB SQL API provides extensions such as full text search and R-Tree index. To enable these extensions, do the following:
</p>
<div class="orderedlist">
<ol type="1">
<li>
Open the Berkeley DB solution in Visual Studio.
</li>
<li>
Specify <span class="emphasis"><em>SQLITE_ENABLE_FTS3</em></span> or <span class="emphasis"><em>SQLITE_ENABLE_RTREE</em></span> in <span class="emphasis"><em>Preprocessor Definitions</em></span> of the <code class="literal">db_sql</code> project.
</li>
<li>
Re-build the <code class="literal">db_sql</code> project.
</li>
</ol>
</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_jdbc"></a>Building the JDBC Driver</h3>
</div>
</div>
</div>
<p>
This section describes the steps to build the JDBC driver.</p>
<div class="orderedlist">
<ol type="1">
<li>
Configure your build environment. For information on how to configure to build Java applications, see <a class="xref" href="build_win_java.html" title="Building the Java API">Building the Java API</a>.
</li>
<li>
Build the SQL project in Debug mode.
</li>
<li>Open Visual Studio.
</li>
<li>
Select <span class="emphasis"><em>File</em></span> -> <span class="emphasis"><em>Add</em></span> -> <span class="emphasis"><em>Existing Project</em></span>.
</li>
<li>
Select <code class="filename">build_windows/db_sql_jdbc.vcproj</code> and add it to the Berkeley_DB solution.
This adds the <code class="filename">db_sql_jdbc</code> Visual Studio project to the Berkeley_DB solution file.
</li>
<li>
Build the <code class="filename">db_sql_jdbc</code> project in Visual Studio.
</li>
</ol>
</div>
<p>
You can test the build by entering the following commands from the <code class="literal">db\build_windows\Win32\Debug</code> directory:
</p>
<table class="simplelist" border="0" summary="Simple list">
<tr>
<td> javac -cp ".;jdbc.jar" -d . ..\..\..\sql\jdbc\test3.java </td>
</tr>
<tr>
<td>java -cp ".;jdbc.jar" test3 </td>
</tr>
</table>
<p>
</p>
<p>
When building the JDBC driver, if you may see an error message: "SQLite.JDBC2x.JDBCConnection is not abstract and does not override abstract method in java.sql.Connection".
</p>
<p>This means that your Java environment requires <code class="literal">JDBC2z.*</code> instead of <code class="literal">JDBC2x.*</code>. To resolve this problem, do the following:
</p>
<div class="itemizedlist">
<ul type="disc">
<li>
In the Solution Explorer, right-click the <code class="literal">db_sql_jdbc</code> project and select <span class="emphasis"><em>properties</em></span>.
</li>
<li>
In the <span class="emphasis"><em>Configuration Properties -> Build Events -> Pre-Build Event</em></span> section, alter the command to refer to <code class="literal">JDBC2z</code> instead of <code class="literal">JDBC2x</code>.
</li>
</ul>
</div>
</div>
<div class="sect2" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a id="idp50458920"></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="idp50454376"></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="idp50462240"></a>Modifying Sample Code</h4>
</div>
</div>
</div>
<p>Before running the sample 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">"D:\\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="idp50468544"></a>Building and Running the JDBC Sample code</h4>
</div>
</div>
</div>
<p>See <a class="xref" href="build_win_sql.html#build_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>In the <code class="literal">db\build_windows\Win32\Debug</code> directory, run following commands:
<pre class="programlisting">
$ javac -classpath ".;jdbc.jar" -d . \path\to\jdbc_ex\*.java
$ java -classpath ".;jdbc.jar" <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 2 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="idp50482120"></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="idp50479984"></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 SQLite ODBC driver Windows installer package for <a class="ulink" href="http://www.ch-werner.de/sqliteodbc/sqliteodbc.exe" target="_top">32 bit Windows</a> or <a class="ulink" href="http://www.ch-werner.de/sqliteodbc/sqliteodbc_w64.exe" target="_top">64 bit Windows</a>.
</li>
<li>
Download and install the latest <a class="ulink" href="http://www.microsoft.com/downloads/details.aspx?familyid=5067faf8-0db4-429a-b502-de4329c8c850" target="_top">Microsoft Data Access Components (MDAC) SDK</a>. The MDAC SDK is only required for testing the installation.
</li>
</ol>
</div>
</div>
<div class="sect3" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h4 class="title"><a id="idp50493096"></a>Building the Library</h4>
</div>
</div>
</div>
<div class="orderedlist">
<ol type="1">
<li>
Build the SQL project in Release mode. See <a class="xref" href="build_win_sql.html" title="Building the SQL API">Building the SQL API</a>.
</li>
<li>Open Visual Studio.</li>
<li>Load the Berkeley_DB solution file into Visual Studio.</li>
<li>Set the build target to <span class="emphasis"><em>Release</em></span></li>
<li>Build the solution.</li>
<li>
Select <span class="emphasis"><em>File</em></span> -> <span class="emphasis"><em>Add</em></span> -> <span class="emphasis"><em>Existing Project</em></span>.
</li>
<li>
Select <code class="filename">build_windows/db_sql_odbc.vcproj</code> and add it to the Berkeley_DB solution.
This adds the <code class="filename">db_sql_odbc</code> Visual Studio project to the Berkeley_DB solution file.
</li>
<li>Build the <code class="filename">db_sql_odbc</code> project. This can be done by right-clicking the <code class="filename">db_sql_odbc</code> project in the project explorer panel, and selecting <code class="literal">build</code>.</li>
</ol>
</div>
<p>The <code class="literal">sqlite3odbc.dll</code>, <code class="literal">libdb_sql51.dll</code> and <code class="literal">libdb51.dll</code> files are now built.</p>
</div>
<div class="sect3" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h4 class="title"><a id="idp50472752"></a>Installing the Library</h4>
</div>
</div>
</div>
<p>Copy the dll files built in the <span class="emphasis"><em>Building the Library</em></span> section to the Windows system folder.</p>
<p>The Windows system folder is different on different systems, but is often <code class="literal">C:\WINDOWS\System32</code>.</p>
</div>
<div class="sect3" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h4 class="title"><a id="idp50471912"></a>Testing the ODBC Install</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>Open the Unicode ODBCTest application. On Windows XP: <span class="emphasis"><em>Windows start</em></span> -> <span class="emphasis"><em>Microsoft Data Access SDK 2.8</em></span> -> <span class="emphasis"><em>ODBCTest (Unicode, x86).</em></span></li>
<li>Select the <span class="emphasis"><em>Conn</em></span> -> <span class="emphasis"><em>Full Connect...</em></span> menu item.</li>
<li>Select <code class="literal">SQLite3 Datasource</code> and click <code class="literal">OK</code>.</li>
<li>Select the <span class="emphasis"><em>Stmt</em></span> -> <span class="emphasis"><em>SQLExecDirect...</em></span> menu item.</li>
<li>Enter <code class="literal">CREATE TABLE t1(x);</code> in the <code class="literal">Statement</code> text box and click <code class="literal">OK</code>.</li>
<li>Verify that no error messages were output to the error window.</li>
</ol>
</div>
</div>
</div>
<div class="sect2" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a id="idp50455320"></a> Using the ADO.NET Driver
</h3>
</div>
</div>
</div>
<p>This section describes the steps to use the ADO.NET driver made by <a class="ulink" href="http://sqlite.phxsoftware.com" target="_top">phxsoftware</a>.
The Berkeley DB development team has tested version 1.0.66.0 of the ADO.NET driver.
</p>
<div class="orderedlist">
<ol type="1">
<li>Download and unzip <code class="literal">SQLite-1.0.66.0-binaries.zip</code>.
The .NET binary, <code class="literal">System.Data.SQLite.dll</code>, is located in the <code class="literal">ManagedOnly</code> directory.
</li>
<li>Build the Berkeley DB SQL API. For more information, see <a class="xref" href="build_win_sql.html" title="Building the SQL API">Building the SQL API</a>.
If you have installed the Windows binaries, you can ignore this step.</li>
<li>Copy <code class="literal">System.Data.SQLite.dll and libdb51.dll </code>into a directory.
If you have installed the Windows binaries, copy <code class="literal">System.Data.SQLite.dll</code> into the <code class="literal">bin</code> directory of the installation.</li>
<li> Copy <code class="literal">libdb_sql51.dll</code> to <code class="literal">sqlite3.dll</code>.
Place <code class="literal">sqlite3.dll</code> in the same directory as <code class="literal">System.Data.SQLite.dll</code>.</li>
<li>Add this directory to the environment variable PATH. Alternatively, you can copy the dlls into the directory from which the applications is run.
If you have installed binaries, the environment variable PATH is already set to include the installation's <code class="literal">bin</code> directory.
</li>
</ol>
</div>
<div class="sect3" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h4 class="title"><a id="idp50479640"></a>Running the ADO.NET Test Suite
</h4>
</div>
</div>
</div>
<p>This section describes how to run the test suite made by phxsoftware.</p>
<div class="orderedlist">
<ol type="1">
<li> Download the driver and build Berkeley DB as described above.</li>
<li>Unzip and copy <code class="literal">libdb_sql51.dll</code> and <code class="literal">libdb51.dll</code> into the <code class="literal">ManagedOnly</code> directory.</li>
<li>Copy <code class="literal">libdb_sql51.dll</code> to <code class="literal">sqlite3.dll</code>.</li>
<li>Run <code class="literal">test.exe</code> from the <code class="literal">ManagedOnly</code> directory.</li>
</ol>
</div>
<p>When running the test suite, exclude <code class="literal">LockTest</code> and <code class="literal">MultithreadingTest</code> due to differences between SQLite locking and Berkeley DB locking.
For more information, see the <a href="../bdb-sql/lockingnotes.html" class="olink">Berkeley DB SQL Guide</a>. You should also exclude <code class="literal">FunctionWithCollation</code> and
<code class="literal">FunctionWithCollation2</code> tests because they use extension functions which are not a part of the default SQLite distribution. For more information,
see <a class="ulink" href="http://www.sqlite.org/contrib" target="_top">http://www.sqlite.org/contrib.</a></p>
</div>
</div>
</div>
<div class="navfooter">
<hr />
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left"><a accesskey="p" href="build_win_csharp.html">Prev</a> </td>
<td width="20%" align="center">
<a accesskey="u" href="build_win.html">Up</a>
</td>
<td width="40%" align="right"> <a accesskey="n" href="build_win_tcl.html">Next</a></td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Building the C# API </td>
<td width="20%" align="center">
<a accesskey="h" href="index.html">Home</a>
</td>
<td width="40%" align="right" valign="top"> Building the Tcl API</td>
</tr>
</table>
</div>
</body>
</html>
|