Database

Enterprise Browser 1.8

Overview

Database is low-level API to access SQLite local database.

Enabling the API

There are two methods of enabling the Database API:

  • Include all ebapi modules
  • Include only the required API modules

For either of these methods, you'll need to include files from the /Enterprise Browser/JavaScript Files/Enterprise Browser directory on the computer that you installed the Enterprise Browser.

Include all JS API modules

To include all JS APIs, copy the ebapi-modules.js file to a location accessible by the app's files and include a reference to the JavaScript file in the app's HTML. For instance, to include the modules file in the app's index.html, copy the file to the same directory as that index.html and add the following line to the HTML's HEAD section:


<script type="text/javascript" charset="utf-8" src="ebapi-modules.js"></script>

Note: that the pathing for this file is relative to the current page.

This will define the EB class within the page. Any page you need to use the modules will need to have the .js file included in this fashion.

Include only the required modules

To include single APIs, you must first include the ebapi.js in your HTML as well as the API file you want to use. For instance, to use the Database API, I would add the following code to my HTML file(s), assuming the API files have been copied to the same directory as the HTML.


<script type="text/javascript" charset="utf-8" src="ebapi.js"></script>
<script type="text/javascript" charset="utf-8" src="eb.database.js"></script>

The ebapi.js file is necessary for all single API inclusions.

Methods

Destructor close()

Closes the database. The database will not be accessible until it is opened again.

Parameters

  • callback : CallBackHandler

Returns

Synchronous Return:

  • Void

Platforms

  • Android
  • Windows Mobile
  • Windows CE

Method Access:

  • Class Method: This method is a destructor and can only be accessed via the object that was created by the new constructor.
    • myObj.close()

commitTransaction()

Commit database transaction. Saves all updates to the database from the start of the transaction.

Parameters

  • callback : CallBackHandler

Returns

Synchronous Return:

  • Void

Platforms

  • Android
  • Windows Mobile
  • Windows CE

Method Access:

  • Instance Method: This method can be accessed via an instance object of this class:
    • myObject.commitTransaction()

destroyTable(STRING tableName)

Destroys a database table.

Parameters

  • tableName : STRING

    Table name to destroy.

  • callback : CallBackHandler

Returns

Synchronous Return:

  • Void

Platforms

  • Android
  • Windows Mobile
  • Windows CE

Method Access:

  • Instance Method: This method can be accessed via an instance object of this class:
    • myObject.destroyTable(STRING tableName)

destroyTables(HASH propertyMap)

Destroy a list of database tables.

Parameters

  • propertyMap : HASH

    • include : ARRAY

      Include tables.

    • exclude : ARRAY

      Exclude tables.

  • callback : CallBackHandler

Returns

Synchronous Return:

  • Void

Platforms

  • Android
  • Windows Mobile
  • Windows CE

Method Access:

  • Instance Method: This method can be accessed via an instance object of this class:
    • myObject.destroyTables(HASH propertyMap)

executeBatchSql(STRING sqlStmt)

Execute a series of sql statements included in the sqlStmt string parameter.

Parameters

  • sqlStmt : STRING

    The SQL statement.

  • callback : CallBackHandler

Returns

Synchronous Return:

  • Void

Platforms

  • Android
  • Windows Mobile
  • Windows CE

Method Access:

  • Instance Method: This method can be accessed via an instance object of this class:
    • myObject.executeBatchSql(STRING sqlStmt)

executeSql(STRING sqlStmt, ARRAY args)

Execute the sql statement specified in the method's parameters.

Parameters

  • sqlStmt : STRING

    The SQL statement.

  • args : ARRAY Optional

    Array of the sql expressions.

  • callback : CallBackHandler

Callback

Async Callback Returning Parameters: ARRAY

    Returns

    Synchronous Return:

    • ARRAY : Array of Hashes. Each Hash item represents record from Database.

    Platforms

    • Android
    • Windows Mobile
    • Windows CE

    Method Access:

    • Instance Method: This method can be accessed via an instance object of this class:
      • myObject.executeSql(STRING sqlStmt, ARRAY args)

    Constructor new EB.Database(STRING dbPath, STRING dbPartition)

    This method is a constructor for this class. Instead of saying EB.Database.initialize(dbPath,dbPartition) you would use new EB.Database(dbPath,dbPartition). ex: var db = new EB.Database(EB.Application.databaseFilePath('test'), 'test'); Make sure you issue a .close() when you are finished using the database. If the database file does not exist it will be created using a default SQL schema. Do not use predefined partition names: app, user, local. Do not open the same database file in different partitions. Do not use the same partition for different database files. Do not open the same file twice.

    Parameters

    • dbPath : STRING

      The path to the database. Databases stored at the path provided by Application.databaseFilePath.

    • dbPartition : STRING

      The database partition. Used as a file name for database and when connecting to RhoConnect server.

    • callback : CallBackHandler

    Returns

    Synchronous Return:

    • Void

    Platforms

    • Android
    • Windows Mobile
    • Windows CE

    Method Access:

    • Class Method: This method is a constructor and can only be accessed via the new construct.
      • var myObj = new EB.Database(STRING dbPath, STRING dbPartition)

    isTableExist(STRING tableName)

    Will return true or false if the specified table exists in the current database.

    Parameters

    • tableName : STRING

      The name of the table.

    • callback : CallBackHandler

    Callback

    Async Callback Returning Parameters: BOOLEAN

      Returns

      Synchronous Return:

      • BOOLEAN

      Platforms

      • Android
      • Windows Mobile
      • Windows CE

      Method Access:

      • Instance Method: This method can be accessed via an instance object of this class:
        • myObject.isTableExist(STRING tableName)

      rollbackTransaction()

      Rollback database transaction. This will cancel any pending actions to the database that were executed since the last Start and before a commit.

      Parameters

      • callback : CallBackHandler

      Returns

      Synchronous Return:

      • Void

      Platforms

      • Android
      • Windows Mobile
      • Windows CE

      Method Access:

      • Instance Method: This method can be accessed via an instance object of this class:
        • myObject.rollbackTransaction()

      startTransaction()

      Start database transaction. All operations will not be the saved to the database until a commit is executed.

      Parameters

      • callback : CallBackHandler

      Returns

      Synchronous Return:

      • Void

      Platforms

      • Android
      • Windows Mobile
      • Windows CE

      Method Access:

      • Instance Method: This method can be accessed via an instance object of this class:
        • myObject.startTransaction()