Commits

Grace Batumbya  committed ce49c53

Fixes #116: Move to JDBC 4.
Driver is packaged as sqlite-jdbc4-VERSION.jar
At least JDK 6 is needed to build the driver.

  • Participants
  • Parent commits 417045e
  • Branches feature/jdbc4

Comments (0)

Files changed (48)

 Work in progress:
 
+* Issue #116: Move to Java 6
+    * Created new branch refactor/JDBC4
+    * Jar is packaged as sqlite-jdbc4*
 * Issue #65 - Calling Statement.setMaxRows(N) has the effect of returning N+1 rows
 * Issue #64 - ArrayIndexOutOfBoundsException when calling ResultSetMetaData.getScale() for VARCHAR column types
 * Issue #56 - Implement getBinaryStream() in RS.java
 
 $(SQLITE_ARCHIVE):
 	@mkdir -p $(@D)
-	curl -o$@ http://www.sqlite.org/$(SQLITE_AMAL_PREFIX).zip
+	curl -o$@ http://www.sqlite.org/2013/$(SQLITE_AMAL_PREFIX).zip
 
 $(SQLITE_UNPACKED): $(SQLITE_ARCHIVE)
 	unzip -qo $< -d $(TARGET)
 	@mkdir -p $(@D)
 	$(JAVAC) -source 1.5 -target 1.5 -sourcepath $(SRC) -d $(SQLITE_OUT) $<
 
-jni-header: $(SRC)/org/sqlite/NativeDB.h
+jni-header: $(SRC)/org/sqlite/core/NativeDB.h
 
-$(SQLITE_OUT)/NativeDB.h: $(SQLITE_OUT)/org/sqlite/NativeDB.class
-	$(JAVAH) -classpath $(SQLITE_OUT) -jni -o $@ org.sqlite.NativeDB
+$(SQLITE_OUT)/NativeDB.h: $(SQLITE_OUT)/org/sqlite/core/NativeDB.class
+	$(JAVAH) -classpath $(SQLITE_OUT) -jni -o $@ org.sqlite.core.NativeDB
 
 test:
 	mvn test
 	    $(SQLITE_FLAGS) \
 	    $(SQLITE_OUT)/sqlite3.c
 
-$(SQLITE_OUT)/$(LIBNAME): $(SQLITE_OUT)/sqlite3.o $(SRC)/org/sqlite/NativeDB.c $(SQLITE_OUT)/NativeDB.h
+$(SQLITE_OUT)/$(LIBNAME): $(SQLITE_OUT)/sqlite3.o $(SRC)/org/sqlite/core/NativeDB.c $(SQLITE_OUT)/NativeDB.h
 	@mkdir -p $(@D)
-	$(CC) $(CFLAGS) -c -o $(SQLITE_OUT)/NativeDB.o $(SRC)/org/sqlite/NativeDB.c
+	$(CC) $(CFLAGS) -c -o $(SQLITE_OUT)/NativeDB.o $(SRC)/org/sqlite/core/NativeDB.c
 	$(CC) $(CFLAGS) -o $@ $(SQLITE_OUT)/*.o $(LINKFLAGS)
 	$(STRIP) $@
 
 
 News
 ====
+*   2014 January 5th: [sqlite-jdbc4-3.8.2-SNAPSHOT](https://bitbucket.org/xerial/sqlite-jdbc/downloads/sqlite-jdbc-3.8.2-SNAPSHOT.jar) Introduced JDBC4 version of driver. (Requires at least Java 6).
+    *   Source code is on branch [feature/jdbc4](https://bitbucket.org/xerial/sqlite-jdbc/branch/feature/jdbc4)
 *   2013 August 27th: sqlite-jdbc-3.8.0 snapshot version is [available](https://oss.sonatype.org/content/repositories/snapshots/org/xerial/sqlite-jdbc/3.8.0-SNAPSHOT/)
 *   2013 August 19th: [sqlite-jdbc-3.7.15-M1](https://bitbucket.org/xerial/sqlite-jdbc/downloads/sqlite-jdbc-3.7.15-M1.jar)
 *   2013 March 24th : [sqlite-jdbc-3.7.15-SNAPSHOT-2](https://bitbucket.org/xerial/sqlite-jdbc/downloads/sqlite-jdbc-3.7.15-SNAPSHOT-2.jar)
-version=3.7.15
+version=3.8.2
 
   <modelVersion>4.0.0</modelVersion>
   <groupId>org.xerial</groupId>
-  <artifactId>sqlite-jdbc</artifactId>
-  <version>3.7.15-SNAPSHOT</version>
+  <artifactId>sqlite-jdbc4</artifactId>
+  <version>3.8.2-SNAPSHOT</version>
   <name>SQLite JDBC</name>
   <description>SQLite JDBC library</description>
 
         <artifactId>maven-compiler-plugin</artifactId>
 	<version>3.1</version>
         <configuration>
-          <compilerArgument>
-            -Xbootclasspath/p:${basedir}/lib/jdbc-api-1.4.jar
-          </compilerArgument>
           <source>1.5</source>
-          <target>1.5</target>
+          <target>1.6</target>
         </configuration>
       </plugin>
       
 
   <dependencies>
     <dependency>
-      <groupId>org.xerial.thirdparty</groupId>
-      <artifactId>jdbc-api</artifactId>
-      <version>1.4</version>
-      <scope>provided</scope>
-    </dependency>
-    <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>4.8.2</version>

File src/main/java/org/sqlite/Codes.java

-/*
- * Copyright (c) 2007 David Crawshaw <david@zentus.com>
- * 
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-package org.sqlite;
-
-interface Codes
-{
-    /** Successful result */
-    public static final int SQLITE_OK         =   0;
-
-    /** SQL error or missing database */
-    public static final int SQLITE_ERROR      =   1;
-
-    /** An internal logic error in SQLite */
-    public static final int SQLITE_INTERNAL   =   2;
-
-    /** Access permission denied */
-    public static final int SQLITE_PERM       =   3;
-
-    /** Callback routine requested an abort */
-    public static final int SQLITE_ABORT      =   4;
-
-    /** The database file is locked */
-    public static final int SQLITE_BUSY       =   5;
-
-    /** A table in the database is locked */
-    public static final int SQLITE_LOCKED     =   6;
-
-    /** A malloc() failed */
-    public static final int SQLITE_NOMEM      =   7;
-
-    /** Attempt to write a readonly database */
-    public static final int SQLITE_READONLY   =   8;
-
-    /** Operation terminated by sqlite_interrupt() */
-    public static final int SQLITE_INTERRUPT  =   9;
-
-    /** Some kind of disk I/O error occurred */
-    public static final int SQLITE_IOERR      =  10;
-
-    /** The database disk image is malformed */
-    public static final int SQLITE_CORRUPT    =  11;
-
-    /** (Internal Only) Table or record not found */
-    public static final int SQLITE_NOTFOUND   =  12;
-
-    /** Insertion failed because database is full */
-    public static final int SQLITE_FULL       =  13;
-
-    /** Unable to open the database file */
-    public static final int SQLITE_CANTOPEN   =  14;
-
-    /** Database lock protocol error */
-    public static final int SQLITE_PROTOCOL   =  15;
-
-    /** (Internal Only) Database table is empty */
-    public static final int SQLITE_EMPTY      =  16;
-
-    /** The database schema changed */
-    public static final int SQLITE_SCHEMA     =  17;
-
-    /** Too much data for one row of a table */
-    public static final int SQLITE_TOOBIG     =  18;
-
-    /** Abort due to constraint violation */
-    public static final int SQLITE_CONSTRAINT =  19;
-
-    /** Data type mismatch */
-    public static final int SQLITE_MISMATCH   =  20;
-
-    /** Library used incorrectly */
-    public static final int SQLITE_MISUSE     =  21;
-
-    /** Uses OS features not supported on host */
-    public static final int SQLITE_NOLFS      =  22;
-
-    /** Authorization denied */
-    public static final int SQLITE_AUTH       =  23;
-
-    /** sqlite_step() has another row ready */
-    public static final int SQLITE_ROW        =  100;
-
-    /** sqlite_step() has finished executing */
-    public static final int SQLITE_DONE       =  101;
-
-
-    // types returned by sqlite3_column_type()
-
-    public static final int SQLITE_INTEGER    =  1;
-    public static final int SQLITE_FLOAT      =  2;
-    public static final int SQLITE_TEXT       =  3;
-    public static final int SQLITE_BLOB       =  4;
-    public static final int SQLITE_NULL       =  5;
-}

File src/main/java/org/sqlite/DB.java

-/*
- * Copyright (c) 2007 David Crawshaw <david@zentus.com>
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-package org.sqlite;
-
-import java.sql.BatchUpdateException;
-import java.sql.SQLException;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-/*
- * This class is the interface to SQLite. It provides some helper functions
- * used by other parts of the driver. The goal of the helper functions here
- * are not only to provide functionality, but to handle contractual
- * differences between the JDBC specification and the SQLite C API.
- *
- * The process of moving SQLite weirdness into this class is incomplete.
- * You'll still find lots of code in Stmt and PrepStmt that are doing
- * implicit contract conversions. Sorry.
- *
- * The subclass, NativeDB, provides the actual access to SQLite functions.
- */
-abstract class DB implements Codes
-{
-    /** The JDBC Connection that 'owns' this database instance. */
-    SQLiteConnection                          conn   = null;
-
-    /** The "begin;"and "commit;" statement handles. */
-    long                          begin  = 0;
-    long                          commit = 0;
-
-    /** Tracer for statements to avoid unfinalized statements on db close. */
-    private final Map<Long, Stmt> stmts  = new HashMap<Long, Stmt>();
-
-    // WRAPPER FUNCTIONS ////////////////////////////////////////////
-
-    /**
-     * Aborts any pending operation and returns at its earliest opportunity.
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/interrupt.html">http://www.sqlite.org/c3ref/interrupt.html</a>
-     */
-    abstract void interrupt() throws SQLException;
-
-    /**
-     * Sets a <a href="http://www.sqlite.org/c3ref/busy_handler.html">busy handler</a> that sleeps
-     * for a specified amount of time when a table is locked.
-     * @param ms Time to sleep in milliseconds.
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/busy_timeout.html">http://www.sqlite.org/c3ref/busy_timeout.html</a>
-     */
-    abstract void busy_timeout(int ms) throws SQLException;
-
-    /**
-     * Return English-language text that describes the error as either UTF-8 or UTF-16.
-     * @return Error description in English.
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/errcode.html">http://www.sqlite.org/c3ref/errcode.html</a>
-     */
-    abstract String errmsg() throws SQLException;
-
-    /**
-     * Returns the value for SQLITE_VERSION, SQLITE_VERSION_NUMBER, and SQLITE_SOURCE_ID C
-     * preprocessor macros that are associated with the library.
-     * @return Compile-time SQLite version information.
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/libversion.html">http://www.sqlite.org/c3ref/libversion.html</a>
-     * @see <a href="http://www.sqlite.org/c3ref/c_source_id.html">http://www.sqlite.org/c3ref/c_source_id.html</a>
-     */
-    abstract String libversion() throws SQLException;
-
-    /**
-     * @return Number of rows that were changed, inserted or deleted by the last
-     * SQL statement
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/changes.html">http://www.sqlite.org/c3ref/changes.html</a>
-     */
-    abstract int changes() throws SQLException;
-
-    /**
-     * @return Number of row changes caused by INSERT, UPDATE or DELETE statements
-     * since the database connection was opened.
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/total_changes.html">http://www.sqlite.org/c3ref/total_changes.html</a>
-     */
-    abstract int total_changes() throws SQLException;
-
-    /**
-     * Enables or disables the sharing of the database cache and schema data structures between
-     * connections to the same database.
-     * @param enable True to enable; false otherwise.
-     * @return <a href="http://www.sqlite.org/c3ref/c_abort.html">Result Codes</a>
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/enable_shared_cache.html">http://www.sqlite.org/c3ref/enable_shared_cache.html</a>
-     * @see org.sqlite.SQLiteErrorCode
-     */
-    abstract int shared_cache(boolean enable) throws SQLException;
-
-    /**
-     * Enables or disables loading of SQLite extensions.
-     * @param enable True to enable; false otherwise.
-     * @return <a href="http://www.sqlite.org/c3ref/c_abort.html">Result Codes</a>
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/load_extension.html">http://www.sqlite.org/c3ref/load_extension.html</a>
-     */
-    abstract int enable_load_extension(boolean enable) throws SQLException;
-
-    /**
-     * Executes an SQL statement using the process of compiling, evaluating, and destroying the
-     * prepared statement object.
-     * @param sql SQL statement to be executed.
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/exec.html">http://www.sqlite.org/c3ref/exec.html</a>
-     */
-    final synchronized void exec(String sql) throws SQLException {
-        long pointer = 0;
-        try {
-            pointer = prepare(sql);
-            switch (step(pointer)) {
-            case SQLITE_DONE:
-                ensureAutoCommit();
-                return;
-            case SQLITE_ROW:
-                return;
-            default:
-                throwex();
-            }
-        }
-        finally {
-            finalize(pointer);
-        }
-    }
-
-    /**
-     * Creates an SQLite interface to a database for the given connection.
-     * @param conn The connection.
-     * @param file The database.
-     * @param openFlags File opening configurations
-     * (<a href="http://www.sqlite.org/c3ref/c_open_autoproxy.html">http://www.sqlite.org/c3ref/c_open_autoproxy.html</a>)
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/open.html">http://www.sqlite.org/c3ref/open.html</a>
-     */
-    final synchronized void open(SQLiteConnection conn, String file, int openFlags) throws SQLException {
-        this.conn = conn;
-        _open(file, openFlags);
-    }
-
-    /**
-     * Closes a database connection and finalizes any remaining statements before
-     * the closing operation.
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/close.html">http://www.sqlite.org/c3ref/close.html</a>
-     */
-    final synchronized void close() throws SQLException {
-        // finalize any remaining statements before closing db
-        synchronized (stmts) {
-            Iterator<Map.Entry<Long, Stmt>> i = stmts.entrySet().iterator();
-            while (i.hasNext()) {
-                Map.Entry<Long, Stmt> entry = i.next();
-                Stmt stmt = entry.getValue();
-                finalize(entry.getKey().longValue());
-                if (stmt != null) {
-                    stmt.pointer = 0;
-                }
-                i.remove();
-            }
-        }
-
-        // remove memory used by user-defined functions
-        free_functions();
-
-        // clean up commit object
-        if (begin != 0) {
-            finalize(begin);
-            begin = 0;
-        }
-        if (commit != 0) {
-            finalize(commit);
-            commit = 0;
-        }
-
-        _close();
-    }
-
-    /**
-     * Complies the an SQL statement.
-     * @param stmt The SQL statement to compile.
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/prepare.html">http://www.sqlite.org/c3ref/prepare.html</a>
-     */
-    final synchronized void prepare(Stmt stmt) throws SQLException {
-        if (stmt.pointer != 0) {
-            finalize(stmt);
-        }
-        stmt.pointer = prepare(stmt.sql);
-        stmts.put(new Long(stmt.pointer), stmt);
-    }
-
-    /**
-     * Destroys a statement.
-     * @param stmt The statement to destroy.
-     * @return <a href="http://www.sqlite.org/c3ref/c_abort.html">Result Codes</a>
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/finalize.html">http://www.sqlite.org/c3ref/finalize.html</a>
-     */
-    final synchronized int finalize(Stmt stmt) throws SQLException {
-        if (stmt.pointer == 0) {
-            return 0;
-        }
-        int rc = SQLITE_ERROR;
-        try {
-            rc = finalize(stmt.pointer);
-        }
-        finally {
-            stmts.remove(new Long(stmt.pointer));
-            stmt.pointer = 0;
-        }
-        return rc;
-    }
-
-    /**
-     * Creates an SQLite interface to a database with the provided open flags.
-     * @param filename The database to open.
-     * @param openFlags File opening configurations
-     * (<a href="http://www.sqlite.org/c3ref/c_open_autoproxy.html">http://www.sqlite.org/c3ref/c_open_autoproxy.html</a>)
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/open.html">http://www.sqlite.org/c3ref/open.html</a>
-     */
-    protected abstract void _open(String filename, int openFlags) throws SQLException;
-
-    /**
-     * Closes the SQLite interface to a database.
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/close.html">http://www.sqlite.org/c3ref/close.html</a>
-     */
-    protected abstract void _close() throws SQLException;
-
-    /**
-     * Complies, evaluates, executes and commits an SQL statement.
-     * @param sql An SQL statement.
-     * @return <a href="http://www.sqlite.org/c3ref/c_abort.html">Result Codes</a>
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/exec.html">http://www.sqlite.org/c3ref/exec.html</a>
-     */
-    protected abstract int _exec(String sql) throws SQLException;
-
-    /**
-     * Complies an SQL statement.
-     * @param sql An SQL statement.
-     * @return <a href="http://www.sqlite.org/c3ref/c_abort.html">Result Codes</a>
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/prepare.html">http://www.sqlite.org/c3ref/prepare.html</a>
-     */
-    protected abstract long prepare(String sql) throws SQLException;
-
-    /**
-     * Destroys a prepared statement.
-     * @param stmt Pointer to the statement pointer.
-     * @return <a href="http://www.sqlite.org/c3ref/c_abort.html">Result Codes</a>
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/finalize.html">http://www.sqlite.org/c3ref/finalize.html</a>
-     */
-    protected abstract int finalize(long stmt) throws SQLException;
-
-    /**
-     * Evaluates a statement.
-     * @param stmt Pointer to the statement.
-     * @return <a href="http://www.sqlite.org/c3ref/c_abort.html">Result Codes</a>
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/step.html">http://www.sqlite.org/c3ref/step.html</a>
-     */
-    protected abstract int step(long stmt) throws SQLException;
-
-    /**
-     * Sets a prepared statement object back to its initial state,
-     * ready to be re-executed.
-     * @param stmt Pointer to the statement.
-     * @return <a href="http://www.sqlite.org/c3ref/c_abort.html">Result Codes</a>
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/reset.html">http://www.sqlite.org/c3ref/reset.html</a>
-     */
-    protected abstract int reset(long stmt) throws SQLException;
-
-    /**
-     * Reset all bindings on a prepared statement (reset all host parameters to NULL).
-     * @param stmt Pointer to the statement.
-     * @return <a href="http://www.sqlite.org/c3ref/c_abort.html">Result Codes</a>
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/clear_bindings.html">http://www.sqlite.org/c3ref/clear_bindings.html</a>
-     */
-    abstract int clear_bindings(long stmt) throws SQLException; // TODO remove?
-
-    /**
-     * @param stmt Pointer to the statement.
-     * @return Number of parameters in a prepared SQL.
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/bind_parameter_count.html">http://www.sqlite.org/c3ref/bind_parameter_count.html</a>
-     */
-    abstract int bind_parameter_count(long stmt) throws SQLException;
-
-    /**
-     * @param stmt Pointer to the statement.
-     * @return Number of columns in the result set returned by the prepared statement.
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/column_count.html">http://www.sqlite.org/c3ref/column_count.html</a>
-     */
-    abstract int column_count(long stmt) throws SQLException;
-
-    /**
-     * @param stmt Pointer to the statement.
-     * @param col Number of column.
-     * @return Datatype code for the initial data type of the result column.
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/column_blob.html">http://www.sqlite.org/c3ref/column_blob.html</a>
-     */
-    abstract int column_type(long stmt, int col) throws SQLException;
-
-    /**
-     * @param stmt Pointer to the statement.
-     * @param col Number of column.
-     * @return Declared type of the table column for prepared statement.
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/column_decltype.html">http://www.sqlite.org/c3ref/column_decltype.html</a>
-     */
-    abstract String column_decltype(long stmt, int col) throws SQLException;
-
-    /**
-     * @param stmt Pointer to the statement.
-     * @param col Number of column.
-     * @return Original text of column name which is the declared in the CREATE TABLE statement.
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/column_database_name.html">http://www.sqlite.org/c3ref/column_database_name.html</a>
-     */
-    abstract String column_table_name(long stmt, int col) throws SQLException;
-
-    /**
-     * @param stmt Pointer to the statement.
-     * @param col The number of column.
-     * @return Name assigned to a particular column in the result set of a SELECT statement.
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/column_name.html">http://www.sqlite.org/c3ref/column_name.html</a>
-     */
-    abstract String column_name(long stmt, int col) throws SQLException;
-
-    /**
-     * @param stmt Pointer to the statement.
-     * @param col Number of column.
-     * @return Value of the column as text data type in the result set of a SELECT statement.
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/column_blob.html">http://www.sqlite.org/c3ref/column_blob.html</a>
-     */
-    abstract String column_text(long stmt, int col) throws SQLException;
-
-    /**
-     * @param stmt Pointer to the statement.
-     * @param col Number of column.
-     * @return BLOB value of the column in the result set of a SELECT statement
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/column_blob.html">http://www.sqlite.org/c3ref/column_blob.html</a>
-     */
-    abstract byte[] column_blob(long stmt, int col) throws SQLException;
-
-    /**
-     * @param stmt Pointer to the statement.
-     * @param col Number of column.
-     * @return DOUBLE value of the column in the result set of a SELECT statement
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/column_blob.html">http://www.sqlite.org/c3ref/column_blob.html</a>
-     */
-    abstract double column_double(long stmt, int col) throws SQLException;
-
-    /**
-     * @param stmt Pointer to the statement.
-     * @param col Number of column.
-     * @return LONG value of the column in the result set of a SELECT statement.
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/column_blob.html">http://www.sqlite.org/c3ref/column_blob.html</a>
-     */
-    abstract long column_long(long stmt, int col) throws SQLException;
-
-    /**
-     * @param stmt Pointer to the statement.
-     * @param col Number of column.
-     * @return INT value of column in the result set of a SELECT statement.
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/column_blob.html">http://www.sqlite.org/c3ref/column_blob.html</a>
-     */
-    abstract int column_int(long stmt, int col) throws SQLException;
-
-    /**
-     * Binds NULL value to prepared statements with the pointer to the statement object and the
-     * index of the SQL parameter to be set to NULL.
-     * @param stmt Pointer to the statement.
-     * @param pos The index of the SQL parameter to be set to NULL.
-     * @return <a href="http://www.sqlite.org/c3ref/c_abort.html">Result Codes</a>
-     * @throws SQLException
-     */
-    abstract int bind_null(long stmt, int pos) throws SQLException;
-
-    /**
-     * Binds int value to prepared statements with the pointer to the statement object, the index of
-     * the SQL parameter to be set and the value to bind to the parameter.
-     * @param stmt Pointer to the statement.
-     * @param pos The index of the SQL parameter to be set.
-     * @param v Value to bind to the parameter.
-     * @return <a href="http://www.sqlite.org/c3ref/c_abort.html">Result Codes</a>
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/bind_blob.html">http://www.sqlite.org/c3ref/bind_blob.html</a>
-     */
-    abstract int bind_int(long stmt, int pos, int v) throws SQLException;
-
-    /**
-     * Binds long value to prepared statements with the pointer to the statement object, the index
-     * of the SQL parameter to be set and the value to bind to the parameter.
-     * @param stmt Pointer to the statement.
-     * @param pos The index of the SQL parameter to be set.
-     * @param v Value to bind to the parameter.
-     * @return <a href="http://www.sqlite.org/c3ref/c_abort.html">Result Codes</a>
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/bind_blob.html">http://www.sqlite.org/c3ref/bind_blob.html</a>
-     */
-    abstract int bind_long(long stmt, int pos, long v) throws SQLException;
-
-    /**
-     * Binds double value to prepared statements with the pointer to the statement object, the index
-     * of the SQL parameter to be set and the value to bind to the parameter.
-     * @param stmt Pointer to the statement.
-     * @param pos Index of the SQL parameter to be set.
-     * @param v Value to bind to the parameter.
-     * @return <a href="http://www.sqlite.org/c3ref/c_abort.html">Result Codes</a>
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/bind_blob.html">http://www.sqlite.org/c3ref/bind_blob.html</a>
-     */
-    abstract int bind_double(long stmt, int pos, double v) throws SQLException;
-
-    /**
-     * Binds text value to prepared statements with the pointer to the statement object, the index
-     * of the SQL parameter to be set and the value to bind to the parameter.
-     * @param stmt Pointer to the statement.
-     * @param pos Index of the SQL parameter to be set.
-     * @param v value to bind to the parameter.
-     * @return <a href="http://www.sqlite.org/c3ref/c_abort.html">Result Codes</a>
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/bind_blob.html">http://www.sqlite.org/c3ref/bind_blob.html</a>
-     */
-    abstract int bind_text(long stmt, int pos, String v) throws SQLException;
-
-    /**
-     * Binds blob value to prepared statements with the pointer to the statement object, the index
-     * of the SQL parameter to be set and the value to bind to the parameter.
-     * @param stmt Pointer to the statement.
-     * @param pos Index of the SQL parameter to be set.
-     * @param v Value to bind to the parameter.
-     * @return <a href="http://www.sqlite.org/c3ref/c_abort.html">Result Codes</a>
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/bind_blob.html">http://www.sqlite.org/c3ref/bind_blob.html</a>
-     */
-    abstract int bind_blob(long stmt, int pos, byte[] v) throws SQLException;
-
-    /**
-     * Sets the result of an SQL function as NULL with the pointer to the SQLite database context.
-     * @param context Pointer to the SQLite database context.
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/result_blob.html">http://www.sqlite.org/c3ref/result_blob.html</a>
-     */
-    abstract void result_null(long context) throws SQLException;
-
-    /**
-     * Sets the result of an SQL function as text data type with the pointer to the SQLite database
-     * context and the the result value of String.
-     * @param context Pointer to the SQLite database context.
-     * @param val Result value of an SQL function.
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/result_blob.html">http://www.sqlite.org/c3ref/result_blob.html</a>
-     */
-    abstract void result_text(long context, String val) throws SQLException;
-
-    /**
-     * Sets the result of an SQL function as blob data type with the pointer to the SQLite database
-     * context and the the result value of byte array.
-     * @param context Pointer to the SQLite database context.
-     * @param val Result value of an SQL function.
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/result_blob.html">http://www.sqlite.org/c3ref/result_blob.html</a>
-     */
-    abstract void result_blob(long context, byte[] val) throws SQLException;
-
-    /**
-     * Sets the result of an SQL function as double data type with the pointer to the SQLite
-     * database context and the the result value of double.
-     * @param context Pointer to the SQLite database context.
-     * @param val Result value of an SQL function.
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/result_blob.html">http://www.sqlite.org/c3ref/result_blob.html</a>
-     */
-    abstract void result_double(long context, double val) throws SQLException;
-
-    /**
-     * Sets the result of an SQL function as long data type with the pointer to the SQLite database
-     * context and the the result value of long.
-     * @param context Pointer to the SQLite database context.
-     * @param val Result value of an SQL function.
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/result_blob.html">http://www.sqlite.org/c3ref/result_blob.html</a>
-     */
-    abstract void result_long(long context, long val) throws SQLException;
-
-    /**
-     * Sets the result of an SQL function as int data type with the pointer to the SQLite database
-     * context and the the result value of int.
-     * @param context Pointer to the SQLite database context.
-     * @param val Result value of an SQL function.
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/result_blob.html">http://www.sqlite.org/c3ref/result_blob.html</a>
-     */
-    abstract void result_int(long context, int val) throws SQLException;
-
-    /**
-     * Sets the result of an SQL function as an error with the pointer to the SQLite database
-     * context and the the error of String.
-     * @param context Pointer to the SQLite database context.
-     * @param err Error result of an SQL function.
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/result_blob.html">http://www.sqlite.org/c3ref/result_blob.html</a>
-     */
-    abstract void result_error(long context, String err) throws SQLException;
-
-    /**
-     * @param f SQLite function object.
-     * @param arg Pointer to the parameter of the SQLite function or aggregate.
-     * @return Parameter value of the given SQLite function or aggregate in bytes data type.
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/value_blob.html">http://www.sqlite.org/c3ref/value_blob.html</a>
-     */
-    abstract int value_bytes(Function f, int arg) throws SQLException;
-
-    /**
-     * @param f SQLite function object.
-     * @param arg Pointer to the parameter of the SQLite function or aggregate.
-     * @return Parameter value of the given SQLite function or aggregate in text data type.
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/value_blob.html">http://www.sqlite.org/c3ref/value_blob.html</a>
-     */
-    abstract String value_text(Function f, int arg) throws SQLException;
-
-    /**
-     * @param f SQLite function object.
-     * @param arg Pointer to the parameter of the SQLite function or aggregate.
-     * @return Parameter value of the given SQLite function or aggregate in blob data type.
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/value_blob.html">http://www.sqlite.org/c3ref/value_blob.html</a>
-     */
-    abstract byte[] value_blob(Function f, int arg) throws SQLException;
-
-    /**
-     * @param f SQLite function object.
-     * @param arg Pointer to the parameter of the SQLite function or aggregate.
-     * @return Parameter value of the given SQLite function or aggregate in double data type
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/value_blob.html">http://www.sqlite.org/c3ref/value_blob.html</a>
-     */
-    abstract double value_double(Function f, int arg) throws SQLException;
-
-    /**
-     * @param f SQLite function object.
-     * @param arg Pointer to the parameter of the SQLite function or aggregate.
-     * @return Parameter value of the given SQLite function or aggregate in long data type.
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/value_blob.html">http://www.sqlite.org/c3ref/value_blob.html</a>
-     */
-    abstract long value_long(Function f, int arg) throws SQLException;
-
-    /**
-     * Accesses the parameter values on the function or aggregate in int data type with the function
-     * object and the parameter value.
-     * @param f SQLite function object.
-     * @param arg Pointer to the parameter of the SQLite function or aggregate.
-     * @return Parameter value of the given SQLite function or aggregate.
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/value_blob.html">http://www.sqlite.org/c3ref/value_blob.html</a>
-     */
-    abstract int value_int(Function f, int arg) throws SQLException;
-
-    /**
-     * @param f SQLite function object.
-     * @param arg Pointer to the parameter of the SQLite function or aggregate.
-     * @return Parameter datatype of the function or aggregate in int data type.
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/value_blob.html">http://www.sqlite.org/c3ref/value_blob.html</a>
-     */
-    abstract int value_type(Function f, int arg) throws SQLException;
-
-    /**
-     * Create a user defined function with given function name and the function object.
-     * @param name The function name to be created.
-     * @param f SQLite function object.
-     * @return <a href="http://www.sqlite.org/c3ref/c_abort.html">Result Codes</a>
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/create_function.html">http://www.sqlite.org/c3ref/create_function.html</a>
-     */
-    abstract int create_function(String name, Function f) throws SQLException;
-
-    /**
-     * De-registers a user defined function
-     * @param name Name of the function to de-registered.
-     * @return <a href="http://www.sqlite.org/c3ref/c_abort.html">Result Codes</a>
-     * @throws SQLException
-     */
-    abstract int destroy_function(String name) throws SQLException;
-
-    /**
-     * Unused as we use the user_data pointer to store a single word.
-     * @throws SQLException
-     */
-    abstract void free_functions() throws SQLException;
-
-    /**
-     * @param dbName Database name to be backed up.
-     * @param destFileName Target backup file name.
-     * @param observer ProgressObserver object.
-     * @return <a href="http://www.sqlite.org/c3ref/c_abort.html">Result Codes</a>
-     * @throws SQLException
-     *
-     */
-    abstract int backup(String dbName, String destFileName, ProgressObserver observer) throws SQLException;
-
-    /**
-     * @param dbName Database name for restoring data.
-     * @param sourceFileName Source file name.
-     * @param observer ProgressObserver object.
-     * @return <a href="http://www.sqlite.org/c3ref/c_abort.html">Result Codes</a>
-     * @throws SQLException
-     *
-     */
-    abstract int restore(String dbName, String sourceFileName, ProgressObserver observer) throws SQLException;
-
-    public static interface ProgressObserver
-    {
-        public void progress(int remaining, int pageCount);
-    }
-
-    /**
-     * Returns an array describing the attributes (not null, primary key and auto increment) of columns.
-     * @param stmt Pointer to the statement.
-     * @return Column attribute array.<br/>
-     * index[col][0] = true if column constrained NOT NULL;<br/>
-     * index[col][1] = true if column is part of the primary key; <br/>
-     * index[col][2] = true if column is auto-increment.
-     * @throws SQLException
-     */
-    abstract boolean[][] column_metadata(long stmt) throws SQLException;
-
-    // COMPOUND FUNCTIONS ////////////////////////////////////////////
-
-    /**
-     * Returns an array of column names in the result set of the SELECT statement.
-     * @param stmt Stmt object.
-     * @return String array of column names.
-     * @throws SQLException
-     */
-    final synchronized String[] column_names(long stmt) throws SQLException {
-        String[] names = new String[column_count(stmt)];
-        for (int i = 0; i < names.length; i++) {
-            names[i] = column_name(stmt, i);
-        }
-        return names;
-    }
-
-    /**
-     * Bind values to prepared statements
-     * @param stmt Pointer to the statement.
-     * @param pos Index of the SQL parameter to be set to NULL.
-     * @param v Value to bind to the parameter.
-     * @return <a href="http://www.sqlite.org/c3ref/c_abort.html">Result Codes</a>
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/bind_blob.html">http://www.sqlite.org/c3ref/bind_blob.html</a>
-     */
-    final synchronized int sqlbind(long stmt, int pos, Object v) throws SQLException {
-        pos++;
-        if (v == null) {
-            return bind_null(stmt, pos);
-        }
-        else if (v instanceof Integer) {
-            return bind_int(stmt, pos, ((Integer) v).intValue());
-        }
-        else if (v instanceof Short) {
-            return bind_int(stmt, pos, ((Short) v).intValue());
-        }
-        else if (v instanceof Long) {
-            return bind_long(stmt, pos, ((Long) v).longValue());
-        }
-        else if (v instanceof Float) {
-            return bind_double(stmt, pos, ((Float) v).doubleValue());
-        }
-        else if (v instanceof Double) {
-            return bind_double(stmt, pos, ((Double) v).doubleValue());
-        }
-        else if (v instanceof String) {
-            return bind_text(stmt, pos, (String) v);
-        }
-        else if (v instanceof byte[]) {
-            return bind_blob(stmt, pos, (byte[]) v);
-        }
-        else {
-            throw new SQLException("unexpected param type: " + v.getClass());
-        }
-    }
-
-    /**
-     * Submits a batch of commands to the database for execution.
-     * @see java.sql.Statement#executeBatch()
-     * @param stmt Pointer of Stmt object.
-     * @param count Number of SQL statements.
-     * @param vals Array of parameter values.
-     * @return Array of the number of rows changed or inserted or deleted for each command if all
-     *         commands execute successfully;
-     * @throws SQLException
-     */
-    final synchronized int[] executeBatch(long stmt, int count, Object[] vals) throws SQLException {
-        if (count < 1) {
-            throw new SQLException("count (" + count + ") < 1");
-        }
-
-        final int params = bind_parameter_count(stmt);
-
-        int rc;
-        int[] changes = new int[count];
-
-        try {
-            for (int i = 0; i < count; i++) {
-                reset(stmt);
-                for (int j = 0; j < params; j++) {
-                    if (sqlbind(stmt, j, vals[(i * params) + j]) != SQLITE_OK) {
-                        throwex();
-                    }
-                }
-
-                rc = step(stmt);
-                if (rc != SQLITE_DONE) {
-                    reset(stmt);
-                    if (rc == SQLITE_ROW) {
-                        throw new BatchUpdateException("batch entry " + i + ": query returns results", changes);
-                    }
-                    throwex();
-                }
-
-                changes[i] = changes();
-            }
-        }
-        finally {
-            ensureAutoCommit();
-        }
-
-        reset(stmt);
-        return changes;
-    }
-
-    /**
-     * @see <a href="http://www.sqlite.org/c_interface.html#sqlite_exec">http://www.sqlite.org/c_interface.html#sqlite_exec</a>
-     * @param stmt Stmt object.
-     * @param vals Array of parameter values.
-     * @return True if a row of ResultSet is ready; false otherwise.
-     * @throws SQLException
-     */
-    final synchronized boolean execute(Stmt stmt, Object[] vals) throws SQLException {
-        if (vals != null) {
-            final int params = bind_parameter_count(stmt.pointer);
-            if (params != vals.length) {
-                throw new SQLException("assertion failure: param count (" + params + ") != value count (" + vals.length
-                        + ")");
-            }
-
-            for (int i = 0; i < params; i++) {
-                if (sqlbind(stmt.pointer, i, vals[i]) != SQLITE_OK) {
-                    throwex();
-                }
-            }
-        }
-
-        int statusCode = step(stmt.pointer);
-        switch (statusCode) {
-        case SQLITE_DONE:
-            reset(stmt.pointer);
-            ensureAutoCommit();
-            return false;
-        case SQLITE_ROW:
-            return true;
-        case SQLITE_BUSY:
-        case SQLITE_LOCKED:
-        case SQLITE_MISUSE:
-            throw newSQLException(statusCode);
-        default:
-            finalize(stmt);
-            throw newSQLException(statusCode);
-        }
-
-    }
-
-    /**
-     * Executes the given SQL statement using the one-step query execution interface.
-     * @param sql SQL statement to be executed.
-     * @return True if a row of ResultSet is ready; false otherwise.
-     * @throws SQLException
-     * @see <a href="http://www.sqlite.org/c3ref/exec.html">http://www.sqlite.org/c3ref/exec.html</a>
-     */
-    final synchronized boolean execute(String sql) throws SQLException {
-        int statusCode = _exec(sql);
-        switch (statusCode) {
-        case SQLITE_OK:
-            return false;
-        case SQLITE_DONE:
-            ensureAutoCommit();
-            return false;
-        case SQLITE_ROW:
-            return true;
-        default:
-            throw newSQLException(statusCode);
-        }
-    }
-
-    /**
-     * Execute an SQL INSERT, UPDATE or DELETE statement with the Stmt object and an array of
-     * parameter values of the SQL statement..
-     * @param stmt Stmt object.
-     * @param vals Array of parameter values.
-     * @return Number of database rows that were changed or inserted or deleted by the most
-     *         recently completed SQL.
-     * @throws SQLException
-     */
-    final synchronized int executeUpdate(Stmt stmt, Object[] vals) throws SQLException {
-        if (execute(stmt, vals)) {
-            throw new SQLException("query returns results");
-        }
-        reset(stmt.pointer);
-        return changes();
-    }
-
-    /**
-     * Throws SQLException with error message.
-     * @throws SQLException
-     */
-    final void throwex() throws SQLException {
-        throw new SQLException(errmsg());
-    }
-
-    /**
-     * Throws SQLException with error code.
-     * @param errorCode Error code to be passed.
-     * @throws SQLException
-     */
-    final void throwex(int errorCode) throws SQLException {
-        throw newSQLException(errorCode);
-    }
-
-    /**
-     * Throws SQL Exception with error code and message.
-     * @param errorCode Error code to be passed.
-     * @param errorMessage Error message to be passed.
-     * @throws SQLException
-     */
-    final void throwex(int errorCode, String errorMessage) throws SQLException {
-        throw newSQLException(errorCode, errorMessage);
-    }
-
-    /**
-     * Throws formated SQLException with error code and message.
-     * @param errorCode Error code to be passed.
-     * @param errorMessage Error message to be passed.
-     * @return Formated SQLException with error code and message.
-     * @throws SQLException
-     */
-    static SQLException newSQLException(int errorCode, String errorMessage) throws SQLException {
-        SQLiteErrorCode code = SQLiteErrorCode.getErrorCode(errorCode);
-        SQLException e = new SQLException(String.format("%s (%s)", code, errorMessage), null, code.code);
-        return e;
-    }
-
-    /**
-     * Throws SQL Exception with error code.
-     * @param errorCode Error code to be passed.
-     * @return SQLException with error code and message.
-     * @throws SQLException
-     */
-    private SQLException newSQLException(int errorCode) throws SQLException {
-        return newSQLException(errorCode, errmsg());
-    }
-
-    /**
-     * SQLite and the JDBC API have very different ideas about the meaning
-     * of auto-commit. Under JDBC, when executeUpdate() returns in
-     * auto-commit mode (the default), the programmer assumes the data has
-     * been written to disk. In SQLite however, a call to sqlite3_step()
-     * with an INSERT statement can return SQLITE_OK, and yet the data is
-     * still in limbo.
-     *
-     * This limbo appears when another statement on the database is active,
-     * e.g. a SELECT. SQLite auto-commit waits until the final read
-     * statement finishes, and then writes whatever updates have already
-     * been OKed. So if a program crashes before the reads are complete,
-     * data is lost. E.g:
-     *
-     *     select begins
-     *     insert
-     *     select continues
-     *     select finishes
-     *
-     * Works as expected, however
-     *
-     *     select beings
-     *     insert
-     *     select continues
-     *     crash
-     *
-     * Results in the data never being written to disk.
-     *
-     * As a solution, we call "commit" after every statement in auto-commit
-     * mode.
-     * @throws SQLException
-     */
-    final void ensureAutoCommit() throws SQLException {
-        if (!conn.getAutoCommit()) {
-            return;
-        }
-
-        if (begin == 0) {
-            begin = prepare("begin;");
-        }
-        if (commit == 0) {
-            commit = prepare("commit;");
-        }
-
-        try {
-            if (step(begin) != SQLITE_DONE)
-             {
-                return; // assume we are in a transaction
-            }
-            if (step(commit) != SQLITE_DONE) {
-                reset(commit);
-                throwex();
-            }
-            //throw new SQLException("unable to auto-commit");
-        }
-        finally {
-            reset(begin);
-            reset(commit);
-        }
-    }
-}

File src/main/java/org/sqlite/ExtendedCommand.java

 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.sqlite.core.DB;
+
 /**
  * parsing SQLite specific extension of SQL command
  * 
         }
 
         /**
-         * @see org.sqlite.ExtendedCommand.SQLExtension#execute(org.sqlite.DB)
+         * @see org.sqlite.ExtendedCommand.SQLExtension#execute(org.sqlite.core.DB)
          */
         public void execute(DB db) throws SQLException {
             db.restore(targetDB, srcFile, null);

File src/main/java/org/sqlite/Function.java

 import java.sql.Connection;
 import java.sql.SQLException;
 
+import org.sqlite.core.Codes;
+import org.sqlite.core.DB;
+
 /** Provides an interface for creating SQLite user-defined functions.
  *
  * <p>A subclass of <tt>org.sqlite.Function</tt> can be registered with

File src/main/java/org/sqlite/MetaData.java

-/*
- * Copyright (c) 2007 David Crawshaw <david@zentus.com>
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-package org.sqlite;
-
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.sql.Struct;
-import java.sql.Types;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-class MetaData implements DatabaseMetaData
-{
-    private SQLiteConnection              conn;
-    private PreparedStatement
-            getTables             = null,   getTableTypes        = null,
-            getTypeInfo           = null,   getCatalogs          = null,
-            getSchemas            = null,   getUDTs              = null,
-            getColumnsTblName     = null,   getSuperTypes        = null,
-            getSuperTables        = null,   getTablePrivileges   = null,
-            getIndexInfo          = null,   getProcedures        = null,
-            getProcedureColumns   = null,   getAttributes        = null,
-            getBestRowIdentifier  = null,   getVersionColumns    = null,
-            getColumnPrivileges   = null;
-
-    /**
-     * Used to save generating a new statement every call.
-     */
-    private PreparedStatement getGeneratedKeys = null;
-
-    /**
-     * Reference count.
-     */
-    int refCount = 1;
-
-    /**
-     * Constructor that applies the Connection object.
-     * @param conn Connection object.
-     */
-    MetaData(SQLiteConnection conn) {
-        this.conn = conn;
-    }
-
-    /**
-     * @throws SQLException
-     */
-    void checkOpen() throws SQLException {
-        if (conn == null) {
-            throw new SQLException("connection closed");
-        }
-    }
-
-    /**
-     * @throws SQLException
-     */
-    synchronized void close() throws SQLException {
-        if (conn == null || refCount > 0) {
-            return;
-        }
-
-        try {
-            if (getTables != null) {
-                getTables.close();
-            }
-            if (getTableTypes != null) {
-                getTableTypes.close();
-            }
-            if (getTypeInfo != null) {
-                getTypeInfo.close();
-            }
-            if (getCatalogs != null) {
-                getCatalogs.close();
-            }
-            if (getSchemas != null) {
-                getSchemas.close();
-            }
-            if (getUDTs != null) {
-                getUDTs.close();
-            }
-            if (getColumnsTblName != null) {
-                getColumnsTblName.close();
-            }
-            if (getSuperTypes != null) {
-                getSuperTypes.close();
-            }
-            if (getSuperTables != null) {
-                getSuperTables.close();
-            }
-            if (getTablePrivileges != null) {
-                getTablePrivileges.close();
-            }
-            if (getIndexInfo != null) {
-                getIndexInfo.close();
-            }
-            if (getProcedures != null) {
-                getProcedures.close();
-            }
-            if (getProcedureColumns != null) {
-                getProcedureColumns.close();
-            }
-            if (getAttributes != null) {
-                getAttributes.close();
-            }
-            if (getBestRowIdentifier != null) {
-                getBestRowIdentifier.close();
-            }
-            if (getVersionColumns != null) {
-                getVersionColumns.close();
-            }
-            if (getColumnPrivileges != null) {
-                getColumnPrivileges.close();
-            }
-            if (getGeneratedKeys != null) {
-                getGeneratedKeys.close();
-            }
-
-            getTables = null;
-            getTableTypes = null;
-            getTypeInfo = null;
-            getCatalogs = null;
-            getSchemas = null;
-            getUDTs = null;
-            getColumnsTblName = null;
-            getSuperTypes = null;
-            getSuperTables = null;
-            getTablePrivileges = null;
-            getIndexInfo = null;
-            getProcedures = null;
-            getProcedureColumns = null;
-            getAttributes = null;
-            getBestRowIdentifier = null;
-            getVersionColumns = null;
-            getColumnPrivileges = null;
-            getGeneratedKeys = null;
-        }
-        finally {
-            conn = null;
-        }
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getConnection()
-     */
-    public Connection getConnection() {
-        return conn;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getDatabaseMajorVersion()
-     */
-    public int getDatabaseMajorVersion() {
-        return 3;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getDatabaseMinorVersion()
-     */
-    public int getDatabaseMinorVersion() {
-        return 0;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getDriverMajorVersion()
-     */
-    public int getDriverMajorVersion() {
-        return 1;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getDriverMinorVersion()
-     */
-    public int getDriverMinorVersion() {
-        return 1;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getJDBCMajorVersion()
-     */
-    public int getJDBCMajorVersion() {
-        return 2;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getJDBCMinorVersion()
-     */
-    public int getJDBCMinorVersion() {
-        return 1;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getDefaultTransactionIsolation()
-     */
-    public int getDefaultTransactionIsolation() {
-        return Connection.TRANSACTION_SERIALIZABLE;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getMaxBinaryLiteralLength()
-     */
-    public int getMaxBinaryLiteralLength() {
-        return 0;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getMaxCatalogNameLength()
-     */
-    public int getMaxCatalogNameLength() {
-        return 0;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getMaxCharLiteralLength()
-     */
-    public int getMaxCharLiteralLength() {
-        return 0;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getMaxColumnNameLength()
-     */
-    public int getMaxColumnNameLength() {
-        return 0;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getMaxColumnsInGroupBy()
-     */
-    public int getMaxColumnsInGroupBy() {
-        return 0;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getMaxColumnsInIndex()
-     */
-    public int getMaxColumnsInIndex() {
-        return 0;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getMaxColumnsInOrderBy()
-     */
-    public int getMaxColumnsInOrderBy() {
-        return 0;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getMaxColumnsInSelect()
-     */
-    public int getMaxColumnsInSelect() {
-        return 0;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getMaxColumnsInTable()
-     */
-    public int getMaxColumnsInTable() {
-        return 0;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getMaxConnections()
-     */
-    public int getMaxConnections() {
-        return 0;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getMaxCursorNameLength()
-     */
-    public int getMaxCursorNameLength() {
-        return 0;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getMaxIndexLength()
-     */
-    public int getMaxIndexLength() {
-        return 0;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getMaxProcedureNameLength()
-     */
-    public int getMaxProcedureNameLength() {
-        return 0;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getMaxRowSize()
-     */
-    public int getMaxRowSize() {
-        return 0;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getMaxSchemaNameLength()
-     */
-    public int getMaxSchemaNameLength() {
-        return 0;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getMaxStatementLength()
-     */
-    public int getMaxStatementLength() {
-        return 0;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getMaxStatements()
-     */
-    public int getMaxStatements() {
-        return 0;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getMaxTableNameLength()
-     */
-    public int getMaxTableNameLength() {
-        return 0;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getMaxTablesInSelect()
-     */
-    public int getMaxTablesInSelect() {
-        return 0;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getMaxUserNameLength()
-     */
-    public int getMaxUserNameLength() {
-        return 0;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getResultSetHoldability()
-     */
-    public int getResultSetHoldability() {
-        return ResultSet.CLOSE_CURSORS_AT_COMMIT;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getSQLStateType()
-     */
-    public int getSQLStateType() {
-        return sqlStateSQL99;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getDatabaseProductName()
-     */
-    public String getDatabaseProductName() {
-        return "SQLite";
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getDatabaseProductVersion()
-     */
-    public String getDatabaseProductVersion() throws SQLException {
-        return conn.libversion();
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getDriverName()
-     */
-    public String getDriverName() {
-        return "SQLiteJDBC";
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getDriverVersion()
-     */
-    public String getDriverVersion() {
-        return conn.getDriverVersion();
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getExtraNameCharacters()
-     */
-    public String getExtraNameCharacters() {
-        return "";
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getCatalogSeparator()
-     */
-    public String getCatalogSeparator() {
-        return ".";
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getCatalogTerm()
-     */
-    public String getCatalogTerm() {
-        return "catalog";
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getSchemaTerm()
-     */
-    public String getSchemaTerm() {
-        return "schema";
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getProcedureTerm()
-     */
-    public String getProcedureTerm() {
-        return "not_implemented";
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getSearchStringEscape()
-     */
-    public String getSearchStringEscape() {
-        return null;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getIdentifierQuoteString()
-     */
-    public String getIdentifierQuoteString() {
-        return " ";
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getSQLKeywords()
-     */
-    public String getSQLKeywords() {
-        return "";
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getNumericFunctions()
-     */
-    public String getNumericFunctions() {
-        return "";
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getStringFunctions()
-     */
-    public String getStringFunctions() {
-        return "";
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getSystemFunctions()
-     */
-    public String getSystemFunctions() {
-        return "";
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getTimeDateFunctions()
-     */
-    public String getTimeDateFunctions() {
-        return "";
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getURL()
-     */
-    public String getURL() {
-        return conn.url();
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#getUserName()
-     */
-    public String getUserName() {
-        return null;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#allProceduresAreCallable()
-     */
-    public boolean allProceduresAreCallable() {
-        return false;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#allTablesAreSelectable()
-     */
-    public boolean allTablesAreSelectable() {
-        return true;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#dataDefinitionCausesTransactionCommit()
-     */
-    public boolean dataDefinitionCausesTransactionCommit() {
-        return false;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#dataDefinitionIgnoredInTransactions()
-     */
-    public boolean dataDefinitionIgnoredInTransactions() {
-        return false;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#doesMaxRowSizeIncludeBlobs()
-     */
-    public boolean doesMaxRowSizeIncludeBlobs() {
-        return false;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#deletesAreDetected(int)
-     */
-    public boolean deletesAreDetected(int type) {
-        return false;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#insertsAreDetected(int)
-     */
-    public boolean insertsAreDetected(int type) {
-        return false;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#isCatalogAtStart()
-     */
-    public boolean isCatalogAtStart() {
-        return true;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#locatorsUpdateCopy()
-     */
-    public boolean locatorsUpdateCopy() {
-        return false;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#nullPlusNonNullIsNull()
-     */
-    public boolean nullPlusNonNullIsNull() {
-        return true;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#nullsAreSortedAtEnd()
-     */
-    public boolean nullsAreSortedAtEnd() {
-        return !nullsAreSortedAtStart();
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#nullsAreSortedAtStart()
-     */
-    public boolean nullsAreSortedAtStart() {
-        return true;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#nullsAreSortedHigh()
-     */
-    public boolean nullsAreSortedHigh() {
-        return true;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#nullsAreSortedLow()
-     */
-    public boolean nullsAreSortedLow() {
-        return !nullsAreSortedHigh();
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#othersDeletesAreVisible(int)
-     */
-    public boolean othersDeletesAreVisible(int type) {
-        return false;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#othersInsertsAreVisible(int)
-     */
-    public boolean othersInsertsAreVisible(int type) {
-        return false;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#othersUpdatesAreVisible(int)
-     */
-    public boolean othersUpdatesAreVisible(int type) {
-        return false;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#ownDeletesAreVisible(int)
-     */
-    public boolean ownDeletesAreVisible(int type) {
-        return false;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#ownInsertsAreVisible(int)
-     */
-    public boolean ownInsertsAreVisible(int type) {
-        return false;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#ownUpdatesAreVisible(int)
-     */
-    public boolean ownUpdatesAreVisible(int type) {
-        return false;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#storesLowerCaseIdentifiers()
-     */
-    public boolean storesLowerCaseIdentifiers() {
-        return false;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#storesLowerCaseQuotedIdentifiers()
-     */
-    public boolean storesLowerCaseQuotedIdentifiers() {
-        return false;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#storesMixedCaseIdentifiers()
-     */
-    public boolean storesMixedCaseIdentifiers() {
-        return true;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#storesMixedCaseQuotedIdentifiers()
-     */
-    public boolean storesMixedCaseQuotedIdentifiers() {
-        return false;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#storesUpperCaseIdentifiers()
-     */
-    public boolean storesUpperCaseIdentifiers() {
-        return false;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#storesUpperCaseQuotedIdentifiers()
-     */
-    public boolean storesUpperCaseQuotedIdentifiers() {
-        return false;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#supportsAlterTableWithAddColumn()
-     */
-    public boolean supportsAlterTableWithAddColumn() {
-        return false;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#supportsAlterTableWithDropColumn()
-     */
-    public boolean supportsAlterTableWithDropColumn() {
-        return false;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#supportsANSI92EntryLevelSQL()
-     */
-    public boolean supportsANSI92EntryLevelSQL() {
-        return false;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#supportsANSI92FullSQL()
-     */
-    public boolean supportsANSI92FullSQL() {
-        return false;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#supportsANSI92IntermediateSQL()
-     */
-    public boolean supportsANSI92IntermediateSQL() {
-        return false;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#supportsBatchUpdates()
-     */
-    public boolean supportsBatchUpdates() {
-        return true;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#supportsCatalogsInDataManipulation()
-     */
-    public boolean supportsCatalogsInDataManipulation() {
-        return false;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#supportsCatalogsInIndexDefinitions()
-     */
-    public boolean supportsCatalogsInIndexDefinitions() {
-        return false;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#supportsCatalogsInPrivilegeDefinitions()
-     */
-    public boolean supportsCatalogsInPrivilegeDefinitions() {
-        return false;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#supportsCatalogsInProcedureCalls()
-     */
-    public boolean supportsCatalogsInProcedureCalls() {
-        return false;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#supportsCatalogsInTableDefinitions()
-     */
-    public boolean supportsCatalogsInTableDefinitions() {
-        return false;
-    }
-
-    /**
-     * @see java.sql.DatabaseMetaData#supportsColumnAliasing()