Chapter 6. Using Symbian SQL
Armed with an understanding of the key concepts described in previous chapters, you should now be ready to dive in and look at how to use Symbian SQL in your app. This chapter discusses the key classes –
RSqlStatement – and covers supporting and utility classes. All APIs discussed in this chapter are declared in the Symbian SQL header file
The Database Connection Class
RSqlDatabase class provides key APIs for managing databases. In this section, we discuss how to connect to a database, create and delete databases, attach multiple databases to a single connection, execute SQL, and set and retrieve database parameters.
Connecting and Disconnecting
In order to access a database, you must first establish a connection to it. When you have finished accessing the database, you must then close the connection. Symbian provides the
RSqlDatabase class to represent a database connection. You open a connection to a database by calling the
Open() API on the connection object. Two variants of this API are provided, one leaving and one not:
TInt Open(const TDesC& aDbFileName, const TDesC8* aConfig=NULL); void OpenL(const TDesC& aDbFileName, const TDesC8* aConfig=NULL);
aDbFileName is the name of the database. If the filename is not valid or the file does not exist, the API returns an error. It is also an error if the connection is open already. The argument
aConfig is an optional text descriptor which may contain configuration options. ...