org.sqlite
Class Database

java.lang.Object
  extended by org.sqlite.Database

public class Database
extends java.lang.Object

sqlite3 wrapper class.
NOTE: SQLite 3.3.5 based.


Field Summary
protected  java.util.Properties info
          database properties
 
Constructor Summary
Database(java.lang.String filename, java.util.Properties info)
          open database.
 
Method Summary
 void beginTransaction(TransactionType type)
          begin transaction.
 int changes()
          invoke sqlite3_changes() function.
 void clearAuthorizer()
          invoke sqlite3_set_authorizer() function.
 void clearBusyHandler()
          invoke sqlite3_set_authorizer() function.
 void clearCollationNeededHandler()
          invoke sqlite3_collation_needed() function.
 void clearCommitHook()
          invoke sqlite3_commit_hook() function.
 void clearProfiler()
          invoke sqlite3_profile() function.
 void clearProgressHandler()
          invoke sqlite3_progress_handler() function.
 void clearRollbackHook()
          invoke sqlite3_rollback_hook() function.
 void clearTracer()
          invoke sqlite3_trace() function.
 void clearUpdateHook()
          invoke sqlite3_update_hook() function.
 void close()
          invoke sqlite3_close() function.
 void commitTransaction()
          commit toransaction.
 void createCollationSequence(Collator col)
          invoke sqlite3_create_collation() function.
 void createFunction(Function func)
          invoke sqlite3_create_function() function.
 void disableSharedCache()
          invoke sqlite3_enable_shared_cache(false) function.
 void dropCollationSequence(Collator col)
          invoke sqlite3_create_function() function.
 void dropCollationSequence(java.lang.String name)
          invoke sqlite3_create_function() function.
 void dropFunction(Function func)
          invoke sqlite3_create_function() function.
 void dropFunction(java.lang.String name)
          invoke sqlite3_create_function() function.
 void enableSharedCache()
          invoke sqlite3_enable_shared_cache(true) function.
 void execute(java.lang.String sql)
          invoke sqlite3_exec() function.
 void execute(java.lang.String sql, ExecCallback callback, SWIGTYPE_p_p_char errmsg)
          invoke sqlite3_exec() function.
protected  void finalize()
          Close database if database is not closed yet.
 boolean getAutoCommit()
          invoke sqlite3_get_autocommit() function.
 int getBusyTimeout()
          Returns the value of timeout(ms).
 ColumnMetaData getColumnMetaData(java.lang.String dbName, java.lang.String tableName, java.lang.String columnName)
          invoke sqlite3_table_column_metadata() function.
 int getLastError()
          invoke sqlite3_errcode() function.
 java.lang.String getLastErrorMessage()
          invoke sqlite3_errmsg() function.
 java.lang.String getProductName()
          It always returns "SQLite".
 java.util.List<java.lang.String[]> getTable(java.lang.String sql, SWIGTYPE_p_p_char errmsg)
          invoke sqlite3_get_table() function.
 void interrupt()
          invoke sqlite3_interrupt() function.
 boolean isClosed()
          Retrieves whether this Database object has been closed.
 boolean isInMemoryMode()
          true is returned for the In-Memory mode.
 boolean isReadOnly()
          It always returns false.
NOTE: The sqlite3_open_v2() function is not supported in this version.
 long lastInsertRowId()
          invoke sqlite3_last_insert_rowid() function.
protected  void open(java.lang.String filename)
          invoke sqlite3_open() function.
 void pragma(java.lang.String[] commands)
          execute PRAGMA commands by sqlite3_exec() finction.
 Statement prepare(java.lang.String sql)
          create UNMANAGED Statement instance.
 Statement prepare(java.lang.String sql, SQLite3StmtPtrPtr ppStmt)
          create MANAGED Statement instance.
 java.util.List<Statement> prepareMultiple(java.lang.String sql)
          create multiple UNMANAGED Statement instance.
 void rollbackTransaction()
          rollback transaction.
 void setAuthorizer(Authorizer auth)
          invoke sqlite3_set_authorizer() function.
 void setBusyHandler(BusyHandler busy)
          invoke sqlite3_busy_handler() function.
 void setBusyTimeout(int ms)
          invoke sqlite3_busy_timeout() function.
 void setCollationNeededHandler(CollationNeededHandler needed)
          invoke sqlite3_collation_needed() function.
 void setCommitHook(CommitHook hook)
          invoke sqlite3_commit_hook() function.
 void setProfiler(Profiler profiler)
          invoke sqlite3_profile() function.
 void setProgressHandler(ProgressHandler prog)
          invoke sqlite3_progress_handler() function.
 void setRollbackHook(RollbackHook hook)
          invoke sqlite3_rollback_hook() function.
 void setTracer(Tracer tracer)
          invoke sqlite3_trace() function.
 void setUpdateHook(UpdateHook hook)
          invoke sqlite3_update_hook() function.
 int totalChanges()
          invoke sqlite3_total_changes() function.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

info

protected final java.util.Properties info
database properties

Constructor Detail

Database

public Database(java.lang.String filename,
                java.util.Properties info)
         throws java.sql.SQLException
open database.

Parameters:
filename - database file path
info - database properties
Throws:
java.sql.SQLException - When the return value of the sqlite3_open() function is not SQLITE_OK.
Method Detail

getProductName

public java.lang.String getProductName()
It always returns "SQLite".

Returns:
"SQLite"

isInMemoryMode

public boolean isInMemoryMode()
true is returned for the In-Memory mode.

Returns:
true is returned for the In-Memory mode.

open

protected void open(java.lang.String filename)
             throws java.sql.SQLException
invoke sqlite3_open() function.

Parameters:
filename - database file path
Throws:
java.sql.SQLException - When the return value of the sqlite3_open() function is not SQLITE_OK.
See Also:
Opening A New Database Connection

isReadOnly

public boolean isReadOnly()
It always returns false.
NOTE: The sqlite3_open_v2() function is not supported in this version.

Returns:
false.

isClosed

public boolean isClosed()
Retrieves whether this Database object has been closed.

Returns:
true if this Database object is closed. false if it is still open.

close

public void close()
           throws java.sql.SQLException
invoke sqlite3_close() function.

Throws:
java.sql.SQLException - When the return value of the sqlite3_close() function is not SQLITE_OK.
See Also:
Closing A Database Connection

getAutoCommit

public boolean getAutoCommit()
invoke sqlite3_get_autocommit() function.

Returns:
true if auto commit mode.
See Also:
Test To See If The Database Is In Auto-Commit Mode

setBusyTimeout

public void setBusyTimeout(int ms)
                    throws java.sql.SQLException
invoke sqlite3_busy_timeout() function.

Parameters:
ms - milliseconds
Throws:
java.sql.SQLException - When the return value of the sqlite3_busy_timeout() function is not SQLITE_OK.
See Also:
Set A Busy Timeout

getBusyTimeout

public int getBusyTimeout()
Returns the value of timeout(ms).

Returns:
timeout(ms) value.

execute

public void execute(java.lang.String sql)
             throws java.sql.SQLException
invoke sqlite3_exec() function.

Parameters:
sql - SQL to be evaluated
Throws:
java.sql.SQLException - When the return value of the sqlite3_exec() function is not SQLITE_OK.
See Also:
One-Step Query Execution Interface, execute(String, ExecCallback, SWIGTYPE_p_p_char)

execute

public void execute(java.lang.String sql,
                    ExecCallback callback,
                    SWIGTYPE_p_p_char errmsg)
             throws java.sql.SQLException
invoke sqlite3_exec() function.

Parameters:
sql - SQL to be evaluated
callback - callback object
errmsg - Error message written here
Throws:
java.sql.SQLException - When the return value of the sqlite3_exec() function is not SQLITE_OK.
See Also:
One-Step Query Execution Interface

pragma

public void pragma(java.lang.String[] commands)
            throws java.sql.SQLException
execute PRAGMA commands by sqlite3_exec() finction.

Parameters:
commands - the command list without semicolon
Throws:
java.sql.SQLException - When the return value of the sqlite3_exec() function is not SQLITE_OK.
See Also:
Pragma statements supported by SQLite, execute(String)

beginTransaction

public void beginTransaction(TransactionType type)
                      throws java.sql.SQLException
begin transaction.

Parameters:
type - transaction type.
Throws:
java.sql.SQLException - When the return value of the sqlite3_exec() function is not SQLITE_OK.
See Also:
BEGIN TRANSACTION

commitTransaction

public void commitTransaction()
                       throws java.sql.SQLException
commit toransaction.

Throws:
java.sql.SQLException - When the return value of the sqlite3_exec() function is not SQLITE_OK.
See Also:
BEGIN TRANSACTION

rollbackTransaction

public void rollbackTransaction()
                         throws java.sql.SQLException
rollback transaction.

Throws:
java.sql.SQLException - When the return value of the sqlite3_exec() function is not SQLITE_OK.
See Also:
BEGIN TRANSACTION

prepare

public Statement prepare(java.lang.String sql,
                         SQLite3StmtPtrPtr ppStmt)
                  throws java.sql.SQLException
create MANAGED Statement instance.

Parameters:
sql - SQL to be evaluated
ppStmt - SQLite3StmtPtrPtr object
Returns:
Statement object
Throws:
java.sql.SQLException - When the return value of the sqlite3_prepare() function is not SQLITE_OK.
See Also:
Compiling An SQL Statement

prepare

public Statement prepare(java.lang.String sql)
                  throws java.sql.SQLException
create UNMANAGED Statement instance.

Parameters:
sql - SQL to be evaluated
Returns:
Statement object
Throws:
java.sql.SQLException - When the return value of the sqlite3_prepare() function is not SQLITE_OK.
See Also:
Compiling An SQL Statement

prepareMultiple

public java.util.List<Statement> prepareMultiple(java.lang.String sql)
                                          throws java.sql.SQLException
create multiple UNMANAGED Statement instance.

Parameters:
sql - SQL to be evaluated
Returns:
array of Statement
Throws:
java.sql.SQLException - When the return value of the sqlite3_prepare() function is not SQLITE_OK.
See Also:
Compiling An SQL Statement

interrupt

public void interrupt()
invoke sqlite3_interrupt() function.

See Also:
Interrupt A Long-Running Query

changes

public int changes()
invoke sqlite3_changes() function.

Returns:
the number of database rows that were changed or inserted or deleted by the most recently completed SQL statement on the connection specified.
See Also:
Count The Number Of Rows Modified, totalChanges()

totalChanges

public int totalChanges()
invoke sqlite3_total_changes() function.

Returns:
the number of row changes caused by INSERT, UPDATE or DELETE statements since the database handle was opened.
See Also:
Total Number Of Rows Modified, changes()

lastInsertRowId

public long lastInsertRowId()
invoke sqlite3_last_insert_rowid() function.

Returns:
the rowid of the most recent successful INSERT into the database from the database connection.
See Also:
Last Insert Rowid

getColumnMetaData

public ColumnMetaData getColumnMetaData(java.lang.String dbName,
                                        java.lang.String tableName,
                                        java.lang.String columnName)
                                 throws java.sql.SQLException
invoke sqlite3_table_column_metadata() function.

Parameters:
dbName - database name
tableName - table name
columnName - column name
Returns:
the meta-data about a specific column of a specific database table accessible using the connection.
Throws:
java.sql.SQLException - When the return value of the sqlite3_table_column_metadata() function is not SQLITE_OK.
See Also:
Extract Metadata About A Column Of A Table

createFunction

public void createFunction(Function func)
                    throws java.sql.SQLException
invoke sqlite3_create_function() function.

Parameters:
func - User-Defined function
Throws:
java.sql.SQLException - When the return value of the sqlite3_create_function() function is not SQLITE_OK.
See Also:
Create Or Redefine SQL Functions

dropFunction

public void dropFunction(Function func)
                  throws java.sql.SQLException
invoke sqlite3_create_function() function.

Parameters:
func - User-Defined function
Throws:
java.sql.SQLException - When the return value of the sqlite3_create_function() function is not SQLITE_OK.
See Also:
Create Or Redefine SQL Functions

dropFunction

public void dropFunction(java.lang.String name)
                  throws java.sql.SQLException
invoke sqlite3_create_function() function.

Parameters:
name - the function name
Throws:
java.sql.SQLException - When the return value of the sqlite3_create_function() function is not SQLITE_OK.
See Also:
Create Or Redefine SQL Functions

createCollationSequence

public void createCollationSequence(Collator col)
                             throws java.sql.SQLException
invoke sqlite3_create_collation() function.

Parameters:
col - User-Defined Collating Sequences
Throws:
java.sql.SQLException - When the return value of the sqlite3_create_collation() function is not SQLITE_OK.
See Also:
Define New Collating Sequences

dropCollationSequence

public void dropCollationSequence(Collator col)
                           throws java.sql.SQLException
invoke sqlite3_create_function() function.

Parameters:
col - User-Defined Collating Sequences
Throws:
java.sql.SQLException - When the return value of the sqlite3_create_collation() function is not SQLITE_OK.
See Also:
Define New Collating Sequences

dropCollationSequence

public void dropCollationSequence(java.lang.String name)
                           throws java.sql.SQLException
invoke sqlite3_create_function() function.

Parameters:
name - the collation sequence name
Throws:
java.sql.SQLException - When the return value of the sqlite3_create_collation() function is not SQLITE_OK.
See Also:
Define New Collating Sequences

setAuthorizer

public void setAuthorizer(Authorizer auth)
                   throws java.sql.SQLException
invoke sqlite3_set_authorizer() function.

Parameters:
auth - authorizer
Throws:
java.sql.SQLException - When the return value of the sqlite3_set_authorizer() function is not SQLITE_OK.
See Also:
Compile-Time Authorization Callbacks

clearAuthorizer

public void clearAuthorizer()
                     throws java.sql.SQLException
invoke sqlite3_set_authorizer() function.

Throws:
java.sql.SQLException - When the return value of the sqlite3_set_authorizer() function is not SQLITE_OK.
See Also:
Compile-Time Authorization Callbacks

setBusyHandler

public void setBusyHandler(BusyHandler busy)
                    throws java.sql.SQLException
invoke sqlite3_busy_handler() function.

Parameters:
busy - busy handler
Throws:
java.sql.SQLException - When the return value of the sqlite3_busy_handler() function is not SQLITE_OK.
See Also:
Register A Callback To Handle SQLITE_BUSY Errors

clearBusyHandler

public void clearBusyHandler()
                      throws java.sql.SQLException
invoke sqlite3_set_authorizer() function.

Throws:
java.sql.SQLException - When the return value of the sqlite3_busy_handler() function is not SQLITE_OK.
See Also:
Register A Callback To Handle SQLITE_BUSY Errors

setCollationNeededHandler

public void setCollationNeededHandler(CollationNeededHandler needed)
                               throws java.sql.SQLException
invoke sqlite3_collation_needed() function.

Parameters:
needed - the CollationNeededHandler object
Throws:
java.sql.SQLException - When the return value of the sqlite3_collation_needed() function is not SQLITE_OK.
See Also:
Collation Needed Callbacks

clearCollationNeededHandler

public void clearCollationNeededHandler()
                                 throws java.sql.SQLException
invoke sqlite3_collation_needed() function.

Throws:
java.sql.SQLException - When the return value of the sqlite3_collation_needed() function is not SQLITE_OK.
See Also:
Collation Needed Callbacks

setProgressHandler

public void setProgressHandler(ProgressHandler prog)
invoke sqlite3_progress_handler() function.

Parameters:
prog - progress handler
See Also:
Query Progress Callbacks

clearProgressHandler

public void clearProgressHandler()
invoke sqlite3_progress_handler() function.

See Also:
Query Progress Callbacks

setCommitHook

public void setCommitHook(CommitHook hook)
invoke sqlite3_commit_hook() function.

Parameters:
hook - commit hoot
See Also:
Commit And Rollback Notification Callbacks

clearCommitHook

public void clearCommitHook()
invoke sqlite3_commit_hook() function.

See Also:
Commit And Rollback Notification Callbacks

setRollbackHook

public void setRollbackHook(RollbackHook hook)
invoke sqlite3_rollback_hook() function.

Parameters:
hook - rollback hoot
See Also:
Commit And Rollback Notification Callbacks

clearRollbackHook

public void clearRollbackHook()
invoke sqlite3_rollback_hook() function.

See Also:
Commit And Rollback Notification Callbacks

setUpdateHook

public void setUpdateHook(UpdateHook hook)
invoke sqlite3_update_hook() function.

Parameters:
hook - update hoot
See Also:
Data Change Notification Callbacks

clearUpdateHook

public void clearUpdateHook()
invoke sqlite3_update_hook() function.

See Also:
Data Change Notification Callbacks

setProfiler

public void setProfiler(Profiler profiler)
invoke sqlite3_profile() function.

Parameters:
profiler - profiler
See Also:
Tracing And Profiling Functions

clearProfiler

public void clearProfiler()
invoke sqlite3_profile() function.

See Also:
Tracing And Profiling Functions

setTracer

public void setTracer(Tracer tracer)
invoke sqlite3_trace() function.

Parameters:
tracer - tracer
See Also:
Tracing And Profiling Functions

clearTracer

public void clearTracer()
invoke sqlite3_trace() function.

See Also:
Tracing And Profiling Functions

enableSharedCache

public void enableSharedCache()
                       throws java.sql.SQLException
invoke sqlite3_enable_shared_cache(true) function.

Throws:
java.sql.SQLException - When the return value of the sqlite3_enable_shared_cache() function is not SQLITE_OK.
See Also:
Enable Or Disable Shared Pager Cache

disableSharedCache

public void disableSharedCache()
                        throws java.sql.SQLException
invoke sqlite3_enable_shared_cache(false) function.

Throws:
java.sql.SQLException - When the return value of the sqlite3_enable_shared_cache() function is not SQLITE_OK.
See Also:
Enable Or Disable Shared Pager Cache

getLastError

public int getLastError()
invoke sqlite3_errcode() function.

Returns:
the numeric result code or extended result code for the most recent failed sqlite3_* API call associated with sqlite3 handle 'db'.
See Also:
Error Codes And Messages, Result Codes, Extended Result Codes

getLastErrorMessage

public java.lang.String getLastErrorMessage()
invoke sqlite3_errmsg() function.

Returns:
the numeric result code or extended result code for the most recent failed sqlite3_* API call associated with sqlite3 handle 'db'.
See Also:
Error Codes And Messages

getTable

public java.util.List<java.lang.String[]> getTable(java.lang.String sql,
                                                   SWIGTYPE_p_p_char errmsg)
                                            throws java.sql.SQLException
invoke sqlite3_get_table() function.

Parameters:
sql - SQL to be evaluated
errmsg - Error message written here
Returns:
Results of the query
Throws:
java.sql.SQLException - When the return value of the sqlite3_get_table() function is not SQLITE_OK.
See Also:
Convenience Routines For Running Queries

finalize

protected void finalize()
                 throws java.lang.Throwable
Close database if database is not closed yet.

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable