The Database API requires EB 3.0.6.0 (or later).
Overview
Database is low-level API to access a local SQLite 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, include files from the /Enterprise Browser/JavaScript Files/Enterprise Browser
directory on the computer where Enterprise Browser is installed.
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>
This will define the EB class within the page. Note that the path for this file is relative to the current page (index.html). Any page on which the modules are required will need to have the required .js file(s) included in this fashion.
Include only the required modules
To include individual APIs, you must first include the ebapi.js
in your HTML, and then the additional required API file(s). For instance, to use the Database API, add the following code to the HTML file(s). Again, this assumes that relevant 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>
In the code lines above, notice that
ebapi.js
is included first, followed byeb.database.js
, which is the Database API for Enterprise Browser. This coding is required on each HTML page whenever an individual API will be called from that page.
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()
Remarks
SD Card Access
SD Card access is disabled on devices running Android 11 (and later). Learn more.
Any references to device path must be directed to:
/enterprise/device/enterprisebrowser
or/Android/data/com.zebra.mdna.enterprisebrowser/