org.h2.android

## Class H2Database

- java.lang.Object
- - org.h2.android.H2Database

    public class H2Database
    extends java.lang.Object

This class represents a database connection.

### Nested Class Summary

Nested Classes
`static interface` `H2Database.CursorFactory` The cursor factory.

### Field Summary

Fields
`static int` `CONFLICT_ABORT` When a conflict occurs, abort the current statement, but don't roll back the transaction.
`static int` `CONFLICT_FAIL` When a conflict occurs, return SQLITE_CONSTRAINT, but don't roll back the transaction.
`static int` `CONFLICT_IGNORE` When a conflict occurs, continue, but don't modify the conflicting row.
`static int` `CONFLICT_NONE` When a conflict occurs, do nothing.
`static int` `CONFLICT_REPLACE` When a conflict occurs, the existing rows are replaced.
`static int` `CONFLICT_ROLLBACK` When a conflict occurs, the transaction is rolled back.
`static int` `CREATE_IF_NECESSARY` Create a new database if it doesn't exist.
`static int` `NO_LOCALIZED_COLLATORS` This flag has no effect.
`static int` `OPEN_READONLY` Open the database in read-only mode.
`static int` `OPEN_READWRITE` Open the database in read-write mode (default).

### Method Summary

Methods
`void` `beginTransaction()` Start a transaction.
`void` `beginTransactionWithListener(H2TransactionListener transactionListener)` Start a transaction.
`void` `close()` Close the connection.
`H2Statement` `compileStatement(java.lang.String sql)` Prepare a statement.
`static H2Database` `create(H2Database.CursorFactory factory)` Create a new in-memory database.
`int` `delete(java.lang.String table, java.lang.String whereClause, java.lang.String[] whereArgs)` Delete a number of rows in this database.
`void` `endTransaction()` End the transaction.
`void` `execSQL(java.lang.String sql)` Execute the given statement.
`void` `execSQL(java.lang.String sql, java.lang.Object[] bindArgs)` Execute the given statement.
`static java.lang.String` `findEditTable(java.lang.String tables)` TODO
`long` `getMaximumSize()` Get the maximum size of the database file in bytes.
`long` `getPageSize()` Get the page size of the database in bytes.
`java.lang.String` `getPath()` Get the name of the database file.
`java.util.Map<java.lang.String,java.lang.String>` `getSyncedTables()` TODO
`int` `getVersion()` Get the database version.
`long` `insert(java.lang.String table, java.lang.String nullColumnHack, android.content.ContentValues values)` Insert a row.
`long` `insertOrThrow(java.lang.String table, java.lang.String nullColumnHack, android.content.ContentValues values)` Try to insert a row.
`long` `insertWithOnConflict(java.lang.String table, java.lang.String nullColumnHack, android.content.ContentValues initialValues, int conflictAlgorithm)` Try to insert a row, using the given conflict resolution option.
`boolean` `inTransaction()` Check if there is an open transaction.
`boolean` `isDbLockedByCurrentThread()` Check if the database is locked by the current thread.
`boolean` `isDbLockedByOtherThreads()` Check if the database is locked by a different thread.
`boolean` `isOpen()` Check if the connection is open.
`boolean` `isReadOnly()` Check if the connection is read-only.
`void` `markTableSyncable(java.lang.String table, java.lang.String deletedTable)` TODO
`void` `markTableSyncable(java.lang.String table, java.lang.String foreignKey, java.lang.String updateTable)` TODO
`boolean` `needUpgrade(int newVersion)` Check if an upgrade is required.
`static H2Database` `openDatabase(java.lang.String path, H2Database.CursorFactory factory, int flags)` Open a connection to the given database.
`static H2Database` `openOrCreateDatabase(java.io.File file, H2Database.CursorFactory factory)` Open a connection to the given database.
`static H2Database` `openOrCreateDatabase(java.lang.String path, H2Database.CursorFactory factory)` Open a connection to the given database.
`android.database.Cursor` `query(boolean distinct, java.lang.String table, java.lang.String[] columns, java.lang.String selection, java.lang.String[] selectionArgs, java.lang.String groupBy, java.lang.String having, java.lang.String orderBy, java.lang.String limit)` Execute the SELECT statement for the given parameters.
`android.database.Cursor` `query(java.lang.String table, java.lang.String[] columns, java.lang.String selection, java.lang.String[] selectionArgs, java.lang.String groupBy, java.lang.String having, java.lang.String orderBy)` Execute the SELECT statement for the given parameters.
`android.database.Cursor` `query(java.lang.String table, java.lang.String[] columns, java.lang.String selection, java.lang.String[] selectionArgs, java.lang.String groupBy, java.lang.String having, java.lang.String orderBy, java.lang.String limit)` Execute the SELECT statement for the given parameters.
`android.database.Cursor` `queryWithFactory(H2Database.CursorFactory cursorFactory, boolean distinct, java.lang.String table, java.lang.String[] columns, java.lang.String selection, java.lang.String[] selectionArgs, java.lang.String groupBy, java.lang.String having, java.lang.String orderBy, java.lang.String limit)` Execute the SELECT statement for the given parameters.
`android.database.Cursor` `rawQuery(java.lang.String sql, java.lang.String[] selectionArgs)` Execute the query.
`android.database.Cursor` `rawQueryWithFactory(H2Database.CursorFactory cursorFactory, java.lang.String sql, java.lang.String[] selectionArgs, java.lang.String editTable)` Execute the query using the given cursor factory.
`static int` `releaseMemory()` Try to release memory.
`long` `replace(java.lang.String table, java.lang.String nullColumnHack, android.content.ContentValues initialValues)` Replace an existing row in the database.
`long` `replaceOrThrow(java.lang.String table, java.lang.String nullColumnHack, android.content.ContentValues initialValues)` Try to replace an existing row in the database.
`void` `setLocale(java.util.Locale locale)` Set the locale.
`void` `setLockingEnabled(boolean lockingEnabled)` Enable or disable thread safety.
`long` `setMaximumSize(long numBytes)` Set the maximum database file size.
`void` `setPageSize(long numBytes)` Set the database page size.
`void` `setTransactionSuccessful()` Mark the transaction as completed successfully.
`void` `setVersion(int version)` Update the database version.
`static java.lang.RuntimeException` `unsupported()` Create a new RuntimeException that says this feature is not supported.
`int` `update(java.lang.String table, android.content.ContentValues values, java.lang.String whereClause, java.lang.String[] whereArgs)` Update one or multiple rows.
`int` `updateWithOnConflict(java.lang.String table, android.content.ContentValues values, java.lang.String whereClause, java.lang.String[] whereArgs, int conflictAlgorithm)` Update one or multiple rows.
`boolean` `yieldIfContended()` Deprecated. deprecated in API Level 3, use yieldIfContendedSafely
`boolean` `yieldIfContendedSafely()` Temporarily pause the transaction.
`boolean` `yieldIfContendedSafely(long sleepAfterYieldDelay)` Temporarily pause the transaction.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### CONFLICT_ABORT

    public static final int CONFLICT_ABORT

When a conflict occurs, abort the current statement, but don't roll back the transaction. This is the default value.

See Also:
  Constant Field Values

#### CONFLICT_FAIL

    public static final int CONFLICT_FAIL

When a conflict occurs, return SQLITE_CONSTRAINT, but don't roll back the transaction.

See Also:
  Constant Field Values

#### CONFLICT_IGNORE

    public static final int CONFLICT_IGNORE

When a conflict occurs, continue, but don't modify the conflicting row.

See Also:
  Constant Field Values

#### CONFLICT_NONE

    public static final int CONFLICT_NONE

When a conflict occurs, do nothing.

See Also:
  Constant Field Values

#### CONFLICT_REPLACE

    public static final int CONFLICT_REPLACE

When a conflict occurs, the existing rows are replaced.

See Also:
  Constant Field Values

#### CONFLICT_ROLLBACK

    public static final int CONFLICT_ROLLBACK

When a conflict occurs, the transaction is rolled back.

See Also:
  Constant Field Values

#### CREATE_IF_NECESSARY

    public static final int CREATE_IF_NECESSARY

Create a new database if it doesn't exist.

See Also:
  Constant Field Values

#### NO_LOCALIZED_COLLATORS

    public static final int NO_LOCALIZED_COLLATORS

This flag has no effect.

See Also:
  Constant Field Values

#### OPEN_READONLY

    public static final int OPEN_READONLY

Open the database in read-only mode.

See Also:
  Constant Field Values

#### OPEN_READWRITE

    public static final int OPEN_READWRITE

Open the database in read-write mode (default).

See Also:
  Constant Field Values

### Method Detail

#### create

    public static H2Database create(H2Database.CursorFactory factory)

Create a new in-memory database.

Parameters:
  `factory` - the cursor factory
Returns:
  a connection to this database

#### openDatabase

    public static H2Database openDatabase(java.lang.String path,
                          H2Database.CursorFactory factory,
                          int flags)

Open a connection to the given database.

Parameters:
  `path` - the database file name
  `factory` - the cursor factory
  `flags` - 0, or a combination of OPEN_READONLY and CREATE_IF_NECESSARY
Returns:
  a connection to this database

#### openOrCreateDatabase

    public static H2Database openOrCreateDatabase(java.io.File file,
                                  H2Database.CursorFactory factory)

Open a connection to the given database. The database is created if it doesn't exist yet.

Parameters:
  `file` - the database file
  `factory` - the cursor factory
Returns:
  a connection to this database

#### openOrCreateDatabase

    public static H2Database openOrCreateDatabase(java.lang.String path,
                                  H2Database.CursorFactory factory)

Open a connection to the given database. The database is created if it doesn't exist yet.

Parameters:
  `path` - the database file name
  `factory` - the cursor factory
Returns:
  a connection to this database

#### beginTransaction

    public void beginTransaction()

Start a transaction.

#### beginTransactionWithListener

    public void beginTransactionWithListener(H2TransactionListener transactionListener)

Start a transaction.

Parameters:
  `transactionListener` - the transaction listener to use

#### close

    public void close()

Close the connection.

#### compileStatement

    public H2Statement compileStatement(java.lang.String sql)

Prepare a statement.

Parameters:
  `sql` - the statement
Returns:
  the prepared statement

#### delete

    public int delete(java.lang.String table,
             java.lang.String whereClause,
             java.lang.String[] whereArgs)

Delete a number of rows in this database.

Parameters:
  `table` - the table
  `whereClause` - the condition
  `whereArgs` - the parameter values
Returns:
  the number of rows deleted

#### endTransaction

    public void endTransaction()

End the transaction.

#### execSQL

    public void execSQL(java.lang.String sql,
               java.lang.Object[] bindArgs)

Execute the given statement.

Parameters:
  `sql` - the statement
  `bindArgs` - the parameter values

#### execSQL

    public void execSQL(java.lang.String sql)

Execute the given statement.

Parameters:
  `sql` - the statement

#### findEditTable

    public static java.lang.String findEditTable(java.lang.String tables)

TODO

Parameters:
  `tables` - the list of tables
Returns:
  TODO

#### getMaximumSize

    public long getMaximumSize()

Get the maximum size of the database file in bytes.

Returns:
  the maximum size

#### getPageSize

    public long getPageSize()

Get the page size of the database in bytes.

Returns:
  the page size

#### getPath

    public java.lang.String getPath()

Get the name of the database file.

Returns:
  the database file name

#### getSyncedTables

    public java.util.Map<java.lang.String,java.lang.String> getSyncedTables()

TODO

Returns:
  TODO

#### getVersion

    public int getVersion()

Get the database version.

Returns:
  the database version

#### inTransaction

    public boolean inTransaction()

Check if there is an open transaction.

Returns:
  true if there is

#### insert

    public long insert(java.lang.String table,
              java.lang.String nullColumnHack,
              android.content.ContentValues values)

Insert a row.

Parameters:
  `table` - the table
  `nullColumnHack` - not used
  `values` - the values
Returns:
  TODO

#### insertOrThrow

    public long insertOrThrow(java.lang.String table,
                     java.lang.String nullColumnHack,
                     android.content.ContentValues values)

Try to insert a row.

Parameters:
  `table` - the table
  `nullColumnHack` - not used
  `values` - the values
Returns:
  TODO

#### insertWithOnConflict

    public long insertWithOnConflict(java.lang.String table,
                            java.lang.String nullColumnHack,
                            android.content.ContentValues initialValues,
                            int conflictAlgorithm)

Try to insert a row, using the given conflict resolution option.

Parameters:
  `table` - the table
  `nullColumnHack` - not used
  `initialValues` - the values
  `conflictAlgorithm` - what conflict resolution to use
Returns:
  TODO

#### isDbLockedByCurrentThread

    public boolean isDbLockedByCurrentThread()

Check if the database is locked by the current thread.

Returns:
  true if it is

#### isDbLockedByOtherThreads

    public boolean isDbLockedByOtherThreads()

Check if the database is locked by a different thread.

Returns:
  true if it is

#### isOpen

    public boolean isOpen()

Check if the connection is open.

Returns:
  true if it is

#### isReadOnly

    public boolean isReadOnly()

Check if the connection is read-only.

Returns:
  true if it is

#### markTableSyncable

    public void markTableSyncable(java.lang.String table,
                         java.lang.String deletedTable)

TODO

Parameters:
  `table` - the table
  `deletedTable` - TODO

#### markTableSyncable

    public void markTableSyncable(java.lang.String table,
                         java.lang.String foreignKey,
                         java.lang.String updateTable)

TODO

Parameters:
  `table` - the table
  `foreignKey` - the foreign key
  `updateTable` - TODO

#### needUpgrade

    public boolean needUpgrade(int newVersion)

Check if an upgrade is required.

Parameters:
  `newVersion` - the new version
Returns:
  true if the current version doesn't match

#### query

    public android.database.Cursor query(boolean distinct,
                                java.lang.String table,
                                java.lang.String[] columns,
                                java.lang.String selection,
                                java.lang.String[] selectionArgs,
                                java.lang.String groupBy,
                                java.lang.String having,
                                java.lang.String orderBy,
                                java.lang.String limit)

Execute the SELECT statement for the given parameters.

Parameters:
  `distinct` - if only distinct rows should be returned
  `table` - the table
  `columns` - the list of columns
  `selection` - TODO
  `selectionArgs` - TODO
  `groupBy` - the group by list or null
  `having` - the having condition or null
  `orderBy` - the order by list or null
  `limit` - the limit or null
Returns:
  the cursor

#### query

    public android.database.Cursor query(java.lang.String table,
                                java.lang.String[] columns,
                                java.lang.String selection,
                                java.lang.String[] selectionArgs,
                                java.lang.String groupBy,
                                java.lang.String having,
                                java.lang.String orderBy)

Execute the SELECT statement for the given parameters.

Parameters:
  `table` - the table
  `columns` - the list of columns
  `selection` - TODO
  `selectionArgs` - TODO
  `groupBy` - the group by list or null
  `having` - the having condition or null
  `orderBy` - the order by list or null
Returns:
  the cursor

#### query

    public android.database.Cursor query(java.lang.String table,
                                java.lang.String[] columns,
                                java.lang.String selection,
                                java.lang.String[] selectionArgs,
                                java.lang.String groupBy,
                                java.lang.String having,
                                java.lang.String orderBy,
                                java.lang.String limit)

Execute the SELECT statement for the given parameters.

Parameters:
  `table` - the table
  `columns` - the list of columns
  `selection` - TODO
  `selectionArgs` - TODO
  `groupBy` - the group by list or null
  `having` - the having condition or null
  `orderBy` - the order by list or null
  `limit` - the limit or null
Returns:
  the cursor

#### queryWithFactory

    public android.database.Cursor queryWithFactory(H2Database.CursorFactory cursorFactory,
                                           boolean distinct,
                                           java.lang.String table,
                                           java.lang.String[] columns,
                                           java.lang.String selection,
                                           java.lang.String[] selectionArgs,
                                           java.lang.String groupBy,
                                           java.lang.String having,
                                           java.lang.String orderBy,
                                           java.lang.String limit)

Execute the SELECT statement for the given parameters.

Parameters:
  `cursorFactory` - the cursor factory to use
  `distinct` - if only distinct rows should be returned
  `table` - the table
  `columns` - the list of columns
  `selection` - TODO
  `selectionArgs` - TODO
  `groupBy` - the group by list or null
  `having` - the having condition or null
  `orderBy` - the order by list or null
  `limit` - the limit or null
Returns:
  the cursor

#### rawQuery

    public android.database.Cursor rawQuery(java.lang.String sql,
                                   java.lang.String[] selectionArgs)

Execute the query.

Parameters:
  `sql` - the SQL statement
  `selectionArgs` - the parameter values
Returns:
  the cursor

#### rawQueryWithFactory

    public android.database.Cursor rawQueryWithFactory(H2Database.CursorFactory cursorFactory,
                                              java.lang.String sql,
                                              java.lang.String[] selectionArgs,
                                              java.lang.String editTable)

Execute the query using the given cursor factory.

Parameters:
  `cursorFactory` - the cursor factory
  `sql` - the SQL statement
  `selectionArgs` - the parameter values
  `editTable` - TODO
Returns:
  the cursor

#### releaseMemory

    public static int releaseMemory()

Try to release memory.

Returns:
  TODO

#### replace

    public long replace(java.lang.String table,
               java.lang.String nullColumnHack,
               android.content.ContentValues initialValues)

Replace an existing row in the database.

Parameters:
  `table` - the table
  `nullColumnHack` - ignored
  `initialValues` - the values
Returns:
  TODO

#### replaceOrThrow

    public long replaceOrThrow(java.lang.String table,
                      java.lang.String nullColumnHack,
                      android.content.ContentValues initialValues)

Try to replace an existing row in the database.

Parameters:
  `table` - the table
  `nullColumnHack` - ignored
  `initialValues` - the values
Returns:
  TODO

#### setLocale

    public void setLocale(java.util.Locale locale)

Set the locale.

Parameters:
  `locale` - the new locale

#### setLockingEnabled

    public void setLockingEnabled(boolean lockingEnabled)

Enable or disable thread safety.

Parameters:
  `lockingEnabled` - the new value

#### setMaximumSize

    public long setMaximumSize(long numBytes)

Set the maximum database file size.

Parameters:
  `numBytes` - the file size in bytes
Returns:
  the effective maximum size

#### setPageSize

    public void setPageSize(long numBytes)

Set the database page size. The value can not be changed once the database exists.

Parameters:
  `numBytes` - the page size

#### setTransactionSuccessful

    public void setTransactionSuccessful()

Mark the transaction as completed successfully.

#### setVersion

    public void setVersion(int version)

Update the database version.

Parameters:
  `version` - the version

#### update

    public int update(java.lang.String table,
             android.content.ContentValues values,
             java.lang.String whereClause,
             java.lang.String[] whereArgs)

Update one or multiple rows.

Parameters:
  `table` - the table
  `values` - the values
  `whereClause` - the where condition
  `whereArgs` - the parameter values
Returns:
  the number of rows updated

#### updateWithOnConflict

    public int updateWithOnConflict(java.lang.String table,
                           android.content.ContentValues values,
                           java.lang.String whereClause,
                           java.lang.String[] whereArgs,
                           int conflictAlgorithm)

Update one or multiple rows.

Parameters:
  `table` - the table
  `values` - the values
  `whereClause` - the where condition
  `whereArgs` - the parameter values
  `conflictAlgorithm` - the conflict resolution option
Returns:
  the number of rows updated

#### yieldIfContended

    @Deprecated
    public boolean yieldIfContended()

Deprecated. deprecated in API Level 3, use yieldIfContendedSafely
TODO

Returns:
  TODO

#### yieldIfContendedSafely

    public boolean yieldIfContendedSafely(long sleepAfterYieldDelay)

Temporarily pause the transaction.

Parameters:
  `sleepAfterYieldDelay` - TODO
Returns:
  TODO

#### yieldIfContendedSafely

    public boolean yieldIfContendedSafely()

Temporarily pause the transaction.

Returns:
  TODO

#### unsupported

    public static java.lang.RuntimeException unsupported()

Create a new RuntimeException that says this feature is not supported.

Returns:
  the runtime exception