Persistentdata for beginners: Symbian SQL

Dilbert.com

Symbian SQL is the client-server database that incorporates SQLite.

SQLite is a public-domain relational database library that is ACID compliant. Most readers of this blog will have used SQLite today. It is probably the most widely deployed SQL database engine in the world. It is included in Mozilla Firefox, Skype, PHP, iPhone, Android, McAfee anti-virus and many other products. It is included in Symbian devices starting from SymbianOS v9.3 (i.e. all Symbian PDKs).

Symbian SQL was created to provide a Symbian C++ API that would allow secure shared databases to be created according to a security policy and to introduce a shared memory cache between clients to reduce RAM usage. A description of the architecture is available in the Symbian SQL overview wiki page.

Symbian SQL offers three types of databases:

  1. Public – a database stored in the public area of the filesystem
  2. Private – a database stored in an executable’s private directory and only accessible to that executable
  3. Secure shared – a database stored in the Symbian SQL server’s private directory, shared with other clients according to a security policy defined by the executable which creates the database

Symbian SQL API

The Symbian SQL API is defined in the sqldb.h header file. Client code should link to sqldb.lib. The purpose of each class is summarised below:

API Purpose
RSqlDatabase A SQL database handle. It can be used to create, open and close a database, attach databases and execute SQL statements
RSqlBlobReadStream Handle to a binary or text blob for reading column data. It is used to transfer large binary or text column data from the SQL server to the client without the need to allocate memory to hold the entire column data. Available in Symbian^3 onwards
RSqlBlobWriteStream Handle to a binary or text blob for writing parameters. It is used to bind large binary or text column data without the need to allocate memory to hold the entire parameter data in the client. Available in Symbian^3 onwards
TSqlBlob Utility methods to read and write the contents of an entire blob in a single call. Available in Symbian^3 onwards
RSqlColumnReadStream Read stream for column data. This class is superceded by RSqlBlobReadStream in Symbian^3 which is more memory efficient
RSqlParamWriteStream Write stream for column data. This class is superceded by RSqlBlobWriteStream in Symbian^3 which is more memory efficient
RSqlSecurityPolicy Defines the security policies for a secure shared database
RSqlStatement A SQL statement used for data retrieval and manipulation
TSqlScalarFullSelectQuery An optimised API for the execution of SQL statements that return a single row consisting of a single column value
RSqlDatabase::TSize Class to hold a database size and database free space

Further resources

  • Symbian^3 reference documentation for Symbian SQL
  • The how to use Symbian SQL wiki page on developer.symbian.org describes the most important API methods and includes code examples
  • Guidance on how to optimise Symbian SQL usage is available on developer.symbian.org
  • The Symbian SQL wiki page on developer.symbian.org is the index for all wiki content relating to the Symbian SQL API and implementation
  • The Symbian Press booklet on Data Sharing and Persistence with Symbian C++ includes a section on Symbian SQL usage
  • Coming up next…

    The next part of the Persistentdata for beginners series will cover the SQLite 3 API component – the C API for SQLite.

  • Advertisements

    One Response to “Persistentdata for beginners: Symbian SQL”

    1. Sebastian Brannstrom Says:

      I can strongly recommend the FLOSS Weekly interview with Richard Hipp, the founder of SQLite: http://twit.tv/floss26

    Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out / Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out / Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out / Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out / Change )

    Connecting to %s


    %d bloggers like this: