All applications running on the BlackBerry® PlayBook™ tablet run within their own sandbox. This security model, prevents Adobe® AIR® applications from interacting with each other's sandbox. Therefore when a db file is created within the application storage directory "<appname>/app/", other applications do not have read/write permissions to that db file.
For persistance data to be readily accessed by other applications outside the application sand box, the data can be stored via "<appname>/shared/misc" which is a public directory. Hence, when databases are being created, they can either be private by storing it within the application storage directory, or be made public by storing it within a shared public directory.
Users must grant your application access to the folders within the shared directory. To request access, you will need to include the following snippet in your blackberry-tablet.xml file.
The main method for establishing, opening and querying a database is as follows:
new SQLConnection():void - Calling the connection constructure, to open a new connection.
open():voidoropenAsync():void - Open a connection to a database file at the specified location in the file system.
execute():void - Executes the SQL query against the database that is connected to the SQLConnection object.
The following snippets of code illustrates how you can establish a connection and conduct transcations of a database:
Creating a SQLite connection:
// Creating a connection private var sqlConQLConnection = new SQLConnection();
Creating a database File:
private var employeeDB:File; // Path to a database file employeeDB = File.applicationStorageDirectory.resolvePath('employee.db');
Opening the database:
// Opening the file Asynchronously sqlCon.openAsync(employeeDB); sqlCon.addEventListener(SQLEvent.OPEN, openDB);
Linking the query Object to the database connection:
private var query:SQLStatement = new SQLStatement();
// Linking the statement to the sqlConnection query.sqlConnection = sqlCon;
Creating a table and executing the query:
query.text = "CREATE TABLE IF NOT EXISTS employee_table" + "( id INTEGER PRIMARY KEY AUTOINCREMENT, firstname TEXT, lastname TEXT, email TEXT, " + " position TEXT, company TEXT, department TEXT, phone TEXT, country TEXT);";
// Executing the query. query.execute();
See the following learning resources for more information on the API used in this article: